Open TheSHEEEP opened 5 years ago
Here is the project, if you want to have a look yourself (only tested on linux, but I don't think that's a problem any more...): procmeshtest.zip
CSGMesh is unrelated to gdprocmesh. I hope to one day add boolean functions to procmesh.. I'm guessing CSGMesh is getting confused chopping up the UVs of the original mesh
I know that gdprocmesh is unrelated to gdprocmesh, but I thought that maybe there was a problem in how the UVs are constructed in gdprocmesh that somehow causes problems in combination with CSGMesh.
But if you say it isn't so, I'll go ahead and report this on the Godot repo.
Btw, this is the thread I opened, just in case someone sees this issue and wants to follow it: https://github.com/godotengine/godot/issues/28661
@BastiaanOlij A new theory has come up in the Godot Discord that you might be able to help with: gdprocmesh produces normals that are somehow broken - this might explain why the top/bottom/start/end of the walls on the mesh generated are broken. But the rest of the mesh looks fine. However, when used as a source for CSGMesh, these broken normals somehow mess up with the CSG builder, resulting in the different look. After all, for triplanar mapping, the normals, instead of the UVs, are used for the texturing - so it would make sense that the difference between both meshes are the normals.
Could that be a possibility?
As a side note, I tried using the Generate Normals node, but it wants vertices and indices - where could I get those from, given a surface (the output of extrude shape)?
This "normals are the problem"-theory has got me thinking and at least I found a workaround: I added more vertices to the shape that gets extruded to form the walls (now I use a curve to form the shape of the wall as you can see by its new triangular top, before I simply used the Rectangle Shape). These new vertices seem to have made sure that all the faces get proper normals both in the original mesh and that mesh used as source for CSGMesh. You can still see a small rendering error on the leftmost side (where the wall "starts"), but this workaround is "good enough" to continue with my project until the underlying bug is fixed.
I still think there is a bug here, either in gdprocmesh not generating proper normals or CSGMesh messing up normals under certain conditions.
So, this has finally been cleared up:
It seems that indeed gdprocmesh produces broken normals, or at least ones incompatible with CSG: https://github.com/godotengine/godot/issues/28661#issuecomment-667759353
I'd say incompatible with CSG:) There are different strategies to creating normals depending on whether you want a smooth of flat look. A more flat look requires vertices to be duplicated and I remember looking into the way CSG merges things where that creates some weird effects. You'd probably get similar issues when creating a shape in say Blender depending on how you set your normals.
Unless I've got the bitangents and tangets inverted, I remember that was an issue that we ended up changing in Godot so possibly Procmesh was never updated to follow suit
New day, new issue ;) However, I have a feeling that this one might not actually be related to gdprocmesh, but I'm not certain.
I created a procedural mesh with two outputs, then copied the MeshArray, then created a new CSGMesh and pasted the MeshArray as its Mesh. The geometry seems to work perfectly fine (as does the interaction with other CSG nodes, so that's awesome).
However, for some reason, the material (of one of the submeshes) becomes "shredded with lines":
As you can see, where the CSGMesh becomes cut out by a CSGCylinder, the wall actually looks better. At first I thought this was a problem with the display of the CSGMesh in the editor (as that tends to show a blue wireframe on top of the actual mesh), but it is just the same when viewed in the final scene.
I'm not entirely sure what is the cause of this. Could be the UVs in combination with the triplanar setting, but I'm not certain. As I said, I also don't know if this is even a gdprocmesh problem or related to the CSGMesh, or the triplanar mapping, etc. All I do know is that I expected the CSGMesh to look exactly like the original MeshArray, but it doesn't.
If you are certain this has nothing to do with the module, I'll open an issue about this on the main Godot tracker. I don't really want to spam this issue across multiple repos if we can exclude some causes first ;) Maybe you have a better idea what this could be related to if it isn't gdprocmesh.