Coder Social home page Coder Social logo

Comments (5)

elalish avatar elalish commented on July 20, 2024 1

Is this what you're after?

Mesh a_mesh = ImportMesh('something.glb');
Manifold a(a_mesh);
Manifold b = Manifold.Cube();
Mesh b_mesh = b.GetMesh();
const int aID = a.GetMeshIDs()[0];
const int bID = b.GetMeshIDs()[0];

Manifold c = a ^ b;
MeshRelation rel = c.GetMeshRelation();
Mesh c_mesh = c.GetMesh();
std::vector<int> meshID2Original = Manifold::MeshID2Original();

int c_tri = 0; // referring to c_mesh.triVerts[c_tri]
int triVert = 2; // 0, 1, or 2
BaryRef ref = rel.triBary[c_tri];
Mesh& inMesh = meshID2Original[ref.meshID] == aID ? a_mesh : b_mesh;
glm::ivec3 inTri = inMesh.triVerts[ref.tri];
glm::vec3 uvw = rel.UVW(c_tri, triVert); 

glm::vec3 inProp = {inMesh.vertProp[inMesh.triVerts[inTri][0]],
                            inMesh.vertProp[inMesh.triVerts[inTri][1]],
                            inMesh.vertProp[inMesh.triVerts[inTri][2]]};
float prop = glm::dot(inProp, uvw);

// Or check if(ref.vertBary[triVert] < 0) then this refers to c_mesh.vertPos[ref.vertBary[triVert] + 3]. 
// Otherwise it's a new vertex that will have different properties for each side of the intersection.

This same system works even after many consecutive boolean operations, since it will point each triangle back to whichever original mesh it came from, not just the most recent inputs.

from manifold.

elalish avatar elalish commented on July 20, 2024

GetMeshRelation gives you the mesh id and triangles indices, as well as barycentric coordinates. GetMeshIDs gets the mesh ids. For any newly-constructed manifold this vector will length 1 (since it's a new meshID). If you can give some specifics of the trouble you're having, I'll be happy to help more.

from manifold.

elalish avatar elalish commented on July 20, 2024

These test functions might also give you some idea of how it's used: https://github.com/elalish/manifold/blob/master/test/mesh_test.cpp#L36-L79

from manifold.

fire avatar fire commented on July 20, 2024

Can you do an example of getting the triangle from mesh_b when you boolean intersect a and b? Or boolean add if it's too hard.

from manifold.

fire avatar fire commented on July 20, 2024

Thanks. Maybe we can add to the documentation or a test, but I was able to use this.

from manifold.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.