Thanks for the reply; sorry for the confusion!
A ‘model’ is just a thing in my game, say a humanoid character controlled by the user. In my code that uses three.js, the model is a hierarchy of three.js BoxGeometry
objects, e.g. one for the right forearm, another for the right upper arm, etc. Each of the BoxGeometry
objects is a ‘model object’.
[What’s the standard or common terminology for this?]
I’m procedurally animating the humanoid character by manipulating the skeleton bones. That works fine in terms of producing the expected visual effect of the character moving.
I’d like to calculate collisions with the character and furthermore, calculate collisions with specific model objects, e.g. the BoxGeometry
object for the character’s right forearm.
My initial problem was that, if I moved the character’s right forearm by manipulating the relevant bone, the resulting motion wasn’t applied to the right forearm BoxGeometry
object. I wrote:
For one, the skeleton bones in a sense only affect the model vertices, not the model objects.
Obviously the skeleton bones visually affect the “model objects”. What I was initially surprised to discover was that I couldn’t find any info in the model objects data that they had been affected by the skeleton bones, i.e. the position
of the BoxGeometry
object for the character’s right forearm wasn’t changing even when it was obviously (visually) being animated on the screen.
[Based on my cursory reading of the three.js code, that’s because the effects of ‘skinning’ simply aren’t tracked in the geometry objects. The ‘skinned’ positions are simply calculated by lower-level rendering code.]
So, my code is moving the character’s right forearm by manipulating a bone. That works. But now I want to calculate potential collisions between the forearm object and other objects. How do I determine where in world-space the character’s forearm is? From what I can tell, I have to walk the hierarchy of the character objects and apply the transformations for each of the relevant bones. I think I can do that pretty easily, but only by simplifying the possibilities that the three.js ‘skinning’ features allows.
Again:
For one, the skeleton bones in a sense only affect the model vertices, not the model objects.
This is still probably confusing. My bad!
the skeleton bones in a sense only affect the model vertices
By this, I was just referring to how each vertex in a geometry object has to be associated, via its skinIndices
and skinWeights
properties, with specific bones. Currently, I could associate each vertex with up-to four different bones (and each vertex can be associated with different bones).
… not the model objects
By this, I was referring to the point above about the bones being associated with vertices and also to the point that the “model objects”, e.g. the BoxGeometry
objects in my humanoid character, are not directly associated with any bones.
So, in general, there isn’t any obvious way to determine how transformations made to bones could be applied to an entire BoxGeometry
object. Certainly one could, e.g. calculate the position of the box as the geometrical average of all of its vertices.
But, in my case, AFAICT, I only need or want to use one bone at a time. Thus I can ‘simplify’ (or bypass) the need to solve the general case described above and just assume that, e.g. only one bone is ever ‘rigged’ for any one geometry object. I should then be able to pick any vertex, determine what bone it’s rigged to, and calculate the bone’s transformation to the object itself.
Given all of the above, it seems like I might be better off simply not using the three.js Skeleton
features and, e.g. animating the humanoid character some other way (“bespoke ‘skeleton’ code”).