Jump to content

[SOLVED] Have some problem to set Textures in earth Model


photo

Recommended Posts

Hello, dear everyone, I have new problem

 

I have create a earth model with 3 LOD levels

 

the LOD level 0 with 2 tiles, a tile is actually a dynamic mesh.

the LOD level 1 with 8 tiles

the LOD level 2 with 32 tiles.

 

I set each tile a different diffuse texture image with the following code:

 

take LOD level 1 as an example(some pseduo code)

 

// start with a circulation to create each tile

ObjectMeshDynamic *pLod1[8];

// 8 image object with image data

Image image[8];

 

for (int i = 0; i < 7; i++)

{

ObjectMeshDynamic *pTile = new ObjectMeshDynamic;

pLod1 = pTile;

// some add vertex, normal, index and texture coordinate code, omitted

.........

 

// set material for the tile

pTile->setMaterial("mesh_base", "*");

pTile->setProperty("surface_base","*");

 

// get the material of the tile and set a diffuse texture image

Material* mat = pTile->getMaterial(0);

Texture* texture = mat->getImageTexture(0);

texture->setImage(image);

}

 

when rendered , all 8 tile only show the last texture image and seems all 8 tile share a same material.

So what is the right method to set each tile a independent material when changing its parameters does not affect other tiles?

please help!

 

LOD 0

post-512-0-12740600-1350361730_thumb.png

 

LOD 1

post-512-0-27729100-1350361766_thumb.png

 

LOD 2

post-512-0-89848600-1350361808_thumb.png

Link to comment

Thanks ulf,

 

int setImageTextureImage(int id,Image image,int dynamic) ;

 

i did not see such a interface with three paremeters in my project, is it deprecated? I only see

a interface with two paremeters.

 

int setImageTextureImage(int num,const Image ℑ);

 

Then how to create an individual material instances ? can show me some example code for reference

Link to comment

i did not see such a interface with three paremeters in my project, is it deprecated? I only see

a interface with two paremeters.

 

It's brand new, see this post for background.

 

Then how to create an individual material instances ? can show me some example code for reference

 

Have a look into the numerous UNIGINE code examples e.g. for Objects and documentation for engine.materials .cloneMaterial(). Maybe it's even simpler with Object::getMaterialInherit()

Link to comment

You are lucky, found some snippet

  // created inherited materials
  engine.materials.inheritMaterial( "mesh_base", "bug/bug.mat", "red_white" );
  engine.materials.inheritMaterial( "mesh_base", "bug/bug.mat", "green_white");

// object for red-white diffuse texture update
  object_red_white = add_editor(Unigine::createBox(vec3(10.0f)));
  object_red_white.setWorldTransform(translate(Vec3(0.0f,-15.0f,10.0f)));
  object_red_white.setMaterial("red_white", "*");
  object_red_white.setProperty("surface_base","*");

  updateImage( image, RED_WHITE );
  material = object_red_white.getMaterialInherit(0);

  material.setImageTextureImage( material.findTexture("diffuse"), imageA, 1);


  // object for green-white diffuse texture update
 object_green_white = add_editor(Unigine::createBox(vec3(10.0f)));
 object_green_white.setWorldTransform(translate(Vec3(0.0f,0.0f,10.0f)));
 object_green_white.setMaterial("green_white","*");
 object_green_white.setProperty("surface_base","*");

 material = object_green_white.getMaterialInherit(0);

 material.setImageTextureImage( material.findTexture("diffuse"), imageB, 1);

Link to comment
×
×
  • Create New...