{"action":"created","issue":{"url":"https://api.github.com/repos/mrdoob/three.js/issues/6881","labels_url":"https://api.github.com/repos/mrdoob/three.js/issues/6881/labels{/name}","comments_url":"https://api.github.com/repos/mrdoob/three.js/issues/6881/comments","events_url":"https://api.github.com/repos/mrdoob/three.js/issues/6881/events","html_url":"https://github.com/mrdoob/three.js/issues/6881","id":96145899,"number":6881,"title":"Untangling the ThreeJS animation structure","user":{"login":"bhouston","id":588541,"avatar_url":"https://avatars.githubusercontent.com/u/588541?v=3","gravatar_id":"","url":"https://api.github.com/users/bhouston","html_url":"https://github.com/bhouston","followers_url":"https://api.github.com/users/bhouston/followers","following_url":"https://api.github.com/users/bhouston/following{/other_user}","gists_url":"https://api.github.com/users/bhouston/gists{/gist_id}","starred_url":"https://api.github.com/users/bhouston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhouston/subscriptions","organizations_url":"https://api.github.com/users/bhouston/orgs","repos_url":"https://api.github.com/users/bhouston/repos","events_url":"https://api.github.com/users/bhouston/events{/privacy}","received_events_url":"https://api.github.com/users/bhouston/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mrdoob/three.js/labels/Enhancement","name":"Enhancement","color":"deffdb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-07-20T19:57:40Z","updated_at":"2015-07-23T20:21:03Z","closed_at":null,"body":"Been looking at modernizing/formalizing the ThreeJS animation framework to be more similar to Unity/Unreal Engine 4.  There is a lot of great code in ThreeJS but there is a bit of missing top level organization of animation structures, rather there is a lot of duplication.\r\n\r\nHere are the classes I've been studying today:\r\n\r\n- SkinnedMesh - derived from Mesh, adds support for array of Bone and Skeleton\r\n\r\nThe AnimationHandler/Animation pair:\r\n\r\n- AnimationHandler - a global object for creating and advancing playing Animation\r\n- Animation - a hierarchy of keyframe animation tracks usually used for bones on a skinned mesh, closely linked to AnimationHandler.\r\n\r\nThe following is not compatible with the Animation/AnimationHandler framework:\r\n\r\n- KeyframeAnimation - AnimationHandler independent Keyframe track, only used by Collada example.\r\n- MorphAnimation - AnimationHandler independent MorphTarget animation, only used by *morphtargets_horse.html examples.\r\n\r\nThe following combine scheduling of animations with meshes/mesh hierarchies:\r\n\r\n- BlendCharacter - SkinnedMesh + Animation Scheduler (sometimes used with manually animated morph targets, such as in webgl_animation_skinning_morph.html)\r\n- MorphAnimMesh - single Morph Target animation (for simple repeating things.)\r\n- MorphBlendMesh - multiple Morph Target  animation blending (meshes that change between morph target animations.)\r\n- UCSCharacter - SkinnedMesh + Animation (only used in webgl_morphtargets_human.html)\r\n- MD2Character - A bunch of MorphAnimMeshes (used only in webgl_morphtargets_md2.html)\r\n- MD2Charactercomplex - A bunch of MorphBlendMeshes (used only in webgl_morphtargets_md2_control.html)\r\n\r\nI'm trying to think of a way of reducing all of these classes into a clearer structure.\r\n\r\nI think a structure similar to this might be the way forward:\r\n\r\n- Track - a keyframe animation that contains a name, a set of keys that are composed of times and values.  Keys can be weights, or pos/rot/scale.  The name of the track can refer to morphTargets or bones/nodes or possibly other values within a node.  (We could even abstract Track to not be keyframed, it could be equation based as well if we get the interface right.)\r\n- Clip - a set of tracks with a name, duration.  An animation sequence, such as blink, walk, jump, etc.  Can be a morph or a keyframe or maybe both.  Similar to [Unity's AnimationClip class](http://docs.unity3d.com/ScriptReference/AnimationClip.html)\r\n- Action - a clip that is being played.  Would be associated with a root node to which the Track names would be relative.  Would have a blend weight associated with it and can be queued into animation system.  Could optionally loop and have a play speed.  (Will likely require more parameters for various edge cases.)  Similar to [Unity's AnimationState class](http://docs.unity3d.com/ScriptReference/AnimationState.html)\r\n- Mixer - a container for a number of actions.  Would be responsible for applying the actions to the hierarchy -- it would be sort of like AnimationHandler, it could be global or there could be multiple -- I'm open on this case.  It would be responsible for blending between actions.\r\n- Animator - a higher level structure on top of Mixer that would contain the logic to do things like walk, run, jump, it would do that by managing what actions are queued up and how they are blended between in order to create a smooth result.  (Will have to be easy to extend to support new entity behaviors.)  Similar to [Unity's Animator class](http://docs.unity3d.com/ScriptReference/Animator.html)\r\n\r\nI would get rid of AnimationHandler, Animation (replaced by Clip/Track), KeyframeAnimation  (replaced by Track), MorphAnimation  (replaced by Track), BlendCharacter (replaced by Mixer/Clip/Track), MorphAnimMesh (replaced by Mixer/Clip/Track), MorphBlendMesh (replaced by Animator/Mixer/Clip/Track), USCCharacter, MD2Character, MD2CharacterComplex (replaced by Animator/Mixer/Clip/Track), or at least deprecate them in favor for the Track/Clip/Action/Mixer/Animator design, and this design could drive any objects in ThreeJS, including Materials, Lights and Cameras, if you so desired.\r\n\r\nBasically this is a more flexible and actually simpler design.\r\n\r\nThe above is very similar to Unity/Unreal Engine."},"comment":{"url":"https://api.github.com/repos/mrdoob/three.js/issues/comments/124228763","html_url":"https://github.com/mrdoob/three.js/issues/6881#issuecomment-124228763","issue_url":"https://api.github.com/repos/mrdoob/three.js/issues/6881","id":124228763,"user":{"login":"bhouston","id":588541,"avatar_url":"https://avatars.githubusercontent.com/u/588541?v=3","gravatar_id":"","url":"https://api.github.com/users/bhouston","html_url":"https://github.com/bhouston","followers_url":"https://api.github.com/users/bhouston/followers","following_url":"https://api.github.com/users/bhouston/following{/other_user}","gists_url":"https://api.github.com/users/bhouston/gists{/gist_id}","starred_url":"https://api.github.com/users/bhouston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhouston/subscriptions","organizations_url":"https://api.github.com/users/bhouston/orgs","repos_url":"https://api.github.com/users/bhouston/repos","events_url":"https://api.github.com/users/bhouston/events{/privacy}","received_events_url":"https://api.github.com/users/bhouston/received_events","type":"User","site_admin":false},"created_at":"2015-07-23T20:21:03Z","updated_at":"2015-07-23T20:21:03Z","body":"One other Track type could be a Procedural / Equation Track type.  Basically something like ```getAt( time ) { return Math.cos( time ); }```."}}