If you want the flag to be pasted all over the green part as well you will either need to cut the texture correctly and set it there or use a single material with correct uv mapping.
“correct uv mapping” is a rather interesting subject First it is your decision how uvs are mapped around this kind of object. There are tools that can help you here, but if you want to do it programmatically you will need to know where each point is and assign the right uv coordinates for it.
However, the diffuse texture applies to the whole mesh, so even the back part of the mesh is textured with the flag… I think you would need to split the object into two parts if you want different texturing on the front/back.
You should either add a new material to the multi material to account for the new submesh, or simply disable submeshes when calling cCSG.toMesh (4th parameter to false).
When you need different materials for different parts but still want a single mesh (for ease of use, as opposed to having one mesh per part), but in your case you wan’t the same material applied for the whole mesh.
I’m thinking there are at least two ways to do this. (I haven’t tried these myself.) One would be to add geometry for the vertical walls and use a different material on them (or maybe change the normals to face a direction >180 degrees of the light to make them black). Another would be use a custom shader with derivative (dfdy, dfdx) checks to black out the vertical parts.
Hi @Evgeni_Popov, it turns out my idea for getting the sides and bottom to be solid did not work… You mentioned somehow splitting the object into two parts so I can get a different texture for sides and bottom? How would I go about doing that? Thanks!
I don’t really know how you can create separated objects, as you are using CSG… The easiest way would be to build it in Blender or a DCC tool like that.
I don’t know, I think Vertex_Definitions exists for a long time. We can’t test in the Playground for the time being, however, as using an older version of Babylon is broken at the time (should be fixed today).
In my production code, I needed to switch the Z direction by rotating the mesh before my CSG.
Bottom line, using this change,
matPrinted.Fragment_Custom_Diffuse( vec3 d1 = dFdx(vLocalPos); vec3 d2 = dFdy(vLocalPos); if (abs(d1.z) > 1e-3 || abs(d2.z) > 1e-3) baseColor.rgb = vec3(0.2, 0.2, 0.2); );
I was able to modify your code a bit to get the Texture on sides (in what is now my Z direction to turn black. but the bottom still has the texture
I have tried everything I could think of but can’t figure out how to keep the top texture and turn the bottom black… ) here is snapshot of the bottom with some subtracted meshes
it’s the vLocalPos.y < 0.5 which is handling the color of the flat part under the part. You will need to adapt it if the top/bottom axis is not the Y axis for your mesh.