Jump to content

[SOLVED] Problem in ObjectMesh::setMaterial function


photo

Recommended Posts

Posted

Hello,

 

I am trying to assign a material through ObjectMesh object using setMaterial() with following mentioned values, but it is not reflecting onto the mesh.

 

I am programically adding the mesh & assigning the materials for each mesh created. How can I assign a color as material properly. I have taken the "players_red" value from the editor just for testing purpose.

 

ObjectMesh.setMaterial("players_red", "*"); //This material is not applying on the mesh

ObjectMesh.setWorldTransform(myvalue); //This changes according to the myvalue.

 

Can any one help me here.

 

Thanks

Posted

Hi,

Have you ensured "players_red" material is previously loaded before its assignation? Check in your log file if the corresponding material library is loaded with your world. Check engine.materials functions if you want to load that library programatically.

Another way to change material color is using Object::setMaterialParameter()

 

Review Materials and mesh_base sections in documentation, and have a look to samples (for example transparent_00)

Posted

Hey,

 

I was able to add the materials, but now I am having a different issue.

 

I have add my own Init(), Update(), shutdown() function, but when I add

 

#include < samples/materials/common/materials.h>

 

it give an parsing error because init(), update() are already defined in materials.h. Can anyone tell me how to override these function, so that I can use my init(), update() function instead of materials.

 

Is it that I have to rewrite the materials functionality without using materials.h?

 

Thanks

Posted

In this moment I don't have access to sources, but I think you only have to implement update_scene and create_scene functions.

Posted

neither do I have source code. I am trying to solve by adding my own functions

 

Thanks for your help guyzz

Posted

If you are making your own test and you include "samples/materials/common/materials.h", you should implement

 

(From materials.h file)

 

create_scene:

// create scene
string text = call("create_scene");

 

update_scene:

// update scene
if(is_function("update_scene")) {
 thread("update_scene");
}

clear_scene:

// clear scene
if(is_function("clear_scene")) {
 call("clear_scene");
}

Posted

Hey,

 

I have added my funcationality for init(), update() & shutdown() & are been called properly. As I am very new to the Unigine, I am bit confused in assigning the material through string paramter for first agrument in ObjectMesh::setMaterial().

 

Where should the .dds file need to be stored for applying them as materials & where should .mat file need to be placed. Because currently my script is not able to find the mentioned materials.

 

Currently I have placed *.mat file at ./ folder (current folder) & textures at ./materials/textures/ & have given the same path in the *.mat file for the textures.

 

I am getting Object::setMaterial(): can't find "materials_****" material error in log file

 

Can anyone help me out?

 

Thanks

Posted

Providing a test scene will be helpful - so we can help you.

Posted

Hey attached is the sample which contain the above mentioned issue. Please check for the mistake & suggest the solution.

 

Thanks

TestMaterials.zip

Posted

Has any one able to check the sample for the error?

Posted

You did not load a material library to start with. Without it, materials cannot be loaded. You can either:

  • Load it via engine.materials.addWorldLibrary() or
  • Load it from script or in the editor and save the world. In this case a material library associated with the world will be written into *.world file.

post-13-0-19101800-1344925509_thumb.jpg

×
×
  • Create New...