Skip to content

Commit f204e2b

Browse files
committed
GLTFLoader: Replaced _ with library approach.
1 parent 74e9571 commit f204e2b

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

examples/js/loaders/GLTFLoader.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ THREE.GLTFLoader.prototype = {
5151

5252
console.time( 'GLTFLoader' );
5353

54+
var library = {
55+
buffers: {},
56+
bufferViews: {},
57+
accessors: {},
58+
meshes: {},
59+
nodes: {},
60+
scenes: {}
61+
};
62+
5463
// buffers
5564

5665
var buffers = json.buffers;
@@ -65,7 +74,7 @@ THREE.GLTFLoader.prototype = {
6574

6675
if ( buffer.uri.indexOf( header ) === 0 ) {
6776

68-
buffer._arraybuffer = stringToArrayBuffer( buffer.uri.substr( header.length ) );
77+
library.buffers[ bufferId ] = stringToArrayBuffer( buffer.uri.substr( header.length ) );
6978

7079
}
7180

@@ -80,9 +89,9 @@ THREE.GLTFLoader.prototype = {
8089
for ( var bufferViewId in bufferViews ) {
8190

8291
var bufferView = bufferViews[ bufferViewId ];
83-
var arraybuffer = buffers[ bufferView.buffer ]._arraybuffer;
92+
var arraybuffer = library.buffers[ bufferView.buffer ];
8493

85-
bufferView._arraybuffer = arraybuffer.slice( bufferView.byteOffset, bufferView.byteOffset + bufferView.byteLength );
94+
library.bufferViews[ bufferViewId ] = arraybuffer.slice( bufferView.byteOffset, bufferView.byteOffset + bufferView.byteLength );
8695

8796
}
8897

@@ -107,13 +116,13 @@ THREE.GLTFLoader.prototype = {
107116

108117
var accessor = accessors[ accessorId ];
109118

110-
var arraybuffer = bufferViews[ accessor.bufferView ]._arraybuffer;
119+
var arraybuffer = library.bufferViews[ accessor.bufferView ];
111120
var itemSize = TYPE_SIZES[ accessor.type ];
112121
var TypedArray = COMPONENT_TYPES[ accessor.componentType ];
113122

114123
var array = new TypedArray( arraybuffer, accessor.byteOffset, accessor.count * itemSize );
115124

116-
accessor._bufferattribute = new THREE.BufferAttribute( array, itemSize );
125+
library.accessors[ accessorId ] = new THREE.BufferAttribute( array, itemSize );
117126

118127
}
119128

@@ -141,14 +150,14 @@ THREE.GLTFLoader.prototype = {
141150

142151
if ( primitive.indices ) {
143152

144-
geometry.setIndex( accessors[ primitive.indices ]._bufferattribute );
153+
geometry.setIndex( library.accessors[ primitive.indices ] );
145154

146155
}
147156

148157
for ( var attributeId in attributes ) {
149158

150159
var attribute = attributes[ attributeId ];
151-
var bufferAttribute = accessors[ attribute ]._bufferattribute;
160+
var bufferAttribute = library.accessors[ attribute ];
152161

153162
switch ( attributeId ) {
154163

@@ -172,7 +181,7 @@ THREE.GLTFLoader.prototype = {
172181

173182
}
174183

175-
mesh._geometries = geometries;
184+
library.meshes[ meshId ] = geometries;
176185

177186
}
178187

@@ -219,7 +228,7 @@ THREE.GLTFLoader.prototype = {
219228

220229
var meshId = node.meshes[ i ];
221230

222-
var geometries = meshes[ meshId ]._geometries;
231+
var geometries = library.meshes[ meshId ];
223232

224233
var group = new THREE.Group();
225234
group.name = geometries.name;
@@ -237,7 +246,7 @@ THREE.GLTFLoader.prototype = {
237246

238247
}
239248

240-
node._object = object;
249+
library.nodes[ nodeId ] = object;
241250

242251
}
243252

@@ -249,7 +258,7 @@ THREE.GLTFLoader.prototype = {
249258

250259
var child = node.children[ i ];
251260

252-
node._object.add( nodes[ child ]._object );
261+
library.nodes[ nodeId ].add( library.nodes[ child ] );
253262

254263
}
255264

@@ -267,19 +276,19 @@ THREE.GLTFLoader.prototype = {
267276
for ( var i = 0; i < scene.nodes.length; i ++ ) {
268277

269278
var node = scene.nodes[ i ];
270-
container.add( nodes[ node ]._object );
279+
container.add( library.nodes[ node ] );
271280

272281
}
273282

274-
scene._container = container;
283+
library.scenes[ sceneId ] = container;
275284

276285
}
277286

278287
console.timeEnd( 'GLTFLoader' );
279288

280289
return {
281290

282-
scene: json.scenes[ json.scene ]._container
291+
scene: library.scenes[ json.scene ]
283292

284293
};
285294

0 commit comments

Comments
 (0)