Jump to content

save .mat file in 2.6.1


photo

Recommended Posts

Hello lightmap,

To save a material in 2.6.1 you can get the material from the materials manager by name via the Materials::findMaterial(const char * name)` method and then use the Material::save(const char *path) method to save it.

// get material from the Materials manager
MaterialPtr my_mat = Materials::get()->findMaterial("my_material");

if (my_mat)
{
	// set albedo color to red
	my_mat->setParameter("albedo_color", Unigine::Math::vec4(1.0f, 0.0f, 0.0f, 1.0f));

  	// save material to a file
	my_mat->save("my_material.mat");
}

But remember, that manual and base materials cannot be saved.

If you want to create a copy of a material and tweak it, use Material::clone() or Material::inherit() methods.

Thanks!

Link to comment

Hello fox,

just a bit confused that now unigine save materials as single file for each single material... and not single mat file for all model materials - or I'm wrong? (as I recall - no material library since 2.6)

so now material guid, stored in node file, and mat_file will be queried from guids.db? what method refresh this information? when I add new material trough base_mat.inherit()

thanks

Edited by lightmap
Link to comment

You're right material libraries were removed, and now each material is stored in a separate file. All changes in Materials system were described here (see the Materials system refactoring section).

There is something you should be aware of: GUID of a material, and GUID of a *.mat file are not the same thing. To store a link to a certain material in a *.node file you need the GUID of the material, not the file. The guids.db file stores GUIDs of files.

So, basically, you do as follows:

  • Inherit a material
  • Assign the new created material to a surface (or surfaces of the object)
  • Save you object to a *.node file.

In this case the *.node file will store a GUID of your material.

Hope this helps!

Thanks!

 

  • Like 1
Link to comment
×
×
  • Create New...