Freedom-of-Form-Foundation / anatomy3d

A CAD tool for humanoid anatomy alterations. See the anatomy3d-blender repository for more recent work.
https://freedomofform.org/1856/3d-anatomy-project-scope-phase-1-focus-on-a-limb-joint/
GNU General Public License v2.0
7 stars 5 forks source link

Initial commits for the Anatomy Engine #5

Closed Lathreas closed 3 years ago

Lathreas commented 3 years ago

Hey all!

I've added some basic classes and a simple test geometry which can serve as the base of the rest of the engine. It's not completely finished, of course, as the Character.cs, Species.cs and anatomy files need to be expanded a lot more and some other classes also need to be properly implemented.

The folder structure is intended to be as follows (things in parentheses are not yet included):

anatomy3d
  + engine
     + geometry
        - Surface.cs
        - Hemisphere.cs
        - Cylinder.cs
        - Curve.cs
        - Line.cs
        - Vertex.cs
        - Capsule.cs
        - (...)
     + anatomy
        - BodyPart.cs
        - Joint.cs
        - Bone.cs
        - (Muscle.cs)
        + joints
           - HingeJoint.cs
           - (BallJoint.cs)
           - (SaddleJoint.cs)
           - (PivotJoint.cs)
           - (PlaneJoint.cs)
           - (CondyloidJoint.cs)
        + bones
           - LongBone.cs
           - (ShortBone.cs)
           - (SesamoidBone.cs)
           - (FlatBone.cs)
           - (IrregularBone.cs)
        + (muscles)
           - (... to be designed)
        + (skin)
        + (other types)
    + renderable
        - Mesh.cs
    - Character.cs
    - Species.cs
    - Main.cs

In geometry, all (abstract or real) mathematical geometric objects are defined, such as cylinder surfaces, hemispheres, and various curves. In anatomy, all physically relevant derived classes of BodyPart can be found, so these are basically the basic elements of the full anatomic model. In renderable I intended to put a general class that can be sent to whatever render engine we use, but it's currently not used yet and alternative methods exist for now.

Character.cs and Species.cs will ultimately serve as the containers for the full model as per Luna's recommendation. This is of course not yet implemented, but hopefully we will get to that soon.

This code is currently capable of generating the base meshes required for rendering. It defines the abstract mathematical representation of a point (Vertex.cs), a simple curve (Line.cs) and several surfaces (Cylinder.cs, Hemisphere.cs, Capsule.cs). A capsule is a cylinder with two hemispheres placed on top.

I tested the code to see if it outputs something sensible as VBO and IBOs, but I haven't been able to test it fully rendered yet, so it likely contains some bugs still. Depending on the coordinate system used by the render engine, I might have flipped the normals, so then it would render inside-out. Should be easy to fix once we know that, though.

In Main.cs there's a simple example showing how to use the system so far. It generates a Character that contains a single bone and a single joint. One can get the mesh (VBO+IBO) for each BodyPart by invoking the GenerateMesh method of the geometric surface, as can be seen in Main.cs. Feel free to suggest improvements in coding style, implementation or project structure!

LongBone bone = new LongBone();
UVMesh mesh = bone.GetGeometry().GenerateMesh(32, 32);
List<Vertex> vertexList = mesh.VertexList;
List<int> indexList = mesh.IndexList;
Lathreas commented 3 years ago

I've added a UVMesh class, which contains both the VBO and IBO, such that it is no longer possible to get varying resolution from one object when running GenerateMesh(). I also examined the possibility of making the internal functions GenerateIndexList and GenerateVertexList private instead of public, but it seems we'll need to be able to access these functions separately when only one of the two lists is needed, such as when regenerating only the vertices (then the indices would remain the same). There are more elegant solutions than that, but in order to pick the best one we need to know a bit more about how the rest of the code is set up, so I think I'll keep it at this for now and revisit later if needed.

Lathreas commented 3 years ago

Sorry for the huge amount of deletions, that was due to removing the Unity Project to allow it to compile. If that's not wanted (e.g. if a renaming would be preferred) just let me know, but considering we'll be using Godot from now on I suppose this is the cleanest way.

I also set up the Godot project and opening it in the latest version of Godot-with-mono (for C# support), it should compile and run. I'll post some instructions on how to set Godot up on Linux in a minute.

The files in the "gui/" folder are placeholders, they serve as an example of how to render a bone. Feel free to change, rename or remove them later on when you're working on the GUI and no longer need them.

the-og-gear commented 3 years ago

Merging with 1 approval