未验证 提交 f66fc35c 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #13339 from 1d2d3d/LegacyGLTFLoaderMinimalShaderUpdate

Updated LegacyGLTFLoader.js shader parsing
......@@ -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>
......
......@@ -175,8 +175,18 @@ var Loader = function ( editor ) {
reader.addEventListener( 'load', function ( event ) {
var contents = event.target.result;
var loader;
if ( isGltf1( contents ) ) {
loader = new THREE.LegacyGLTFLoader();
} else {
loader = new THREE.GLTFLoader();
}
var loader = new THREE.GLTFLoader();
loader.parse( contents, '', function ( result ) {
result.scene.name = filename;
......@@ -572,4 +582,39 @@ var Loader = function ( editor ) {
}
function isGltf1( contents ) {
var resultContent;
if ( typeof contents === 'string' ) {
// contents is a JSON string
resultContent = contents;
} else {
var magic = THREE.LoaderUtils.decodeText( new Uint8Array( contents, 0, 4 ) );
if ( magic === 'glTF' ) {
// contents is a .glb file; extract the version
var version = new DataView( contents ).getUint32( 4, true );
return version < 2;
} else {
// contents is a .gltf file
resultContent = THREE.LoaderUtils.decodeText( new Uint8Array( contents ) );
}
}
var json = JSON.parse( resultContent );
return ( json.asset != undefined && json.asset.version[ 0 ] < 2 );
}
};
......@@ -31,7 +31,7 @@ THREE.LegacyGLTFLoader = ( function () {
loader.load( url, function ( data ) {
scope.parse( data, onLoad, path );
scope.parse( data, path, onLoad );
}, onProgress, onError );
......@@ -49,7 +49,7 @@ THREE.LegacyGLTFLoader = ( function () {
},
parse: function ( data, callback, path ) {
parse: function ( data, path, callback ) {
var content;
var extensions = {};
......@@ -1634,6 +1634,26 @@ THREE.LegacyGLTFLoader = ( function () {
geometry.addAttribute( 'skinIndex', bufferAttribute );
break;
default:
if ( ! primitive.material ) break;
var material = json.materials[ primitive.material ];
if ( ! material.technique ) break;
var parameters = json.techniques[ material.technique ].parameters || {};
for( var attributeName in parameters ) {
if ( parameters [ attributeName ][ 'semantic' ] === attributeId ) {
geometry.addAttribute( attributeName, bufferAttribute );
}
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册