Hi again.

As I have a look at it again (quite old code...): It might be a good 
idea to use a set instead of a vector to avoid multiple occurences of 
the same material (->shared cores), but I'm working on something 
completely different at this very moment (C#/.NET, *sigh*), so you're on 
your own here.

Yours,
Dominik

Dominik Rau schrieb:
> Hi Sebastian.
>
> Sebastian Knödel schrieb:
>> (...)
>> Is there a simple possibility or do I have to traverse all the 
>> subnodes and check them for theire Materials to add my Shader??
>>   
>
> I think the latter. But to save some of your time, you can just use 
> these two methods (I use them static in a OSGTools class)
>
> OSG::ChunkMaterialPtr OSGTools::getChunkMaterial(OSG::NodePtr node){
>    OSG::NodeCorePtr pCore = node->getCore();
>    OSG::ChunkMaterialPtr cm=OSG::NullFC;
>    if ( pCore != OSG::NullFC &&
>        
> pCore->getType().isDerivedFrom(OSG::MaterialGroup::getClassType()) ){
>        OSG::MaterialGroupPtr g=OSG::MaterialGroupPtr::dcast(pCore);
>        cm=OSG::ChunkMaterialPtr::dcast(g->getMaterial());
>    }
>    else if ( pCore != OSG::NullFC &&
>        pCore->getType().isDerivedFrom(OSG::Geometry::getClassType()) ){
>        OSG::GeometryPtr g=OSG::GeometryPtr::dcast(pCore);
>        cm=OSG::ChunkMaterialPtr::dcast(g->getMaterial());
>    }
>    return cm;
> }
>
> void  OSGTools::getAllMaterials(OSG::NodePtr 
> node,std::vector<OSG::ChunkMaterialPtr> &mats){
>  OSG::ChunkMaterialPtr cm=getChunkMaterial(node);
>  if(cm!=OSG::NullFC){
>    mats.push_back(cm);
>  }
>  for (int i=0; i<node->getNChildren(); i++)
>        getAllMaterials(node->getChild(i),mats);
> }
>
> Just call getAllMaterials with an empty vector<OSG::ChunkMaterialPtr> 
> on any node and you should get what you need.
>
> HTH,
> Dominik
>
>
>> Actually I'm a bit lost. I thought it wouldn't be that difficult.
>>
>> I hope somebody has an idea.
>>
>> Thanks
>>
>> Carsten Neumann wrote:
>>  
>>>     Hello Sebastian,
>>>
>>> Sebastian Knödel wrote:
>>>      
>>>> Thanks for the fast reply.
>>>> But this doesn't work.
>>>> The materialgroup contains no material at that point.
>>>> So if I use mg->getMaterial() I receive always a NullFC.
>>>> But I unerstand the problem.
>>>> Somehow I have to add the shaderchunk to the OSGMaterial that holds 
>>>> the original materialdata.
>>>>           
>>> exactly.
>>>
>>>      
>>>> But how can I access the Material of any loaded geometry and add my 
>>>> shader chunk???
>>>>           
>>> that depends a bit on what type of file your model is stored in. 
>>> AFAIK the vrml loader uses material groups, but other loaders 
>>> probably add the material directly to the geometry, i.e. you can get 
>>> it by:
>>>
>>> GeometryPtr geo = Geometry::dcast(model->getCore());
>>> MaterialPtr mat = geo->getMaterial();
>>>
>>>      
>>>> I tried something like
>>>>
>>>> if(model->getCore()->getType().isDerivedFrom( 
>>>> ChunkMaterial::getClassType())){
>>>>     mat = model->getCore();
>>>>           
>>>      mat = ChunkMaterial::dcast(model->getCore());
>>>
>>>      
>>>>     mat->addChunk(shaderchunk);
>>>> }
>>>>
>>>> any comment?
>>>>           
>>> Material and hence ChunkMaterial is not derived from NodeCore, so 
>>> the above test is always false.
>>>
>>>     Hope it helps,
>>>         Carsten
>>>
>>>      
>>>> thanks
>>>>
>>>> Andreas Zieringer wrote:
>>>>          
>>>>> Hi Sebastian,
>>>>>
>>>>> you are replacing the original material with your own shader 
>>>>> material.
>>>>>
>>>>> replace this line:
>>>>>
>>>>> mg->setMaterial(createSimpleShaderMaterial());
>>>>>
>>>>> with something like this:
>>>>>
>>>>> ChunkMaterialPtr mat = ChunkMaterialPtr::dcast(mg->getMaterial());
>>>>>
>>>>> if(mat != NullFC)
>>>>> {
>>>>>      beginEditCP(mat);
>>>>>          mat->addChunk(_shl);
>>>>>      endEditCP(mat);
>>>>> }
>>>>>
>>>>> Andreas
>>>>>
>>>>>                
>>>>>> Hi there,
>>>>>>
>>>>>> I'm using different glsl shader (phong, etc.) to create different 
>>>>>> visualizations of my models in my scene.
>>>>>> In my shaders I would like to use the original material 
>>>>>> properties resp. textures that belong to the model and were 
>>>>>> loaded with the geometry from file.
>>>>>>
>>>>>> When I load the tie fighter model I would like to use the 
>>>>>> original material colors in my shader.
>>>>>> I tried to do so by using the built-in gl_FrontColor.diffuse in 
>>>>>> the Vertex Shader and pass it through to the Fragment Shader.
>>>>>> But the gl_FrontColor (diffuse/ambient/specular) is all the time 
>>>>>> (0.0,0.0,0.0,0.0)/black, meaning that its not available.
>>>>>> It seems that the OpenGL material isn't anymore valid for any 
>>>>>> reason when I use a shader.
>>>>>>
>>>>>> Afterwards I tried to use the textures of the model in my shader. 
>>>>>> In Performer the corresponding texture of the currently rendered 
>>>>>> geometry was bind to texture unit 0. Thus it was easy to use the 
>>>>>> textures in the shader. It seams that OpenSG binds the textures 
>>>>>> to different textures units. Because when I used texture unit 0 
>>>>>> in my shader, the wrong textures were visualized with wrong parts 
>>>>>> of my model.
>>>>>> So my question is how to acces the textures in my shader, which 
>>>>>> were loaded with the model? Because I don't know the exact 
>>>>>> texture units OpenSG binds them to.
>>>>>>
>>>>>> Perhaps I don't set up the shader corrctly and the OpenGL State 
>>>>>> isn't anymore available.
>>>>>>
>>>>>> I attached an example to show the problem.
>>>>>>
>>>>>> thanks for any comment.
>>>>>>
>>>>>> Sebastian Knödel
>>>>>>                       
>>>>>                 
>>>> ------------------------------------------------------------------------- 
>>>>
>>>> This SF.net email is sponsored by: Splunk Inc.
>>>> Still grepping through log files to find problems?  Stop.
>>>> Now Search log events and configuration files using AJAX and a 
>>>> browser.
>>>> Download your FREE copy of Splunk now >>  http://get.splunk.com/
>>>> _______________________________________________
>>>> Opensg-users mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/opensg-users
>>>>
>>>>           
>>> ------------------------------------------------------------------------- 
>>>
>>> This SF.net email is sponsored by: Splunk Inc.
>>> Still grepping through log files to find problems?  Stop.
>>> Now Search log events and configuration files using AJAX and a browser.
>>> Download your FREE copy of Splunk now >>  http://get.splunk.com/
>>> _______________________________________________
>>> Opensg-users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/opensg-users
>>>       
>>
>>
>> ------------------------------------------------------------------------- 
>>
>> This SF.net email is sponsored by: Splunk Inc.
>> Still grepping through log files to find problems?  Stop.
>> Now Search log events and configuration files using AJAX and a browser.
>> Download your FREE copy of Splunk now >>  http://get.splunk.com/
>> _______________________________________________
>> Opensg-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/opensg-users
>>
>>
>>   
>
>


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to