How to use the Uint16BufferAttribute function from three
Find comprehensive JavaScript three.Uint16BufferAttribute code examples handpicked from public code repositorys.
three.Uint16BufferAttribute is a class in the Three.js library that represents a buffer attribute containing unsigned 16-bit integers.
202 203 204 205 206 207 208 209 210 211
case Uint16Array: attributeData = new dracoDecoder.DracoUInt16Array(); decoder.GetAttributeUInt16ForAllPoints( dracoGeometry, attribute, attributeData); geometryBuffer[ attributeName ] = new Uint16Array( numValues ); TypedBufferAttribute = THREE.Uint16BufferAttribute; break; case Uint32Array: attributeData = new dracoDecoder.DracoUInt32Array();
+ 5 other calls in file
649 650 651 652 653 654 655 656 657 658
// build BufferGeometry. const geometry = new three_1.BufferGeometry(); geometry.setAttribute('position', new three_1.Float32BufferAttribute(positions, 3)); geometry.setAttribute('normal', new three_1.Float32BufferAttribute(normals, 3)); geometry.setAttribute('uv', new three_1.Float32BufferAttribute(uvs, 2)); geometry.setAttribute('skinIndex', new three_1.Uint16BufferAttribute(skinIndices, 4)); geometry.setAttribute('skinWeight', new three_1.Float32BufferAttribute(skinWeights, 4)); geometry.setIndex(indices); for (let i = 0, il = groups.length; i < il; i += 1) { geometry.addGroup(groups[i].offset, groups[i].count, i);
+ 4 other calls in file
How does three.Uint16BufferAttribute work?
Sure! three.Uint16BufferAttribute is a class in the Three.js library that represents a buffer attribute containing unsigned 16-bit integers. A buffer attribute in Three.js is a set of data that can be used to define the geometry or material of a 3D object. Buffer attributes are stored in typed arrays, which are low-level representations of binary data in JavaScript. To use three.Uint16BufferAttribute, you first need to create an instance of the class. You pass in the data you want to store in the buffer attribute as an array of unsigned 16-bit integers, along with an optional itemSize argument that specifies the number of values per item in the buffer (defaulting to 1). For example, consider the following code: javascript Copy code {{{{{{{ import * as THREE from 'three'; const data = new Uint16Array([0, 1, 2, 3, 4, 5]); const attribute = new THREE.Uint16BufferAttribute(data, 1); In this example, we first import the three module from Three.js. We then define a data variable containing an array of unsigned 16-bit integers. We create a new instance of THREE.Uint16BufferAttribute, passing in data as the first argument and 1 as the second argument to specify that each item in the buffer has a single value. Once you have created a THREE.Uint16BufferAttribute, you can use it to define the geometry or material of a 3D object in Three.js. For example, you might use a buffer attribute to define the positions, colors, or normals of vertices in a 3D model. In addition to THREE.Uint16BufferAttribute, the Three.js library provides a wide range of other buffer attributes for working with different types of data, such as THREE.Float32BufferAttribute for floating-point values and THREE.BufferAttribute for generic binary data.
1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
} if (skeleton) { geo.addAttribute( 'skinIndex', new THREE.Uint16BufferAttribute(buffers.weightsIndices, 4), ); geo.addAttribute( 'skinWeight',
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import * as THREE from "three"; const positions = new Uint16Array([0, 0, 0, 1, 1, 0, 0, 1, 0]); const indices = new Uint16Array([0, 1, 2]); const geometry = new THREE.BufferGeometry(); geometry.setAttribute( "position", new THREE.Uint16BufferAttribute(positions, 3) ); geometry.setIndex(new THREE.Uint16BufferAttribute(indices, 1)); const material = new THREE.MeshBasicMaterial({ color: 0xffffff }); const mesh = new THREE.Mesh(geometry, material);
In this example, we first import the three module from Three.js. We define a positions variable containing an array of unsigned 16-bit integers representing the x, y, and z coordinates of three vertices in 3D space. We also define an indices variable containing an array of unsigned 16-bit integers representing the indices of the vertices that make up a triangle in the geometry. We create a new instance of THREE.BufferGeometry, which is a container for defining the geometry of a 3D object in Three.js. We call the setAttribute method on the geometry, passing in 'position' as the first argument and a new instance of THREE.Uint16BufferAttribute as the second argument. This sets the vertex positions of the geometry to the values in the positions array, with three values per vertex. We call the setIndex method on the geometry, passing in a new instance of THREE.Uint16BufferAttribute as the argument. This sets the indices of the vertices that make up a triangle in the geometry to the values in the indices array, with one value per vertex. We create a new instance of THREE.MeshBasicMaterial, which is a basic material for rendering a 3D object in Three.js. We create a new instance of THREE.Mesh, passing in the geometry and material as arguments. This creates a new 3D mesh object that we can add to a scene and render in a Three.js application. This code demonstrates how THREE.Uint16BufferAttribute can be used to define the geometry of a 3D object in Three.js using unsigned 16-bit integers.
three.Vector3 is the most popular function in three (22341 examples)