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: [EMAIL PROTECTED] 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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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: [EMAIL PROTECTED] 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,

>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. <[EMAIL PROTECTED]> wrote:


        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
        [email protected]
        
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
        




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

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

http://www.fontys.nl/disclaimer

The above disclaimer applies to this e-mail message.
----------------------------------------------------------------




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

http://www.fontys.nl/disclaimer

The above disclaimer applies to this e-mail message.
----------------------------------------------------------------

<<winmail.dat>>

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to