Skip to content

Commit 447de7e

Browse files
committed
Fixed BufferGeometry example
1 parent 950cf43 commit 447de7e

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

docs/api/core/BufferAttribute.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@
1010
<h1>[name]</h1>
1111

1212
<div class="desc">
13-
This class stores data for an attribute associated with a [page:BufferGeometry]. See that page for details. This class is used to store builtin attributes such as vertex position, normals, color, etc., but can also be used in your code to store custom attributes in a [page:BufferGeometry].
13+
This class stores data for an attribute associated with a [page:BufferGeometry]. See that page for details and a usage example. This class is used to store builtin attributes such as vertex position, normals, color, etc., but can also be used in your code to store custom attributes in a [page:BufferGeometry].
1414
</div>
1515

16-
<h2>Example</h2>
17-
18-
<code>todo</code>
19-
2016
<h2>Constructor</h2>
2117
<h3>[name]([page:Array array], [page:Integer itemSize])</h3>
2218
<div>

docs/api/core/BufferGeometry.html

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,33 @@ <h1>[name]</h1>
2424
<h3>Example</h3>
2525
<code>
2626
var geometry = new THREE.BufferGeometry();
27-
2827
// create a simple square shape. We duplicate the top left and bottom right
2928
// vertices because each vertex needs to appear once per triangle.
30-
var vertexCount = 6;
31-
var vertices = new Float32Array( vertexCount * 3 ); // three components per vertex
32-
var vertexPositions = [ [-1, 1, 0], [1, 1, 0], [1, -1, 0],
33-
[-1, 1, 0], [1,-1, 0], [-1,-1, 0] ];
34-
29+
var vertexPositions = [
30+
[-1.0, -1.0, 1.0],
31+
[ 1.0, -1.0, 1.0],
32+
[ 1.0, 1.0, 1.0],
33+
34+
[ 1.0, 1.0, 1.0],
35+
[-1.0, 1.0, 1.0],
36+
[-1.0, -1.0, 1.0]
37+
];
38+
var vertices = new Float32Array( vertexPositions.length * 3 ); // three components per vertex
39+
3540
// components of the position vector for each vertex are stored
3641
// contiguously in the buffer.
37-
for ( var i = 0; i < vertexPosition.length; i++ )
42+
for ( var i = 0; i < vertexPositions.length; i++ )
3843
{
39-
vertices[ i + 0 ] = vertexPositions[i][0];
40-
vertices[ i + 1 ] = vertexPositions[i][1];
41-
vertices[ i + 2 ] = vertexPositions[i][2];
44+
vertices[ i*3 + 0 ] = vertexPositions[i][0];
45+
vertices[ i*3 + 1 ] = vertexPositions[i][1];
46+
vertices[ i*3 + 2 ] = vertexPositions[i][2];
4247
}
4348

4449
// itemSize = 3 because there are 3 values (components) per vertex
4550
geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
46-
4751
var material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
4852
var mesh = new THREE.Mesh( geometry, material );
4953
</code>
50-
View the source of the fromGeometry method for
5154

5255
<h3>Accessing attributes</h3>
5356
<p>

0 commit comments

Comments
 (0)