Jump to content

Change textures at runtime


Chiblue
 Share

Recommended Posts

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.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

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..

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

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

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...