Skip to content
Merged
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
10 changes: 7 additions & 3 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ class GLTFWriter {
/**
* Serializes a userData.
*
* @param {THREE.Object3D|THREE.Material} object
* @param {THREE.Object3D|THREE.Material|THREE.BufferGeometry|THREE.AnimationClip} object
* @param {Object} objectDef
*/
serializeUserData( object, objectDef ) {
Expand Down Expand Up @@ -2279,11 +2279,15 @@ class GLTFWriter {

}

json.animations.push( {
const animationDef = {
name: clip.name || 'clip_' + json.animations.length,
samplers: samplers,
channels: channels
} );
};

this.serializeUserData( clip, animationDef );

json.animations.push( animationDef );

return json.animations.length - 1;

Expand Down
8 changes: 6 additions & 2 deletions examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2376,7 +2376,7 @@ function addUnknownExtensionsToUserData( knownExtensions, object, objectDef ) {
/**
*
* @private
* @param {Object3D|Material|BufferGeometry|Object} object
* @param {Object3D|Material|BufferGeometry|Object|AnimationClip} object
* @param {GLTF.definition} gltfDef
*/
function assignExtrasToUserData( object, gltfDef ) {
Expand Down Expand Up @@ -4213,7 +4213,11 @@ class GLTFParser {

}

return new AnimationClip( animationName, undefined, tracks );
const animation = new AnimationClip( animationName, undefined, tracks );

assignExtrasToUserData( animation, animationDef );

return animation;

} );

Expand Down
19 changes: 17 additions & 2 deletions src/animation/AnimationClip.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ class AnimationClip {
*/
this.uuid = generateUUID();

/**
* An object that can be used to store custom data about the animation clip.
* It should not hold references to functions as these will not be cloned.
*
* @type {Object}
*/
this.userData = {};

// this means it should figure out its duration by scanning the tracks
if ( this.duration < 0 ) {

Expand Down Expand Up @@ -98,6 +106,8 @@ class AnimationClip {
const clip = new this( json.name, json.duration, tracks, json.blendMode );
clip.uuid = json.uuid;

clip.userData = JSON.parse( json.userData || '{}' );

return clip;

}
Expand All @@ -120,7 +130,8 @@ class AnimationClip {
'duration': clip.duration,
'tracks': tracks,
'uuid': clip.uuid,
'blendMode': clip.blendMode
'blendMode': clip.blendMode,
'userData': JSON.stringify( clip.userData ),

};

Expand Down Expand Up @@ -515,7 +526,11 @@ class AnimationClip {

}

return new this.constructor( this.name, this.duration, tracks, this.blendMode );
const clip = new this.constructor( this.name, this.duration, tracks, this.blendMode );

clip.userData = JSON.parse( JSON.stringify( this.userData ) );

return clip;

}

Expand Down
Loading