Skip to content

Commit 6f73cef

Browse files
authored
Docs: Improve BufferGeometry page. (#439)
1 parent c2d44f3 commit 6f73cef

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

types/three/src/core/BufferGeometry.d.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,46 @@ export type NormalOrGLBufferAttributes = Record<
2323
* @example
2424
* ```typescript
2525
* const geometry = new THREE.BufferGeometry();
26+
*
2627
* // create a simple square shape. We duplicate the top left and bottom right
2728
* // vertices because each vertex needs to appear once per triangle.
28-
* const vertices = new Float32Array([
29-
* -1.0, -1.0, 1.0,
30-
* 1.0, -1.0, 1.0,
31-
* 1.0, 1.0, 1.0,
29+
* const vertices = new Float32Array( [
30+
* -1.0, -1.0, 1.0, // v0
31+
* 1.0, -1.0, 1.0, // v1
32+
* 1.0, 1.0, 1.0, // v2
33+
*
34+
* 1.0, 1.0, 1.0, // v3
35+
* -1.0, 1.0, 1.0, // v4
36+
* -1.0, -1.0, 1.0 // v5
37+
* ] );
3238
*
33-
* 1.0, 1.0, 1.0,
34-
* -1.0, 1.0, 1.0,
35-
* -1.0, -1.0, 1.0]);
3639
* // itemSize = 3 because there are 3 values (components) per vertex
37-
* geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
38-
* const material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
39-
* const mesh = new THREE.Mesh(geometry, material);
40+
* geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
41+
* const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
42+
* const mesh = new THREE.Mesh( geometry, material );
43+
* ```
44+
* @example
45+
* ```typescript
46+
* const geometry = new THREE.BufferGeometry();
47+
*
48+
* const vertices = new Float32Array( [
49+
* -1.0, -1.0, 1.0, // v0
50+
* 1.0, -1.0, 1.0, // v1
51+
* 1.0, 1.0, 1.0, // v2
52+
* -1.0, 1.0, 1.0, // v3
53+
* ] );
54+
* geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
55+
*
56+
* const indices = [
57+
* 0, 1, 2,
58+
* 2, 3, 0,
59+
* ];
60+
*
61+
* geometry.setIndex( indices );
62+
* geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
63+
*
64+
* const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
65+
* const mesh = new THREE.Mesh( geometry, material );
4066
* ```
4167
* @see Example: {@link https://threejs.org/examples/#webgl_buffergeometry | Mesh with non-indexed faces}
4268
* @see Example: {@link https://threejs.org/examples/#webgl_buffergeometry_indexed | Mesh with indexed faces}

0 commit comments

Comments
 (0)