In short: How could / should I access the triangulation of a TAbstractGeometryNode?
I’m in the early stages of planning my (as much as possible) cross platform game, and getting used to Lazarus having come from older versions of Delphi. I do have a background in real time machinery control systems, and not games programming. But I believe much of my experience will be applicable / transferable. I’m developing in Windows 10, using the latest version of Lazarus. I have started exploring Castle Game Engine (about a week ago), compiled the Castle_Base package, and run a few demo programs.
I have looked at the Castle editor which looks all good, and I have used it to view demo’s, but I don’t think it will be applicable for the game I have in mind as this will not be based on imported assets and level designs etc.
I must say that what I have seen so far with the development of the engine - this is an awesome project! The code is easy to read and very well documented throughout everything that I have seen so far.
Here is some background on what I want to do:
In what I plan to develop for my game, I want the player to be able to edit / modify the world by using simplified 3D editing tools built into the game. The world will be an underground environment and will store the data in a simple axis aligned cubic grid, with the cells representing 10 metre spatial divisions. The cells will connect to each other where their contents allow a route through free space. In a way this is a simplified version of the old portal rendering systems, but is not portal rendering per se.
From what I have seen so far in the engine, each of my world “cells” would encapsulate a (at least one) TCastleScene object (except if the cell represents empty space). Where cells connect, any contained graphics that straddles the boundary will be contained in two separate TCastleScene objects, but will coincide at the boundary seamlessly. The “cells” in the world can go in and out of scope depending on whether they have a chance of being visible or not. This is just a very simple scheme not based on exact visibility, but simple criteria like distance from the viewpoint etc. Cells that go out of scope will have their TCastleScene removed from the viewport but will not necessarily be freed if memory is not an issue. This would allow in memory TCasleScene’s to be re-added to the viewport quickly if the cell comes back into scope. Where cells come into scope that are not currently in memory then these would need to be loaded from files on the local computer. This might result in needing to free some least recently used cells so that memory and graphics resources are released.
Each cell will have a hash code. This code can be checked against a corresponding code from a server to see if the local copy is dirty, and if so re-load a new cell from the server. When a player modifies the graphics in a cell that they “own”, then when they commit the changes these will be up-loaded to the server. The server will then inform any other players which have that cell in their scope so they can download the changes. All of which will happen transparently.
My understanding is that the TCastleScene root node contains an X3D node graph representing the actual geometry and materials etc.
Now for my actual question :
I want the player to be able to edit the “world”. One of the editing abilities I want is to be able to perform something similar to CSG operations. Say for example the player want to make a tunnel through a solid piece of “ground”,. They would draw a 2D section cut of the tunnel and then extrude this through the ground. Behind the scenes the system will need to “subtract” the tunnel from the ground graphics. This will require finding the intersection of those graphics and deleting everything that would have appeared inside the tunnel.
For this I imagine a method call that takes as parameters a pair of TAbstractGeometryNodes and returns a TIndexedFaceSetNode
which is the result of subtracting the first parameter from the second parameter. This would involve something like intersecting all of the triangles in the two sets of geometry to produce new vertices and edges at the intersect. New faces will need to be generated , and vertices and edges inside the tunnel deleted.
I already know how to intersect pairs of arbitrary triangles in 3D space and compute the line segment intersect in terms of the maths. But what I don’t know is how to access a list of triangles from a TAbstractGeometryNode. I have seen methods that are to do with how an X3D node is triangulated for internal use, and that “OverTriangulation” can be used in order to produce better shading.
But how can I access the triangulation which is already performed by the engine? It would seem better to do this than to re-triangulate myself…