leap71 / PicoGKRuntime

PicoGK Runtime is the C++ framework behind PicoGK a compact and robust geometry kernel for Computational Engineering

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use in Godot Engine for mesh boolean operators on triangle meshes

fire opened this issue · comments

Hi!

I am interested to know if I can use PicoGKRuntime for mesh boolean operators for intersection, subtraction and difference on triangle meshes in Godot Engine. I cannot use C# in the core Godot Engine.

Analysis of the dependencies required means I'd probably need to distribute as a c++ "gdextension".

  1. boost
  2. tbb
  3. c-blosc
  4. openvdb

A common request is to force meshes to be manifold and also autolod (mesh decimation). Extra points for preserving skeleton skinned meshes.

Hi @fire
yes, you can use the PicoGK runtime for this, either through the exported C API, or using the C++ Voxels and Mesh directly. I implemented all of these header-only, so the only things you would need are the compiled dependencies. the openvdb team is currently trying the eliminate the dependency on boost. TBB is required, blosc is only required if you need to deal with compressed .VDB files, which you are probably not.

You could, of course, also use openvdb directly, to do what you want to accomplish, using my source as an inspiration. OpenVDB can look daunting, but once you get the hang of it, it's relatively straightforward.

To retopologize a mesh, youd'd voxelize your mesh with something like this:

// Convert Mesh to Voxels

openvdb::math::Transform::Ptr roTransform 
  = openvdb::math::Transform::createLinearTransform(fVoxelSize);

openvdb::FloatGrid::Ptr roGrid = openvdb::tools::meshToLevelSet<openvdb::FloatGrid>(  
  *roTransform,
  oVertices,
  oTriangles,
  3.0);
  
// Convert Voxels to Mesh
  
std::vector< openvdb::Vec3s > oPoints;
std::vector< openvdb::Vec3I > oTriangles;
std::vector< openvdb::Vec4I > oQuads;
		
openvdb::tools::volumeToMesh<openvdb::FloatGrid>(
  *roGrid,
  oPoints,
  oTriangles,
  oQuads,
  0.0f,
  0.0,
  alse);

// Convert quads to triangles
        
for (const openvdb::Vec4I oQuad : oQuads)
{
    openvdb::Vec3I o1(oQuad[0], oQuad[1], oQuad[2]);
    oTriangles.push_back(o1);

    openvdb::Vec3I o2(oQuad[2], oQuad[3], oQuad[0]);
    oTriangles.push_back(o2);
}
	    
// Now you have all vertices in oPoints and all triangles in oTriangles

The easiest way to see if it is doing what you want is use the PicoGK demo C# code and load various demo STLs and output them, as retopologized meshes.

Voxels vox = new(Mesh.mshFromStlFile(...);
Mesh msh = new(vox); // retopologize
msh.SaveToStlFile(...);

Hope this helps,
Lin

I recall that keeping vertex attributes was a headache. Will investigate.

In conclusion I split the problems:

  1. no solution for making things manifold
  2. Use https://github.com/elalish/manifold for the cad kernel

Thanks for the help though.