I’ve been searching the forum but have not been able to figure this out.
What I’m trying to achieve is dynamically change the color of certain parts of my mesh.
Say for instance some details of a tower change color when it gets captured.
I created the mesh in blender and created two images while texture-painting. I exported those images and then try to slap them on the mesh when needed.
But then I run into a problem. When I load one of the images as a texture and add it as diffuseTexture to a StandardMaterial, the UV mapping seems incorrect when I add it to the mesh (loaded as glb).
When I check the Mesh that is loaded, it uses a PRBMaterial, so I tried that and added the image as the albedoTexture but then the mesh just turns black and the image is nowhere to be seen.
So to sum up, I have multiple questions:
is using multiple textures for changing small details of a mesh a good idea? It’s just base colors, so nothing too heavy performance-wise.
Do I need to use a PRBMaterial if the loadedmesh uses one? Or can I use a StandardMaterial?
Why does the UV Mapping seem off? It is the exact same image used in Blender, where it maps correctly? Not sure if this is a Babylon issue or a Blender issue tbh…
Hi,
Hard to tell just exactly without a PG but I can try anyway:
Well, that’s likely because your imported glb is from the right-handed system and uses a transformNode to conform it to the BJS left-handed system. The material that comes with the mesh is read and applied in conformity. However, the new material you create also needs to have this scaling to display correctly. It depends on how the model is done (on which axis it has been modeled) but in general you will need to set a negativ scaling on the U coordinates of a material/texture created in BJS (and applied to a blender model). If this doesn’t work, try it on V.
Same as above. Note also that when you create a new texture (i.e.: mymat.albedoTexture = new BABYLON.Texture(“textures/mynewtex.jpg”, scene)… what happens is that even though it’s replacing an existing albedoTexture, all properties set to the old texture are gone with the wind. You need to set them again or just update the URL instead of creating new…
again, hard to tell without a PG but note that PBR needs a light/env. If there’s no light or env in the scene, it will show just plain black. Also, check the console to see if there’s an error loading your texture.
I suppose it’s ok. There are other ways. Using UV sets or node material for example. You can also use a spritesheet/cells type of approach. I guess that’s pretty much depending on your needs and in the end, it is ‘per design’. Choose the method that best suits your needs and you can handle easily
No. You can replace the entire material. Simply create a new mat in BJS, then go like 'mesh.material = mynewmat" within or after the import.
The answer is likely from the above. Because of the left-handed VS right-handed system. Point is the UVs are not changed when importing in BJS. So, if its not the same it can only be because of that.
First of all, thanks for taking the time to respond, and thoroughly at that!
Setting vScale = -1 did the trick. Can’t believe I didn’t think of that while I’ve had similar problems before… (+ I had been fiddling with the uScale and vScale this afternoon, just not with negative numbers!)
My day just got a bit better thanks to you, many thanks for that!