spine icon indicating copy to clipboard operation
spine copied to clipboard

Dynamically change mesh texture

Open undimon opened this issue 3 years ago • 4 comments

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?

undimon avatar Nov 09 '21 07:11 undimon

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

ivanpopelyshev avatar Nov 09 '21 09:11 ivanpopelyshev

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?

undimon avatar Nov 09 '21 10:11 undimon

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

ivanpopelyshev avatar Nov 09 '21 10:11 ivanpopelyshev

Ok, I'll try that, thanks!

undimon avatar Nov 09 '21 11:11 undimon