Hi Daniele,
On Fri, 2005-09-30 at 18:59 +0200, Daniele Pagliani wrote:
>
>
> Hi,
>
>
>
> I need to load a vrml model and add to it a materialchunk. How can do
> that? I’m looking for material group nodes, than I try ti get the
> material node and than add a chunk to it, but I cannot understand what
> methods I have to use. Anybody can help me?
This is what I use:
class ChunkAdder
{
public:
ChunkAdder(StateChunkPtr chunk) : _chunk(chunk)
{}
Action::ResultE enter(NodePtr& node)
{
MaterialGroupPtr mg = MaterialGroupPtr::dcast(node->getCore());
if(mg != NullFC)
doAdd(mg->getMaterial());
GeometryPtr geo = GeometryPtr::dcast(node->getCore());
if(geo != NullFC)
doAdd(geo->getMaterial());
return Action::Continue;
}
private:
void doAdd(MaterialPtr m)
{
if(m == NullFC)
return;
ChunkMaterialPtr cm = ChunkMaterialPtr::dcast(m);
if(cm == NullFC)
{
FWARNING(("ChunkAdder::doAdd: Material %p is not a "
"ChunkMaterial, can't add!\n", m.getCPtr()));
return;
}
beginEditCP(cm);
for(int i = 0; i < cm->getChunks().size(); ++i)
// This is a hack for a weird problem in OpenSG
addRefCP(cm->getChunks()[i]);
cm->addChunk(_chunk);
endEditCP(cm);
}
StateChunkPtr _chunk;
};
void addChunkToMaterials(NodePtr node, StateChunkPtr chunk)
{
ChunkAdder adder(chunk);
traverse(node,
osgTypedMethodFunctor1ObjPtrCPtrRef<Action::ResultE,
ChunkAdder,
NodePtr>(
&adder,
&ChunkAdder::enter));
}
Hope it helps
Dirk
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users