Hi All,
I will like to change a SimpleMaterial of a loaded VRML file in OpenSG. I have 
tried three different method and still havent found I a solution and will be 
very grateful for any help.

I will like to get a node e.g SQR_1 from my VRML model (code below) and be able 
to change to the emission color in opensg.
1. When I try to retrieve the Geometry of SQR_1 in this case I always get a 
null pointer.
     NamedNodeFinder f; //from tutorial 10loading
   
    NodePtr sqr = f(scene, "SQR_1");    
    GeometryPtr geo = GeometryPtr::dcast(seed->getCore());   

2. modifying the NamedNodeFinder class of 10loading tutorial to return a 
GeometryPtr of SQR_1, changing the material of the Geometry doesnt affect the 
scenegraph.

Action::ResultE isGeometry(NodePtr& node){
    // this tests if the core is derived from geometry
    if (node->getCore()->getType().isDerivedFrom(Geometry::getClassType())){
        geo = GeometryPtr::dcast(node->getCore());
        return Action::Quit;
    }     
    
    return Action::Continue;
}
 
3. If I use the MaterialGroup of the node all the other objects of the 
scenegraph are changed which is not what I want.
Can some one help
<pre>
Viewpoint {
    position 3 2 10
}                                           
Group {

    children [

    # Ambient lighting

    DirectionalLight {

        direction 0 2 -1

        intensity 0.2

        ambientIntensity 0

    },

    #SQUARES

    DEF SQR_1 Transform {
        translation 0 0 0
                children DEF SQUARE Shape {
                    appearance Appearance {
                        material Material {
                            emissiveColor 0 0 0
                            transparency 0.0
                        }
                    }
                    geometry Box { size .5 0.1 .5}
                }

    },
    DEF SQR_2 Transform { translation 2 0 0  children USE SQUARE },
    DEF SQR_3 Transform { translation 4 0 0  children USE SQUARE },
    DEF SQR_4 Transform { translation 6 0 0  children USE SQUARE },
    DEF SQR_5 Transform { translation 1 0 1  children USE SQUARE },
    
    ]

}
 
GeometryPtr geo = GeometryPtr::dcast(seed->getCore());

        if(geo==NullFC){
            SLOG<<"Geometry NULL "<<endLog;
            return;
        }
            
        SimpleMaterialPtr sm = SimpleMaterial::create();

        beginEditCP(sm, SimpleMaterial::EmissionFieldMask |
                                SimpleMaterial::LitFieldMask);
        {
            sm->setLit(false);
            sm->setEmission(Color3f( 0,0,1));
         }
         endEditCP  (sm, SimpleMaterial::EmissionFieldMask |
                                SimpleMaterial::LitFieldMask);

         beginEditCP(geo, Geometry::MaterialFieldMask);
         {
            geo->setMaterial(sm);
         }
         endEditCP  (geo, Geometry::MaterialFieldMask);
</pre>
thanks 
chenzo

 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to