chao.zhang Posted October 16, 2012 Posted October 16, 2012 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 LOD 1 LOD 2
ulf.schroeter Posted October 16, 2012 Posted October 16, 2012 Mark surface texture images as dynamic, see documentation https://developer.unigine.com/en/docs/1.0/code/scripting/library/class.material#setImageTextureImage_int_Image_int Alternately create your textures in the file system and assign them to individual material instances which can than be assigned to the surfaces.
chao.zhang Posted October 16, 2012 Author Posted October 16, 2012 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
ulf.schroeter Posted October 16, 2012 Posted October 16, 2012 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()
ulf.schroeter Posted October 16, 2012 Posted October 16, 2012 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);
chao.zhang Posted October 16, 2012 Author Posted October 16, 2012 Thanks ulf.schroeter , very helpful. you are really a kind and helpful man.
manguste Posted October 19, 2012 Posted October 19, 2012 Indeed he is :) Chao, you need to update to the latest SDK if you still have not done that.
Recommended Posts