smirnov.oleg Posted May 17, 2019 Share Posted May 17, 2019 Hi! I'm trying to change material parameters of "object water global". Problem is that some parameters are not saved or not applied at all. Here's what I do: 1) Create new material and apply it to water object MaterialPtr core = materials->findMaterial("water_global_base"); MaterialPtr newMat = core->inherit(); newMat->setName("my_water_material_0"); newMat->setPath("materials/my_water_material_0.mat"); newMat->save(); 2) Change material parameters MaterialPtr mat = materials->findMaterial("my_water_material_0"); MaterialPtr core = materials->findMaterial("water_global_beaufort_4"); float fog = mat->getParameter("underwater_fog_transparency"); for (int i = 0; i < core->getNumParameters(); i++) mat->setParameter(i, core->getParameter(i)); mat->setParameter("underwater_fog_transparency", fog); mat->save("materials/my_water_material_0.mat"); 3) Restart the app OR reload materials (via 'materials_reload' console command) I expect: All material's parameters are correctly applied and saved. What i got: Some properties are saved and some are not, this makes water look ugly. After a small research i found that some properties (such as 'wave0_uv_transform') are always saved with default value in material's XML file, ignoring what i passed in setParameter(). Properties are applied correctly before you reload the material. Using UNIGINE SDK 2.7.2.1 Link to comment
andrey-kozlov Posted May 20, 2019 Share Posted May 20, 2019 Hello Oleg, Parameters have their types which can be obtained by getParameterType. And they should be set with methods according to these types. wave0_uv_transform has type PARAMETER_EXPRESSION. That's the snippet for setting it: const auto parameter_id = mat->findParameter("wave0_uv_transform"); assert(mat->getParameterType(parameter_id) == Material::PARAMETER_EXPRESSION); const auto value = Math::vec4(1.0, 2.0, 3.0, 4.0); mat->setParameterExpression(parameter_id, String::format("vec4(%f,%f,%f,%f)", value.x, value.y, value.z, value.w)); We're currently working on improvement of that API. Link to comment
smirnov.oleg Posted May 20, 2019 Author Share Posted May 20, 2019 Hello Andrey. Using setParameterExpression() solved my problem. Thanks. Link to comment
Recommended Posts