[osg-users] manipulating vertices from a node loaded by ReadNodeFile()

126 views
Skip to first unread message

Bokhorst,Rene R.

unread,
Jun 26, 2008, 9:56:19 AM6/26/08
to osg-...@lists.openscenegraph.org
Hey there,

I've been browsing the mail archive to find the answer to my question but I haven't found anything at all. I basically want to manipulate the vertices of a model loaded by the osgDB::ReadNodeFile() function. ReadNodeFile() returns a osg::Node. I was hoping this might actually be a osg::Geode, but apparently it isn't.

Reason I want to do this is because I have 1600 different building models. But all of these building models are already positioned in their correct position and rotation (instead of each building being built around 0,0,0). So basically if I load my 1600 models and all position them on 0,0,0 I have a complete and perfectly aligned town. I want to move every building back to 0,0,0 so that I can re-use them. I've already used osg to find their position by finding the center of their bounding box. And now I want to substract that position from the vertices of every building and save them. Anyone know how to achieve this?

Thank you in advance,

Rene


----------------------------------------------------------------
Op deze e-mail zijn de volgende voorwaarden van toepassing:

http://www.fontys.nl/disclaimer

The above disclaimer applies to this e-mail message.
----------------------------------------------------------------
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Rajesh Karnik

unread,
Jun 26, 2008, 10:06:01 AM6/26/08
to OpenSceneGraph Users
hello Rene,

I am not sure i have understood your query..

But probably attaching a Matrix Transform as a parent should work.

Regards,
Rajesh.

Paul Melis

unread,
Jun 26, 2008, 10:07:13 AM6/26/08
to OpenSceneGraph Users
Hoi,

Bokhorst,Rene R. wrote:
> I've been browsing the mail archive to find the answer to my question but I haven't found anything at all. I basically want to manipulate the vertices of a model loaded by the osgDB::ReadNodeFile() function. ReadNodeFile() returns a osg::Node. I was hoping this might actually be a osg::Geode, but apparently it isn't.
>

A Geode is a subclass of Node, but osgDB::readNodeFile always returns a
Node*. You can check if you actually get back a Geode by doing a dynamic
cast, e.g.

osg::Node* node = osgDB::readNodeFile(...);
osg::Geode* geode = dynamic_cast<osg::Geode*>(node);
if (geode) { // it's a Geode... }


> Reason I want to do this is because I have 1600 different building models. But all of these building models are already positioned in their correct position and rotation (instead of each building being built around 0,0,0). So basically if I load my 1600 models and all position them on 0,0,0 I have a complete and perfectly aligned town. I want to move every building back to 0,0,0 so that I can re-use them. I've already used osg to find their position by finding the center of their bounding box. And now I want to substract that position from the vertices of every building and save them. Anyone know how to achieve this?
>

You can try to add a separate MatrixTransform above each building's root
node and set its DataVariance to STATIC followed by running
osgUtil::Optimizer on the subgraph with option
FLATTEN_STATIC_TRANSFORMS. If all other transforms in the subgraph also
have static variance then this should 'push' the transform into the
vertices by transforming them to their final positions. You can then
save each building's subgraph with writeNodeFile()

Paul

Serge Lages

unread,
Jun 26, 2008, 10:07:43 AM6/26/08
to OpenSceneGraph Users
Hi Rene,

From you geodes, take the drawables, cast them into geometries and recover the vertex list with getVertexArray.

On Thu, Jun 26, 2008 at 3:56 PM, Bokhorst,Rene R. <r.bok...@fontys.nl> wrote:



--
Serge Lages
http://www.tharsis-software.com

Bokhorst,Rene R.

unread,
Jun 26, 2008, 12:23:02 PM6/26/08
to OpenSceneGraph Users
thank you, I think this is what I'm looking for. I'm gonna try it soon. I'll let you know.

Regards,

Rene

________________________________

winmail.dat

Bokhorst,Rene R.

unread,
Jun 26, 2008, 12:25:09 PM6/26/08
to OpenSceneGraph Users
thanks for replying, but the problem is that the osg::Node* returned by ReadNodeFile() is not a osg::Geode().

________________________________

From: osg-user...@lists.openscenegraph.org on behalf of Serge Lages
Sent: Thu 6/26/2008 4:07 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] manipulating vertices from a node loaded byReadNodeFile()


Hi Rene,


--
Serge Lages
http://www.tharsis-software.com <http://www.tharsis-software.com/>

winmail.dat

Jean-Sébastien Guay

unread,
Jun 26, 2008, 12:26:54 PM6/26/08
to OpenSceneGraph Users
Hello Rene,

> I've been browsing the mail archive to find the answer to my question but I haven't found anything at all. I basically want to manipulate the vertices of a model loaded by the osgDB::ReadNodeFile() function. ReadNodeFile() returns a osg::Node. I was hoping this might actually be a osg::Geode, but apparently it isn't.

To add to what Paul Melis said, in addition to the osg::Node* actually
pointing to an osg::Geode*, it could be that there are some transforms
above the geode itself. So you may need to use a NodeVisitor to find
your actual Geode, and then do whatever you want to do with the
underlying Geometry objects (which you will also dynamic_cast from the
osg::Drawable* returned from geode->getDrawable(i) ).

It could be a useful exercise to convert your models to .osg format,
which is plain text and can be inspected.

osgconv model.flt model.osg (for example, if it's an flt)

This will tell you what the structure will be once the model is loaded
into OSG. readNodeFile returns the top node in that structure.

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/

Gordon Tomlinson

unread,
Jun 26, 2008, 2:24:38 PM6/26/08
to OpenSceneGraph Users
Well you will have to walk the node returned by ReadNodeFile scenegraph,
typically with a nodevisitor

until you find osg::geode, look through the sample and examples they show
how to walk a scenegraph and how to create nodes and geom, the mail archives
while also contain pointers if not code on how to do this

heres an old example from my faq's of a nodevisitor
http://www.vis-sim.com/osg/code/osgcode_bbox1.htm which also shows how to
get the geodes

_____

From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of
Bokhorst,Rene R.
Sent: Thursday, June 26, 2008 12:25 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] manipulating vertices from a node
loadedbyReadNodeFile()

thanks for replying, but the problem is that the osg::Node* returned by
ReadNodeFile() is not a osg::Geode().

_____

From: osg-user...@lists.openscenegraph.org on behalf of Serge Lages

winmail.dat

CG

unread,
Jun 26, 2008, 10:32:01 PM6/26/08
to OpenSceneGraph Users
Hi,
 
Sorry for the off thread, if I can recover the vertex list, is it possible to create runtime crater (cause by explosion)? Any examples out there?

Regards,
Cg

Date: Thu, 26 Jun 2008 18:25:09 +0200
From: r.bok...@fontys.nl
To: osg-...@lists.openscenegraph.org


Always-on security tools provide safer ways to connect and share anywhere. Find out more. Windows Live

Bokhorst,Rene R.

unread,
Jun 30, 2008, 9:46:45 AM6/30/08
to OpenSceneGraph Users
yes, I suspect so.

Regards,

Rene

________________________________

Regards,
Cg


________________________________

________________________________


--
Serge Lages
http://www.tharsis-software.co m <http://www.tharsis-software.com/>


________________________________

Always-on security tools provide safer ways to connect and share anywhere. Find out more. Windows Live <http://get.live.com/familysafety/overview>

winmail.dat

Bokhorst,Rene R.

unread,
Jun 30, 2008, 10:09:32 AM6/30/08
to OpenSceneGraph Users
Thanks for the link, I tried it out and finally got some results! I did encounter one more problem though. I wrote this piece of code to acquire the vertices and manipulate them.

void
MoveGeode(
osg::Geode* geode,
osg::Vec3 trans)
{
for (unsigned int i = 0 ; i < geode->getNumDrawables() ; i += 1 )
{
osg::Drawable* drawable = geode->getDrawable(i);
osg::Geometry* geom = dynamic_cast<osg::Geometry *>(drawable);
for ( unsigned int ipr = 0 ; ipr < geom->getNumPrimitiveSets() ; ipr += 1)
{
osg::PrimitiveSet* prset = geom->getPrimitiveSet(ipr);
osg::Vec3Array* verts = dynamic_cast<osg::Vec3Array*>(geom->getVertexArray());
if ( verts != NULL )
{
unsigned int ic;
unsigned int i2;
unsigned int nprim=0;
osg::notify(osg::WARN) << "Prim set type "<< prset->getMode() << std::endl;
for ( ic = 0 ; ic < prset->getNumIndices() ; ic += 1 )
{
// NB the vertices are held in the drawable -
osg::notify(osg::WARN) << "vertex " << ic << " is index "<<prset->index(ic) << " at " <<
(* verts)[prset->index(ic)].x() << "," <<
(* verts)[prset->index(ic)].y() << "," <<
(* verts)[prset->index(ic)].z() << std::endl;
(* verts)[prset->index(ic)] -= trans;
osg::notify(osg::WARN) << "vertex " << ic << " is index "<<prset->index(ic) << " at " <<
(* verts)[prset->index(ic)].x() << "," <<
(* verts)[prset->index(ic)].y() << "," <<
(* verts)[prset->index(ic)].z() << std::endl;
}
}
}
}
}

void
MoveModel(
osg::Node* node,
osg::Vec3 trans)
{
FindGeodeNodeVisitor finder;
node->accept(finder);
std::vector<osg::Geode*> foundGeodes = finder.GetFoundGeodes();
for ( unsigned int i = 0 ; i < foundGeodes.size() ; i += 1 )
{
MoveGeode(foundGeodes[i], trans);
}
}

void
SimpleOSGMapFormat::FromZeroToAbsolute(
MapObject* mo,
osg::ref_ptr<osg::Node> mModel)
{
osg::BoundingBox bbound;
bbound.expandBy(mModel->getBound());
osg::Vec3 transPos = bbound.center();
transPos.set(transPos.x(), transPos.y(), 0.0f);
mo->x = transPos.x();
mo->y = transPos.y();
mo->z = 0.0f;//newPos.z();
MoveModel(mModel.get(), transPos);
}

The first couple of vertices worked like a charm, my vertices were around (250,-250,5) as I suspected and they moved to around (0,0,5) perfectly. But then I came across some vertices that were already around (0,0,0), and they were subsequently moved to (-250, 250, 5). A quick look at the original model in milkshape confirms that this cannot be the case, so I suspect that these vertices are saved relative to something else's position. Can someone confirm this, and maybe provide me with a good overview of how these vertices are saved exactly?

It could have to do with how many Geodes I found in my underlying Node. I simply retrieved ALL of them, and manipulate them all equally.

Any ideas?

Regards,

Rene

PS, here's a link to one of the models I want to move to (0,0,0).
http://gentlemenguild.com/CaveEd/block_in_pompeii.middle_lod.b1369.obj
http://gentlemenguild.com/CaveEd/block_in_pompeii.middle_lod.b1369.osg

________________________________

Van: osg-user...@lists.openscenegraph.org namens Gordon Tomlinson
Verzonden: do 26-6-2008 20:24
Aan: 'OpenSceneGraph Users'
Onderwerp: Re: [osg-users] manipulating vertices from a nodeloadedbyReadNodeFile()


Well you will have to walk the node returned by ReadNodeFile scenegraph, typically with a nodevisitor

until you find osg::geode, look through the sample and examples they show how to walk a scenegraph and how to create nodes and geom, the mail archives while also contain pointers if not code on how to do this

heres an old example from my faq's of a nodevisitor http://www.vis-sim.com/osg/code/osgcode_bbox1.htm which also shows how to get the geodes

________________________________

From: osg-user...@lists.openscenegraph.org [mailto:osg-user...@lists.openscenegraph.org] On Behalf Of Bokhorst,Rene R.
Sent: Thursday, June 26, 2008 12:25 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] manipulating vertices from a node loadedbyReadNodeFile()


thanks for replying, but the problem is that the osg::Node* returned by ReadNodeFile() is not a osg::Geode().

________________________________

winmail.dat
Reply all
Reply to author
Forward
0 new messages