Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor determines GLTF version and uses appropriate loader #13333

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<script src="../examples/js/loaders/ColladaLoader.js"></script>
<script src="../examples/js/loaders/FBXLoader.js"></script>
<script src="../examples/js/loaders/GLTFLoader.js"></script>
<script src="../examples/js/loaders/deprecated/LegacyGLTFLoader.js"></script>
<script src="../examples/js/loaders/KMZLoader.js"></script>
<script src="../examples/js/loaders/MD2Loader.js"></script>
<script src="../examples/js/loaders/OBJLoader.js"></script>
Expand Down
54 changes: 53 additions & 1 deletion editor/js/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,18 @@ var Loader = function ( editor ) {

var contents = event.target.result;

var loader = new THREE.GLTFLoader();
var loader;

if ( isGltf1( contents ) ) {

loader = new THREE.LegacyGLTFLoader();

} else {

loader = new THREE.GLTFLoader();

}

loader.parse( contents, '', function ( result ) {

result.scene.name = filename;
Expand Down Expand Up @@ -572,4 +583,45 @@ var Loader = function ( editor ) {

}

function isGltf1( contents ) {

var resultContent;

if ( typeof contents === 'string' ) {

resultContent = contents;

} else {

var magic = THREE.LoaderUtils.decodeText( new Uint8Array( contents, 0, 4 ) );

if ( magic === 'glTF' ) {

try {

extensions[ EXTENSIONS.KHR_BINARY_GLTF ] = new GLTFBinaryExtension( contents );

} catch ( error ) {

// dunno what it is, but it's definitely not OK
return false;

}

resultContent = extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content;

} else {

resultContent = THREE.LoaderUtils.decodeText( new Uint8Array( contents ) );

}

}

var json = JSON.parse( resultContent );

return ( json.asset != undefined && json.asset.version[ 0 ] < 2 );

}

};