Similar, but different, objects being picked

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

Similar, but different, objects being picked

Postby LunaRebirth » Sun Jun 11, 2017 3:02 am

Hello,

I'm having an issue where when I do something for an object that is the same mesh as another object, it does that thing for both.
So for example, I'm using the code:
cpp Code: Select all
IAnimatedMeshSceneNode* Mouse::getMesh()
{
    core::line3d<f32> ray = Game::smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(Game::device->getCursorControl()->getPosition());
    core::vector3df intersection;
    core::triangle3df hitTriangle;
    scene::IAnimatedMeshSceneNode * selectedSceneNode =
        (IAnimatedMeshSceneNode*)Game::smgr->getSceneCollisionManager()->getSceneNodeAndCollisionPointFromRay(
                ray,
                intersection, // This will be the position of the collision
                hitTriangle, // This will be the triangle hit in the collision
                0, // This ensures that only nodes that we have
                        // set up to be pickable are considered
                0); // Check the entire scene (this is actually the implicit default)
 
    return selectedSceneNode;
}

to get the node at click position.

Then if I use code
cpp Code: Select all
Game::smgr->getMeshManipulator()->setVertexColors(Mouse::getMesh(), SColor(255,255,255,255));

to set the color to white, it will set all objects that are similar, but not the same object, to white.

Similarly, if I update the bone position of one mesh, the bones of all the other meshes will also update.
So if I set the animation loop on one object to be a running motion, all other similar models will also do the run loop when they shouldn't.

Take this picture for example,
Only one head mesh should be green, not both.

If one starts walking, the other also starts walking in place.
Last edited by LunaRebirth on Tue Jul 11, 2017 4:51 pm, edited 1 time in total.
LunaRebirth
 
Posts: 301
Joined: Sun May 11, 2014 12:13 am

Re: Similar, but different, objects being picked

Postby CuteAlien » Sun Jun 11, 2017 10:13 am

OK, I have to admit I'm somewhat shocked now. I always thought that was only complicated - didn't realize Irrlicht didn't allow copying of animated meshes at all. You can have different animations (you have to set setFrameLoop for each node to it's own values - if you set one to (0,0) it will not be animated even if other nodes are animated).

But creating real copies of animated meshes doesn't seem to be possible -simply a big missing feature in Irrlicht :-(
I had split my meshes in the past in a base-mesh and a mesh containing the skeleton animations - so I kinda automatically worked around that and didn't even notice this.

One workaround - kick the mesh out of the meshcache, but grab() it first so you keep it in memory. Then you can load it again and get a real copy. Second workaround - check-out new svn trunk of Irrlicht (will merge into ogl-es soon, probably later today). I just modified getMesh function -you can now pass an alternative cacheName. So you can create copies on loading. It's not perfect (it loads the mesh again each time), but at least somewhat better than first workaround.

And well - I guess creating copies of all the animated mesh formats with mesh-manipulator (or clone() functions for animated meshes) is a todo now. But sounds like a big task. Anyone else interested in doing that maybe?

edit: Oh my - I think your problem will still not be solved. Because you don't get the base-mesh - only the current copy of the animated mesh. Which would mean you would have to set colors each frame (very expensive...).
You probably have a skinned mesh - so I think (not tested) you have to cast to ISkinnedMesh and then use getMeshBuffers() to get the non-animated base-mesh. And that's the one you probably want to change.
IRC: #irrlicht on irc.freenode.net
Code snippets, patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Free racer created with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
User avatar
CuteAlien
Admin
 
Posts: 8362
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Similar, but different, objects being picked

Postby LunaRebirth » Sun Jun 11, 2017 4:53 pm

Hmm, that's too bad.

Unfortunately setting the animation for other objects did not solve the issue for all dudes walking in place.
It might be because I'm animating their bones with setJointMode(EJUOR_CONTROL) and controlling them each frame (setting bones a child of another bone crashes irrlicht) like so:
cpp Code: Select all
for (int x = 0; x < this->children.size(); x++) {
      IAnimatedMeshSceneNode* m = this->children[x];
      for (int i = 0; i < this->b->getJointCount(); i++) {
          IBoneSceneNode* thisB = this->b->getJointNode(i);
          if (!thisB)
              continue;
          char* name = (char*)thisB->getName();
 
          IBoneSceneNode* mB = m->getJointNode(name);
          if (!mB)
              continue;
 
          mB->setPosition(thisB->getPosition());
          mB->setRotation(thisB->getRotation());
      }
}
LunaRebirth
 
Posts: 301
Joined: Sun May 11, 2014 12:13 am

Re: Similar, but different, objects being picked

Postby CuteAlien » Sun Jun 11, 2017 6:08 pm

Hm, could be. But if you want to change thiings you have to work with mesh-copies anyway. So better to use the new function (loading a new mesh for each copy you need). Can later (one day...) be optimized by copying meshes in memory after loading.
IRC: #irrlicht on irc.freenode.net
Code snippets, patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Free racer created with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
User avatar
CuteAlien
Admin
 
Posts: 8362
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Similar, but different, objects being picked

Postby LunaRebirth » Sun Jun 11, 2017 9:58 pm

Thanks, removing it from mesh cache seemed to work.
LunaRebirth
 
Posts: 301
Joined: Sun May 11, 2014 12:13 am

Re: Similar, but different, objects being picked

Postby LunaRebirth » Wed Aug 16, 2017 4:42 am

I hadn't have this issue continue to happen until last night.
Looks like it started to happen after I ran in release mode instead of debug.

If I Sleep(100) after setting a mesh, the issue is solved. Otherwise, it seems Irrlicht still can't tell two IAnimatedMeshSceneNode's apart when they use the same mesh, even after removing it from cache.
LunaRebirth
 
Posts: 301
Joined: Sun May 11, 2014 12:13 am

Re: Similar, but different, objects being picked

Postby CuteAlien » Wed Aug 16, 2017 9:30 am

Mesh-cache doesn't have any timers. Only timer I know about in regards to meshbuffers are hardware buffers on the graphic card. But you shouldn't have those yet directly after loading a mesh.

I also noticed btw that you can rename meshes in the mesh-cache, so no need to remove them.
IRC: #irrlicht on irc.freenode.net
Code snippets, patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Free racer created with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
User avatar
CuteAlien
Admin
 
Posts: 8362
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Similar, but different, objects being picked

Postby hendu » Wed Aug 16, 2017 4:59 pm

You really should use shaders to set such per-object colors and other visible attributes. No mesh duplication or costly memory operations.
hendu
 
Posts: 2587
Joined: Sat Dec 18, 2010 12:53 pm

Re: Similar, but different, objects being picked

Postby LunaRebirth » Wed Aug 16, 2017 11:34 pm

CuteAlien wrote:I also noticed btw that you can rename meshes in the mesh-cache, so no need to remove them.


Cool that worked. Removing only did after Sleep()'ing
LunaRebirth
 
Posts: 301
Joined: Sun May 11, 2014 12:13 am

Re: Similar, but different, objects being picked

Postby LunaRebirth » Wed Aug 16, 2017 11:35 pm

hendu wrote:You really should use shaders to set such per-object colors and other visible attributes. No mesh duplication or costly memory operations.


I'll definitely look into that. Thanks
LunaRebirth
 
Posts: 301
Joined: Sun May 11, 2014 12:13 am


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest