Thanks for your reply.

I managed to find the MaterialGroup node that was above the geometry node
and cast it into a ChunkMaterial. But I'm having great difficulty in
casting the ChunkMaterial into TextureChunk.

Here is my code at the moment,

osg::ChunkMaterialPtr material = osg::ChunkMaterialPtr::dcast(m);
osg::beginEditCP (material);
osg::MFStateChunkPtr* chunks = material->getMFChunks();
osg::TextureChunkPtr texture_chunk = osg::NullFC;
for ( osg::MFStateChunkPtr::const_iterator i = chunks->begin(); i !=
chunks->end(); i++ )
{
  if ((*i)->getType() == osg::TextureChunk::getClassType())
  {
     texture_chunk = osg::TextureChunkPtr::dcast(*i);
  }
}
if (texture_chunk != osg::NullFC)
{
  std::cout << "create textureChunk" << std::endl;
}
osg::endEditCP (material);

The "create textureChunk" is never run in my code. I basing most of what
I've done on this code example from this example :
http://www.vrac.iastate.edu/~cjust/templateweb/templateapps/1.1/programmer.reference/OpenSGModel_8cpp.html

Btw, is the osg::beginEditCP (material); and osg::endEditCP (material);
really neccessary ?

I would appreciate any help or advice.

Thank you.


>
> Hi,
>
> [EMAIL PROTECTED] wrote:
>
>>Hi..
>>
>>We are trying to change the texture on a characters head. The character
>> is
>>a vrml model which is loaded in to the program. We have managed to get
>>hold of the correct node and obtain the geometry of that node. We want to
>>change the image in the material of the node and use the same texture
>>coordinates that is stored in the file. Below is some code which tries to
>>do this, but doesn't work. Basically we are trying to change only the
>>image field of the material and leave the rest of the material as it is.
>>
>>GeometryPtr geo = GeometryPtr::dcast(node->getCore());
>>SimpleTexturedMaterialPtr material =
>>SimpleTexturedMaterialPtr::dcast(node>getCore());
>>beginEditCP(material,SimpleTexturedMaterial::ImageFieldMask);
>>material->setImage(image);
>>endEditCP(material,SimpleTexturedMaterial::ImageFieldMask);
>>
>>
>>Can anyone help?
>>Any comments will be appreciated!
>>
>>
> well, I had a look into both VRML loaders of OpenSG.
>
> The problem with your code above is that the VRML loader does not attach
> materials directly to geometry
> but uses a MaterialGroup node above the geometry. If you have the
> geometry node you have to search for
> the first node above which is a MaterialGroup node.
>
> The material in this MaterialGroup is not a SimpleTexturedMaterial, but
> the most general ChunkMaterial.
> Therein you find chunks
>    TextureChunk  which contains the texture Image
>    MaterialChunk which contains the Phong material coefficients
>
> Greetings,
> Christoph
>
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> _______________________________________________
> Opensg-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/opensg-users
>



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to