Change model texture in runtime


#1

Add some way to change model texture in runtime. To make something like skins or animated textures.


#2

I think this is coming soon based on mentions of being able to dynamically change textures and materials at runtime.


#3

I am waiting too for this feature …


#4

@britzl just got this issue in my project. I am downloading many png images from a server and I need to display them on the screen. I am using model component with a quad mesh. When I load an image and set it as a texture for one object on the screen, all objects get this image.
Is it still impossible to create a new separate resource for a model and load it with downloaded data?


#5

What are the images/how are they being used?


#6

Images are PNG icons for some sort of a catalog. I create a list view of items with a name label and an icon. Game objects are created with factory.create(), so they share the resource. I want to change the texture resource individually, but they change altogether.


#7

You can try gui.new_texture. I don’t use it, but looks like it can change texture in runtime. Model still can’t change texture. PNG file save (SOLVED)


#8

Are the sizes of the images consistent? https://github.com/subsoap/imagebatch might help as a starting point possibly.


#9

Good stuff, but still won’t solve the issue entirely.


#10

Hm. Any way to use gui texture in the game object world?


#11

Transfer world coord to gui coords every frame, to update gui pos. Or create and attach gui to go. Not good way but no normal way, for changing texture.


#12

I think it must have feature for engine. Plz add it. @sven @britzl


#13

that’s necessary feature.


#14

Hm. Any way to use gui texture in the game object world?

Not an expert but I do think you should be able to kinda do it with some workarounds.

  1. Copy the GUI material from the builtins folder and changed the tag to tile. This will make it move with the camera (will be rendered in worldspace), but the positions changes from a parent go will not propegate to the gui. Therefore:
  2. Create a script that tracks the delta position of the go and send that to the gui. This isn’t free because you would have to send a message to the gui each frame.

parent_gui.script

local position

function init(self)
	position = go.get_position()
	self.action = {x=position.x, y=position.y, dx=0, dy=0}
end

function update(self, dt)
	position = go.get_position()
	self.action.dx = self.action.x - position.x
	self.action.dy = self.action.y - position.y

	self.action.x = position.x
	self.action.y = position.y
	
	msg.post(".", "parent_update", self.action)
end

world_gui.gui_script

function init(self)
	self.root = gui.get_node("root")
end

function on_message(self, message_id, message, sender)
	if message_id == hash("parent_update") then
		local p = gui.get_position(self.root)
		p.x = p.x - message.dx
		p.y = p.y - message.dy
		gui.set_position(self.root, p)
	end
end

Collection Setup
09