Hello Mike,

Usually I would not do this with an update callback, but taken this aside I think you have to clone the models nodes to achieve "unique" transforms for each instance. In my renderer I clone models with articulated parts (in my case there are osgSim::Multiswitch and osgSim::DOFTransform nodes below the models) and address the nodes directly. This way the structure of the model is cloned, but the geometries, textures etc. are not.

As you are talking about icons, I'm not quite sure if you are using switches and DoFs in any way, but the general idea is the same. You will have to clone the model/icon whatever.

I use a function like this:

osg::Node*cloneStructure(osg::Node* original)
{
    osg::CopyOp::CopyFlags copy_flags;
    copy_flags = osg::CopyOp::DEEP_COPY_ALL;
    copy_flags = copy_flags & ~(osg::CopyOp::DEEP_COPY_DRAWABLES);
    copy_flags = copy_flags & ~(osg::CopyOp::DEEP_COPY_IMAGES);
    copy_flags = copy_flags & ~(osg::CopyOp::DEEP_COPY_TEXTURES);

    return dynamic_cast<osg::Node*>(original->clone(copy_flags));
}

After this I usually run a visitor per clone to get the dof/switch nodes.
Maybe you can do the same for your icons and put the node references into your user data

cheers
Sebastian


We are developing an osg-based application which requires the use of various 
vehicle models, which we have modeled at several levels-of-detail.

The highest level of detail for each of these vehicle models include 
articulated parts such as turrets that move in azimuth and guns that move in 
elevation (e.g. tanks).

Because the osg file is somewhat substantial, we do not want to load the same 
osg file for each entity in our simulation. If we had ten tanks to render, 
loading and using ten duplicate osg files wouldn't be so bad, but we need to 
support rendering dozens of different vehicle types with hundreds upon hundreds 
of vehicles of each type.

Therefore we took the advice found in the OpenSceneGraph beginners guide (page 
101 and 102) and have implemented a system whereby one detailed osg model is 
made the shared child of dozens or hundreds of parents (each of which is an 
osg::MatrixTransformation). During execution, we simply update the 
rotation/translation or these MatrixTransformation nodes and our single model 
is displayed in dozens or hundreds of unique locations and orientations.

But we also need this single model to be posed in a different way for each of 
the represented players: Tank1's turret and gun are at different angles than 
Tank2's turret and gun, etc.

So I have attempted to implement UpdateCallbacks in order to pose my tank model 
each time it needs to be rendered for a given player.

On the matrixTransform for each entity, I call setUserData() with some 
entity-specific data, then call setUpdateCallback with a callback object 
descended from NodeCallback:


Code:

class articulatedIconCallback : public osg::NodeCallback
{
public:
// called every time a player's matrixTransform node is updated during update 
traversal
virtual void operator()(osg::Node* n, osg::NodeVisitor* nv)
{
osg::ref_ptr<articulatedIconDataType> iconData = 
dynamic_cast<articulatedIconDataType*> ( n->getUserData() );
if (iconData)
{
iconData->updateIcon();
}
traverse(n,nv);
}
};




In my implementation of updateIcon(), the code retrieves the entity-specific data 
(MatrixTransformation->getUserData) in order to determine the turret and gun angles for 
that unique player, then proceeds to descend into the node hierarchy of the osg model, 
looking for nodes with specific names which mark them as an articulation point. For 
instance, we look for a matrixTransform node (internal to the osg model hierarchy) with the 
name "TURRET_AZIMUTH". If we find it, we set the matrix accordingly. We carry on 
and do the same for gun elevation and other articulated parts.

The problem is that this appears not to be working. All the player models are 
positioned and oriented correctly, but each and every player which shares an 
osg model shares the same turrent/gun angles, as if the last player processed 
is applying his data to all the players.

In general, am I correct in expecting setUpdateCallback to behave this way? Is 
there something specific I need to do to in order for this approach to work? Is 
there a different, preferred approach I should be using? Any help will be 
greatly appreciated!

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=51734#51734





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to