Skip to content

Commit

Permalink
docs(bufferGeometry): adding indexed version code example (#25824)
Browse files Browse the repository at this point in the history
* docs(bufferGeometry): adding indexed version code example

* updating doc + adding 2 live examples

* Update BufferGeometry.html

* removing browser examples

* fixing sentences

* Update BufferGeometry.html

---------

Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
  • Loading branch information
abernier and Mugen87 authored Apr 14, 2023
1 parent e0a631f commit 7310a82
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions docs/api/en/core/BufferGeometry.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ <h1>[name]</h1>
</p>

<h2>Code Example</h2>

<code>
const geometry = new THREE.BufferGeometry();

// create a simple square shape. We duplicate the top left and bottom right
// vertices because each vertex needs to appear once per triangle.
const vertices = new Float32Array( [
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, -1.0, 1.0, // v0
1.0, -1.0, 1.0, // v1
1.0, 1.0, 1.0, // v2

1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
-1.0, -1.0, 1.0
1.0, 1.0, 1.0, // v3
-1.0, 1.0, 1.0, // v4
-1.0, -1.0, 1.0 // v5
] );

// itemSize = 3 because there are 3 values (components) per vertex
Expand All @@ -40,6 +42,29 @@ <h2>Code Example</h2>
const mesh = new THREE.Mesh( geometry, material );
</code>

<h3>Indexed version</h3>

<code>
const geometry = new THREE.BufferGeometry();

const vertices = new Float32Array( [
-1.0, -1.0, 1.0, // v0
1.0, -1.0, 1.0, // v1
1.0, 1.0, 1.0, // v2
-1.0, 1.0, 1.0, // v3
] );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );

const indices = [
0, 1, 2,
2, 3, 0,
];
geometry.setIndex( indices );

const material = new THREE.MeshBasicMaterial( { color: 0x00ffff } );
const mesh = new THREE.Mesh( geometry, material );
</code>

<h2>Examples</h2>
<p>
[example:webgl_buffergeometry Mesh with non-indexed faces]<br />
Expand Down

0 comments on commit 7310a82

Please sign in to comment.