Hi Ralf,

If you need to keep the memory around then use a ref_ptr<> to the
HeightField, but... this will keep the memory around so if you do no longer
need it you might want to implement a scheme to free it, such as watching
when the ref count goes to one.

The other approach is to use an observer_ptr<> that doesn't change the ref
count of the HeightFiled, and gets reset to 0 when the HeightField get
deleted.  You can also use a custom osg::Observer to watch for object
deletions as well.

Robert

On Fri, Apr 3, 2009 at 11:22 AM, Ralf Stokholm <[email protected]>wrote:

> Hi Robert (list)
>
> Im trying to use the ReadFileCallback to load the heightfield int my
> physics engine.
>
> So far I have been using a CullVisitor to grap the triangles from the
> finished scene, but it has major drawback in that it forces me to load
> the data as meshes which is terrible for memmory and takes a long time
> to load.
>
> It seams im able to load the data as heightfields from the
> ReadFileCallback, but this leads to my next problem. I need a way to
> reference the data later, to be able to remove it when tiles are
> deletet and disable it when tiles are disabled by the scene
> cullvisitor.
>
> Is there a way to relate the nodes i visit in my ReadFileCallback to
> nodes i visit in a special cullvisitor for the final scenegraph?
>
> Basically do you have any hints on how to syncronise the state of my
> physics engine with the state of my Paged VPB terrain?
>
> Brgs.
>
> Ralf Stokholm
>
>
> 2009/4/2 Ralf Stokholm <[email protected]>:
> > Hi Robert
> >
> > Thanks a lot, was starting to get at this but using a more primitive
> > approach of running through all the children of the node that I did
> > get.
> >
> > Will try to implement your method.
> >
> > Brgs.
> >
> > Ralf Stokholm
> >
> > 2009/4/2 Robert Osfield <[email protected]>:
> >> Hi Ralf,
> >>
> >> You'll need to write a custom NodeVisitor that traverses through the
> loaded
> >> scene graph and picks out the TerrainTile using dyanmic cast.   It just
> so
> >> happens that I'm actually working on a ReadFileCallback/custom Visitor
> that
> >> does pick out all the TerrainTile's in a subgraph (there will typically
> be
> >> one, two or four due to the quad tree structure generated by VPB.)
> >>
> >> The visitor looks like:
> >>
> >> class FindTerrainTileVisitor : public osg::NodeVisitor
> >> {
> >> public:
> >>     FindTerrainTileVisitor():
> >>         osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
> >>     {
> >>     }
> >>
> >>     void reset()
> >>     {
> >>         _terrainTiles.clear();
> >>     }
> >>
> >>     void apply(osg::Group& group)
> >>     {
> >>         osgTerrain::TerrainTile* terrainTile =
> >> dynamic_cast<osgTerrain::TerrainTile*>(&group);
> >>         if (terrainTile)
> >>         {
> >>             _terrainTiles.push_back(terrainTile);
> >>         }
> >>         else
> >>         {
> >>             traverse(group);
> >>         }
> >>     }
> >>
> >>     typedef std::list< osg::ref_ptr<osgTerrain::TerrainTile> >
> TerrainTiles;
> >>     TerrainTiles _terrainTiles;
> >> };
> >>
> >> The custom ReadFileCallback's readNode method looks like:
> >>
> >>     virtual osgDB::ReaderWriter::ReadResult readNode(const std::string&
> >> filename, const osgDB::ReaderWriter::Options* options)
> >>     {
> >>         osg::notify(osg::NOTICE)<<"Loading tile "<<filename<<std::endl;
> >>         osgDB::ReaderWriter::ReadResult result =
> >> osgDB::Registry::instance()->readNodeImplementation(filename,options);
> >>         if (result.validNode())
> >>         {
> >>             FindTerrainTileVisitor fttv;
> >>             result.getNode()->accept(fttv);
> >>             for(FindTerrainTileVisitor::TerrainTiles::iterator itr =
> >> fttv._terrainTiles.begin();
> >>                 itr != fttv._terrainTiles.end();
> >>                 ++itr)
> >>             {
> >>                 osgTerrain::TerrainTile* terrainTile = itr->get();
> >>                 ///.... my stuff omitted, put your  stuff here
> >>             }
> >>          }
> >>       }
> >>
> >>
> >> Robert.
> >>
> >> On Thu, Apr 2, 2009 at 1:05 PM, Ralf Stokholm <[email protected]>
> >> wrote:
> >>>
> >>> Hi List
> >>>
> >>> Im trying to get the heightfiled data from a VPB terrain using
> >>> ReadFileCallback.
> >>>
> >>> I use the code from readfile callback like this.
> >>>
> >>>   class MyReadFileCallback : public osgDB::Registry::ReadFileCallback
> >>>   {
> >>>   public:
> >>>      virtual osgDB::ReaderWriter::ReadResult readNode(const
> >>> std::string& fileName, const osgDB::ReaderWriter::Options* options)
> >>>      {
> >>>         // note when calling the Registry to do the read you have to
> >>> call readNodeImplementation NOT readNode, as this will
> >>>         // cause on infinite recusive loop.
> >>>         osgDB::ReaderWriter::ReadResult result =
> >>> osgDB::Registry::instance()->readNodeImplementation(fileName,options);
> >>>         if (result.validHeightField())
> >>>         {
> >>>            LOG_ERROR("Found a valid HeightField");
> >>>         }
> >>>         return result;
> >>>      }
> >>>   };
> >>>
> >>> The idea was simply to see if I had the heightfield available, but
> >>> even though I have verified that it gets called it is never a valid
> >>> heightfield.
> >>>
> >>> This is on a terrain build using VPB with the --TERRAIN option.
> >>>
> >>> Shouldent I be able to get the heightfieldnodes?
> >>>
> >>> Brgs.
> >>>
> >>> Ralf Stokholm
> >>> _______________________________________________
> >>> osg-users mailing list
> >>> [email protected]
> >>>
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >>
> >>
> >> _______________________________________________
> >> osg-users mailing list
> >> [email protected]
> >>
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >>
> >>
> >
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to