Git Product home page Git Product logo

ofxcorkcsg's Introduction

ofxCorkCsg by Neil Mendoza

ofxCorkCsg

Constructive solid geometry (mesh boolean) addon for openFrameworks v0.10+ based on this fork of the Cork library.

Usage

The addon includes mesh generation functions that create meshes that will work "out of the box" with the boolean operations:

  • void cylinder(ofMesh& mesh, float height, float radius)
  • void sphere(ofMesh& mesh, float radius)
  • void box(ofMesh& mesh, float width, float height, float depth)
  • void octohedron(ofMesh& mesh, float width, float height)

To use the library, generate a mesh and then execute one of the operations.

// input meshes
ofMesh boxMesh, sphereMesh;

// create box
ofxCorkCsg::box(boxMesh, 150.f, 150.f, 150.f);

// create sphere
ofxCorkCsg::sphere(sphereMesh, 100.f);

// output mesh
ofMesh outMesh;

// result = A U B
ofxCorkCsg::computeUnion(boxMesh, sphereMesh, outMesh);

// result = A - B
// ofxCorkCsg::computeDifference(boxMesh, sphereMesh, outMesh);

// result = A ^ B
// ofxCorkCsg::computeIntersection(boxMesh, sphereMesh, outMesh);

// result = A XOR B
// ofxCorkCsg::computeSymmetricDifference(boxMesh, sphereMesh, outMesh);

Cork Mesh Format

The boolean functions that take ofMesh objects as input convert them to Cork's mesh format, CorkTriMesh. This conversion copies the vertices and indices. If you are going to be doing repeated operations on meshes that do not change then it would be more efficient to convert them to ofxCorkCsg::MeshWrapper objects and call the boolean functions on those.

ofMesh in0Mesh, in1Mesh, outMesh;

// generate or load in0 and in1 here

ofxCorkCsg::MeshWrapper in0Wrapper(in0Mesh);
ofxCorkCsg::MeshWrapper in1Wrapper(in1Mesh);
ofxCorkCsg::computeUnion(in0Wrapper, in1Wrapper, outMesh);

The wrapper contains an instance of Cork's native CorkTriMesh that is publicly accessible as wrapper.corkTriMesh.

Mesh Requirements

If you decide to use a mesh that is not generated by the addon then it needs to satisfy the following requirements:

  • Wateright
  • Counter-clockwise triangle winding
  • Shared vertices
  • Primitive mode OF_PRIMITIVE_TRIANGLES

The ofxCorkCsg::unifyVertices(const ofMesh& inMesh, ofMesh& outMesh) function will share a mesh's vertices for you.

ofMesh nonSharedMesh;

// generate or load nonSharedMesh here

ofMesh sharedMesh;

ofxCorkCsg::unifyVertices(nonSharedMesh, sharedMesh);

If you are unsure whether a mesh you are working with satisfies Cork's requirements, the Cork API has an isSolid(CorkTriMesh mesh) function that will check the mesh and log any problems.

ofMesh isThisOk;

// generate or load mesh here

ofxCorkCsg::MeshWrapper wrapper(isThisOk);

isSolid(wrapper.corkTriMesh);

Compatibility

The addon is compatible with openFrameworks v0.10, at the time of writing, this is the master branch on github rather than the stable download from the website.

Cork is dependent on the GMP library and at the moment only the OSX version is included here.

ofxcorkcsg's People

Contributors

neilmendoza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

samw3

ofxcorkcsg's Issues

crash on example-simple

cool addon!

if I run example-simple and hit "2" I see this crash:

the  edge is 0x1030c5eb8,  0x0
   1
coordinates for triangles
the tri
[-22.4144,-50,-83.6516]
[-35.3553,-70.7107,-61.2372]
[-43.3013,-50,-75]
[9.29832e-06,-75,-75]
[-75,-75,-75]
[7.62939e-06,-7.39098e-06,-75]
ENSURE FAILED at ../../../addons/ofxCorkCsg/libs/cork/src/mesh/mesh.isct.inl, line #333:
    vert
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: ENSURE FAILED
(lldb) 

Simple difference operations not working, depending on parameters

This operation works

	ofxCorkCsg::box(mesh1, 300, 300, 50);
	ofxCorkCsg::box(mesh2, 200, 200, 160);
	ofxCorkCsg::computeDifference(mesh1, mesh2, outMesh);

And this doens't work

	ofxCorkCsg::box(mesh1, 300, 300, 50);
	ofxCorkCsg::box(mesh2, 240, 240, 160);
	ofxCorkCsg::computeDifference(mesh1, mesh2, outMesh);

Cheers!

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.