I have a couple of questions about animated meshes. I would normally look at the code, but don’t have that option right now…
Does the raycast method take into account the animation currently applied to mesh at that time. For instance, with the Ogre model running his feet are in different positions - would the raycast sometimes hit and sometimes not depending on the state of that animation?
At what point is the mesh actually updated? Is it in the controlUpdate method, or is there a subsequent method that actually applies the deformation calculated in this?
Regarding #1, it is not exactly true. The collision tree will only get generated once on the first raycast. Unfortunately we have yet to implement an efficient collision algorithm for animated models.
Sorry for taking so long to respond, been trying to implement stepped animations into my game.
So, if I understand correctly, if I have a skeletal animation deforming a mesh to wave an arm, the ray trace will not actually detect a collision with where the arm is, but rather where the arm was when the first ray was cast?
Is there any way I can incorporate animated movements into the collision behaviour, even only if with bounding boxes?
mattm said:
Sorry for taking so long to respond, been trying to implement stepped animations into my game.
So, if I understand correctly, if I have a skeletal animation deforming a mesh to wave an arm, the ray trace will not actually detect a collision with where the arm is, but rather where the arm was when the first ray was cast?
Is there any way I can incorporate animated movements into the collision behaviour, even only if with bounding boxes?
Matt
You can force the bounding box to update via Mesh.updateBound() or Spatial.updateModelBound()
So after calling updateModelBound will a ray trace collision be calculated for the new mesh shape. If not, is there a ray trace I can use that does just the bounding boxes?
I am recreating a scene from a particular point in time. I use this to determine if I hit anything.
To do this I:
Move the node containing the mesh to the point it was at that time
Apply the animation that was present at that time
The I need to call updateModelBound() to get the new bounds as present after the animation, correct?
If I then want to do the raycast there and then (not wait for an update call) I think I then need to update the geometric state of my node to apply the new model bounds to the world bounds - is this correct? Otherwise it seems the ray will not even consider a possible collision?
I know this is not the normal way to do things, but I need to do this (or something like it) so I can see if a shot hit ‘in the past’ so to speak.
Thanks for all the help, I will get there eventually!
Fantastic. And looking at the code if I call this on a node it then calls the method on the children under it so I end up with an updated model with the bounds representing the new animated position, brilliant!
One final, final, question on the matter…
Is there anyway, using a raytrace, that I can tell the ray to stop if it collides with the bounding box, i.e. not bother with the rather more expensive actual mesh check? I know I can do this by building a ‘bounding box’ version of the model and doing it my self, but don’t want to reinvent the wheel slightly squarer if there is already a perfectly round one…or something like that!
Ok, I think I am confusing myself here. Would it be to re-cap what I think/have done…
On a node not attached to the root node I want to reconstruct a scene as it was at time t in order to see if a shot fired then hits. I have the animation times and positions of the object at this time. So I do the following:
I move the mesh to required point, with the required rotation.
I apply an animation to the mesh and force updateControl to be called. This deforms the mesh. However, because there is no required refresh for them the bounding boxes of the mesh are not redrawn and therefore still represent the un-animated mesh.
If I fire a ray now it may not collide even if it passes through the mesh as the bounding boxes are not aligned with where the mesh is.
I call spatial.updateModelBounds and then getWorldBounds. The first of these forces a refresh of the bounds, allowing the second call to do its work and correctly update the bounding boxes.
When I now fire the ray I get the expected collision behaviour, including collision of the actual mesh.
is the above correct? it seems to fit with what I have observed. If this is the case that is great, I can go with that. If not what have I misunderstood (or, if it is shorter, what have I understood :O)!
But if I don’t call something to then update the world bounds any collisions are eliminated at the first step it does not intersect the world bounds (which are no longer in line with the model bounds)!
Sorry, I just realised I may have been talking utter rubbish. I need to look at what is happening more closely as sometimes it seems to work fine and others it does not.
In all this testing etc I think I may have forgotten an important point. Will the raycast use the actual mesh positions after the animation has been applied, or will only the bounding boxes be updated? Really sorry for going over this yet again, but I am struggling to explain what I am observing with my test cases!
I think I have answered my own question. Only the bounding volumes are update w.r.t the ray. The ray always uses the first mesh position when calculating its actual vertices hits. So you can in the changing bounding volume with the ray cast, but not the changing mesh? Does that sound correct?
I’m not sure I understand the question. Animated meshes are the best way to animate a character so I want to use them. I would then like what the players are seeing to represent what they hit, to within reason. I am happy to use just the bounding volumes if that is the way JMonkey currently works, it just means that I will have to define my meshes with that in mind so the bounding volumes fit with the limbs etc.