Skip to content
Merged
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
39 changes: 30 additions & 9 deletions examples/js/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,29 @@ THREE.GLTFExporter.prototype = {

}

/**
* Serializes a userData.
*
* @param {THREE.Object3D|THREE.Material} object
* @returns {Object}
*/
function serializeUserData( object ) {

try {

return JSON.parse( JSON.stringify( object.userData ) );

} catch ( error ) {

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

return {};

}

}

/**
* Process a buffer to append to the default one.
* @param {ArrayBuffer} buffer
Expand Down Expand Up @@ -936,6 +959,12 @@ THREE.GLTFExporter.prototype = {

}

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

gltfMaterial.extras = serializeUserData( material );

}

outputJSON.materials.push( gltfMaterial );

var index = outputJSON.materials.length - 1;
Expand Down Expand Up @@ -1512,15 +1541,7 @@ THREE.GLTFExporter.prototype = {

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

try {

gltfNode.extras = JSON.parse( JSON.stringify( object.userData ) );

} catch ( e ) {

throw new Error( 'THREE.GLTFExporter: userData can\'t be serialized' );

}
gltfNode.extras = serializeUserData( object );

}

Expand Down