Am i doing this right? (meta-Tri-Selector)

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.
Post Reply
WaxyChicken
Posts: 95
Joined: Sat Jun 25, 2011 6:15 am

Am i doing this right? (meta-Tri-Selector)

Post by WaxyChicken »

I can add 100 trees from my map editor, save and add 100 more.
then load them up in the game map using the saved files.

The next step was to make them solid.
This would be exceptionally nice for non-plant objects - such as a barrel, box, or an entire building.

The problem is that my FPS is dropping from near 100 to 20-something just for putting in ONE tree.
Apparently i'm somehow overburdening the engine with Meta Triangle Selector.
(i say this because i have near the same FPS weather i use one tree or 300 trees.
it's me trying to include collisions with them that is lagging the program)

I'm wondering if I'm misunderstanding how to use the Meta triangle selector
Any help would be appreciated

Code: Select all

 
            selector = smgr.CreateMetaTriangleSelector
            ' q3node = main map mesh.
            ObjectOnMapSelector = smgr.CreateTriangleSelector(q3node.Mesh, q3node)
            selector.AddTriangleSelector(ObjectOnMapSelector)
 
            ' PlantNodes = other objects added via map editor
            For I As Integer = 0 To 100
                If PlantNodes(I) IsNot Nothing Then
                    ObjectOnMapSelector = smgr.CreateTriangleSelector(PlantNodes(I).Mesh, PlantNodes(I))
                    selector.AddTriangleSelector(ObjectOnMapSelector)
                End If
            Next
 
            q3node.TriangleSelector = selector
 

If i'm translating it to C dialect properly for you to read, then it should look something like this:

Code: Select all

 
 
                        selector = smgr::CreateMetaTriangleSelector;
                        // q3node is the main map mesh
                        ObjectOnMapSelector = smgr::CreateTriangleSelector(q3node::Mesh, q3node);
                        selector::AddTriangleSelector(ObjectOnMapSelector);
 
                        // plant nodes are objects added latter through the map editor
                        for (int ObjectCount = 0; ObjectCount <= 100; I++)
                        {
                                if (PlantNodes[ObjectCount] != nullptr)
                                {
                                        ObjectOnMapSelector = smgr::CreateTriangleSelector(PlantNodes[ObjectCount]->Mesh, PlantNodes[ObjectCount]);
                                        selector::AddTriangleSelector[ObjectOnMapSelector];
                                }
                        }
 
                        q3node->TriangleSelector = selector;
 
 
(you will also see some name differences due to the wrapper - such as the prefix letter "i" being dropped with things like IMetaTriangle)

Any help on how i may be misusing the IMetaTriangleSelector would be greatly appreciated.
this FPS is KILLING ME!

(yes, i still have FPS tied to game loops for now - but just so i can notice excessive system burdens like I'm seeing now)
_______________________________________________________
You could argue with me all day long about which language is best.
But what it comes down to is:
which language is best for YOU and which language is best for ME.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Am i doing this right? (meta-Tri-Selector)

Post by hybrid »

Well, adding a few hundred collision tests will definitely influence FPS. Maybe think about a physics engine or reduce the collision accuracy (maybe it's ok to just stop at an invisible wall around the trees, or at least use just a few boxes instead of the exakt triangle collisions for each leaf).
WaxyChicken
Posts: 95
Joined: Sat Jun 25, 2011 6:15 am

Re: Am i doing this right? (meta-Tri-Selector)

Post by WaxyChicken »

WaxyChicken wrote:The problem is that my FPS is dropping from near 100 to 20-something just for putting in ONE tree.
it says check to see if up to 100 are used.
but I'm only using one.
the rest are being skipped.
_______________________________________________________
You could argue with me all day long about which language is best.
But what it comes down to is:
which language is best for YOU and which language is best for ME.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Am i doing this right? (meta-Tri-Selector)

Post by hybrid »

Don't know what you meant with that post, maybe rephrase. Your code shows that you have 100 collision tests. Also, check if using the box test of the triangle selector helps. Also, I just added a few improvements to SVN/trunk, which should make this lots faster. Also, make your triangle list as small as possible (maybe just one or two tris). This should enable a few shortcuts, and you only want to know if you collide anywhere, don't you?
WaxyChicken
Posts: 95
Joined: Sat Jun 25, 2011 6:15 am

Re: Am i doing this right? (meta-Tri-Selector)

Post by WaxyChicken »

it checks the 100 to see which are being used.
if they are being used then it adds a selector to them.

let me rephrase part of it in psudocode:
( only plantnodes[0] is being used)
 

Code: Select all

 
            selector = smgr.CreateMetaTriangleSelector
 
            ' q3node = main map mesh. make a selector for it
            ObjectOnMapSelector = smgr.CreateTriangleSelector(q3node.Mesh, q3node)
 
            add that selector to our Meta Triangle Selector
            selector.AddTriangleSelector(ObjectOnMapSelector)
 
 Count 0 to 100 with icounter {
            ' PlantNodes = other objects added via map editor
 
                If PlantNodes[icounter] Is Being Used Then
 
                    Make a selector for that node
                    ObjectOnMapSelector = smgr.CreateTriangleSelector(PlantNodes[Icounter].Mesh, PlantNodes[Icounter])
 
                    add that selector to our meta triangle selector
                    selector.AddTriangleSelector(ObjectOnMapselector)
                End If
            Next icounter }
 
this is our final triangle selector. contains main map mesh and any planted objects. bind it to our main map mesh.
 q3node.TriangleSelector = selector
 
i'm wondering if i'm binding the main map mesh 2x somewhere (80+k polygons in the map)
that would definitely explain the over burden.
the tree only has about 150 polygons.
_______________________________________________________
You could argue with me all day long about which language is best.
But what it comes down to is:
which language is best for YOU and which language is best for ME.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Am i doing this right? (meta-Tri-Selector)

Post by hybrid »

Ok, now it makes sense. Since the PlantNodes[ObjectCount] wasn't set anywhere, it wasn't clear what is happening. You should probably use a octree selector for your q3 map, as it reduces the overhead significantly. Question is also what you're doing with the selectors. Are you creating collision response animators somewhere, or call the getTriangles? Since you say that you have problems only when adding the trees, it doesn't seem to be a problem with the level mesh?!
WaxyChicken
Posts: 95
Joined: Sat Jun 25, 2011 6:15 am

Re: Am i doing this right? (meta-Tri-Selector)

Post by WaxyChicken »

I'm doing both: collision response animator for An FPS camera and get triangle for collision tweaks. i also will be adding another mesh and selector later for glass breakage (detection only applied to bullets and area of effect explosions)

ok: so I make a meta triangle selector as the "all in one" selector for collision tests but add type OctreeTriangleSelectors to it instead of just plain TriangleSelector.

I'll give that a shot tonight.
Thanks again hybrid. You are always a big help.
:)

I was using just one octree selector for the map before and thought i had to switch to TriangleSelector when using MetaTriangleSelector. Hopefully a Meta of OctTree will resolve the performance drop I encumbered from a Meta of TriangleSelector.
_______________________________________________________
You could argue with me all day long about which language is best.
But what it comes down to is:
which language is best for YOU and which language is best for ME.
WaxyChicken
Posts: 95
Joined: Sat Jun 25, 2011 6:15 am

Re: Am i doing this right? (meta-Tri-Selector)

Post by WaxyChicken »

Like a charm, Hybrid. Tested with 100 trees and i only face a 10FPS drop.

Thanks again. :)
_______________________________________________________
You could argue with me all day long about which language is best.
But what it comes down to is:
which language is best for YOU and which language is best for ME.
Post Reply