提交 55504ff8 编写于 作者: M Mugen87

removal of THREE.MeshFaceMaterial

上级 de30c4d4
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
<h3>[property:Integer materialIndex]</h3> <h3>[property:Integer materialIndex]</h3>
<div> <div>
Material index (points to [page:MeshFaceMaterial MeshFaceMaterial.materials]). Material index (points to [page:MultiMaterial MultiMaterial.materials]).
</div> </div>
<h2>Methods</h2> <h2>Methods</h2>
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
materials -- The materials for the object. materials -- The materials for the object.
</div> </div>
<div> <div>
Creates an new Object3D an new mesh for each material defined in materials. Beware that this is not the same as Meshfacematerial which defines multiple material for 1 mesh.<br /> Creates an new Object3D an new mesh for each material defined in materials. Beware that this is not the same as MultiMaterial which defines multiple material for 1 mesh.<br />
This is mostly useful for object that need a material and a wireframe implementation. This is mostly useful for object that need a material and a wireframe implementation.
</div> </div>
......
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
'models/animated/monster/monster.js', 'models/animated/monster/monster.js',
// Function when resource is loaded // Function when resource is loaded
function ( geometry, materials ) { function ( geometry, materials ) {
var material = new THREE.MeshFaceMaterial( materials ); var material = new THREE.MultiMaterial( materials );
var object = new THREE.Mesh( geometry, material ); var object = new THREE.Mesh( geometry, material );
scene.add( object ); scene.add( object );
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<h1>[name]</h1> <h1>[name]</h1>
<div class="desc"> <div class="desc">
A Material to define multiple materials for the same geometry. A Material to define multiple materials for the same geometry.
The geometry decides which material is used for which faces by the [page:Face3 faces materialindex]. The geometry decides which material is used for which faces by the [page:Face3 faces materialindex].
The materialindex corresponds with the index of the material in the materials array. The materialindex corresponds with the index of the material in the materials array.
</div> </div>
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
materials -- The materials for the geometry. materials -- The materials for the geometry.
</div> </div>
<div> <div>
Creates a MeshFaceMaterial with the correct materials. Creates a MultiMaterial with the correct materials.
</div> </div>
......
...@@ -72,7 +72,7 @@ var list = { ...@@ -72,7 +72,7 @@ var list = {
[ "Material", "api/materials/Material" ], [ "Material", "api/materials/Material" ],
[ "MeshBasicMaterial", "api/materials/MeshBasicMaterial" ], [ "MeshBasicMaterial", "api/materials/MeshBasicMaterial" ],
[ "MeshDepthMaterial", "api/materials/MeshDepthMaterial" ], [ "MeshDepthMaterial", "api/materials/MeshDepthMaterial" ],
[ "MeshFaceMaterial", "api/materials/MeshFaceMaterial" ], [ "MultiMaterial", "api/materials/MultiMaterial" ],
[ "MeshLambertMaterial", "api/materials/MeshLambertMaterial" ], [ "MeshLambertMaterial", "api/materials/MeshLambertMaterial" ],
[ "MeshNormalMaterial", "api/materials/MeshNormalMaterial" ], [ "MeshNormalMaterial", "api/materials/MeshNormalMaterial" ],
[ "MeshPhongMaterial", "api/materials/MeshPhongMaterial" ], [ "MeshPhongMaterial", "api/materials/MeshPhongMaterial" ],
......
...@@ -451,7 +451,7 @@ var Loader = function ( editor ) { ...@@ -451,7 +451,7 @@ var Loader = function ( editor ) {
if ( result.materials.length > 1 ) { if ( result.materials.length > 1 ) {
material = new THREE.MeshFaceMaterial( result.materials ); material = new THREE.MultiMaterial( result.materials );
} else { } else {
......
...@@ -36,7 +36,7 @@ Sidebar.Animation = function ( editor ) { ...@@ -36,7 +36,7 @@ Sidebar.Animation = function ( editor ) {
var material = child.material; var material = child.material;
if ( material instanceof THREE.MeshFaceMaterial ) { if ( material instanceof THREE.MultiMaterial ) {
for ( var i = 0; i < material.materials.length; i ++ ) { for ( var i = 0; i < material.materials.length; i ++ ) {
......
...@@ -368,7 +368,7 @@ ...@@ -368,7 +368,7 @@
}, },
"materialIndex": { "materialIndex": {
"!type": "number", "!type": "number",
"!doc": "Material index (points to [page:MeshFaceMaterial MeshFaceMaterial.materials])." "!doc": "Material index (points to [page:MultiMaterial MultiMaterial.materials])."
}, },
"clone": { "clone": {
"!type": "fn() -> +THREE.Face3", "!type": "fn() -> +THREE.Face3",
...@@ -960,7 +960,7 @@ ...@@ -960,7 +960,7 @@
"prototype": { "prototype": {
"createMultiMaterialObject": { "createMultiMaterialObject": {
"!type": "fn(geometry: +THREE.Geometry, materials: []) -> +THREE.Object3D", "!type": "fn(geometry: +THREE.Geometry, materials: []) -> +THREE.Object3D",
"!doc": "Creates an new Object3D an new mesh for each material defined in materials. Beware that this is not the same as Meshfacematerial which defines multiple material for 1 mesh.<br>\n\t\tThis is mostly useful for object that need a material and a wireframe implementation." "!doc": "Creates an new Object3D an new mesh for each material defined in materials. Beware that this is not the same as MultiMaterial which defines multiple material for 1 mesh.<br>\n\t\tThis is mostly useful for object that need a material and a wireframe implementation."
}, },
"attach": { "attach": {
"!type": "fn(child: +THREE.Object3D, scene: +THREE.Object3D, parent: +THREE.Object3D)", "!type": "fn(child: +THREE.Object3D, scene: +THREE.Object3D, parent: +THREE.Object3D)",
...@@ -2839,8 +2839,8 @@ ...@@ -2839,8 +2839,8 @@
"!doc": "A material for drawing geometry by depth. Depth is based off of the camera near and far plane. White is nearest, black is farthest.", "!doc": "A material for drawing geometry by depth. Depth is based off of the camera near and far plane. White is nearest, black is farthest.",
"!type": "fn(parameters: object)" "!type": "fn(parameters: object)"
}, },
"MeshFaceMaterial": { "MultiMaterial": {
"!url": "http://threejs.org/docs/#Reference/materials/MeshFaceMaterial", "!url": "http://threejs.org/docs/#Reference/materials/MultiMaterial",
"prototype": { "prototype": {
"materials": { "materials": {
"!type": "[]", "!type": "[]",
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
]; ];
mesh = new THREE.Mesh( new THREE.BoxGeometry( 300, 300, 300, 7, 7, 7 ), new THREE.MeshFaceMaterial( materials ) ); mesh = new THREE.Mesh( new THREE.BoxGeometry( 300, 300, 300, 7, 7, 7 ), new THREE.MultiMaterial( materials ) );
mesh.scale.x = - 1; mesh.scale.x = - 1;
scene.add( mesh ); scene.add( mesh );
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
]; ];
mesh = new THREE.Mesh( new THREE.BoxGeometry( 300, 300, 300, 7, 7, 7 ), new THREE.MeshFaceMaterial( materials ) ); mesh = new THREE.Mesh( new THREE.BoxGeometry( 300, 300, 300, 7, 7, 7 ), new THREE.MultiMaterial( materials ) );
mesh.scale.x = - 1; mesh.scale.x = - 1;
scene.add( mesh ); scene.add( mesh );
......
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
var centerOffset = -0.5 * ( geometry.boundingBox.max.x - geometry.boundingBox.min.x ); var centerOffset = -0.5 * ( geometry.boundingBox.max.x - geometry.boundingBox.min.x );
var material = new THREE.MeshFaceMaterial( [ var material = new THREE.MultiMaterial( [
new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, overdraw: 0.5 } ), new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, overdraw: 0.5 } ),
new THREE.MeshBasicMaterial( { color: 0x000000, overdraw: 0.5 } ) new THREE.MeshBasicMaterial( { color: 0x000000, overdraw: 0.5 } )
] ); ] );
......
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
} }
materials.push( new THREE.MeshFaceMaterial( materials ) ); materials.push( new THREE.MultiMaterial( materials ) );
objects = []; objects = [];
......
...@@ -299,8 +299,8 @@ THREE.Car = function () { ...@@ -299,8 +299,8 @@ THREE.Car = function () {
var s = scope.modelScale, var s = scope.modelScale,
delta = new THREE.Vector3(); delta = new THREE.Vector3();
var bodyFaceMaterial = new THREE.MeshFaceMaterial( scope.bodyMaterials ); var bodyFaceMaterial = new THREE.MultiMaterial( scope.bodyMaterials );
var wheelFaceMaterial = new THREE.MeshFaceMaterial( scope.wheelMaterials ); var wheelFaceMaterial = new THREE.MultiMaterial( scope.wheelMaterials );
// body // body
......
...@@ -44,7 +44,7 @@ THREE.UCSCharacter = function() { ...@@ -44,7 +44,7 @@ THREE.UCSCharacter = function() {
geometry.computeBoundingBox(); geometry.computeBoundingBox();
geometry.computeVertexNormals(); geometry.computeVertexNormals();
mesh = new THREE.SkinnedMesh( geometry, new THREE.MeshFaceMaterial() ); mesh = new THREE.SkinnedMesh( geometry, new THREE.MultiMaterial() );
mesh.name = config.character; mesh.name = config.character;
scope.root.add( mesh ); scope.root.add( mesh );
......
...@@ -1169,7 +1169,7 @@ THREE.ColladaLoader = function () { ...@@ -1169,7 +1169,7 @@ THREE.ColladaLoader = function () {
if ( num_materials > 1 ) { if ( num_materials > 1 ) {
material = new THREE.MeshFaceMaterial( used_materials_array ); material = new THREE.MultiMaterial( used_materials_array );
} }
......
...@@ -1693,7 +1693,7 @@ THREE.MMDLoader.prototype.createMesh = function ( model, texturePath, onProgress ...@@ -1693,7 +1693,7 @@ THREE.MMDLoader.prototype.createMesh = function ( model, texturePath, onProgress
var scope = this; var scope = this;
var geometry = new THREE.Geometry(); var geometry = new THREE.Geometry();
var material = new THREE.MeshFaceMaterial(); var material = new THREE.MultiMaterial();
var helper = new THREE.MMDLoader.DataCreationHelper(); var helper = new THREE.MMDLoader.DataCreationHelper();
var initVartices = function () { var initVartices = function () {
...@@ -2534,7 +2534,7 @@ THREE.MMDLoader.prototype.createMesh = function ( model, texturePath, onProgress ...@@ -2534,7 +2534,7 @@ THREE.MMDLoader.prototype.createMesh = function ( model, texturePath, onProgress
var bodyB = rigidBodies[ p.rigidBodyIndex2 ]; var bodyB = rigidBodies[ p.rigidBodyIndex2 ];
/* /*
* Refer http://www20.atpages.jp/katwat/wp/?p=4135 * Refer http://www20.atpages.jp/katwat/wp/?p=4135
* for what this is for * for what this is for
*/ */
if ( bodyA.type !== 0 && bodyB.type === 2 ) { if ( bodyA.type !== 0 && bodyB.type === 2 ) {
...@@ -4516,4 +4516,3 @@ THREE.MMDHelper.prototype = { ...@@ -4516,4 +4516,3 @@ THREE.MMDHelper.prototype = {
} }
}; };
...@@ -224,7 +224,7 @@ THREE.SceneLoader.prototype = { ...@@ -224,7 +224,7 @@ THREE.SceneLoader.prototype = {
if ( ! objJSON.material ) { if ( ! objJSON.material ) {
material = new THREE.MeshFaceMaterial( result.face_materials[ objJSON.geometry ] ); material = new THREE.MultiMaterial( result.face_materials[ objJSON.geometry ] );
} }
...@@ -232,9 +232,9 @@ THREE.SceneLoader.prototype = { ...@@ -232,9 +232,9 @@ THREE.SceneLoader.prototype = {
// if there is just empty face material // if there is just empty face material
// (must create new material as each model has its own face material) // (must create new material as each model has its own face material)
if ( ( material instanceof THREE.MeshFaceMaterial ) && material.materials.length === 0 ) { if ( ( material instanceof THREE.MultiMaterial ) && material.materials.length === 0 ) {
material = new THREE.MeshFaceMaterial( result.face_materials[ objJSON.geometry ] ); material = new THREE.MultiMaterial( result.face_materials[ objJSON.geometry ] );
} }
...@@ -1077,7 +1077,7 @@ THREE.SceneLoader.prototype = { ...@@ -1077,7 +1077,7 @@ THREE.SceneLoader.prototype = {
} }
// second pass through all materials to initialize MeshFaceMaterials // second pass through all materials to initialize MultiMaterials
// that could be referring to other materials out of order // that could be referring to other materials out of order
for ( matID in data.materials ) { for ( matID in data.materials ) {
......
...@@ -478,7 +478,7 @@ THREE.Projector = function () { ...@@ -478,7 +478,7 @@ THREE.Projector = function () {
var material = object.material; var material = object.material;
var isFaceMaterial = material instanceof THREE.MeshFaceMaterial; var isFaceMaterial = material instanceof THREE.MultiMaterial;
var objectMaterials = isFaceMaterial === true ? object.material : null; var objectMaterials = isFaceMaterial === true ? object.material : null;
for ( var v = 0, vl = vertices.length; v < vl; v ++ ) { for ( var v = 0, vl = vertices.length; v < vl; v ++ ) {
......
...@@ -685,22 +685,22 @@ ...@@ -685,22 +685,22 @@
}, },
"face": { "face": {
"type": "MeshFaceMaterial", "type": "MultiMaterial",
"parameters": {} "parameters": {}
}, },
"multi_1": { "multi_1": {
"type": "MeshFaceMaterial", "type": "MultiMaterial",
"parameters": {} "parameters": {}
}, },
"multi_2": { "multi_2": {
"type": "MeshFaceMaterial", "type": "MultiMaterial",
"parameters": { "materials": [ "phong_compressed_cube", "phong_man", "phong_hand", "minecraft", "backsignals" ] } "parameters": { "materials": [ "phong_compressed_cube", "phong_man", "phong_hand", "minecraft", "backsignals" ] }
}, },
"multi_veyron": { "multi_veyron": {
"type": "MeshFaceMaterial", "type": "MultiMaterial",
"parameters": { "materials": [ "interior", "chrome", "darkerchrome", "glass", "chrome", "chrome", "backlights", "backsignals" ] } "parameters": { "materials": [ "interior", "chrome", "darkerchrome", "glass", "chrome", "chrome", "backlights", "backsignals" ] }
} }
......
...@@ -223,7 +223,7 @@ ...@@ -223,7 +223,7 @@
} }
mesh = new THREE.SkinnedMesh( geometry, new THREE.MeshFaceMaterial( materials ) ); mesh = new THREE.SkinnedMesh( geometry, new THREE.MultiMaterial( materials ) );
mesh.name = "Knight Mesh"; mesh.name = "Knight Mesh";
mesh.position.set( x, y - bb.min.y * s, z ); mesh.position.set( x, y - bb.min.y * s, z );
mesh.scale.set( s, s, s ); mesh.scale.set( s, s, s );
...@@ -233,7 +233,7 @@ ...@@ -233,7 +233,7 @@
mesh.receiveShadow = true; mesh.receiveShadow = true;
mesh2 = new THREE.SkinnedMesh( geometry, new THREE.MeshFaceMaterial( materials ) ); mesh2 = new THREE.SkinnedMesh( geometry, new THREE.MultiMaterial( materials ) );
mesh2.name = "Lil' Bro Mesh"; mesh2.name = "Lil' Bro Mesh";
mesh2.position.set( x - 240, y - bb.min.y * s, z + 500 ); mesh2.position.set( x - 240, y - bb.min.y * s, z + 500 );
mesh2.scale.set( s / 2, s / 2, s / 2 ); mesh2.scale.set( s / 2, s / 2, s / 2 );
......
...@@ -564,7 +564,7 @@ ...@@ -564,7 +564,7 @@
geometry.sortFacesByMaterialIndex(); geometry.sortFacesByMaterialIndex();
var m = new THREE.MeshFaceMaterial(), var m = new THREE.MultiMaterial(),
s = CARS[ car ].scale * 1, s = CARS[ car ].scale * 1,
r = CARS[ car ].init_rotation, r = CARS[ car ].init_rotation,
materials = CARS[ car ].materials, materials = CARS[ car ].materials,
......
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
materials[ 0 ].shading = THREE.FlatShading; materials[ 0 ].shading = THREE.FlatShading;
mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) ); mesh = new THREE.Mesh( geometry, new THREE.MultiMaterial( materials ) );
mesh.position.x = 400; mesh.position.x = 400;
mesh.scale.x = mesh.scale.y = mesh.scale.z = 250; mesh.scale.x = mesh.scale.y = mesh.scale.z = 250;
scene.add( mesh ); scene.add( mesh );
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
materials[ 0 ].shading = THREE.FlatShading; materials[ 0 ].shading = THREE.FlatShading;
mesh2 = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) ); mesh2 = new THREE.Mesh( geometry, new THREE.MultiMaterial( materials ) );
mesh2.position.x = - 400; mesh2.position.x = - 400;
mesh2.scale.x = mesh2.scale.y = mesh2.scale.z = 250; mesh2.scale.x = mesh2.scale.y = mesh2.scale.z = 250;
scene.add( mesh2 ); scene.add( mesh2 );
......
...@@ -168,7 +168,7 @@ ...@@ -168,7 +168,7 @@
var geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings ); var geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );
var mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) ); var mesh = new THREE.Mesh( geometry, new THREE.MultiMaterial( materials ) );
mesh.position.set( 50, 100, 50 ); mesh.position.set( 50, 100, 50 );
......
...@@ -169,7 +169,7 @@ ...@@ -169,7 +169,7 @@
loader.load( 'obj/lucy/Lucy100k_bin.js', function ( geometry, materials ) { loader.load( 'obj/lucy/Lucy100k_bin.js', function ( geometry, materials ) {
addMesh( geometry, 0.75, 900, 0, 0, 0,0,0, new THREE.MeshPhongMaterial( { color: 0x030303, specular: 0x990000, shininess: 30 } ) ); addMesh( geometry, 0.75, 900, 0, 0, 0,0,0, new THREE.MeshPhongMaterial( { color: 0x030303, specular: 0x990000, shininess: 30 } ) );
addMesh( geometry, 0.75, 300, 0, 0, 0,0,0, new THREE.MeshFaceMaterial( materials ) ); addMesh( geometry, 0.75, 300, 0, 0, 0,0,0, new THREE.MultiMaterial( materials ) );
addMesh( geometry, 0.75, -300, 0, 0, 0,0,0, new THREE.MeshPhongMaterial( { color: 0x111111, specular: 0xffaa00, shininess: 10 } ) ); addMesh( geometry, 0.75, -300, 0, 0, 0,0,0, new THREE.MeshPhongMaterial( { color: 0x111111, specular: 0xffaa00, shininess: 10 } ) );
addMesh( geometry, 0.75, -900, 0, 0, 0,0,0, new THREE.MeshPhongMaterial( { color: 0x555555, specular: 0x666666, shininess: 10 } ) ); addMesh( geometry, 0.75, -900, 0, 0, 0,0,0, new THREE.MeshPhongMaterial( { color: 0x555555, specular: 0x666666, shininess: 10 } ) );
......
...@@ -181,7 +181,7 @@ ...@@ -181,7 +181,7 @@
} }
material = new THREE.MeshFaceMaterial( [ material = new THREE.MultiMaterial( [
new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.FlatShading } ), // front new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.FlatShading } ), // front
new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.SmoothShading } ) // side new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.SmoothShading } ) // side
] ); ] );
......
...@@ -218,7 +218,7 @@ ...@@ -218,7 +218,7 @@
} }
material = new THREE.MeshFaceMaterial( [ material = new THREE.MultiMaterial( [
new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.FlatShading } ), // front new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.FlatShading } ), // front
new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.SmoothShading } ) // side new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.SmoothShading } ) // side
] ); ] );
......
...@@ -195,7 +195,7 @@ ...@@ -195,7 +195,7 @@
} }
material = new THREE.MeshFaceMaterial( [ material = new THREE.MultiMaterial( [
new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.FlatShading } ), // front new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.FlatShading } ), // front
new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.SmoothShading } ) // side new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.SmoothShading } ) // side
] ); ] );
......
...@@ -278,7 +278,7 @@ ...@@ -278,7 +278,7 @@
hackMaterials( materials ); hackMaterials( materials );
var material = new THREE.MeshFaceMaterial( materials ); var material = new THREE.MultiMaterial( materials );
mesh = new THREE.Mesh( geometry, material ); mesh = new THREE.Mesh( geometry, material );
mesh.position.set( x, y, z ); mesh.position.set( x, y, z );
......
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
material.morphTargets = true; material.morphTargets = true;
material.color.setHex( 0xffaaaa ); material.color.setHex( 0xffaaaa );
var faceMaterial = new THREE.MeshFaceMaterial( materials ); var faceMaterial = new THREE.MultiMaterial( materials );
for ( var i = 0; i < 729; i ++ ) { for ( var i = 0; i < 729; i ++ ) {
...@@ -138,7 +138,7 @@ ...@@ -138,7 +138,7 @@
mesh.updateMatrix(); mesh.updateMatrix();
scene.add( mesh ); scene.add( mesh );
mixer.clipAction( geometry.animations[0], mesh ) mixer.clipAction( geometry.animations[0], mesh )
.setDuration( 1 ) // one second .setDuration( 1 ) // one second
.startAt( - Math.random() ) // random phase (already running) .startAt( - Math.random() ) // random phase (already running)
......
...@@ -220,7 +220,7 @@ ...@@ -220,7 +220,7 @@
function createScene( geometry, materials, x, y, z, b ) { function createScene( geometry, materials, x, y, z, b ) {
zmesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) ); zmesh = new THREE.Mesh( geometry, new THREE.MultiMaterial( materials ) );
zmesh.position.set( x, y, z ); zmesh.position.set( x, y, z );
zmesh.scale.set( 3, 3, 3 ); zmesh.scale.set( 3, 3, 3 );
scene.add( zmesh ); scene.add( zmesh );
......
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
} }
addMesh( geometry, new THREE.MeshFaceMaterial( materials ) ); addMesh( geometry, new THREE.MultiMaterial( materials ) );
particleLight = new THREE.Mesh( new THREE.SphereGeometry( 4, 8, 8 ), new THREE.MeshBasicMaterial( { color: 0xffffff } ) ); particleLight = new THREE.Mesh( new THREE.SphereGeometry( 4, 8, 8 ), new THREE.MeshBasicMaterial( { color: 0xffffff } ) );
scene.add( particleLight ); scene.add( particleLight );
......
...@@ -572,7 +572,7 @@ ...@@ -572,7 +572,7 @@
geometry.sortFacesByMaterialIndex(); geometry.sortFacesByMaterialIndex();
var m = new THREE.MeshFaceMaterial(), var m = new THREE.MultiMaterial(),
s = CARS[ car ].scale * 1, s = CARS[ car ].scale * 1,
r = CARS[ car ].init_rotation, r = CARS[ car ].init_rotation,
materials = CARS[ car ].materials, materials = CARS[ car ].materials,
......
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
} }
var mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) ); var mesh = new THREE.Mesh( geometry, new THREE.MultiMaterial( materials ) );
mesh.scale.multiplyScalar( 100 ); mesh.scale.multiplyScalar( 100 );
scene.add( mesh ); scene.add( mesh );
......
...@@ -107,7 +107,7 @@ ...@@ -107,7 +107,7 @@
]; ];
mesh = new THREE.Mesh( new THREE.BoxGeometry( 10000, 10000, 10000, 7, 7, 7 ), new THREE.MeshFaceMaterial( materials ) ); mesh = new THREE.Mesh( new THREE.BoxGeometry( 10000, 10000, 10000, 7, 7, 7 ), new THREE.MultiMaterial( materials ) );
mesh.scale.x = - 1; mesh.scale.x = - 1;
scene.add(mesh); scene.add(mesh);
......
...@@ -61,45 +61,45 @@ ...@@ -61,45 +61,45 @@
// //
object = createObject( createMeshFaceMaterial(), 4 ); object = createObject( createMultiMaterial(), 4 );
object.position.set( -400, 0, 200 ); object.position.set( -400, 0, 200 );
scene.add( object ); scene.add( object );
objectNewGeometry = object; objectNewGeometry = object;
object = createObject( createMeshFaceMaterial(), 4 ); object = createObject( createMultiMaterial(), 4 );
object.position.set( -200, 0, 200 ); object.position.set( -200, 0, 200 );
scene.add( object ); scene.add( object );
objectToggleAddRemove = object; objectToggleAddRemove = object;
object = createObject( createMeshFaceMaterial(), 4 ); object = createObject( createMultiMaterial(), 4 );
object.position.set( 0, 0, 200 ); object.position.set( 0, 0, 200 );
scene.add( object ); scene.add( object );
objectRandomizeFaces = object; objectRandomizeFaces = object;
/* /*
These are not yet used but they are ready to be shown These are not yet used but they are ready to be shown
object = createObject( createMeshFaceMaterial(), 4 ); object = createObject( createMultiMaterial(), 4 );
object.position.set( 200, 0, 200 ); object.position.set( 200, 0, 200 );
scene.add( object ); scene.add( object );
// //
object = createObject( createMeshFaceMaterial(), 4 ); object = createObject( createMultiMaterial(), 4 );
object.position.set( -400, 0, 0 ); object.position.set( -400, 0, 0 );
scene.add( object ); scene.add( object );
object = createObject( createMeshFaceMaterial(), 4 ); object = createObject( createMultiMaterial(), 4 );
object.position.set( -200, 0, 0 ); object.position.set( -200, 0, 0 );
scene.add( object ); scene.add( object );
object = createObject( createMeshFaceMaterial(), 4 ); object = createObject( createMultiMaterial(), 4 );
object.position.set( 0, 0, 0 ); object.position.set( 0, 0, 0 );
scene.add( object ); scene.add( object );
object = createObject( createMeshFaceMaterial(), 4 ); object = createObject( createMultiMaterial(), 4 );
object.position.set( 200, 0, 0 ); object.position.set( 200, 0, 0 );
scene.add( object ); scene.add( object );
object = createObject( createMeshFaceMaterial(), 4 ); object = createObject( createMultiMaterial(), 4 );
object.position.set( 400, 0, 0 ); object.position.set( 400, 0, 0 );
scene.add( object ); scene.add( object );
*/ */
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
return geometry; return geometry;
} }
function createMeshFaceMaterial(){ function createMultiMaterial(){
var materials = []; var materials = [];
materials.push(new THREE.MeshBasicMaterial({color: 0xff0000})); materials.push(new THREE.MeshBasicMaterial({color: 0xff0000}));
materials.push(new THREE.MeshBasicMaterial({color: 0xffff00})); materials.push(new THREE.MeshBasicMaterial({color: 0xffff00}));
...@@ -144,7 +144,7 @@ ...@@ -144,7 +144,7 @@
materials.push(new THREE.MeshBasicMaterial({color: 0x00ffff})); materials.push(new THREE.MeshBasicMaterial({color: 0x00ffff}));
materials.push(new THREE.MeshBasicMaterial({color: 0x0000ff})); materials.push(new THREE.MeshBasicMaterial({color: 0x0000ff}));
materials.push(new THREE.MeshBasicMaterial({color: 0xff00ff})); materials.push(new THREE.MeshBasicMaterial({color: 0xff00ff}));
var material = new THREE.MeshFaceMaterial(materials); var material = new THREE.MultiMaterial(materials);
return material; return material;
} }
......
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
} }
skinnedMesh = new THREE.SkinnedMesh(geometry, new THREE.MeshFaceMaterial(materials)); skinnedMesh = new THREE.SkinnedMesh(geometry, new THREE.MultiMaterial(materials));
skinnedMesh.scale.set( 1, 1, 1 ); skinnedMesh.scale.set( 1, 1, 1 );
scene.add( skinnedMesh ); scene.add( skinnedMesh );
......
...@@ -136,7 +136,7 @@ THREE.MaterialLoader.prototype = { ...@@ -136,7 +136,7 @@ THREE.MaterialLoader.prototype = {
if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap ); if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity; if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
// MeshFaceMaterial // MultiMaterial
if ( json.materials !== undefined ) { if ( json.materials !== undefined ) {
......
...@@ -252,7 +252,7 @@ THREE.Mesh.prototype.raycast = ( function () { ...@@ -252,7 +252,7 @@ THREE.Mesh.prototype.raycast = ( function () {
} else if ( geometry instanceof THREE.Geometry ) { } else if ( geometry instanceof THREE.Geometry ) {
var fvA, fvB, fvC; var fvA, fvB, fvC;
var isFaceMaterial = material instanceof THREE.MeshFaceMaterial; var isFaceMaterial = material instanceof THREE.MultiMaterial;
var materials = isFaceMaterial === true ? material.materials : null; var materials = isFaceMaterial === true ? material.materials : null;
var vertices = geometry.vertices; var vertices = geometry.vertices;
......
...@@ -251,7 +251,7 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) { ...@@ -251,7 +251,7 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
var geometry = _objects.update( object ); var geometry = _objects.update( object );
var material = object.material; var material = object.material;
if ( material instanceof THREE.MeshFaceMaterial ) { if ( material instanceof THREE.MultiMaterial ) {
var groups = geometry.groups; var groups = geometry.groups;
var materials = material.materials; var materials = material.materials;
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
"src/materials/MeshPhongMaterial.js", "src/materials/MeshPhongMaterial.js",
"src/materials/MeshDepthMaterial.js", "src/materials/MeshDepthMaterial.js",
"src/materials/MeshNormalMaterial.js", "src/materials/MeshNormalMaterial.js",
"src/materials/MeshFaceMaterial.js", "src/materials/MultiMaterial.js",
"src/materials/SpriteMaterial.js", "src/materials/SpriteMaterial.js",
"src/textures/Texture.js", "src/textures/Texture.js",
"src/textures/CompressedTexture.js", "src/textures/CompressedTexture.js",
......
...@@ -48,8 +48,8 @@ class ChunkedIndent(object): ...@@ -48,8 +48,8 @@ class ChunkedIndent(object):
self.force_rounding = force_rounding self.force_rounding = force_rounding
def encode(self): def encode(self):
# Turn the flat array into an array of arrays where each subarray is of # Turn the flat array into an array of arrays where each subarray is of
# length chunk_size. Then string concat the values in the chunked # length chunk_size. Then string concat the values in the chunked
# arrays, delimited with a ', ' and round the values finally append # arrays, delimited with a ', ' and round the values finally append
# '{CHUNK}' so that we can find the strings with regex later # '{CHUNK}' so that we can find the strings with regex later
if not self.value: if not self.value:
return None return None
...@@ -58,8 +58,8 @@ class ChunkedIndent(object): ...@@ -58,8 +58,8 @@ class ChunkedIndent(object):
else: else:
return ['{CHUNK}%s' % ', '.join(str(f) for f in self.value[i:i+self.size]) for i in range(0, len(self.value), self.size)] return ['{CHUNK}%s' % ', '.join(str(f) for f in self.value[i:i+self.size]) for i in range(0, len(self.value), self.size)]
# This custom encoder looks for instances of NoIndent or ChunkedIndent. # This custom encoder looks for instances of NoIndent or ChunkedIndent.
# When it finds # When it finds
class CustomEncoder(json.JSONEncoder): class CustomEncoder(json.JSONEncoder):
def default(self, obj): def default(self, obj):
if isinstance(obj, NoIndent) or isinstance(obj, ChunkedIndent): if isinstance(obj, NoIndent) or isinstance(obj, ChunkedIndent):
...@@ -156,7 +156,7 @@ def setBit(value, position, on): ...@@ -156,7 +156,7 @@ def setBit(value, position, on):
else: else:
mask = ~(1 << position) mask = ~(1 << position)
return (value & mask) return (value & mask)
def generate_uvs(uv_layers): def generate_uvs(uv_layers):
layers = [] layers = []
for uvs in uv_layers: for uvs in uv_layers:
...@@ -176,7 +176,7 @@ def generate_uvs(uv_layers): ...@@ -176,7 +176,7 @@ def generate_uvs(uv_layers):
# ##################################################### # #####################################################
def hasUniqueName(o, class_id): def hasUniqueName(o, class_id):
scene = o.GetScene() scene = o.GetScene()
object_name = o.GetName() object_name = o.GetName()
object_id = o.GetUniqueID() object_id = o.GetUniqueID()
object_count = scene.GetSrcObjectCount(class_id) object_count = scene.GetSrcObjectCount(class_id)
...@@ -184,7 +184,7 @@ def hasUniqueName(o, class_id): ...@@ -184,7 +184,7 @@ def hasUniqueName(o, class_id):
for i in range(object_count): for i in range(object_count):
other = scene.GetSrcObject(class_id, i) other = scene.GetSrcObject(class_id, i)
other_id = other.GetUniqueID() other_id = other.GetUniqueID()
other_name = other.GetName() other_name = other.GetName()
if other_id == object_id: if other_id == object_id:
continue continue
...@@ -193,11 +193,11 @@ def hasUniqueName(o, class_id): ...@@ -193,11 +193,11 @@ def hasUniqueName(o, class_id):
return True return True
def getObjectName(o, force_prefix = False): def getObjectName(o, force_prefix = False):
if not o: if not o:
return "" return ""
object_name = o.GetName() object_name = o.GetName()
object_id = o.GetUniqueID() object_id = o.GetUniqueID()
if not force_prefix: if not force_prefix:
...@@ -210,7 +210,7 @@ def getObjectName(o, force_prefix = False): ...@@ -210,7 +210,7 @@ def getObjectName(o, force_prefix = False):
return prefix + object_name return prefix + object_name
def getMaterialName(o, force_prefix = False): def getMaterialName(o, force_prefix = False):
object_name = o.GetName() object_name = o.GetName()
object_id = o.GetUniqueID() object_id = o.GetUniqueID()
if not force_prefix: if not force_prefix:
...@@ -248,7 +248,7 @@ def getPrefixedName(o, prefix): ...@@ -248,7 +248,7 @@ def getPrefixedName(o, prefix):
return (prefix + '_%s_') % o.GetUniqueID() + o.GetName() return (prefix + '_%s_') % o.GetUniqueID() + o.GetName()
# ##################################################### # #####################################################
# Triangulation # Triangulation
# ##################################################### # #####################################################
def triangulate_node_hierarchy(node): def triangulate_node_hierarchy(node):
node_attribute = node.GetNodeAttribute(); node_attribute = node.GetNodeAttribute();
...@@ -259,7 +259,7 @@ def triangulate_node_hierarchy(node): ...@@ -259,7 +259,7 @@ def triangulate_node_hierarchy(node):
node_attribute.GetAttributeType() == FbxNodeAttribute.eNurbsSurface or \ node_attribute.GetAttributeType() == FbxNodeAttribute.eNurbsSurface or \
node_attribute.GetAttributeType() == FbxNodeAttribute.ePatch: node_attribute.GetAttributeType() == FbxNodeAttribute.ePatch:
converter.TriangulateInPlace(node); converter.TriangulateInPlace(node);
child_count = node.GetChildCount() child_count = node.GetChildCount()
for i in range(child_count): for i in range(child_count):
triangulate_node_hierarchy(node.GetChild(i)) triangulate_node_hierarchy(node.GetChild(i))
...@@ -274,24 +274,24 @@ def triangulate_scene(scene): ...@@ -274,24 +274,24 @@ def triangulate_scene(scene):
# Generate Material Object # Generate Material Object
# ##################################################### # #####################################################
def generate_texture_bindings(material_property, material_params): def generate_texture_bindings(material_property, material_params):
# FBX to Three.js texture types # FBX to Three.js texture types
binding_types = { binding_types = {
"DiffuseColor": "map", "DiffuseColor": "map",
"DiffuseFactor": "diffuseFactor", "DiffuseFactor": "diffuseFactor",
"EmissiveColor": "emissiveMap", "EmissiveColor": "emissiveMap",
"EmissiveFactor": "emissiveFactor", "EmissiveFactor": "emissiveFactor",
"AmbientColor": "lightMap", # "ambientMap", "AmbientColor": "lightMap", # "ambientMap",
"AmbientFactor": "ambientFactor", "AmbientFactor": "ambientFactor",
"SpecularColor": "specularMap", "SpecularColor": "specularMap",
"SpecularFactor": "specularFactor", "SpecularFactor": "specularFactor",
"ShininessExponent": "shininessExponent", "ShininessExponent": "shininessExponent",
"NormalMap": "normalMap", "NormalMap": "normalMap",
"Bump": "bumpMap", "Bump": "bumpMap",
"TransparentColor": "transparentMap", "TransparentColor": "transparentMap",
"TransparencyFactor": "transparentFactor", "TransparencyFactor": "transparentFactor",
"ReflectionColor": "reflectionMap", "ReflectionColor": "reflectionMap",
"ReflectionFactor": "reflectionFactor", "ReflectionFactor": "reflectionFactor",
"DisplacementColor": "displacementMap", "DisplacementColor": "displacementMap",
"VectorDisplacementColor": "vectorDisplacementMap" "VectorDisplacementColor": "vectorDisplacementMap"
} }
...@@ -330,7 +330,7 @@ def generate_material_object(material): ...@@ -330,7 +330,7 @@ def generate_material_object(material):
if implementation: if implementation:
print("Shader materials are not supported") print("Shader materials are not supported")
elif material.GetClassId().Is(FbxSurfaceLambert.ClassId): elif material.GetClassId().Is(FbxSurfaceLambert.ClassId):
ambient = getHex(material.Ambient.Get()) ambient = getHex(material.Ambient.Get())
...@@ -425,10 +425,10 @@ def generate_material_object(material): ...@@ -425,10 +425,10 @@ def generate_material_object(material):
return output return output
def generate_proxy_material_object(node, material_names): def generate_proxy_material_object(node, material_names):
material_type = 'MeshFaceMaterial' material_type = 'MultiMaterial'
material_params = { material_params = {
'materials' : material_names 'materials' : material_names
} }
output = { output = {
...@@ -450,7 +450,7 @@ def extract_materials_from_node(node, material_dict): ...@@ -450,7 +450,7 @@ def extract_materials_from_node(node, material_dict):
node = mesh.GetNode() node = mesh.GetNode()
if node: if node:
material_count = node.GetMaterialCount() material_count = node.GetMaterialCount()
material_names = [] material_names = []
for l in range(mesh.GetLayerCount()): for l in range(mesh.GetLayerCount()):
materials = mesh.GetLayer(l).GetMaterials() materials = mesh.GetLayer(l).GetMaterials()
...@@ -499,7 +499,7 @@ def generate_material_dict(scene): ...@@ -499,7 +499,7 @@ def generate_material_dict(scene):
return material_dict return material_dict
# ##################################################### # #####################################################
# Generate Texture Object # Generate Texture Object
# ##################################################### # #####################################################
def generate_texture_object(texture): def generate_texture_object(texture):
...@@ -512,7 +512,7 @@ def generate_texture_object(texture): ...@@ -512,7 +512,7 @@ def generate_texture_object(texture):
url = texture.GetFileName() url = texture.GetFileName()
else: else:
url = getTextureName( texture ) url = getTextureName( texture )
#url = replace_inFolder2OutFolder( url ) #url = replace_inFolder2OutFolder( url )
#print( url ) #print( url )
...@@ -532,7 +532,7 @@ def generate_texture_object(texture): ...@@ -532,7 +532,7 @@ def generate_texture_object(texture):
'anisotropy': True 'anisotropy': True
} }
return output return output
# ##################################################### # #####################################################
...@@ -540,11 +540,11 @@ def generate_texture_object(texture): ...@@ -540,11 +540,11 @@ def generate_texture_object(texture):
# ##################################################### # #####################################################
def replace_inFolder2OutFolder(url): def replace_inFolder2OutFolder(url):
folderIndex = url.find(inputFolder) folderIndex = url.find(inputFolder)
if folderIndex != -1: if folderIndex != -1:
url = url[ folderIndex+len(inputFolder): ] url = url[ folderIndex+len(inputFolder): ]
url = outputFolder + url url = outputFolder + url
return url return url
# ##################################################### # #####################################################
...@@ -552,11 +552,11 @@ def replace_inFolder2OutFolder(url): ...@@ -552,11 +552,11 @@ def replace_inFolder2OutFolder(url):
# ##################################################### # #####################################################
def replace_OutFolder2inFolder(url): def replace_OutFolder2inFolder(url):
folderIndex = url.find(outputFolder) folderIndex = url.find(outputFolder)
if folderIndex != -1: if folderIndex != -1:
url = url[ folderIndex+len(outputFolder): ] url = url[ folderIndex+len(outputFolder): ]
url = inputFolder + url url = inputFolder + url
return url return url
# ##################################################### # #####################################################
...@@ -589,14 +589,14 @@ def extract_material_textures(material_property, texture_dict): ...@@ -589,14 +589,14 @@ def extract_material_textures(material_property, texture_dict):
def extract_textures_from_node(node, texture_dict): def extract_textures_from_node(node, texture_dict):
name = node.GetName() name = node.GetName()
mesh = node.GetNodeAttribute() mesh = node.GetNodeAttribute()
#for all materials attached to this mesh #for all materials attached to this mesh
material_count = mesh.GetNode().GetSrcObjectCount(FbxSurfaceMaterial.ClassId) material_count = mesh.GetNode().GetSrcObjectCount(FbxSurfaceMaterial.ClassId)
for material_index in range(material_count): for material_index in range(material_count):
material = mesh.GetNode().GetSrcObject(FbxSurfaceMaterial.ClassId, material_index) material = mesh.GetNode().GetSrcObject(FbxSurfaceMaterial.ClassId, material_index)
#go through all the possible textures types #go through all the possible textures types
if material: if material:
texture_count = FbxLayerElement.sTypeTextureCount() texture_count = FbxLayerElement.sTypeTextureCount()
for texture_index in range(texture_count): for texture_index in range(texture_count):
material_property = material.FindProperty(FbxLayerElement.sTextureChannelNames(texture_index)) material_property = material.FindProperty(FbxLayerElement.sTextureChannelNames(texture_index))
...@@ -644,13 +644,13 @@ def extract_fbx_vertex_positions(mesh): ...@@ -644,13 +644,13 @@ def extract_fbx_vertex_positions(mesh):
r = FbxVector4(r[0], r[1], r[2], 1) r = FbxVector4(r[0], r[1], r[2], 1)
s = node.GeometricScaling.Get() s = node.GeometricScaling.Get()
s = FbxVector4(s[0], s[1], s[2], 1) s = FbxVector4(s[0], s[1], s[2], 1)
hasGeometricTransform = False hasGeometricTransform = False
if t[0] != 0 or t[1] != 0 or t[2] != 0 or \ if t[0] != 0 or t[1] != 0 or t[2] != 0 or \
r[0] != 0 or r[1] != 0 or r[2] != 0 or \ r[0] != 0 or r[1] != 0 or r[2] != 0 or \
s[0] != 1 or s[1] != 1 or s[2] != 1: s[0] != 1 or s[1] != 1 or s[2] != 1:
hasGeometricTransform = True hasGeometricTransform = True
if hasGeometricTransform: if hasGeometricTransform:
geo_transform = FbxMatrix(t,r,s) geo_transform = FbxMatrix(t,r,s)
else: else:
...@@ -666,7 +666,7 @@ def extract_fbx_vertex_positions(mesh): ...@@ -666,7 +666,7 @@ def extract_fbx_vertex_positions(mesh):
elif hasGeometricTransform: elif hasGeometricTransform:
transform = geo_transform transform = geo_transform
if transform: if transform:
for i in range(len(positions)): for i in range(len(positions)):
v = positions[i] v = positions[i]
...@@ -688,16 +688,16 @@ def extract_fbx_vertex_normals(mesh): ...@@ -688,16 +688,16 @@ def extract_fbx_vertex_normals(mesh):
layered_normal_values = [] layered_normal_values = []
poly_count = mesh.GetPolygonCount() poly_count = mesh.GetPolygonCount()
control_points = mesh.GetControlPoints() control_points = mesh.GetControlPoints()
for l in range(mesh.GetLayerCount()): for l in range(mesh.GetLayerCount()):
mesh_normals = mesh.GetLayer(l).GetNormals() mesh_normals = mesh.GetLayer(l).GetNormals()
if not mesh_normals: if not mesh_normals:
continue continue
normals_array = mesh_normals.GetDirectArray() normals_array = mesh_normals.GetDirectArray()
normals_count = normals_array.GetCount() normals_count = normals_array.GetCount()
if normals_count == 0: if normals_count == 0:
continue continue
...@@ -718,13 +718,13 @@ def extract_fbx_vertex_normals(mesh): ...@@ -718,13 +718,13 @@ def extract_fbx_vertex_normals(mesh):
r = FbxVector4(r[0], r[1], r[2], 1) r = FbxVector4(r[0], r[1], r[2], 1)
s = node.GeometricScaling.Get() s = node.GeometricScaling.Get()
s = FbxVector4(s[0], s[1], s[2], 1) s = FbxVector4(s[0], s[1], s[2], 1)
hasGeometricTransform = False hasGeometricTransform = False
if t[0] != 0 or t[1] != 0 or t[2] != 0 or \ if t[0] != 0 or t[1] != 0 or t[2] != 0 or \
r[0] != 0 or r[1] != 0 or r[2] != 0 or \ r[0] != 0 or r[1] != 0 or r[2] != 0 or \
s[0] != 1 or s[1] != 1 or s[2] != 1: s[0] != 1 or s[1] != 1 or s[2] != 1:
hasGeometricTransform = True hasGeometricTransform = True
if hasGeometricTransform: if hasGeometricTransform:
geo_transform = FbxMatrix(t,r,s) geo_transform = FbxMatrix(t,r,s)
else: else:
...@@ -740,7 +740,7 @@ def extract_fbx_vertex_normals(mesh): ...@@ -740,7 +740,7 @@ def extract_fbx_vertex_normals(mesh):
elif hasGeometricTransform: elif hasGeometricTransform:
transform = geo_transform transform = geo_transform
if transform: if transform:
t = FbxVector4(0,0,0,1) t = FbxVector4(0,0,0,1)
transform.SetRow(3, t) transform.SetRow(3, t)
...@@ -761,7 +761,7 @@ def extract_fbx_vertex_normals(mesh): ...@@ -761,7 +761,7 @@ def extract_fbx_vertex_normals(mesh):
for v in range(poly_size): for v in range(poly_size):
control_point_index = mesh.GetPolygonVertex(p, v) control_point_index = mesh.GetPolygonVertex(p, v)
# mapping mode is by control points. The mesh should be smooth and soft. # mapping mode is by control points. The mesh should be smooth and soft.
# we can get normals by retrieving each control point # we can get normals by retrieving each control point
if mesh_normals.GetMappingMode() == FbxLayerElement.eByControlPoint: if mesh_normals.GetMappingMode() == FbxLayerElement.eByControlPoint:
...@@ -788,7 +788,7 @@ def extract_fbx_vertex_normals(mesh): ...@@ -788,7 +788,7 @@ def extract_fbx_vertex_normals(mesh):
elif mesh_normals.GetMappingMode() == FbxLayerElement.eByPolygon or \ elif mesh_normals.GetMappingMode() == FbxLayerElement.eByPolygon or \
mesh_normals.GetMappingMode() == FbxLayerElement.eAllSame or \ mesh_normals.GetMappingMode() == FbxLayerElement.eAllSame or \
mesh_normals.GetMappingMode() == FbxLayerElement.eNone: mesh_normals.GetMappingMode() == FbxLayerElement.eNone:
print("unsupported normal mapping mode for polygon vertex") print("unsupported normal mapping mode for polygon vertex")
vertexId += 1 vertexId += 1
...@@ -819,16 +819,16 @@ def extract_fbx_vertex_colors(mesh): ...@@ -819,16 +819,16 @@ def extract_fbx_vertex_colors(mesh):
layered_color_values = [] layered_color_values = []
poly_count = mesh.GetPolygonCount() poly_count = mesh.GetPolygonCount()
control_points = mesh.GetControlPoints() control_points = mesh.GetControlPoints()
for l in range(mesh.GetLayerCount()): for l in range(mesh.GetLayerCount()):
mesh_colors = mesh.GetLayer(l).GetVertexColors() mesh_colors = mesh.GetLayer(l).GetVertexColors()
if not mesh_colors: if not mesh_colors:
continue continue
colors_array = mesh_colors.GetDirectArray() colors_array = mesh_colors.GetDirectArray()
colors_count = colors_array.GetCount() colors_count = colors_array.GetCount()
if colors_count == 0: if colors_count == 0:
continue continue
...@@ -864,7 +864,7 @@ def extract_fbx_vertex_colors(mesh): ...@@ -864,7 +864,7 @@ def extract_fbx_vertex_colors(mesh):
poly_colors.append(index) poly_colors.append(index)
elif mesh_colors.GetMappingMode() == FbxLayerElement.eByPolygon or \ elif mesh_colors.GetMappingMode() == FbxLayerElement.eByPolygon or \
mesh_colors.GetMappingMode() == FbxLayerElement.eAllSame or \ mesh_colors.GetMappingMode() == FbxLayerElement.eAllSame or \
mesh_colors.GetMappingMode() == FbxLayerElement.eNone: mesh_colors.GetMappingMode() == FbxLayerElement.eNone:
print("unsupported color mapping mode for polygon vertex") print("unsupported color mapping mode for polygon vertex")
vertexId += 1 vertexId += 1
...@@ -907,16 +907,16 @@ def extract_fbx_vertex_uvs(mesh): ...@@ -907,16 +907,16 @@ def extract_fbx_vertex_uvs(mesh):
layered_uv_values = [] layered_uv_values = []
poly_count = mesh.GetPolygonCount() poly_count = mesh.GetPolygonCount()
control_points = mesh.GetControlPoints() control_points = mesh.GetControlPoints()
for l in range(mesh.GetLayerCount()): for l in range(mesh.GetLayerCount()):
mesh_uvs = mesh.GetLayer(l).GetUVs() mesh_uvs = mesh.GetLayer(l).GetUVs()
if not mesh_uvs: if not mesh_uvs:
continue continue
uvs_array = mesh_uvs.GetDirectArray() uvs_array = mesh_uvs.GetDirectArray()
uvs_count = uvs_array.GetCount() uvs_count = uvs_array.GetCount()
if uvs_count == 0: if uvs_count == 0:
continue continue
...@@ -946,13 +946,13 @@ def extract_fbx_vertex_uvs(mesh): ...@@ -946,13 +946,13 @@ def extract_fbx_vertex_uvs(mesh):
poly_uvs.append(index) poly_uvs.append(index)
elif mesh_uvs.GetMappingMode() == FbxLayerElement.eByPolygonVertex: elif mesh_uvs.GetMappingMode() == FbxLayerElement.eByPolygonVertex:
uv_texture_index = mesh_uvs.GetIndexArray().GetAt(vertexId) uv_texture_index = mesh_uvs.GetIndexArray().GetAt(vertexId)
if mesh_uvs.GetReferenceMode() == FbxLayerElement.eDirect or \ if mesh_uvs.GetReferenceMode() == FbxLayerElement.eDirect or \
mesh_uvs.GetReferenceMode() == FbxLayerElement.eIndexToDirect: mesh_uvs.GetReferenceMode() == FbxLayerElement.eIndexToDirect:
poly_uvs.append(uv_texture_index) poly_uvs.append(uv_texture_index)
elif mesh_uvs.GetMappingMode() == FbxLayerElement.eByPolygon or \ elif mesh_uvs.GetMappingMode() == FbxLayerElement.eByPolygon or \
mesh_uvs.GetMappingMode() == FbxLayerElement.eAllSame or \ mesh_uvs.GetMappingMode() == FbxLayerElement.eAllSame or \
mesh_uvs.GetMappingMode() == FbxLayerElement.eNone: mesh_uvs.GetMappingMode() == FbxLayerElement.eNone:
print("unsupported uv mapping mode for polygon vertex") print("unsupported uv mapping mode for polygon vertex")
vertexId += 1 vertexId += 1
...@@ -974,7 +974,7 @@ def generate_color_key(color): ...@@ -974,7 +974,7 @@ def generate_color_key(color):
def generate_uv_key(uv): def generate_uv_key(uv):
return (round(uv[0], 6), round(uv[1], 6)) return (round(uv[0], 6), round(uv[1], 6))
def append_non_duplicate_uvs(source_uvs, dest_uvs, counts): def append_non_duplicate_uvs(source_uvs, dest_uvs, counts):
source_layer_count = len(source_uvs) source_layer_count = len(source_uvs)
for layer_index in range(source_layer_count): for layer_index in range(source_layer_count):
...@@ -993,7 +993,7 @@ def append_non_duplicate_uvs(source_uvs, dest_uvs, counts): ...@@ -993,7 +993,7 @@ def append_non_duplicate_uvs(source_uvs, dest_uvs, counts):
source_uv_layer = source_uvs[layer_index] source_uv_layer = source_uvs[layer_index]
for uv in source_uv_layer: for uv in source_uv_layer:
key = generate_uv_key(uv) key = generate_uv_key(uv)
if key not in dest_uv_layer: if key not in dest_uv_layer:
dest_uv_layer[key] = count dest_uv_layer[key] = count
count += 1 count += 1
...@@ -1005,7 +1005,7 @@ def append_non_duplicate_uvs(source_uvs, dest_uvs, counts): ...@@ -1005,7 +1005,7 @@ def append_non_duplicate_uvs(source_uvs, dest_uvs, counts):
def generate_unique_normals_dictionary(mesh_list): def generate_unique_normals_dictionary(mesh_list):
normals_dictionary = {} normals_dictionary = {}
nnormals = 0 nnormals = 0
# Merge meshes, remove duplicate data # Merge meshes, remove duplicate data
for mesh in mesh_list: for mesh in mesh_list:
node = mesh.GetNode() node = mesh.GetNode()
...@@ -1013,7 +1013,7 @@ def generate_unique_normals_dictionary(mesh_list): ...@@ -1013,7 +1013,7 @@ def generate_unique_normals_dictionary(mesh_list):
if len(normal_values) > 0: if len(normal_values) > 0:
for normal in normal_values: for normal in normal_values:
key = generate_normal_key(normal) key = generate_normal_key(normal)
if key not in normals_dictionary: if key not in normals_dictionary:
normals_dictionary[key] = nnormals normals_dictionary[key] = nnormals
nnormals += 1 nnormals += 1
...@@ -1023,14 +1023,14 @@ def generate_unique_normals_dictionary(mesh_list): ...@@ -1023,14 +1023,14 @@ def generate_unique_normals_dictionary(mesh_list):
def generate_unique_colors_dictionary(mesh_list): def generate_unique_colors_dictionary(mesh_list):
colors_dictionary = {} colors_dictionary = {}
ncolors = 0 ncolors = 0
# Merge meshes, remove duplicate data # Merge meshes, remove duplicate data
for mesh in mesh_list: for mesh in mesh_list:
color_values, color_indices = extract_fbx_vertex_colors(mesh) color_values, color_indices = extract_fbx_vertex_colors(mesh)
if len(color_values) > 0: if len(color_values) > 0:
for color in color_values: for color in color_values:
key = generate_color_key(color) key = generate_color_key(color)
if key not in colors_dictionary: if key not in colors_dictionary:
colors_dictionary[key] = ncolors colors_dictionary[key] = ncolors
ncolors += 1 ncolors += 1
...@@ -1067,7 +1067,7 @@ def generate_colors_from_dictionary(colors_dictionary): ...@@ -1067,7 +1067,7 @@ def generate_colors_from_dictionary(colors_dictionary):
def generate_uvs_from_dictionary_layers(uvs_dictionary_layers): def generate_uvs_from_dictionary_layers(uvs_dictionary_layers):
uv_values = [] uv_values = []
for uvs_dictionary in uvs_dictionary_layers: for uvs_dictionary in uvs_dictionary_layers:
uv_values_layer = [] uv_values_layer = []
for key, index in sorted(uvs_dictionary.items(), key = operator.itemgetter(1)): for key, index in sorted(uvs_dictionary.items(), key = operator.itemgetter(1)):
uv_values_layer.append(key) uv_values_layer.append(key)
uv_values.append(uv_values_layer) uv_values.append(uv_values_layer)
...@@ -1138,7 +1138,7 @@ def process_mesh_vertices(mesh_list): ...@@ -1138,7 +1138,7 @@ def process_mesh_vertices(mesh_list):
for mesh in mesh_list: for mesh in mesh_list:
node = mesh.GetNode() node = mesh.GetNode()
mesh_vertices = extract_fbx_vertex_positions(mesh) mesh_vertices = extract_fbx_vertex_positions(mesh)
vertices.extend(mesh_vertices[:]) vertices.extend(mesh_vertices[:])
vertex_offset += len(mesh_vertices) vertex_offset += len(mesh_vertices)
vertex_offset_list.append(vertex_offset) vertex_offset_list.append(vertex_offset)
...@@ -1154,7 +1154,7 @@ def process_mesh_materials(mesh_list): ...@@ -1154,7 +1154,7 @@ def process_mesh_materials(mesh_list):
#TODO: remove duplicate mesh references #TODO: remove duplicate mesh references
for mesh in mesh_list: for mesh in mesh_list:
node = mesh.GetNode() node = mesh.GetNode()
material_count = node.GetMaterialCount() material_count = node.GetMaterialCount()
if material_count > 0: if material_count > 0:
for l in range(mesh.GetLayerCount()): for l in range(mesh.GetLayerCount()):
...@@ -1186,7 +1186,7 @@ def process_mesh_polygons(mesh_list, normals_to_indices, colors_to_indices, uvs_ ...@@ -1186,7 +1186,7 @@ def process_mesh_polygons(mesh_list, normals_to_indices, colors_to_indices, uvs_
flipWindingOrder = True flipWindingOrder = True
poly_count = mesh.GetPolygonCount() poly_count = mesh.GetPolygonCount()
control_points = mesh.GetControlPoints() control_points = mesh.GetControlPoints()
normal_values, normal_indices = extract_fbx_vertex_normals(mesh) normal_values, normal_indices = extract_fbx_vertex_normals(mesh)
color_values, color_indices = extract_fbx_vertex_colors(mesh) color_values, color_indices = extract_fbx_vertex_colors(mesh)
...@@ -1204,7 +1204,7 @@ def process_mesh_polygons(mesh_list, normals_to_indices, colors_to_indices, uvs_ ...@@ -1204,7 +1204,7 @@ def process_mesh_polygons(mesh_list, normals_to_indices, colors_to_indices, uvs_
uv_indices = uv_indices_layers[l] uv_indices = uv_indices_layers[l]
face_uv_indices = generate_uv_indices_for_poly(poly_index, uv_values, uv_indices, uvs_to_indices_list[l]) face_uv_indices = generate_uv_indices_for_poly(poly_index, uv_values, uv_indices, uvs_to_indices_list[l])
face_uv_layers.append(face_uv_indices) face_uv_layers.append(face_uv_indices)
face_vertices = [] face_vertices = []
for vertex_index in range(poly_size): for vertex_index in range(poly_size):
control_point_index = mesh.GetPolygonVertex(poly_index, vertex_index) control_point_index = mesh.GetPolygonVertex(poly_index, vertex_index)
...@@ -1217,7 +1217,7 @@ def process_mesh_polygons(mesh_list, normals_to_indices, colors_to_indices, uvs_ ...@@ -1217,7 +1217,7 @@ def process_mesh_polygons(mesh_list, normals_to_indices, colors_to_indices, uvs_
material_offset = material_offset_list[mesh_index] material_offset = material_offset_list[mesh_index]
vertex_offset = vertex_offset_list[mesh_index] vertex_offset = vertex_offset_list[mesh_index]
if poly_size > 4: if poly_size > 4:
new_face_normals = [] new_face_normals = []
new_face_colors = [] new_face_colors = []
...@@ -1235,7 +1235,7 @@ def process_mesh_polygons(mesh_list, normals_to_indices, colors_to_indices, uvs_ ...@@ -1235,7 +1235,7 @@ def process_mesh_polygons(mesh_list, normals_to_indices, colors_to_indices, uvs_
for layer in face_uv_layers: for layer in face_uv_layers:
new_face_uv_layers.append([layer[0], layer[i+1], layer[i+2]]) new_face_uv_layers.append([layer[0], layer[i+1], layer[i+2]])
face = generate_mesh_face(mesh, face = generate_mesh_face(mesh,
poly_index, poly_index,
new_face_vertices, new_face_vertices,
new_face_normals, new_face_normals,
...@@ -1246,7 +1246,7 @@ def process_mesh_polygons(mesh_list, normals_to_indices, colors_to_indices, uvs_ ...@@ -1246,7 +1246,7 @@ def process_mesh_polygons(mesh_list, normals_to_indices, colors_to_indices, uvs_
flipWindingOrder) flipWindingOrder)
faces.append(face) faces.append(face)
else: else:
face = generate_mesh_face(mesh, face = generate_mesh_face(mesh,
poly_index, poly_index,
face_vertices, face_vertices,
face_normals, face_normals,
...@@ -1269,12 +1269,12 @@ def generate_mesh_face(mesh, polygon_index, vertex_indices, normals, colors, uv_ ...@@ -1269,12 +1269,12 @@ def generate_mesh_face(mesh, polygon_index, vertex_indices, normals, colors, uv_
if materials: if materials:
hasMaterial = True hasMaterial = True
break break
hasFaceUvs = False hasFaceUvs = False
hasFaceVertexUvs = len(uv_layers) > 0 hasFaceVertexUvs = len(uv_layers) > 0
hasFaceNormals = False hasFaceNormals = False
hasFaceVertexNormals = len(normals) > 0 hasFaceVertexNormals = len(normals) > 0
hasFaceColors = False hasFaceColors = False
hasFaceVertexColors = len(colors) > 0 hasFaceVertexColors = len(colors) > 0
faceType = 0 faceType = 0
...@@ -1324,7 +1324,7 @@ def generate_mesh_face(mesh, polygon_index, vertex_indices, normals, colors, uv_ ...@@ -1324,7 +1324,7 @@ def generate_mesh_face(mesh, polygon_index, vertex_indices, normals, colors, uv_
for polygon_uvs in uv_layers: for polygon_uvs in uv_layers:
tmp.append([polygon_uvs[0], polygon_uvs[3], polygon_uvs[2], polygon_uvs[3]]) tmp.append([polygon_uvs[0], polygon_uvs[3], polygon_uvs[2], polygon_uvs[3]])
uv_layers = tmp uv_layers = tmp
for i in range(nVertices): for i in range(nVertices):
index = vertex_indices[i] + vertex_offset index = vertex_indices[i] + vertex_offset
faceData.append(index) faceData.append(index)
...@@ -1355,10 +1355,10 @@ def generate_mesh_face(mesh, polygon_index, vertex_indices, normals, colors, uv_ ...@@ -1355,10 +1355,10 @@ def generate_mesh_face(mesh, polygon_index, vertex_indices, normals, colors, uv_
index = colors[i] index = colors[i]
faceData.append(index) faceData.append(index)
return faceData return faceData
# ##################################################### # #####################################################
# Generate Mesh Object (for scene output format) # Generate Mesh Object (for scene output format)
# ##################################################### # #####################################################
def generate_scene_output(node): def generate_scene_output(node):
mesh = node.GetNodeAttribute() mesh = node.GetNodeAttribute()
...@@ -1373,17 +1373,17 @@ def generate_scene_output(node): ...@@ -1373,17 +1373,17 @@ def generate_scene_output(node):
normals_to_indices = generate_unique_normals_dictionary(mesh_list) normals_to_indices = generate_unique_normals_dictionary(mesh_list)
colors_to_indices = generate_unique_colors_dictionary(mesh_list) colors_to_indices = generate_unique_colors_dictionary(mesh_list)
uvs_to_indices_list = generate_unique_uvs_dictionary_layers(mesh_list) uvs_to_indices_list = generate_unique_uvs_dictionary_layers(mesh_list)
normal_values = generate_normals_from_dictionary(normals_to_indices) normal_values = generate_normals_from_dictionary(normals_to_indices)
color_values = generate_colors_from_dictionary(colors_to_indices) color_values = generate_colors_from_dictionary(colors_to_indices)
uv_values = generate_uvs_from_dictionary_layers(uvs_to_indices_list) uv_values = generate_uvs_from_dictionary_layers(uvs_to_indices_list)
# Generate mesh faces for the Three.js file format # Generate mesh faces for the Three.js file format
faces = process_mesh_polygons(mesh_list, faces = process_mesh_polygons(mesh_list,
normals_to_indices, normals_to_indices,
colors_to_indices, colors_to_indices,
uvs_to_indices_list, uvs_to_indices_list,
vertex_offsets, vertex_offsets,
material_offsets) material_offsets)
# Generate counts for uvs, vertices, normals, colors, and faces # Generate counts for uvs, vertices, normals, colors, and faces
...@@ -1410,7 +1410,7 @@ def generate_scene_output(node): ...@@ -1410,7 +1410,7 @@ def generate_scene_output(node):
normal_values = ChunkedIndent(normal_values, 15, True) normal_values = ChunkedIndent(normal_values, 15, True)
color_values = ChunkedIndent(color_values, 15) color_values = ChunkedIndent(color_values, 15)
faces = ChunkedIndent(faces, 30) faces = ChunkedIndent(faces, 30)
metadata = { metadata = {
'vertices' : nvertices, 'vertices' : nvertices,
'normals' : nnormals, 'normals' : nnormals,
...@@ -1437,7 +1437,7 @@ def generate_scene_output(node): ...@@ -1437,7 +1437,7 @@ def generate_scene_output(node):
return output return output
# ##################################################### # #####################################################
# Generate Mesh Object (for non-scene output) # Generate Mesh Object (for non-scene output)
# ##################################################### # #####################################################
def generate_non_scene_output(scene): def generate_non_scene_output(scene):
mesh_list = generate_mesh_list(scene) mesh_list = generate_mesh_list(scene)
...@@ -1449,17 +1449,17 @@ def generate_non_scene_output(scene): ...@@ -1449,17 +1449,17 @@ def generate_non_scene_output(scene):
normals_to_indices = generate_unique_normals_dictionary(mesh_list) normals_to_indices = generate_unique_normals_dictionary(mesh_list)
colors_to_indices = generate_unique_colors_dictionary(mesh_list) colors_to_indices = generate_unique_colors_dictionary(mesh_list)
uvs_to_indices_list = generate_unique_uvs_dictionary_layers(mesh_list) uvs_to_indices_list = generate_unique_uvs_dictionary_layers(mesh_list)
normal_values = generate_normals_from_dictionary(normals_to_indices) normal_values = generate_normals_from_dictionary(normals_to_indices)
color_values = generate_colors_from_dictionary(colors_to_indices) color_values = generate_colors_from_dictionary(colors_to_indices)
uv_values = generate_uvs_from_dictionary_layers(uvs_to_indices_list) uv_values = generate_uvs_from_dictionary_layers(uvs_to_indices_list)
# Generate mesh faces for the Three.js file format # Generate mesh faces for the Three.js file format
faces = process_mesh_polygons(mesh_list, faces = process_mesh_polygons(mesh_list,
normals_to_indices, normals_to_indices,
colors_to_indices, colors_to_indices,
uvs_to_indices_list, uvs_to_indices_list,
vertex_offsets, vertex_offsets,
material_offsets) material_offsets)
# Generate counts for uvs, vertices, normals, colors, and faces # Generate counts for uvs, vertices, normals, colors, and faces
...@@ -1542,7 +1542,7 @@ def generate_mesh_list(scene): ...@@ -1542,7 +1542,7 @@ def generate_mesh_list(scene):
return mesh_list return mesh_list
# ##################################################### # #####################################################
# Generate Embed Objects # Generate Embed Objects
# ##################################################### # #####################################################
def generate_embed_dict_from_hierarchy(node, embed_dict): def generate_embed_dict_from_hierarchy(node, embed_dict):
if node.GetNodeAttribute() == None: if node.GetNodeAttribute() == None:
...@@ -1573,7 +1573,7 @@ def generate_embed_dict(scene): ...@@ -1573,7 +1573,7 @@ def generate_embed_dict(scene):
return embed_dict return embed_dict
# ##################################################### # #####################################################
# Generate Geometry Objects # Generate Geometry Objects
# ##################################################### # #####################################################
def generate_geometry_object(node): def generate_geometry_object(node):
...@@ -1636,9 +1636,9 @@ def generate_light_object(node): ...@@ -1636,9 +1636,9 @@ def generate_light_object(node):
if light_type == "directional": if light_type == "directional":
# Three.js directional lights emit light from a point in 3d space to a target node or the origin. # Three.js directional lights emit light from a point in 3d space to a target node or the origin.
# When there is no target, we need to take a point, one unit away from the origin, and move it # When there is no target, we need to take a point, one unit away from the origin, and move it
# into the right location so that the origin acts like the target # into the right location so that the origin acts like the target
if node.GetTarget(): if node.GetTarget():
direction = position direction = position
else: else:
...@@ -1646,7 +1646,7 @@ def generate_light_object(node): ...@@ -1646,7 +1646,7 @@ def generate_light_object(node):
scale = FbxVector4(1,1,1,1) scale = FbxVector4(1,1,1,1)
rotation = transform.GetR() rotation = transform.GetR()
matrix = FbxMatrix(translation, rotation, scale) matrix = FbxMatrix(translation, rotation, scale)
direction = matrix.MultNormalize(FbxVector4(0,1,0,1)) direction = matrix.MultNormalize(FbxVector4(0,1,0,1))
output = { output = {
...@@ -1654,7 +1654,7 @@ def generate_light_object(node): ...@@ -1654,7 +1654,7 @@ def generate_light_object(node):
'color': getHex(light.Color.Get()), 'color': getHex(light.Color.Get()),
'intensity': light.Intensity.Get()/100.0, 'intensity': light.Intensity.Get()/100.0,
'direction': serializeVector3( direction ), 'direction': serializeVector3( direction ),
'target': getObjectName( node.GetTarget() ) 'target': getObjectName( node.GetTarget() )
} }
...@@ -1681,7 +1681,7 @@ def generate_light_object(node): ...@@ -1681,7 +1681,7 @@ def generate_light_object(node):
'distance': light.FarAttenuationEnd.Get(), 'distance': light.FarAttenuationEnd.Get(),
'angle': light.OuterAngle.Get()*math.pi/180, 'angle': light.OuterAngle.Get()*math.pi/180,
'exponent': light.DecayType.Get(), 'exponent': light.DecayType.Get(),
'target': getObjectName( node.GetTarget() ) 'target': getObjectName( node.GetTarget() )
} }
...@@ -1704,7 +1704,7 @@ def generate_ambient_light(scene): ...@@ -1704,7 +1704,7 @@ def generate_ambient_light(scene):
} }
return output return output
# ##################################################### # #####################################################
# Generate Camera Node Objects # Generate Camera Node Objects
# ##################################################### # #####################################################
...@@ -1719,7 +1719,7 @@ def generate_default_camera(): ...@@ -1719,7 +1719,7 @@ def generate_default_camera():
'fov': fov, 'fov': fov,
'near': near, 'near': near,
'far': far, 'far': far,
'position': serializeVector3( position ) 'position': serializeVector3( position )
} }
return output return output
...@@ -1727,7 +1727,7 @@ def generate_default_camera(): ...@@ -1727,7 +1727,7 @@ def generate_default_camera():
def generate_camera_object(node): def generate_camera_object(node):
camera = node.GetNodeAttribute() camera = node.GetNodeAttribute()
position = camera.Position.Get() position = camera.Position.Get()
projection_types = [ "perspective", "orthogonal" ] projection_types = [ "perspective", "orthogonal" ]
projection = projection_types[camera.ProjectionType.Get()] projection = projection_types[camera.ProjectionType.Get()]
...@@ -1784,7 +1784,7 @@ def generate_camera_name_list_from_hierarchy(node, camera_list): ...@@ -1784,7 +1784,7 @@ def generate_camera_name_list_from_hierarchy(node, camera_list):
else: else:
attribute_type = (node.GetNodeAttribute().GetAttributeType()) attribute_type = (node.GetNodeAttribute().GetAttributeType())
if attribute_type == FbxNodeAttribute.eCamera: if attribute_type == FbxNodeAttribute.eCamera:
camera_string = getObjectName(node) camera_string = getObjectName(node)
camera_list.append(camera_string) camera_list.append(camera_string)
for i in range(node.GetChildCount()): for i in range(node.GetChildCount()):
generate_camera_name_list_from_hierarchy(node.GetChild(i), camera_list) generate_camera_name_list_from_hierarchy(node.GetChild(i), camera_list)
...@@ -1798,7 +1798,7 @@ def generate_camera_name_list(scene): ...@@ -1798,7 +1798,7 @@ def generate_camera_name_list(scene):
return camera_list return camera_list
# ##################################################### # #####################################################
# Generate Mesh Node Object # Generate Mesh Node Object
# ##################################################### # #####################################################
def generate_mesh_object(node): def generate_mesh_object(node):
mesh = node.GetNodeAttribute() mesh = node.GetNodeAttribute()
...@@ -1827,7 +1827,7 @@ def generate_mesh_object(node): ...@@ -1827,7 +1827,7 @@ def generate_mesh_object(node):
material_names.append('') material_names.append('')
#If this mesh has more than one material, use a proxy material #If this mesh has more than one material, use a proxy material
material_name = getMaterialName( node, True) if material_count > 1 else material_names[0] material_name = getMaterialName( node, True) if material_count > 1 else material_names[0]
output = { output = {
'geometry': getPrefixedName( node, 'Geometry' ), 'geometry': getPrefixedName( node, 'Geometry' ),
...@@ -1841,11 +1841,11 @@ def generate_mesh_object(node): ...@@ -1841,11 +1841,11 @@ def generate_mesh_object(node):
return output return output
# ##################################################### # #####################################################
# Generate Node Object # Generate Node Object
# ##################################################### # #####################################################
def generate_object(node): def generate_object(node):
node_types = ["Unknown", "Null", "Marker", "Skeleton", "Mesh", "Nurbs", "Patch", "Camera", node_types = ["Unknown", "Null", "Marker", "Skeleton", "Mesh", "Nurbs", "Patch", "Camera",
"CameraStereo", "CameraSwitcher", "Light", "OpticalReference", "OpticalMarker", "NurbsCurve", "CameraStereo", "CameraSwitcher", "Light", "OpticalReference", "OpticalMarker", "NurbsCurve",
"TrimNurbsSurface", "Boundary", "NurbsSurface", "Shape", "LODGroup", "SubDiv", "CachedEffect", "Line"] "TrimNurbsSurface", "Boundary", "NurbsSurface", "Shape", "LODGroup", "SubDiv", "CachedEffect", "Line"]
transform = node.EvaluateLocalTransform() transform = node.EvaluateLocalTransform()
...@@ -1872,7 +1872,7 @@ def generate_object(node): ...@@ -1872,7 +1872,7 @@ def generate_object(node):
return output return output
# ##################################################### # #####################################################
# Parse Scene Node Objects # Parse Scene Node Objects
# ##################################################### # #####################################################
def generate_object_hierarchy(node, object_dict): def generate_object_hierarchy(node, object_dict):
object_count = 0 object_count = 0
...@@ -1898,7 +1898,7 @@ def generate_object_hierarchy(node, object_dict): ...@@ -1898,7 +1898,7 @@ def generate_object_hierarchy(node, object_dict):
if node.GetChildCount() > 0: if node.GetChildCount() > 0:
# Having 'children' above other attributes is hard to read. # Having 'children' above other attributes is hard to read.
# We can send it to the bottom using the last letter of the alphabet 'z'. # We can send it to the bottom using the last letter of the alphabet 'z'.
# This letter is removed from the final output. # This letter is removed from the final output.
if option_pretty_print: if option_pretty_print:
object_data['zchildren'] = object_children object_data['zchildren'] = object_children
...@@ -1959,7 +1959,7 @@ def extract_scene(scene, filename): ...@@ -1959,7 +1959,7 @@ def extract_scene(scene, filename):
scene_settings = scene.GetGlobalSettings() scene_settings = scene.GetGlobalSettings()
# This does not seem to be any help here # This does not seem to be any help here
# global_settings.GetDefaultCamera() # global_settings.GetDefaultCamera()
defcamera = camera_names[0] if len(camera_names) > 0 else "" defcamera = camera_names[0] if len(camera_names) > 0 else ""
if option_default_camera: if option_default_camera:
...@@ -2005,7 +2005,7 @@ def extract_scene(scene, filename): ...@@ -2005,7 +2005,7 @@ def extract_scene(scene, filename):
return output return output
# ##################################################### # #####################################################
# Generate Non-Scene Output # Generate Non-Scene Output
# ##################################################### # #####################################################
def extract_geometry(scene, filename): def extract_geometry(scene, filename):
output = generate_non_scene_output(scene) output = generate_non_scene_output(scene)
...@@ -2017,10 +2017,10 @@ def extract_geometry(scene, filename): ...@@ -2017,10 +2017,10 @@ def extract_geometry(scene, filename):
def write_file(filepath, content): def write_file(filepath, content):
index = filepath.rfind('/') index = filepath.rfind('/')
dir = filepath[0:index] dir = filepath[0:index]
#if not os.path.exists(dir): #if not os.path.exists(dir):
#os.makedirs(dir) #os.makedirs(dir)
out = open(filepath, "w") out = open(filepath, "w")
out.write(content.encode('utf8', 'replace')) out.write(content.encode('utf8', 'replace'))
out.close() out.close()
...@@ -2033,9 +2033,9 @@ def read_file(filepath): ...@@ -2033,9 +2033,9 @@ def read_file(filepath):
def copy_textures(textures): def copy_textures(textures):
texture_dict = {} texture_dict = {}
for key in textures: for key in textures:
url = textures[key]['fullpath'] url = textures[key]['fullpath']
#src = replace_OutFolder2inFolder(url) #src = replace_OutFolder2inFolder(url)
#print( src ) #print( src )
...@@ -2043,11 +2043,11 @@ def copy_textures(textures): ...@@ -2043,11 +2043,11 @@ def copy_textures(textures):
if url in texture_dict: # texture has been copied if url in texture_dict: # texture has been copied
continue continue
if not os.path.exists(url): if not os.path.exists(url):
print("copy_texture error: we can't find this texture at " + url) print("copy_texture error: we can't find this texture at " + url)
continue continue
try: try:
index = url.rfind('/') index = url.rfind('/')
if index == -1: if index == -1:
...@@ -2073,7 +2073,7 @@ def findFilesWithExt(directory, ext, include_path = True): ...@@ -2073,7 +2073,7 @@ def findFilesWithExt(directory, ext, include_path = True):
current_ext = os.path.splitext(filename)[1].lower() current_ext = os.path.splitext(filename)[1].lower()
if current_ext == ext: if current_ext == ext:
if include_path: if include_path:
found.append(os.path.join(root, filename)) found.append(os.path.join(root, filename))
else: else:
found.append(filename) found.append(filename)
return found return found
...@@ -2095,11 +2095,11 @@ if __name__ == "__main__": ...@@ -2095,11 +2095,11 @@ if __name__ == "__main__":
elif platform.system() == 'Linux': elif platform.system() == 'Linux':
msg += '"/usr/local/lib/python2.6/site-packages"' msg += '"/usr/local/lib/python2.6/site-packages"'
elif platform.system() == 'Darwin': elif platform.system() == 'Darwin':
msg += '"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages"' msg += '"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages"'
msg += ' folder.' msg += ' folder.'
print(msg) print(msg)
sys.exit(1) sys.exit(1)
usage = "Usage: %prog [source_file.fbx] [output_file.js] [options]" usage = "Usage: %prog [source_file.fbx] [output_file.js] [options]"
parser = OptionParser(usage=usage) parser = OptionParser(usage=usage)
...@@ -2115,15 +2115,15 @@ if __name__ == "__main__": ...@@ -2115,15 +2115,15 @@ if __name__ == "__main__":
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
option_triangulate = options.triangulate option_triangulate = options.triangulate
option_textures = True if not options.notextures else False option_textures = True if not options.notextures else False
option_copy_textures = True if not options.notexturecopy else False option_copy_textures = True if not options.notexturecopy else False
option_prefix = options.prefix option_prefix = options.prefix
option_geometry = options.geometry option_geometry = options.geometry
option_forced_y_up = options.forceyup option_forced_y_up = options.forceyup
option_default_camera = options.defcamera option_default_camera = options.defcamera
option_default_light = options.deflight option_default_light = options.deflight
option_pretty_print = options.pretty option_pretty_print = options.pretty
# Prepare the FBX SDK. # Prepare the FBX SDK.
sdk_manager, scene = InitializeSdkObjects() sdk_manager, scene = InitializeSdkObjects()
...@@ -2143,17 +2143,17 @@ if __name__ == "__main__": ...@@ -2143,17 +2143,17 @@ if __name__ == "__main__":
if option_triangulate: if option_triangulate:
print("\nForcing geometry to triangles") print("\nForcing geometry to triangles")
triangulate_scene(scene) triangulate_scene(scene)
axis_system = FbxAxisSystem.MayaYUp axis_system = FbxAxisSystem.MayaYUp
if not option_forced_y_up: if not option_forced_y_up:
# According to asset's coordinate to convert scene # According to asset's coordinate to convert scene
upVector = scene.GetGlobalSettings().GetAxisSystem().GetUpVector(); upVector = scene.GetGlobalSettings().GetAxisSystem().GetUpVector();
if upVector[0] == 3: if upVector[0] == 3:
axis_system = FbxAxisSystem.MayaZUp axis_system = FbxAxisSystem.MayaZUp
axis_system.ConvertScene(scene) axis_system.ConvertScene(scene)
inputFolder = args[0].replace( "\\", "/" ); inputFolder = args[0].replace( "\\", "/" );
index = args[0].rfind( "/" ); index = args[0].rfind( "/" );
inputFolder = inputFolder[:index] inputFolder = inputFolder[:index]
...@@ -2161,7 +2161,7 @@ if __name__ == "__main__": ...@@ -2161,7 +2161,7 @@ if __name__ == "__main__":
outputFolder = args[1].replace( "\\", "/" ); outputFolder = args[1].replace( "\\", "/" );
index = args[1].rfind( "/" ); index = args[1].rfind( "/" );
outputFolder = outputFolder[:index] outputFolder = outputFolder[:index]
if option_geometry: if option_geometry:
output_content = extract_geometry(scene, os.path.basename(args[0])) output_content = extract_geometry(scene, os.path.basename(args[0]))
else: else:
...@@ -2176,12 +2176,12 @@ if __name__ == "__main__": ...@@ -2176,12 +2176,12 @@ if __name__ == "__main__":
output_path = os.path.join(os.getcwd(), args[1]) output_path = os.path.join(os.getcwd(), args[1])
write_file(output_path, output_string) write_file(output_path, output_string)
if option_copy_textures: if option_copy_textures:
copy_textures( output_content['textures'] ) copy_textures( output_content['textures'] )
print("\nExported Three.js file to:\n%s\n" % output_path) print("\nExported Three.js file to:\n%s\n" % output_path)
# Destroy all objects created by the FBX SDK. # Destroy all objects created by the FBX SDK.
sdk_manager.Destroy() sdk_manager.Destroy()
sys.exit(0) sys.exit(0)
\ No newline at end of file
...@@ -53,7 +53,7 @@ How to use generated JS file in your HTML document ...@@ -53,7 +53,7 @@ How to use generated JS file in your HTML document
function createScene( geometry, materials ) { function createScene( geometry, materials ) {
var mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) ); var mesh = new THREE.Mesh( geometry, new THREE.MultiMaterial( materials ) );
} }
......
...@@ -53,7 +53,7 @@ How to use generated JS file in your HTML document ...@@ -53,7 +53,7 @@ How to use generated JS file in your HTML document
function createScene( geometry, materials ) { function createScene( geometry, materials ) {
var mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) ); var mesh = new THREE.Mesh( geometry, new THREE.MultiMaterial( materials ) );
} }
......
...@@ -132,7 +132,7 @@ function loadGeometry( data, url ) { ...@@ -132,7 +132,7 @@ function loadGeometry( data, url ) {
} }
var material = new THREE.MeshFaceMaterial( data.materials ); var material = new THREE.MultiMaterial( data.materials );
var mesh; var mesh;
if ( data.geometry.animations !== undefined && data.geometry.animations.length > 0 ) { if ( data.geometry.animations !== undefined && data.geometry.animations.length > 0 ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册