I need to build a tunnel underground, so I need to dig a tunnel on the ground. I found a piece of code on a forum and successfully built it, but encountered a problem. It was done through a stencil, and although the hole was dug on the ground, the other meshes on and below the ground lost their cover because it was probably caused by the application of clearDepthWrite. How should I handle it.
I need a fast, real-time, and lightweight operation. If CSG is used for operation, I think it is too expensive,Is there a better way to achieve it?
I am building an editor for a digital twin project related to traffic, so I need to be able to create tunnels in real-time on the terrain. I think I should adopt your suggestion
Hm. What you have in your screenshot is a ditch not a tunnel
Is a tunnel not simply a straight tube either under-ground or through a hill? So all you needed to worry about then would be entry/exit meshes. The rest of the underground/hill could be made transparent. The tunnel itself would just be a tube mesh.
Yes, I just wrote a demo to verify the results. I will use ExtrudeShape to draw a tunnel based on the path. The entrance and exit parts of the tunnel will be exposed to the ground, and I will find a way to cut off the exposed parts
here is the new demo:
In this demo, I dealt with some issues, but there are still problems. The problem is that the box inside the tunnel should be blue, but when viewed from outside the tunnel entrance, it is green, which is the color of the ground. When entering the tunnel, it appears blue when viewed through the ground
@HiGreg
First of all, thank you,I tried using CSG2 to build it, but for the ground, it displayed “Error while creating the CSG: Not manifold”. I think because the groundMesh is a plane rather than a solid, I tried using stencil again and encountered new problems. Can you give me some advice
At present, I am not familiar with the mechanism of stencil. I think it should be possible to implement my requirements through templates, and I am currently researching it
I have already dealt with the box color issue mentioned above, and it is basically close to the final implementation. Now I am using two tunnel meshes, one for stencil clear and one for display. I am thinking about how to achieve it with one tunnel mesh?
Definitely separate the surface topology and the tunnel, it will be a lot easier to work with. You will be able to select the border of the hole, then simplify/smooth, calculate normals then go ahead with your tunnel geometry using a spline mesh. You can cover the entrance uglyness with the concrete structures if this is what the plan is
Yes, I have tried using a box, but I need to support creating a ground or dynamic terrain through a height map, so a flat box may not be suitable. I have tried creating a height for the ground by modifying VertexData, but for now, I think it may not be the best method. There will definitely be lighter way to deal with this problem. I am researching
Agreed. I’m not sure how to solve the problem of applying a bump map to manifold. What about applying it to the ground top face before CSG2? Does CSG2 retain UVs?
Yes, I am trying to do it,I haven’t found a way yet to separate the surface topology and the tunnel,Can give me some guidance, I need some, a lot guidance
I just need a static model or a one-time dynamic model from data:
Consider using a 3D modelling tool like Blender, scripting is available.
I want a dynamic model driven by data (for example a hole in terrain as a location, tunnel built from a Civils alignment):
Use CSG for the surface and a 3D extruded shape on a spline for the tunnel. Driven by data. You can go backwards and forwards with the data automation and CSG to build a nice complex model.
I want to create a runtime tunnel boring tool with complex concave and convex mesh with no data inputs:
Use the suggestions above with CSG only and good luck!
The trick with CSG2 was to cap both ends of the extruded tunnel shape (cap:BABYLON.Mesh.CAP_ALL) so it is recognized as a solid. For good measure, I also closed the shape (closeShape:true) and removed the end point that repeated the start point.
I put a bump map (normal texture) on the ground. I also created a smooth material with the hope to put that material on the inside of the tunnel. But couldn’t figure out how to do that only on the inside of the tunnel.
I removed all the masking stuff, too.
Edit: assigning the smooth material to the tunnel shape before converting to CSG, and removing the “useMaterial” option when converting back .toMesh(), results in the smooth material in the tunnel while the normalTexture is retained on the ground surface.
The error with no Manifold is likely because you did not initialise CSG - google how to do it.
Is there a way to use CSG2 in a fully ESM application? I want to dig holes in the ground and it would be the best way but I am not able to get it properly initialised.
CSG2 needs to call BABYLON.InitializeCSG2Async(options), This method is asynchronous, so CSG2 operations need to be processed in the then callback of this method