Mesh from an ISceneNode

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
Kapitan
Posts: 4
Joined: Sat Oct 04, 2008 5:18 pm

Mesh from an ISceneNode

Post by Kapitan »

Hi all!!!

I've created my scene on IrrEdit and
loaded with loadscene(), but now i have
to take the mesh of an ISceneNode
(grabbed with getSceneNodeFromId).

Is that possible?

Here:
http://www.irrlicht3d.org/wiki/index.ph ... gCollision

He serialize the node and then
take the name of the mesh.

Is the only way?

Thanks and sorry but i really an
Irrlicht newbie.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

if you have the node, can't you get the mesh with node->getMesh() ?!?!?
(maybe a type cast to IMeshSceneNode needed)

Code: Select all

IMesh* m = ((IMeshSceneNode*)node)->getMesh();
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
lovloss
Posts: 4
Joined: Sun Oct 05, 2008 6:04 am

Post by lovloss »

Acki wrote:if you have the node, can't you get the mesh with node->getMesh() ?!?!?
(maybe a type cast to IMeshSceneNode needed)

Code: Select all

IMesh* m = ((IMeshSceneNode*)node)->getMesh();
Sometimes :) Sometimes you go node->getMesh()->getMesh(0)... i think?
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

lovloss wrote:
Acki wrote:if you have the node, can't you get the mesh with node->getMesh() ?!?!?
(maybe a type cast to IMeshSceneNode needed)

Code: Select all

IMesh* m = ((IMeshSceneNode*)node)->getMesh();
Sometimes :) Sometimes you go node->getMesh()->getMesh(0)... i think?
I think you are thinking of an animated scene node:

Code: Select all

IMesh* m = ((IAnimatedMeshSceneNode*)node)->getMesh(0);
TheQuestion = 2B || !2B
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

First, call ISceneNode::getType(), then cast to the appropriate type based on the result.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Kapitan
Posts: 4
Joined: Sat Oct 04, 2008 5:18 pm

Post by Kapitan »

I've tried both (Mesh and AnimatedMesh cast),
but the result is a null pointer...maybe a bug
or my fault....

I'll try again and i'll post some code.
kornwaretm
Competition winner
Posts: 189
Joined: Tue Oct 16, 2007 3:53 am
Location: Indonesia
Contact:

Post by kornwaretm »

read rogerborg's post above
something like :

Code: Select all

IMesh* mesh = 0;
switch(node->getType()){
case(ESNT_ANIMATED_MESH):{
     mesh = ((IAnimatedMeshSceneNode*)node)->getMesh();
}
case(ESNT_MESH):{
     mesh = ((IMeshSceneNode*)node)->getMesh();
}
//etc.............................. other cast
}
if mesh still 0. check console messages. any model missing?
Kapitan
Posts: 4
Joined: Sat Oct 04, 2008 5:18 pm

Post by Kapitan »

Yes it works, i was using the dynamic_cast
keyword and it told me that there were not
the RTTI.

I've switched using the static_cast keyword
and it works.

Now is:

IMeshNode *msn = static_cast<IMeshNode*>(var)
and perfectly found my mesh.
wuallen
Posts: 67
Joined: Thu Jan 25, 2007 3:07 am
Location: Shanghai

Post by wuallen »

Kapitan wrote:Yes it works, i was using the dynamic_cast
keyword and it told me that there were not
the RTTI.

I've switched using the static_cast keyword
and it works.
I encounted the same problem. I don't know why there is no RTTI.

I use VC2009, is it due to the config of VC2009 or something?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, you shouldn't simply use a dynamic_cast when all you want to do is going down the inheritance hierarchy. That's what static cast is meant for, in the worst case you'd use a reinterpret_cast. dynamic_cast is for navigating across different inheritance branches. RTTI needs to be activated in the project settings, but remember that there's a major runtime penalty related to dynamic_casts.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

hybrid wrote:Well, you shouldn't simply use a dynamic_cast when all you want to do is going down the inheritance hierarchy.
Not true. The dynamic_cast<> operator is there to ensure that object is a complete object of the requested type. Given an ISceneNode* you don't know if you can safely cast down the inheritance heirarchy to IMeshSceneNode*.

As mentioned above, you can use getType() to find the actual type before doing a static_cast<>. That would be safe. This is essentially the same as a dynamic_cast<> because of the virtual dispatch that happens.
hybrid wrote:That's what static cast is meant for, in the worst case you'd use a reinterpret_cast.
A reinterpret_cast<> would be dangerous, as it might give wrong results in the face of multiple inheritance.
hybrid wrote:dynamic_cast is for navigating across different inheritance branches. RTTI needs to be activated in the project settings, but remember that there's a major runtime penalty related to dynamic_casts.
Have you ever profiled the use of RTTI? The runtime cost of RTTI depends on the implementation and the inheritance heirarchy. For a simple heirarchy like that used by ISceneNode*, the runtime cost should be minimal.

Travis
Last edited by vitek on Thu Oct 09, 2008 3:48 pm, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I simply rely on the number given in the C++ optimization guides from Agner Fog and the C++ performance report. I've never profiled any apps for these comparisons.
Kapitan
Posts: 4
Joined: Sat Oct 04, 2008 5:18 pm

Post by Kapitan »

vitek wrote: As mentioned above, you can use getType() to find the actual type before doing a static_cast<>. That would be safe. This is essentially the same as a dynamic_cast<> because of the virtual dispatch that happens.

A reinterpret_cast<> would be dangerous, as it might give wrong results in the face of multiple inheritance.
I quote this because there's a big difference.
The getType() + static_cast is the same theorically
of the dynamic_cast...i don't know the profiling,
i will test it.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Don't bother. I wrote up some code and the results were in-line with what hybrid had posted...

Code: Select all

static_cast<IMeshSceneNode>: 2.37s
static_cast<IAnimatedMeshSceneNode>: 2.29s
dynamic_cast<IMeshSceneNode>: 21.35s
dynamic_cast<IAnimatedMeshSceneNode>: 34.97s
The static_cast<> tests used a call to getType() followed by a static_cast<>, while the dynamic_cast<> tests just did a dynamic_cast<>. Each test was 500,000,000 iterations. I'm open to posting the code if anyone wants to see it.

Travis
wuallen
Posts: 67
Joined: Thu Jan 25, 2007 3:07 am
Location: Shanghai

Post by wuallen »

For choosing static_cast, dynamic_cast or reinterpret_cast, I agree with vitek, and for the performance penalty, I agree hybrid. thanks to every one.
Post Reply