Chiblue Posted February 15, 2010 Share Posted February 15, 2010 I have a model with 3 textures. I load the mesh now and the mat file load my textures but I want to change one of the textures at run time base on a user option. How can I do this? Quote If it's not Tactical realism then you are just playing.. Link to comment Share on other sites More sharing options...
Niosop Posted February 15, 2010 Share Posted February 15, 2010 Take a look at SetMaterialTexture (http://www.leadwerks.com/wiki/index.php?title=Materials#SetMaterialTexture) This will change the texture for all instances of that model though. There's no way to change it for just one instance of the same model if it's animated. If it's a static model then you can duplicate the mesh, paint it and hide the original. Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Rick Posted February 15, 2010 Share Posted February 15, 2010 Tell him about the shader options for changing textures that you made Nio. That was very helpful. Quote Link to comment Share on other sites More sharing options...
Chiblue Posted February 15, 2010 Author Share Posted February 15, 2010 This will change the texture for all instances of that model though. There's no way to change it for just one instance of the same model if it's animated. If it's a static model then you can duplicate the mesh, paint it and hide the original. That is exactly what I want to do, I need to change the texture for that instance of the mesh... so this should work out thanks.. Quote If it's not Tactical realism then you are just playing.. Link to comment Share on other sites More sharing options...
Niosop Posted February 15, 2010 Share Posted February 15, 2010 If you download the LETheora library I made (http://leadwerks.com/werkspace/index.php?app=downloads&showfile=89) there's a utility function for doing it to static meshes in the nio_util.lua file. Here's the code for it: function makeUniqueMesh(ent, meshname) local orig_mesh = ent:FindChild(meshname) local new_mesh = CreateMesh(ent) for surface_index=1, orig_mesh:CountSurfaces() do local orig_surface = ent:FindChild(meshname):GetSurface(surface_index) local new_surface = CreateSurface(new_mesh) for i=1, orig_surface:CountVertices() do new_surface:AddVertex(orig_surface:GetVertexPosition(i-1), orig_surface:GetVertexNormal(i-1), orig_surface:GetVertexTexCoords(i-1,0)) end for i=1, orig_surface:CountTriangles() do new_surface:AddTriangle(orig_surface:TriangleVertex(i-1, 0), orig_surface:TriangleVertex(i-1, 1), orig_surface:TriangleVertex(i-1, 2)) end PaintSurface(new_surface, GetSurfaceMaterial(orig_surface)) end new_mesh:SetPosition(orig_mesh:GetPosition(1),1) new_mesh:SetRotation(orig_mesh:GetRotation(1),1) HideEntity(orig_mesh) UpdateMesh(new_mesh) return new_mesh end You can use PaintEntity on the mesh it returns to change the texture. Again, you can only use it on non-bone animated meshes as we don't have access to the bone information to replicate it. You could also use a special shader and a texture atlas that does a lookup based on the alpha channel. Take a look at this thread for the code: http://leadwerks.com/werkspace/index.php?/topic/607-non-instancing-copy-command/page__hl__atlas__st__20 Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.