How to use the InterleavedBufferAttribute function from three

Find comprehensive JavaScript three.InterleavedBufferAttribute code examples handpicked from public code repositorys.

three.InterleavedBufferAttribute is a class in the Three.js library that represents an attribute array buffer for interleaved vertex data.

1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
  ib = new THREE.InterleavedBuffer(array, byteStride / elementBytes);

  parser.cache.add(ibCacheKey, ib);
}

bufferAttribute = new THREE.InterleavedBufferAttribute(
  ib,
  itemSize,
  (byteOffset % byteStride) / elementBytes,
  normalized
fork icon3
star icon7
watch icon8

+ 14 other calls in file

2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
        ib = new THREE.InterleavedBuffer( array, byteStride / elementBytes );
        parser.cache.add( ibCacheKey, ib );

    }

    bufferAttribute = new THREE.InterleavedBufferAttribute( ib, itemSize, byteOffset % byteStride / elementBytes, normalized );

} else {

    if ( bufferView === null ) {
fork icon2
star icon10
watch icon0

How does three.InterleavedBufferAttribute work?

three.InterleavedBufferAttribute is a class in the Three.js library that represents an attribute of an interleaved buffer. An interleaved buffer is a single buffer that stores multiple attributes (such as positions, colors, or normals) interleaved together. An InterleavedBufferAttribute specifies how to extract a specific attribute from an interleaved buffer, including the size of the attribute, its offset in the buffer, and the type of data used to represent it. This class is used in conjunction with three.InterleavedBuffer to efficiently store and access vertex data for 3D models.

2855
2856
2857
2858
2859
2860
2861
2862
2863
2864

		parser.cache.add( ibCacheKey, ib );

	}

	bufferAttribute = new THREE.InterleavedBufferAttribute( ib, itemSize, ( byteOffset % byteStride ) / elementBytes, normalized );

} else {

	if ( bufferView === null ) {
fork icon2
star icon9
watch icon0

373
374
375
376
377
378
379
380
381
for ( let j = 0, l = attributes.length; j < l; j ++ ) {

    const attribute = attributes[ j ];
    const itemSize = attribute.itemSize;
    const count = attribute.count;
    const iba = new THREE.InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, attribute.normalized );
    res.push( iba );
    offset += itemSize; // Move the data for each attribute into the new interleavedBuffer
    // at the appropriate offset
fork icon2
star icon10
watch icon0

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import * as THREE from "three";

// Create a Float32Array buffer
const positionBuffer = new Float32Array([0, 0, 0, 1, 0, 0, 0, 1, 0]);

// Define the stride (number of elements per vertex)
const stride = 3;

// Create an interleaved buffer attribute with position data
const interleavedBufferAttribute = new THREE.InterleavedBufferAttribute(
  new THREE.InterleavedBuffer(positionBuffer, stride),
  stride,
  0
);

This example creates an InterleavedBufferAttribute containing position data for three vertices. The stride variable is set to 3 because there are three elements per vertex (x, y, and z). The 0 parameter in the InterleavedBufferAttribute constructor specifies the offset from the beginning of the buffer to the position data.

1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
    if (!ib) {
        array = new TypedArray(bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes);
        ib = new three.InterleavedBuffer(array, byteStride / elementBytes);
        parser.cache.add(ibCacheKey, ib);
    }
    bufferAttribute = new three.InterleavedBufferAttribute(ib, itemSize, (byteOffset % byteStride) / elementBytes, normalized);
}
else {
    if (bufferView === null) {
        array = new TypedArray(accessorDef.count * itemSize);
fork icon2
star icon7
watch icon0

239
240
241
242
243
244
245
246
247
248
const setters = ['setX', 'setY', 'setZ', 'setW'];
for (let j = 0, l = attributes.length; j < l; j++) {
    const attribute = attributes[j];
    const itemSize = attribute.itemSize;
    const count = attribute.count;
    const iba = new three_1.InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, attribute.normalized);
    res.push(iba);
    offset += itemSize;
    // Move the data for each attribute into the new interleavedBuffer
    // at the appropriate offset
fork icon1
star icon3
watch icon0

267
268
269
270
271
272
273
274
        -1, 1, 0, 0, 1
    ]);
    const interleavedBuffer = new three_1.InterleavedBuffer(float32Array, 5);
    geometry.setIndex([0, 1, 2, 0, 2, 3]);
    geometry.setAttribute('position', new three_1.InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
    geometry.setAttribute('uv', new three_1.InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
    return geometry;
})();
fork icon1
star icon3
watch icon0

773
774
775
776
777
778
779
780
781
782
if (accessor.byteStride && accessor.byteStride !== elementBytes * itemSize) {
  // Use the full buffer if it's interleaved.
  var array = new TypedArray(arraybuffer); // Integer parameters to IB/IBA are in array elements, not bytes.

  var ib = new THREE.InterleavedBuffer(array, accessor.byteStride / elementBytes);
  return new THREE.InterleavedBufferAttribute(ib, itemSize, accessor.byteOffset / elementBytes);
} else {
  array = new TypedArray(arraybuffer, accessor.byteOffset, accessor.count * itemSize);
  return new THREE.BufferAttribute(array, itemSize);
}
fork icon0
star icon1
watch icon0

+ 9 other calls in file

1848
1849
1850
1851
1852
1853
1854
1855
1856
1857

    ib = new _three.InterleavedBuffer(array, byteStride / elementBytes);
    parser.cache.add(ibCacheKey, ib);
  }

  bufferAttribute = new _three.InterleavedBufferAttribute(ib, itemSize, byteOffset % byteStride / elementBytes, normalized);
} else {
  if (bufferView === null) {
    array = new TypedArray(accessorDef.count * itemSize);
  } else {
fork icon0
star icon1
watch icon0

46
47
48
49
50
51
52
53
54
55
  }

  var instanceDistanceBuffer = new THREE.InstancedInterleavedBuffer( lineDistances, 2, 1 ); // d0, d1

  geometry.addAttribute( 'instanceDistanceStart', new THREE.InterleavedBufferAttribute( instanceDistanceBuffer, 1, 0 ) ); // d0
  geometry.addAttribute( 'instanceDistanceEnd', new THREE.InterleavedBufferAttribute( instanceDistanceBuffer, 1, 1 ) ); // d1

  return this;

};
fork icon0
star icon0
watch icon1

+ 41 other calls in file

72
73
74
75
76
77
78
79
80

}

var instanceBuffer = new THREE.InstancedInterleavedBuffer( lineSegments, 6, 1 ); // xyz, xyz

this.addAttribute( 'instanceStart', new THREE.InterleavedBufferAttribute( instanceBuffer, 3, 0 ) ); // xyz
this.addAttribute( 'instanceEnd', new THREE.InterleavedBufferAttribute( instanceBuffer, 3, 3 ) ); // xyz

//
fork icon0
star icon0
watch icon1

+ 67 other calls in file

1759
1760
1761
1762
1763
1764
1765
1766
1767
1768

		parser.cache.add( ibCacheKey, ib );

	}

	bufferAttribute = new THREE.InterleavedBufferAttribute( ib, itemSize, byteOffset / elementBytes, normalized );

} else {

	if ( bufferView === null ) {
fork icon0
star icon0
watch icon0

+ 8 other calls in file

370
371
372
373
374
375
376
377
378
]);

var interleavedBuffer = new THREE.InterleavedBuffer(float32Array, 5);

geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.addAttribute('position', new THREE.InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
geometry.addAttribute('uv', new THREE.InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));

return geometry;
fork icon0
star icon0
watch icon0

Other functions in three

Sorted by popularity

function icon

three.Vector3 is the most popular function in three (22341 examples)