Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triangulator for dummies #324

Open
Artorias93 opened this issue Feb 5, 2025 · 3 comments
Open

Triangulator for dummies #324

Artorias93 opened this issue Feb 5, 2025 · 3 comments

Comments

@Artorias93
Copy link

Artorias93 commented Feb 5, 2025

Hi @andywiecko!
Thank you so much for your work!

I think it might be useful to have a method that accepts as parameters only a mesh, a parameter of type TriangulatorSettings (with default, customizable value) and eventually a bool for UVs support, and performs input reclamation so as to provide Triangulator with the ones it expects, in the correct format.
Ideally, it would be a method that completely ignores everything about the mesh, whether it is convex, concave, whether it has holes, whether it does not, and returns the mesh processed by Triangulator correctly (perhaps even with support for remapping UVs).

Something like:

public static void RefineMesh(Mesh inputMesh, Triangulator.Settings settings = default, bool mapUVs = true)
{
    //HERE ALL THE OPERATIONS TO PREPARE THE INPUT

    this.Settings = settings;
    Run();

     //HERE ALL THE OPERATIONS TO MODIFY THE INPUT IN THE OUTPUT
}

Do you think it could be possible?

@andywiecko
Copy link
Owner

Hi @Artorias93,
Thank you for reaching out!

I've seen your message in #134. In short, yes, this is possible (with some restrictions).
You can expect my reply with the solutions and remarks this evening (or tomorrow at the latest).

Best,
Andrzej

@Artorias93
Copy link
Author

Omg, thank you for your flash reply!
Your work is really amazing!

@andywiecko
Copy link
Owner

Hi @Artorias93,

I've started pushing components into the package codebase, required for the feature, and designing the proper implementation following all the tests we've conducted in the #134 thread. I believe the best approach would be to provide two additional utilities (with possible parameter overloads) in the andywiecko.BurstTriangulator.Utilities class:

  1. RetriangulateMesh (function, this could also be implemented as an extension?)
  2. RetriangulateMeshJob (struct, job)

The first utility will be a function that handles everything, modifying Mesh in place after a successful triangulation. Internally, it will call the second utility.

The second utility will provide more advanced functionality but will require additional work from the user (MeshData, NativeList, etc.). It will offer full native support with customization and can be executed using Run(), scheduled with Schedule(deps), or integrated into other jobs via Execute(), ensuring maximum performance and flexibility.

Below is a draft of the API (subject to change). My goal is to implement this properly and, I hope, release it next month. If you have any suggestions or feature requests regarding the API, please let me know. I will also continue researching the issues mentioned in #134.

Best,
Andrzej

public static class Utilities { ...

public enum UVMap { None, Planar, Barycentric };

public enum Axis { XY, XZ, YX, YZ, ZX, ZY }

public static void RetriangulateMesh(Mesh mesh, TriangulationSettings settings, Allocator allocator,
    Axis axis = Axis.XY,
    UVMap uvMap = UVMap.None,
    int uvChanelIndex = 0,
    bool recalculateBounds = true,
    bool recalculateNormals = true,
    bool recalculateTangents = true
)
{ ... } 

[BurstCompile]
public struct RetriangulateMeshJob : IJob
{
     RetriangulateMeshJob(MeshData meshData, NativeList<int> triangles, NativeList<Vector3> positions, NativeList<Vector2> uvs, Args args, Allocator allocator, 
          Axis axis = Axis.xy, 
          UVMap uvMap = UVMap.None, 
          int uvChanelIndex = 0,
          ... ) 
         { ... } 

     public void Execute() { ... } 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants