Skip to content

Commit 72aac21

Browse files
committed
GLTFLoader: keep top-level extension data, return parser, add docs.
1 parent c8b13c6 commit 72aac21

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

docs/examples/loaders/GLTFLoader.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@ <h2>Browser compatibility</h2>
8484
<a href="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/stefanpenner/es6-promise">include a polyfill</a>
8585
providing a Promise replacement.</p>
8686

87+
<h2>Custom extensions</h2>
88+
89+
<p>
90+
Metadata from unknown extensions is preserved as “.userData.gltfExtensions” on Object3D, Scene, and Material instances,
91+
or attached to the response “gltf” object. Example:
92+
</p>
93+
94+
<code>
95+
loader.load('foo.gltf', function ( gltf ) {
96+
97+
var scene = gltf.scene;
98+
99+
var mesh = scene.children[ 3 ];
100+
101+
var fooExtension = mesh.userData.gltfExtensions.EXT_foo;
102+
103+
gltf.parser.getDependency( 'bufferView', fooExtension.bufferView )
104+
.then( function ( fooBuffer ) { ... } );
105+
106+
});
107+
</code>
108+
87109
<br>
88110
<hr>
89111

examples/js/loaders/GLTFLoader.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ THREE.GLTFLoader = ( function () {
174174

175175
} );
176176

177-
parser.parse( function ( scene, scenes, cameras, animations, asset ) {
177+
parser.parse( function ( scene, scenes, cameras, animations, json ) {
178178

179179
console.timeEnd( 'GLTFLoader' );
180180

@@ -183,9 +183,13 @@ THREE.GLTFLoader = ( function () {
183183
scenes: scenes,
184184
cameras: cameras,
185185
animations: animations,
186-
asset: asset
186+
asset: json.asset,
187+
parser: parser,
188+
userData: {}
187189
};
188190

191+
addUnknownExtensionsToUserData( extensions, glTF, json );
192+
189193
onLoad( glTF );
190194

191195
}, onError );
@@ -1459,10 +1463,9 @@ THREE.GLTFLoader = ( function () {
14591463
var scenes = dependencies.scenes || [];
14601464
var scene = scenes[ json.scene || 0 ];
14611465
var animations = dependencies.animations || [];
1462-
var asset = json.asset;
14631466
var cameras = dependencies.cameras || [];
14641467

1465-
onLoad( scene, scenes, cameras, animations, asset );
1468+
onLoad( scene, scenes, cameras, animations, json );
14661469

14671470
} ).catch( onError );
14681471

0 commit comments

Comments
 (0)