Skip to content

Commit 0ab16a0

Browse files
committed
Updated loaders and examples to new BufferAttribute pattern.
1 parent 780f9f8 commit 0ab16a0

16 files changed

+91
-91
lines changed

examples/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ <h1><a href="http://threejs.org">three.js</a> / examples</h1>
169169
"webgl_lines_sphere",
170170
"webgl_lines_splines",
171171
"webgl_loader_assimp2json",
172+
"webgl_loader_awd",
172173
"webgl_loader_collada",
173174
"webgl_loader_collada_keyframe",
174175
"webgl_loader_collada_skinning",

examples/js/loaders/AWDLoader.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ THREE.AWDLoader = (function (){
735735
// ------------------
736736
if ( str_type === 1 ) {
737737

738-
attrib = new THREE.Float32Attribute( str_len/12, 3 );
738+
attrib = new THREE.Float32Attribute( ( str_len / 12 ) * 3, 3 );
739739
buffer = attrib.array;
740740

741741
geom.addAttribute( 'position', attrib );
@@ -754,7 +754,7 @@ THREE.AWDLoader = (function (){
754754
// -----------------
755755
else if (str_type === 2) {
756756

757-
attrib = new THREE.Uint16Attribute( str_len/2, 1 );
757+
attrib = new THREE.Uint16Attribute( ( str_len / 2 ), 1 );
758758
geom.addAttribute( 'index', attrib );
759759

760760
geom.offsets.push({
@@ -778,7 +778,7 @@ THREE.AWDLoader = (function (){
778778
// -------------------
779779
else if (str_type === 3) {
780780

781-
attrib = new THREE.Float32Attribute( str_len/8, 2 );
781+
attrib = new THREE.Float32Attribute( ( str_len / 8 ) * 2, 2 );
782782
buffer = attrib.array;
783783

784784
geom.addAttribute( 'uv', attrib );
@@ -794,7 +794,7 @@ THREE.AWDLoader = (function (){
794794
// NORMALS
795795
else if (str_type === 4) {
796796

797-
attrib = new THREE.Float32Attribute( str_len/12, 3 );
797+
attrib = new THREE.Float32Attribute( ( str_len / 12 ) * 3, 3 );
798798
geom.addAttribute( 'normal', attrib );
799799
buffer = attrib.array
800800
idx = 0

examples/js/loaders/UTF8Loader.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,15 @@ THREE.UTF8Loader.prototype.load = function ( jsonUrl, callback, options ) {
2828
THREE.UTF8Loader.BufferGeometryCreator = function () {
2929
};
3030

31-
THREE.UTF8Loader.BufferGeometryCreator.prototype.create = function ( attribArray, indexArray ) {
31+
THREE.UTF8Loader.BufferGeometryCreator.prototype.create = function ( attribArray, indices ) {
3232

33-
var ntris = indexArray.length / 3;
33+
var ntris = indices.length / 3;
3434

3535
var geometry = new THREE.BufferGeometry();
3636

37-
var positions = new THREE.Float32Attribute( ntris * 3, 3 );
38-
var normals = new THREE.Float32Attribute( ntris * 3, 3 );
39-
var uvs = new THREE.Float32Attribute( ntris * 3, 2 );
40-
41-
var positionsArray = positions.array;
42-
var normalsArray = normals.array;
43-
var uvsArray = uvs.array;
37+
var positions = new Float32Array( ntris * 3 * 3 );
38+
var normals = new Float32Array( ntris * 3 * 3 );
39+
var uvs = new Float32Array( ntris * 3 * 2 );
4440

4541
var i, j, offset;
4642
var x, y, z;
@@ -60,9 +56,9 @@ THREE.UTF8Loader.BufferGeometryCreator.prototype.create = function ( attribArray
6056
y = attribArray[ i + 1 ];
6157
z = attribArray[ i + 2 ];
6258

63-
positionsArray[ j++ ] = x;
64-
positionsArray[ j++ ] = y;
65-
positionsArray[ j++ ] = z;
59+
positions[ j++ ] = x;
60+
positions[ j++ ] = y;
61+
positions[ j++ ] = z;
6662

6763
}
6864

@@ -76,8 +72,8 @@ THREE.UTF8Loader.BufferGeometryCreator.prototype.create = function ( attribArray
7672
u = attribArray[ i ];
7773
v = attribArray[ i + 1 ];
7874

79-
uvsArray[ j++ ] = u;
80-
uvsArray[ j++ ] = v;
75+
uvs[ j++ ] = u;
76+
uvs[ j++ ] = v;
8177

8278
}
8379

@@ -92,18 +88,18 @@ THREE.UTF8Loader.BufferGeometryCreator.prototype.create = function ( attribArray
9288
y = attribArray[ i + 1 ];
9389
z = attribArray[ i + 2 ];
9490

95-
normalsArray[ j++ ] = x;
96-
normalsArray[ j++ ] = y;
97-
normalsArray[ j++ ] = z;
91+
normals[ j++ ] = x;
92+
normals[ j++ ] = y;
93+
normals[ j++ ] = z;
9894

9995
}
10096

101-
geometry.addAttribute( 'index', indexArray, 1 );
102-
geometry.addAttribute( 'position', positions );
103-
geometry.addAttribute( 'normal', normals );
104-
geometry.addAttribute( 'uv', uvs );
97+
geometry.addAttribute( 'index', new THREE.Uint32Attribute( indices, 1 ) );
98+
geometry.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
99+
geometry.addAttribute( 'normal', new THREE.Float32Attribute( normals, 3 ) );
100+
geometry.addAttribute( 'uv', new THREE.Float32Attribute( uvs, 2 ) );
105101

106-
geometry.offsets.push( { start: 0, count: indexArray.length, index: 0 } );
102+
geometry.offsets.push( { start: 0, count: indices.length, index: 0 } );
107103

108104
geometry.computeBoundingSphere();
109105

examples/js/loaders/ctm/CTMLoader.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,17 @@ THREE.CTMLoader.prototype.createModel = function ( file, callback ) {
211211
colors = file.body.attrMaps[ 0 ].attr;
212212
}
213213

214-
this.addAttribute( 'index', new THREE.Uint32Attribute( indices.length, 1 ).set( indices ) );
215-
this.addAttribute( 'position', new THREE.Float32Attribute( positions.length, 3 ).set( positions ) );
214+
this.addAttribute( 'index', new THREE.Uint32Attribute( indices, 1 ) );
215+
this.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
216216

217217
if ( normals !== undefined )
218-
this.addAttribute( 'normal', new THREE.Float32Attribute( normals.length, 3 ).set( normals ) );
218+
this.addAttribute( 'normal', new THREE.Float32Attribute( normals, 3 ) );
219219

220220
if ( uvs !== undefined )
221-
this.addAttribute( 'uv', new THREE.Float32Attribute( uvs.length, 2 ).set( uvs ) );
221+
this.addAttribute( 'uv', new THREE.Float32Attribute( uvs, 2 ) );
222222

223223
if ( colors !== undefined )
224-
this.addAttribute( 'color', new THREE.Float32Attribute( colors.length, 4 ).set( colors ) );
224+
this.addAttribute( 'color', new THREE.Float32Attribute( colors, 4 ) );
225225

226226
}
227227

examples/webgl_buffergeometry.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,24 @@
8282

8383
var geometry = new THREE.BufferGeometry();
8484

85-
geometry.addAttribute( 'index', new Uint16Array( triangles * 3 ), 1 );
86-
geometry.addAttribute( 'position', new Float32Array( triangles * 3 * 3 ), 3 );
87-
geometry.addAttribute( 'normal', new Float32Array( triangles * 3 * 3 ), 3 );
88-
geometry.addAttribute( 'color', new Float32Array( triangles * 3 * 3 ), 3 );
89-
9085
// break geometry into
9186
// chunks of 21,845 triangles (3 unique vertices per triangle)
9287
// for indices to fit into 16 bit integer number
9388
// floor(2^16 / 3) = 21845
9489

9590
var chunkSize = 21845;
9691

97-
var indices = geometry.getAttribute( 'index' ).array;
92+
var indices = new Uint16Array( triangles * 3 );
9893

9994
for ( var i = 0; i < indices.length; i ++ ) {
10095

10196
indices[ i ] = i % ( 3 * chunkSize );
10297

10398
}
10499

105-
var positions = geometry.getAttribute( 'position' ).array;
106-
var normals = geometry.getAttribute( 'normal' ).array;
107-
var colors = geometry.getAttribute( 'color' ).array;
100+
var positions = new Float32Array( triangles * 3 * 3 );
101+
var normals = new Float32Array( triangles * 3 * 3 );
102+
var colors = new Float32Array( triangles * 3 * 3 );
108103

109104
var color = new THREE.Color();
110105

@@ -200,6 +195,11 @@
200195

201196
}
202197

198+
geometry.addAttribute( 'index', new THREE.Uint16Attribute( indices, 1 ) );
199+
geometry.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
200+
geometry.addAttribute( 'normal', new THREE.Float32Attribute( normals, 3 ) );
201+
geometry.addAttribute( 'color', new THREE.Float32Attribute( colors, 3 ) );
202+
203203
var offsets = triangles / chunkSize;
204204

205205
for ( var i = 0; i < offsets; i ++ ) {

examples/webgl_buffergeometry_custom_attributes_particles.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,9 @@
137137

138138
geometry = new THREE.BufferGeometry();
139139

140-
geometry.addAttribute( 'position', new Float32Array( particles * 3 ), 3 );
141-
geometry.addAttribute( 'customColor', new Float32Array( particles * 3 ), 3 );
142-
geometry.addAttribute( 'size', new Float32Array( particles ), 1 );
143-
144-
var positions = geometry.getAttribute( 'position' ).array;
145-
var values_color = geometry.getAttribute( 'customColor' ).array;
146-
values_size = geometry.getAttribute( 'size' ).array;
147-
148-
sphere = new THREE.ParticleSystem( geometry, shaderMaterial );
149-
150-
// sphere.sortParticles = true;
140+
var positions = new Float32Array( particles * 3 );
141+
var values_color = new Float32Array( particles * 3 );
142+
values_size = new Float32Array( particles );
151143

152144
var color = new THREE.Color( 0xffaa00 );;
153145

@@ -170,6 +162,14 @@
170162

171163
}
172164

165+
geometry.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
166+
geometry.addAttribute( 'customColor', new THREE.Float32Attribute( values_color, 3 ) );
167+
geometry.addAttribute( 'size', new THREE.Float32Attribute( values_size, 1 ) );
168+
169+
sphere = new THREE.ParticleSystem( geometry, shaderMaterial );
170+
171+
// sphere.sortParticles = true;
172+
173173
scene.add( sphere );
174174

175175
renderer = new THREE.WebGLRenderer();

examples/webgl_buffergeometry_lines.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,8 @@
6969
var geometry = new THREE.BufferGeometry();
7070
var material = new THREE.LineBasicMaterial({ vertexColors: true });
7171

72-
geometry.addAttribute( 'position', new Float32Array( segments * 3 ), 3 );
73-
geometry.addAttribute( 'color', new Float32Array( segments * 3 ), 3 );
74-
75-
var positions = geometry.getAttribute( 'position' ).array;
76-
var colors = geometry.getAttribute( 'color' ).array;
72+
var positions = new Float32Array( segments * 3 );
73+
var colors = new Float32Array( segments * 3 );
7774

7875
var r = 800;
7976

@@ -97,6 +94,9 @@
9794

9895
}
9996

97+
geometry.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
98+
geometry.addAttribute( 'color', new THREE.Float32Attribute( colors, 3 ) );
99+
100100
geometry.computeBoundingSphere();
101101

102102
mesh = new THREE.Line( geometry, material );

examples/webgl_buffergeometry_lines_indexed.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
var colors = [];
7070
var indices_array = [];
7171

72-
// --------------------------------
72+
//
73+
7374
var iteration_count = 4;
7475
var rangle = 60 * Math.PI / 180.0;
7576

@@ -181,9 +182,9 @@
181182
);
182183
// --------------------------------
183184

184-
geometry.addAttribute( 'index', new Uint16Array( indices_array ), 1 );
185-
geometry.addAttribute( 'position', new Float32Array( positions ), 3 );
186-
geometry.addAttribute( 'color', new Float32Array( colors ), 3 );
185+
geometry.addAttribute( 'index', new THREE.Uint16Attribute( indices_array, 1 ) );
186+
geometry.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
187+
geometry.addAttribute( 'color', new THREE.Float32Attribute( colors, 3 ) );
187188
geometry.computeBoundingSphere();
188189

189190
mesh = new THREE.Line( geometry, material, THREE.LinePieces );

examples/webgl_buffergeometry_particles.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,8 @@
6969

7070
var geometry = new THREE.BufferGeometry();
7171

72-
geometry.addAttribute( 'position', new Float32Array( particles * 3 ), 3 );
73-
geometry.addAttribute( 'color', new Float32Array( particles * 3 ), 3 );
74-
75-
var positions = geometry.getAttribute( 'position' ).array;
76-
var colors = geometry.getAttribute( 'color' ).array;
72+
var positions = new Float32Array( particles * 3 );
73+
var colors = new Float32Array( particles * 3 );
7774

7875
var color = new THREE.Color();
7976

@@ -105,6 +102,9 @@
105102

106103
}
107104

105+
geometry.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
106+
geometry.addAttribute( 'color', new THREE.Float32Attribute( colors, 3 ) );
107+
108108
geometry.computeBoundingSphere();
109109

110110
//

examples/webgl_buffergeometry_rawshader.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113

114114
var geometry = new THREE.BufferGeometry();
115115

116-
var vertices = new THREE.Float32Attribute( triangles * 3, 3 );
116+
var vertices = new THREE.Float32Attribute( triangles * 3 * 3, 3 );
117117

118118
for ( var i = 0; i < vertices.length; i ++ ) {
119119

@@ -123,7 +123,7 @@
123123

124124
geometry.addAttribute( 'position', vertices );
125125

126-
var colors = new THREE.Float32Attribute( triangles * 3, 4 );
126+
var colors = new THREE.Float32Attribute( triangles * 3 * 4, 4 );
127127

128128
for ( var i = 0; i < colors.length; i ++ ) {
129129

0 commit comments

Comments
 (0)