[fixed] Triangle selector with animated meshes
[fixed] Triangle selector with animated meshes
Hello.
The problem is that triangle selector uses only single frame (probably frame #0) for detecting collisions.
Simply start 07.Collision example and move mouse near animated mesh scene nodes.
P.S.: checked with trunk rev. 3990.
The problem is that triangle selector uses only single frame (probably frame #0) for detecting collisions.
Simply start 07.Collision example and move mouse near animated mesh scene nodes.
P.S.: checked with trunk rev. 3990.
Re: Triangle selector uses single frame with animated meshes
Since this bug (and the other bug I reported) affects me, I'm I taking a look at the engine source regarding the triangle selector, since I'm sure you guys are busy and have more important parts of the engine to work on.
The reason for this bug is because, the triangle selector gets the mesh for the current frame when the triangle selector is created. But after that, it keeps the same mesh always.
This can be proven by adding the following to the bottom of if (device->isWindowActive()) in example 7:
This will recreate the triangle selector on every frame. The last node created is the far right one, so "node" here refers to that one (the green fella with the helmet and tail).
With this, you will see the collision detection is working correctly with the animation.
According to CTriangleSelector's constructor, it does indeed use the current frame, and not frame 0, hence why recreating the triangle selector every frame solves the problem.
Now, this bug shouldn't be happening because, there's a function CTriangleSelector::update(), which checks if the mesh in the triangle selector is for a different frame, and updates the mesh in the TriangleSelector if necessary.
Now the problem:
There are three getTriangles() functions:
But if you look at the code for them, only the first one actually calls update() at the start!
The example 7 uses both the 2nd and 3rd getTriangles() functions at different times, hence, the mesh is never updated.
So you need to add this to the start of the 2nd and 3rd getTriangles functions:
Also, the constructors should be updated, so that they will initialize the variable "LastMeshFrame"
For this constructor
I'd recommend maybe this:
Change:
To:
This way the LastMeshFrame is initialized from the beginning. Otherwise, the variable isn't initialized, and update() will always be called an extra time the first time, even if the mesh didn't change (since it checks if the animated scene node's current frame = LastMeshFrame)
For the other constructors, if I understand correctly, I think initializing this variable is not necessary, since it wont actually be used. Still, I think its good practice to initialize it on all constructors anyway, and prevents overlooking it if the code is touched again later.
Anyway, that will solve this problem. My problem still isnt solved yet, will look into that now and post in the thread I created if I find something.
The reason for this bug is because, the triangle selector gets the mesh for the current frame when the triangle selector is created. But after that, it keeps the same mesh always.
This can be proven by adding the following to the bottom of if (device->isWindowActive()) in example 7:
Code: Select all
selector = smgr->createTriangleSelector(node);
node->setTriangleSelector(selector);
selector->drop();
With this, you will see the collision detection is working correctly with the animation.
According to CTriangleSelector's constructor, it does indeed use the current frame, and not frame 0, hence why recreating the triangle selector every frame solves the problem.
Now, this bug shouldn't be happening because, there's a function CTriangleSelector::update(), which checks if the mesh in the triangle selector is for a different frame, and updates the mesh in the TriangleSelector if necessary.
Now the problem:
There are three getTriangles() functions:
Code: Select all
//! Gets all triangles.
void CTriangleSelector::getTriangles(core::triangle3df* triangles,
s32 arraySize, s32& outTriangleCount,
const core::matrix4* transform) const
Code: Select all
//! Gets all triangles which lie within a specific bounding box.
void CTriangleSelector::getTriangles(core::triangle3df* triangles,
s32 arraySize, s32& outTriangleCount,
const core::aabbox3d<f32>& box,
const core::matrix4* transform) const
Code: Select all
//! Gets all triangles which have or may have contact with a 3d line.
void CTriangleSelector::getTriangles(core::triangle3df* triangles,
s32 arraySize, s32& outTriangleCount,
const core::line3d<f32>& line,
const core::matrix4* transform) const
The example 7 uses both the 2nd and 3rd getTriangles() functions at different times, hence, the mesh is never updated.
So you need to add this to the start of the 2nd and 3rd getTriangles functions:
Code: Select all
// Update my triangles if necessary
update();
For this constructor
Code: Select all
CTriangleSelector::CTriangleSelector(IAnimatedMeshSceneNode* node)
: SceneNode(reinterpret_cast<ISceneNode*>(node)), AnimatedNode(node)
{
Change:
Code: Select all
IMesh * mesh = animatedMesh->getMesh((s32)AnimatedNode->getFrameNr());
Code: Select all
LastMeshFrame = (s32)AnimatedNode->getFrameNr();
IMesh * mesh = animatedMesh->getMesh(LastMeshFrame);
For the other constructors, if I understand correctly, I think initializing this variable is not necessary, since it wont actually be used. Still, I think its good practice to initialize it on all constructors anyway, and prevents overlooking it if the code is touched again later.
Anyway, that will solve this problem. My problem still isnt solved yet, will look into that now and post in the thread I created if I find something.
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Re: Triangle selector uses single frame with animated meshes
Hmm, okay. That explains why I always thought that this is working. It was just bugged due to the changes I made to triangle selectors a few weeks ago. Anyway, I also changed the initialization in 1.7 which still had a rpoper update for all triangle selector calls. So I'll call this one fixed and we have to find out why your setup is different from this one.
Re: [fixed] Triangle selector with animated meshes
So what´s the status with calling update, is it necessary or handled internally under 1.7.3 and 1.8?
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
Re: [fixed] Triangle selector with animated meshes
Wow! And all the time I was thinking that feature was not supported and I had to resort to "collision boxes" attached to the bones...
So if this is "fixed" we could check collision on a skinned animated mesh?
Done some tests on skinned animated meshes (doors) (Irrlicht 1.8.0) and the collision is only detected at the idle frame (when I created the collision triangles) Could we "buffer" thoses triangles selectors (metatriangleselector style) so when we reach a certain frame, there would not be CPU overhead to get to the collision triangle?
So if this is "fixed" we could check collision on a skinned animated mesh?
Done some tests on skinned animated meshes (doors) (Irrlicht 1.8.0) and the collision is only detected at the idle frame (when I created the collision triangles) Could we "buffer" thoses triangles selectors (metatriangleselector style) so when we reach a certain frame, there would not be CPU overhead to get to the collision triangle?
Re: [fixed] Triangle selector with animated meshes
I think (not tested right now) it should update when you use node->setTriangleSelector for the triangleselector which you have created.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: [fixed] Triangle selector with animated meshes
the docs say that update must be called after animation frame changes...
Re: [fixed] Triangle selector with animated meshes
CTriangleSelector::Update is called automatically each time getTriangles is called now (that was the bugfix mentioned above).
Not sure right now - where in the docs does it tell that some update should be called manually?
@christianclavet: There's no cache so far. Caching the 'Triangles' in CTriangleSelector might indeed be an useful feature. But you wrote like it does not work at all right now?
Not sure right now - where in the docs does it tell that some update should be called manually?
@christianclavet: There's no cache so far. Caching the 'Triangles' in CTriangleSelector might indeed be an useful feature. But you wrote like it does not work at all right now?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: [fixed] Triangle selector with animated meshes
saw it in the header last week... I´ll try to find it.
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
Re: [fixed] Triangle selector with animated meshes
Hi!
@CuteAlien:
Perhaps I do it all wrong. I did not manually update the triangle selector in 1.8.0 and the collision was not working on an animated model (door was skinned and animated to open). Perhaps if I update manually the triangle selector of all my models at each update would fix the problem.
@CuteAlien:
Perhaps I do it all wrong. I did not manually update the triangle selector in 1.8.0 and the collision was not working on an animated model (door was skinned and animated to open). Perhaps if I update manually the triangle selector of all my models at each update would fix the problem.
Re: [fixed] Triangle selector with animated meshes
There should be no need to update manually. It's just important to call setTriangleSelector for the node I think. At least I see no reason for a manual update when looking at the code, I guess I'd have to write a test-case to be certain.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm