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

FBX Converter now exports in a ObjectLoader compatible format #9326

Closed
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
70 changes: 69 additions & 1 deletion src/loaders/ObjectLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,58 @@ Object.assign( THREE.ObjectLoader.prototype, {

}

var resolveReferences = function ( material, uuidStack ) {

if ( material.materials !== undefined ) {

for ( var i = 0, l = material.materials.length; i < l; i ++ ) {

var submaterial = material.materials[ i ];

if ( submaterial instanceof THREE.Reference ) {

if ( uuidStack.indexOf( submaterial.uuid ) < 0 ) {

var resolvedMaterial = materials[ submaterial.uuid ];

if ( resolvedMaterial ) {

material.materials[ i ] = resolvedMaterial;

} else {

console.warn( 'THREE.ObjectLoader.parseMaterials: Failed to resolve referenced material', submaterial.uuid );

}

} else {

console.warn( 'THREE.ObjectLoader.parseMaterials: Cyclic material reference detected', submaterial.uuid );

}


} else {

resolveReferences( material, uuidStack.concat( submaterial.uuid ) );

}

}

}

};

for ( var key in materials ) {

if ( materials.hasOwnProperty( key ) ) {

resolveReferences( materials[ key ], [ key ] );

}

}
}

return materials;
Expand Down Expand Up @@ -530,6 +582,12 @@ Object.assign( THREE.ObjectLoader.prototype, {

break;

case 'LineSegments':

object = new THREE.LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );

break;

case 'PointCloud':
case 'Points':

Expand Down Expand Up @@ -566,7 +624,17 @@ Object.assign( THREE.ObjectLoader.prototype, {
} else {

if ( data.position !== undefined ) object.position.fromArray( data.position );
if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );

if ( data.rotation !== undefined ) {

object.rotation.fromArray( data.rotation );

} else if ( data.quaternion !== undefined ) {

object.quaternion.fromArray( data.quaternion );

}

if ( data.scale !== undefined ) object.scale.fromArray( data.scale );

}
Expand Down
47 changes: 47 additions & 0 deletions src/loaders/Reference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @author Benjamin-Dobell / http://glassechidna.com.au/
*/

THREE.Reference = function ( uuid ) {

this.uuid = uuid;
this.type = 'Reference';

};

THREE.Reference.prototype = {

constructor: THREE.Reference,

toJSON: function ( meta ) {

var data = {
metadata: {
version: 4.4,
type: 'Reference',
generator: 'Reference.toJSON'
}
};

data.uuid = this.uuid;
data.type = this.type;

return data;

},

clone: function () {

return new this.constructor().copy( this );

},

copy: function ( source ) {

this.uuid = source.uuid;

return this;

}

};
1 change: 1 addition & 0 deletions utils/build/includes/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"src/loaders/LoadingManager.js",
"src/loaders/BufferGeometryLoader.js",
"src/loaders/MaterialLoader.js",
"src/loaders/Reference.js",
"src/loaders/ObjectLoader.js",
"src/loaders/TextureLoader.js",
"src/loaders/CubeTextureLoader.js",
Expand Down
Loading