提交 3e4339f3 编写于 作者: A alteredq

Added handling of MeshFaceMaterial.materials to scene format / SceneLoader.

See #2628 and #2623
上级 6fb5b91c
......@@ -7221,8 +7221,10 @@ THREE.BinaryLoader.prototype = Object.create( THREE.Loader.prototype );
THREE.BinaryLoader.prototype.load = function( url, callback, texturePath, binaryPath ) {
texturePath = texturePath ? texturePath : this.extractUrlBase( url );
binaryPath = binaryPath ? binaryPath : this.extractUrlBase( url );
// todo: unify load API to for easier SceneLoader use
texturePath = texturePath && ( typeof texturePath === "string" ) ? texturePath : this.extractUrlBase( url );
binaryPath = binaryPath && ( typeof binaryPath === "string" ) ? binaryPath : this.extractUrlBase( url );
var callbackProgress = this.showProgress ? THREE.Loader.prototype.updateProgress : null;
......@@ -8024,7 +8026,9 @@ THREE.JSONLoader.prototype.load = function ( url, callback, texturePath ) {
var scope = this;
texturePath = texturePath ? texturePath : this.extractUrlBase( url );
// todo: unify load API to for easier SceneLoader use
texturePath = texturePath && ( typeof texturePath === "string" ) ? texturePath : this.extractUrlBase( url );
this.onLoadStart();
this.loadAjaxJSON( this, url, callback, texturePath );
......@@ -10227,6 +10231,30 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
}
// second pass through all materials to initialize MeshFaceMaterials
// that could be referring to other materials out of order
for ( dm in data.materials ) {
m = data.materials[ dm ];
if ( m.parameters.materials ) {
var materialArray = [];
for ( var i = 0; i < m.parameters.materials.length; i ++ ) {
var label = m.parameters.materials[ i ];
materialArray.push( result.materials[ label ] );
}
result.materials[ dm ].materials = materialArray;
}
}
// objects ( synchronous init of procedural primitives )
handle_objects();
......
此差异已折叠。
......@@ -211,6 +211,24 @@
"visible" : true
},
"man_clone_1" : {
"geometry" : "man",
"material" : "multi_1",
"position" : [ 2.5, -10, -25 ],
"rotation" : [ 0, 0, 0 ],
"scale" : [ 0.2, 0.2, 0.2 ],
"visible" : true
},
"man_clone_2" : {
"geometry" : "man",
"material" : "multi_2",
"position" : [ 15, -10, -25 ],
"rotation" : [ 0, 0, 0 ],
"scale" : [ 0.2, 0.2, 0.2 ],
"visible" : true
},
"monster" : {
"type": "dae",
"url" : "models/collada/monster/monster.dae",
......@@ -451,6 +469,11 @@
"url" : "models/skinned/knight.js"
},
"man": {
"type": "binary",
"url" : "obj/male02/Male02_bin.js"
},
"ben": {
"type": "ctm",
"url" : "models/ctm/ben.ctm",
......@@ -663,6 +686,16 @@
"face": {
"type": "MeshFaceMaterial",
"parameters": {}
},
"multi_1": {
"type": "MeshFaceMaterial",
"parameters": {}
},
"multi_2": {
"type": "MeshFaceMaterial",
"parameters": { "materials": [ "phong_compressed_cube", "phong_man", "phong_hand", "minecraft", "backsignals" ] }
}
},
......
......@@ -20,8 +20,10 @@ THREE.BinaryLoader.prototype = Object.create( THREE.Loader.prototype );
THREE.BinaryLoader.prototype.load = function( url, callback, texturePath, binaryPath ) {
texturePath = texturePath ? texturePath : this.extractUrlBase( url );
binaryPath = binaryPath ? binaryPath : this.extractUrlBase( url );
// todo: unify load API to for easier SceneLoader use
texturePath = texturePath && ( typeof texturePath === "string" ) ? texturePath : this.extractUrlBase( url );
binaryPath = binaryPath && ( typeof binaryPath === "string" ) ? binaryPath : this.extractUrlBase( url );
var callbackProgress = this.showProgress ? THREE.Loader.prototype.updateProgress : null;
......
......@@ -17,7 +17,9 @@ THREE.JSONLoader.prototype.load = function ( url, callback, texturePath ) {
var scope = this;
texturePath = texturePath ? texturePath : this.extractUrlBase( url );
// todo: unify load API to for easier SceneLoader use
texturePath = texturePath && ( typeof texturePath === "string" ) ? texturePath : this.extractUrlBase( url );
this.onLoadStart();
this.loadAjaxJSON( this, url, callback, texturePath );
......
......@@ -1066,6 +1066,30 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
}
// second pass through all materials to initialize MeshFaceMaterials
// that could be referring to other materials out of order
for ( dm in data.materials ) {
m = data.materials[ dm ];
if ( m.parameters.materials ) {
var materialArray = [];
for ( var i = 0; i < m.parameters.materials.length; i ++ ) {
var label = m.parameters.materials[ i ];
materialArray.push( result.materials[ label ] );
}
result.materials[ dm ].materials = materialArray;
}
}
// objects ( synchronous init of procedural primitives )
handle_objects();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册