Skip to content

Commit

Permalink
JSM: Regenerated jsm files.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Mar 15, 2019
1 parent c6c08f8 commit dbbc0b2
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ GLTFExporter.prototype = {
embedImages: true,
animations: [],
forceIndices: false,
forcePowerOfTwoTextures: false
forcePowerOfTwoTextures: false,
includeCustomExtensions: false
};

options = Object.assign( {}, DEFAULT_OPTIONS, options );
Expand Down Expand Up @@ -373,21 +374,50 @@ GLTFExporter.prototype = {
* Serializes a userData.
*
* @param {Object3D|Material} object
* @returns {Object}
* @param {Object} gltfProperty
*/
function serializeUserData( object ) {
function serializeUserData( object, gltfProperty ) {

if ( Object.keys( object.userData ).length === 0 ) {

return;

}

try {

return JSON.parse( JSON.stringify( object.userData ) );
var json = JSON.parse( JSON.stringify( object.userData ) );

if ( options.includeCustomExtensions && json.gltfExtensions ) {

if ( gltfProperty.extensions === undefined ) {

gltfProperty.extensions = {};

}

for ( var extensionName in json.gltfExtensions ) {

gltfProperty.extensions[ extensionName ] = json.gltfExtensions[ extensionName ];
extensionsUsed[ extensionName ] = true;

}

delete json.gltfExtensions;

}

if ( Object.keys( json ).length > 0 ) {

gltfProperty.extras = json;

}

} catch ( error ) {

console.warn( 'THREE.GLTFExporter: userData of \'' + object.name + '\' ' +
'won\'t be serialized because of JSON.stringify error - ' + error.message );

return {};

}

}
Expand Down Expand Up @@ -1058,11 +1088,7 @@ GLTFExporter.prototype = {

}

if ( Object.keys( material.userData ).length > 0 ) {

gltfMaterial.extras = serializeUserData( material );

}
serializeUserData( material, gltfMaterial );

outputJSON.materials.push( gltfMaterial );

Expand Down Expand Up @@ -1309,8 +1335,6 @@ GLTFExporter.prototype = {

}

var extras = ( Object.keys( geometry.userData ).length > 0 ) ? serializeUserData( geometry ) : undefined;

var forceIndices = options.forceIndices;
var isMultiMaterial = Array.isArray( mesh.material );

Expand Down Expand Up @@ -1352,7 +1376,7 @@ GLTFExporter.prototype = {
attributes: attributes,
};

if ( extras ) primitive.extras = extras;
serializeUserData( geometry, primitive );

if ( targets.length > 0 ) primitive.targets = targets;

Expand Down Expand Up @@ -1732,11 +1756,7 @@ GLTFExporter.prototype = {

}

if ( object.userData && Object.keys( object.userData ).length > 0 ) {

gltfNode.extras = serializeUserData( object );

}
serializeUserData( object, gltfNode );

if ( object.isMesh || object.isLine || object.isPoints ) {

Expand Down Expand Up @@ -1877,6 +1897,8 @@ GLTFExporter.prototype = {

}

serializeUserData( scene, gltfScene );

}

/**
Expand Down

0 comments on commit dbbc0b2

Please sign in to comment.