Can the method: updateFromMesh could be exposed?

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Can the method: updateFromMesh could be exposed?

Post by christianclavet »

Hi, I'm modifying a mesh in real time, by accessing the meshbuffer and and changing the vertices position. This work ok, but I have to recreate the triangle selector each time so that the "brush" I'm using does the proper collision test with it. I was able to reduce a lot by using approximate position while modifiying the shape. But the reference is "ugly" when I use this.

The "best" solution would be to update the triangle selector while I edit the mesh vertices. I just found in the source that you have exactly what is needed for that purpose:

Code: Select all

void CTriangleSelector::updateFromMesh(const IMesh* mesh) const
from CTriangleSelector.cpp

The way it's used now, it to update the buffer when the animated mesh change the vertices position. So exactly what I'm doing, but manually.

Looking at the source again in CTriangleSelector.h, I see that the method is made protected.

Code: Select all

protected:
    //! Create from a mesh
    virtual void createFromMesh(const IMesh* mesh);
 
    //! Update when the mesh has changed
    virtual void updateFromMesh(const IMesh* mesh) const;
Could you expose updateFromMesh to public so I could call it manually, when I change the vertices on my model and want to update the triangle selector?
chronologicaldot
Competition winner
Posts: 688
Joined: Mon Sep 10, 2012 8:51 am

Re: Can the method: updateFromMesh could be exposed?

Post by chronologicaldot »

Possible solutions:
a) You could try changing the method to public and compile the engine yourself to see if it works.
b) You could inherit the class with a new one and make a wrapper method that exposes the method.
c) You might also consider rewriting the class with the desired method exposed.
The class in general apparently needs work since the comment at the top of the class reads:

Code: Select all

 
//! Stupid triangle selector without optimization
 
-_-
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Can the method: updateFromMesh could be exposed?

Post by christianclavet »

chronologicaldot wrote:Possible solutions:
a) You could try changing the method to public and compile the engine yourself to see if it works.
b) You could inherit the class with a new one and make a wrapper method that exposes the method.
c) You might also consider rewriting the class with the desired method exposed.
The class in general apparently needs work since the comment at the top of the class reads:

Code: Select all

 
//! Stupid triangle selector without optimization
 
-_-
Hi, Thanks! Method A was my first idea, but since the project will be worked on for a couple of year, I think if the Irrlicht team would change it and if it can serve other projects, It's worth a try to ask. If I'm starting to patch all around the Irrlicht code, I will have to maintain theses patches until the end of the project, and I want to update the Irrlicht libs when each new version will come out.

Your method B look very interesting, is there some example on how to wrap a method and have the new class do the same thing as the old class? I think I know how to inherit a class, but changing a method and wrap it... not sure. I could perhaps add a new method in PUBLIC that is a copy of the protected method? Anyway it's really a good direction, until the Irrlicht devs will decide if they change it or not.

I use the triangle selector for about everything in the project. Don't seem to be so non-optimized... Perhaps they forgot to remove that comment.
If something that could be improved, perhaps would be the ray collision test, seem to be expansive.. Wonder if there something that could be done so the test take less time. I'm using a lot of these tests and it has proven to be much faster than using the collision response animator (with less precision). Could a ray test be done with the GPU?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Can the method: updateFromMesh could be exposed?

Post by CuteAlien »

Hm, I needed that half a year ago in my job, but seems I found some other way to do whatever I wanted to do and removed it from my todo again *sigh*. My idea for a solution back then was to add 2 dirty flags:

ITriangleSelector::setTriangleCountDirty();
ITriangleSelector::setTrianglePlacementDirty();

First one to rebuild triangles completely, second one would only update position (no new memory allocations).

Would that sound ok for your case?

I think the reason I preferred dirty flags to exposing the interface was that not all triangleselectors had those update and create functions. Although thinking about it now I would probably prefer having functions. I'll have to look at this stuff once more... been too long.
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
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Can the method: updateFromMesh could be exposed?

Post by christianclavet »

Hi CuteAlien!

Anything that could "update" the triangle selector when the geometry is being modified would be appreciated!
First one to rebuild triangles completely, second one would only update position (no new memory allocations)
By updating position you mean update the vertices position?

Is there some kind of "match" between the indices (vertices) in the triangle selector and in the mesh geometry? Having a direct access to to them (vertices) and if they would match the geometry would permit to update only the changed vertices (delta). This could also be used in vertice animations when we only store the "delta" of the vertices and this "delta" information would be used to change the geometry of the triangle selector....

I don't know how we could achieve that yet, but if we could do that perhaps we could find a way to import "morphs" inside Irrlicht to create vertex animation blended with bones animation. The vertex animation could be used for character expression...

But for my current need, I change the geometry of a subdivided plane in real time (terrain editor), and updating the triangle selector at the same time would allow me to keep it "real time" all the way and not recalculate the triangle selector when the user release the mouse button. (Get the object vertices Y position while it being modified for getting an approximate value for the "brush reference", but I find it ugly.)

I will evaluate the method proposed by chronologicaldot for the moment, but any change the Irrlicht team could do to improve this in the next version, will be used, as I update the library in our project at each new release.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Can the method: updateFromMesh could be exposed?

Post by CuteAlien »

Sorry, I have no idea right now if there is such a match or not. But I got some free days next week and try if I get some Irrlicht coding done then. Updating the triangleselector is something I've missed myself a few times already.
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
Post Reply