The ultimate goal is a simple, easy to use library with functionality akin to OpenSCAD, but usable from mainstream languages (C++ and Python). I currently have a basic implementation functional, including mesh loading and saving (.OFF, .OBJ and .STL), affine transformations, basic primitives and CSG operations union, difference, symmetric difference, and intersection. All of this functionality is available through python via a BOOST.python wrapper.
Here's a sample python script, generating a weird table thing:
from pyCSG import * table = polyhedron() table_top = polyhedron() table_leg = polyhedron() table_top.make_box( 1.0, 1.0, 1.0, True ) table_leg.make_sphere( 0.5, True ) table = table_top.scale( 4.0, 0.25, 3.0 ) table = table.union( table_leg.translate(-1.5,-0.4,-1.0 ) ) table = table.union( table_leg.translate( 1.5,-0.4,-1.0 ) ) table = table.union( table_leg.translate( 1.5,-0.4, 1.0 ) ) table = table.union( table_leg.translate(-1.5,-0.4, 1.0 ) ) torus = polyhedron(); torus.make_torus( 1.0, 0.25, True ) table = table.difference( torus.translate( 0.0, 0.25, 0.0 ) ) table.save_mesh("table.obj");
Which produces the output (viewed in MeshLab):
Note that this is a single watertight mesh suitable for 3D printing, machining or meshing for finite element analysis. I'm still finalizing the API, but will release the code when it's a bit more stable which I hope will make parametric design and optimization much more practical with open source tools.
1 comment:
Post a Comment