blackears / cyclopsLevelBuilder

A Godot plugin to let you block in levels inside the Godot editor.
MIT License
920 stars 36 forks source link

full Discription of Convex_Volume.gd and general block building pipeline? #147

Closed verypleasentusername closed 3 months ago

verypleasentusername commented 3 months ago

Hey! First of all, not really issue releated, but i want to say thanks for such a clean code and design description for almsot every part of this addon. Whenever i had a question i almost immediately got an answer once i looked it up.

Now, can Convex volume and block building parts of code be more explained in the future? im intensely relying on this repo for my map making tool and these part really confused me. Of course, if anything, ill just go and make my own thinking, that might just be less troubling for anyone. My one guess is that block at in-editor state is just "drawing" of it which takes all the info from its ConvexData, and in actual game its when its drawn. Still, how Convex_Volume works is still a mystery to me.

blackears commented 3 months ago

I'm planning to make some changes to the design of this class soon, but the idea is to mimic the data storage formats of systems like OpenGL or Blender. Essentially, you have four different element types that the block object manages - vertex, edge, face and face-vertex tuples. (At the moment there is no face-vertex data - this is one thing I am planning to add - so you can ignore it for now).

Anyhow, each type of data can have any number of pieces of data associated with it. Vertex data has positional data and selection state data. Edges have vertex indices and selection state data, etc. So each element type has multiple data arrays that you can associate with it that describes its function. (I am planning to make this more flexible in the future so you can associate any number of arrays with each element, but for now it has fixed functionality).

When the mesh is built, it is built face by face using the arrays from the face and vertex elements. Meshes are also sometimes regenerated by using a convex hull algorithm to calculate the bounding volume and then comparing face planes to copy face specific data across. The UVs are automatically generated right now using the face transform matrix, but this is another thing I'm thinking of changing.