Three js - Can you clone animations loaded from a collada file?

北慕城南 提交于 2019-12-10 16:27:07

问题


I'm essentially asking the same question as the one found here - https://github.com/mrdoob/three.js/issues/1883 - Using three js I can import a collada scene with basic keyframe animation and play back those animations easily enough, but would like to copy the animation data from one scene object to another.

Is that possible?

At runtime I've noticed that the collada.animations objects contains a - collada.animations[n].node - which appears to be a THREEJS.Mesh object, which I've been trying to replace at runtime (to no avail). I've also noticed that the collada.animations[n].hierarchy[n] object, also contains node property that looks like this:

cameras: Array[0]
channels: Array[9]
controllers: Array[0]
endTime: 2.5
geometries: Array[1]
id: "name_of_exported_object"
keys: Array[2]
matrix: THREE.Matrix4
name: "name_of_exported_object"
nodes: Array[0]
sid: null
sids: Array[9]
startTime: 0
transforms: Array[5]
type: "NODE"

This object appears, by .name and .id, to be tied to the "name_of_exported_object" which I created with my 3D package (Blender)... I don't quite know what this node object is for. How can I change the collada.animation[n] object sufficiently to use the same animation on a dynamically created scene object?


回答1:


Since this question was written a few years ago, the three.js animation system has been rewritten. You no longer need to "clone" animations, you can simply apply them to other objects using different mixers. Example:

var clip; // some THREE.AnimationClip instance.

var mixer1 = new THREE.AnimationMixer( object1 );
var mixer2 = new THREE.AnimationMixer( object2 );

var action1 = mixer1.clipAction( clip );
var action2 = mixer2.clipAction( clip );

action1.play();
action2.play();

This isn't unique to COLLADA, it works for FBX, glTF, and any other formats that three.js supports animation for.



来源:https://stackoverflow.com/questions/14922462/three-js-can-you-clone-animations-loaded-from-a-collada-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!