Hi Marcus,

On Mon, 2005-04-18 at 14:03 +0200, Marcus Lindblom wrote:
> Hi,
> 
> I'm trying to use the Action or NewAction framework to simply traverse a 
> graph and add a materialchunk to all nodes with applicable cores.
> 
> However, I can't really get my head around to what to write. I can't 
> find a really examples at least to what I find.
...
> How to achieve this in as few lines as possible?

The big question is if you want to do this temporarily while rendering,
or permanently as a preprocess. For the temporary case I don't have a
solution, as the state handling is more oriented towards the Materials
right now, and doesn't allow for temporary changes during traversals.

For the permanent case I would use a traverser like the example in the
tutorial 09traverse.cpp. Something like this (warning, untested code):

void doMaterial(MaterialPtr m)
{
    if(m == NullFC)
        return;
    
    ChunkMaterialPtr cm = ChunkMaterialPtr::dcast(m);

    if(cm != NullFC)
    {
        cm->addChunk(newchunk);
    }
}

Action::ResultE changeMaterial(NodePtr& node)
{   
    if(node->getCore()->getType().isDerivedFrom(Geometry::getClassType()))
    {
        GeometryPtr g = GeometryPtr::dcast(node->getCore());
        
        doMaterial(g->getMaterial());
    }   
    if(node->getCore()->getType().isDerivedFrom(MaterialGroup::getClassType()))
    {
        MaterialGroupPtr mg = MaterialGroupPtr::dcast(node->getCore());
        
        doMaterial(mg->getMaterial());
    }   
    
    return Action::Continue; 
}

traverse(scene, 
         osgTypedFunctionFunctor1CPtrRef<Action::ResultE,
                                         NodePtr        >(changeTexture));


It's a couple more lines, mainly because of the safe casts, but it
should work fine.

Hope it helps

        Dirk

-- 
-- Dirk Reiners               OpenSG Forum             [EMAIL PROTECTED] 
-- The OpenSG Open Source Scenegraph:            http://www.opensg.org
-- Join the list at    http://lists.sf.net/lists/listinfo/opensg-users



-------------------------------------------------------
This SF.Net email is sponsored by: New Crystal Reports XI.
Version 11 adds new functionality designed to reduce time involved in
creating, integrating, and deploying reporting solutions. Free runtime info,
new features, or free trial, at: http://www.businessobjects.com/devxi/728
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to