karim.salama Posted November 23, 2020 Share Posted November 23, 2020 Hello, I am trying to update UV texture coordinates for a ObjectMeshStatic for each vertex in runtime. Here is my code for now : const auto value = ...; const int num_vertices = mesh->getNumVertex(0); for (int i = 0; i < num_vertices; i++) { auto tex = mesh->getTexCoord0(i,0); tex.y = value; mesh->setTexCoord0(i, tex, 0); } setTextCoord0 seems to have no effect visually on the mesh. Is there anything I am doing wrong? Is there anyway I can use a UV transform which corresponds to the mesh and not the material? Thanks Link to comment
silent Posted November 24, 2020 Share Posted November 24, 2020 Hi Karim, Have you tried to save the mesh after UV coordinates changes? That should help. How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
karim.salama Posted November 24, 2020 Author Share Posted November 24, 2020 Hi @silent, By saving the mesh you mean saving it as a .mesh file using the saveMesh method? Normally, the uv coordinates are updated in realtime, writing the mesh into disk on each drawcall can reduce the performance. Link to comment
silent Posted November 24, 2020 Share Posted November 24, 2020 If you need to update coordinates in runtime you can try to use ObjectMeshDynamic instead. You can also use expressions for the UV transforms in runtime. For example, in order to simulate some simple animations (like texture sliding across the mesh or scaling): https://developer.unigine.com/en/docs/2.12/editor2/materials_settings/#parameters_tab Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
karim.salama Posted November 24, 2020 Author Share Posted November 24, 2020 Multiple meshes (with the same material) can have different UV transforms. I think the solution is to use a ObjectMeshDynamic instead. I will try this and get back to you to keep you up to date :) Thanks. Link to comment
karim.salama Posted November 24, 2020 Author Share Posted November 24, 2020 It works! I used an ObjectMeshDynamic instead, updated the UV texCoords and called flushVertex at each frame. Thanks again. Link to comment
karim.salama Posted November 24, 2020 Author Share Posted November 24, 2020 Even better! I retried the static mesh and just added flushMesh at the end of the update method and it worked. Link to comment
Recommended Posts