DopeBiscuit Posted April 12, 2017 Share Posted April 12, 2017 Hello guys, I was wondering if there is a way to keep using a mesh's UV map after changing it's material. My game currently uses a cell shader, so I have been giving meshes ShaderMaterials and then calling ShaderMaterial.setTexture() to give it the same texture as before. This successfully applies the cell shader and texture, but the UV map is lost in the process so the texture no longer lines up. I've looked through the mesh, material, submaterials, and texture's attributes and all i can find are u/v offset, scale, and Ang (which are 0, 1, 0 respectively), but in the .babylon file for the model I see an attribute caled "uvs" which I'm assuming is what I need to copy. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 12, 2017 Share Posted April 12, 2017 Hello, uvs are stored inside the mesh so changing the material should not affect it. I think what you lost was the uvscale and offset. But you can easily read them from the previous texture and apply them to the new one Quote Link to comment Share on other sites More sharing options...
DopeBiscuit Posted April 12, 2017 Author Share Posted April 12, 2017 Ok so the only difference I can find between the old diffuseTexture and newMaterial._textures.textureSampler is invertY changing invertY doesn't fix the problem though. Considering it's named _invertY I'm assuming I can't change it? I call newMaterial.setTexture(...).setVector3().setFloats() etc but I don't see a setBool function for invertY. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 12, 2017 Share Posted April 12, 2017 invertY has to set at creation time (when you instantiate the texture) Quote Link to comment Share on other sites More sharing options...
DopeBiscuit Posted April 12, 2017 Author Share Posted April 12, 2017 Ah, I see. I should have checked the parameters i was giving to the new texture, i was calling newMaterial.setTexture("textureSampler", new BABYLON.Texture(diffuseUrl, scene, false, false, 2)) when it should have been newMaterial.setTexture("textureSampler", new BABYLON.Texture(diffuseUrl, scene, false, invertY, 2)) Sigh, I feel dumb lol. Thanks for the help Deltakosh! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 13, 2017 Share Posted April 13, 2017 No worry there is no problem Quote 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.