Hi,
(sorry for the incomplete first mail)
I am trying to change the material of some nodes I imported from VRML.
I found the following post (plus Dirk's answer) in the mailing list
archives.
> Dirk Reiners
> Thu, 27 Oct 2005 17:36:41 -0700
>
>
> 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));
> }
>
>
I wonder if that would still be the way to do it. What I am trying to
achieve is just changing one parameter of the material, e.g. emission or
shininess (to highlight objects). So I instantiated the ChunkAdder class
with the top-node of the imported object and a MaterialChunk, which only
has Emission set. As a result my object is all white (as opposed to the
original blue). How can I change only one component?
My other problem is, that, the change of the material is only visible,
after the object is translated.
And:
The material change does effect all clones of the imported
vrml-geometries, although the default GraphOp of the ScenefileHandler
should be NULL.
Any help is appreciated,
Matthias
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users