spine
spine copied to clipboard
Dynamically change mesh texture
Hey guys! I have an app where I need to replace mesh texture with another one created on the fly.
I could simply do it by:
const newTexture = PIXI.RenderTexture.create({ width: newTextureWidth, height: newTextureHeight })
renderer.render(somePixiContainerToRender, newTexture)
slot.currentMesh.texture = newTexture
But the thing is that a new texture is larger than original, so after replace the mesh looks visually smaller, probably because it keep using the old UVs... I also tried the:
const newTexture = PIXI.RenderTexture.create({ width: newTextureWidth, height: newTextureHeight })
renderer.render(somePixiContainerToRender, newTexture)
spine.hackTextureBySlotName(slotName, newTexture, newTexture.orig);
It gives the same result as previous - image looks smaller and seems that it ignores the 3rd argument with the size.
Can anyone help me with this?
Im out of pixijs, but here's your code:
newTexture.frame.x = ...
newTexture.frame.y = ...
newTexture.frame.width = ...
newTexture.frame.height = ...
newTexture.updateUvs();
spine.hackTextureBySlotName
Thanks! I've checked the frame property of a new texture and it already has the right size and updated UVs, so this didn't change anything. Btw, I've tried to debug and after hackTextureBySlotName call slot has:
slot.currentMesh._texture - still old texture
slot.currentMesh.texture - new one
I've also tried to call spine.update(0) before and after hack call - still no effect, any other suggestions?
It should work, you have to debug it. Sorry, cant give more help on this thing because im out of the project. You can try start discussion in https://github.com/pixijs/pixijs
Ok, I'll try that, thanks!