lightmap Posted March 13, 2018 Share Posted March 13, 2018 Hello in 2.5 I used int save(const char * name) https://developer.unigine.com/en/docs/2.5/api/library/rendering/class.materials but can't find this method in 2.6.1 https://developer.unigine.com/en/docs/2.6.1/api/library/rendering/class.materials how do I save mat file in 2.6.1? thanks Link to comment
fox Posted March 13, 2018 Share Posted March 13, 2018 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
lightmap Posted March 13, 2018 Author Share Posted March 13, 2018 (edited) 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 March 13, 2018 by lightmap Link to comment
fox Posted March 13, 2018 Share Posted March 13, 2018 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! 1 Link to comment
lightmap Posted March 14, 2018 Author Share Posted March 14, 2018 Thanks, turns out with not much changes in code, model converter was migrated to 2.6. Link to comment
Recommended Posts