Hi all,
I just wanted to share the code that worked for me. Since Google didn't find any similar code on the interweb, I post it here for community's reference. Again: I intend to dynamically change the UV Map (aka albedo map) of the Chicago guy. If you look into the model scene definition "man.scene.xml" you will find a structure like this (I abbreviated for clarity's sake):
Code:
<Model name="man" geometry="models/man/man.geo" otherAttributesgohere>
<!-- lots of "Join" elements here -->
<Mesh name="body" lodLevel="1" material="models/man/civilian1.material.xml" otherAttributesgohere/>
<Mesh name="body" material="models/man/civilian1.material.xml" otherAttributesgohere />
<Mesh name="body" lodLevel="2" material="models/man/civilian1.material.xml" otherAttributesgohere />
<Mesh name="body" lodLevel="3" material="models/man/civilian1.material.xml" otherAttributesgohere />
</Model>
This is a scene model with four meshes of which I'd like to access the second one. The mash's associated material "civilian1.material.xml" looks like this (again abbreviated):
Code:
<Material>
<Shader source="shaders/model.shader" />
<!-- here go shader flags -->
<Sampler name="albedoMap" map="models/man/civil01.jpg" />
</Material>
Slowly I arrive at my target

. The sampler called "albedoMap" points to the texture "models/man/civil01.jpg", which I really, really like to exchange by a different UV map, located at "models/man/civil02.jpg". That second UV map needs necessarily to have the exact proportions as the first one since I don't change any model data. To be exact, I just copy-edited the JPG under a new name.
So and here is what I do in my program code:
Code:
//earlier I load the second texture like this
_tex2 = h3dAddResource(H3DResTypes::Texture, "models/man/civil02.jpg", 0);
...
//get the mesh element from the scene model
H3DNode mesh = h3dGetNodeChild(_model, 1); //starting at zero, access the second mesh
//access the mesh's material
int meshMaterial = h3dGetNodeParamI(mesh, H3DMesh::MatResI);
//get the the ressource index for the UV map
int idx = h3dFindResElem(meshMaterial, H3DMatRes::SamplerElem, H3DMatRes::SampNameStr, "albedoMap");
//pull the texture ressource from the material by using the found index
H3DRes texRes = h3dGetResParamI(meshMaterial, H3DMatRes::SamplerElem, idx, H3DMatRes::SampTexResI);
//set the 2nd texture back to the mesh material
h3dSetResParamI(meshMaterial, H3DMatRes::SamplerElem, idx, H3DMatRes::SampTexResI, _tex2);
Voilá, it is done. The only drawback is that all instances of that Chicago guy have now the second texture on themselves. To avoid this, cloning utilizing
h3dCloneResource() is necessary, but until now I just fail to make it right.
Hope this helps, cheers