mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
102.73k stars 35.38k forks source link

skeletal animations #2329

Closed Cappieh closed 10 years ago

Cappieh commented 12 years ago

hi,

i've been working on a little project for a while now. im trying to create a script that allows users to choose their own set of clothing. so far, i've had a lot of succes. my only problem is that my script is not very efficient. in my script i am creating a character that is build from 6 separate meshes that are combined in a object3D. this works fine, i can set the position of the object 3d very easily, but when i start an animation it has to calculate the skeletal animation of each mesh separately while all the meshes uses the same bones and animation. i think this can be optimized by combining the geometry of each part of clothing in one mesh, instead of using a different mesh for each part of clothing. but im not sure how to do it.

my code so far: http://cappiehproductions.nl/threejs/v6/ (it doesnt seem to work on windows for some reason though :/ )

i think this part of my code can be optimized: http://pastebin.com/0eEjUxJA

apendua commented 12 years ago

@Cappieh Good point! I've been also thinking about this issue. I'm pretty sure, that this can be done by a little hack - an ugly one :D Just overwrite the bones attribute of all your meshes with bones of some "master mesh" and then animate only that one. The framework doesn't allow other solutions so far, and I think that this is pretty much due to the file format which assumes that the topology (geometry) and the bones of a skinned mesh are stored in the same file, which is not always the best thing to do IMHO as shown by your example.

On the other hand, it's always good to ask yourself if using different objects for one character is really what you need in your project. At least from the performance point of view, this should be avoided, I think. If you really need to have interchangeable parts in your model, use different geometries (sic!). You can always create them on the fly with tools like: THREE.GeometryUtils.merge. I'm not sure how this routine deals with all the skinning business, but to me it looks like a minor problem. This approach may not seem very optimal at the beginning, but at least it's clean. After all your'e not going to change your character's outfit 60 times per frame, are you? :)