def paintGL(self): # Create a slab. self.polyBlock = csg.box(6,2,4,True) # Punch a hole in it. cyl = csg.cylinder(1,4,True) self.polyBlock -= cyl # Retrieve the vertices and triangles from the # pyPolyCSG mesh, and condition the numpy arrays # for rendering in the paingGL() callback. vertices = self.polyBlock.get_vertices() triangles = self.polyBlock.get_triangles().astype('uint16').flatten() # Make up some colors for the vertices. colors = numpy.array(len(vertices) * [[.7, .7, .7, .999]]) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glLoadIdentity() GL.glTranslated(0.0, 0.0, -10.0) GL.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0) GL.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0) GL.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0) # DBC: Modifications from hellogl.py below this line. scalefactor = .1 GL.glEnableClientState(GL.GL_VERTEX_ARRAY) GL.glScaled(scalefactor, scalefactor, scalefactor) GL.glEnableClientState(GL.GL_COLOR_ARRAY); GL.glColorPointerf(colors) GL.glVertexPointerf(vertices) GL.glDrawElementsui(GL.GL_TRIANGLES, triangles)
def makeObject(self): # Create a slab. self.polyBlock = csg.box(6,2,4,True) # Punch a hole in it. cyl = csg.cylinder(1,4,True) self.polyBlock -= cyl # Retrieve the vertices and triangles from the # pyPolyCSG mesh, and condition the numpy arrays # for rendering in the paingGL() callback. vertices = self.polyBlock.get_vertices() triangles = self.polyBlock.get_triangles().astype('uint16').flatten() # Make up some colors for the vertices. colors = numpy.array(len(vertices) * [[.7, .7, .7, .999]]) # Return a tuple of (vertices, triangles, colors) return (vertices,triangles, colors)
# iterative subtraction of cylinder from box, from Dave Curtis # produces nearly coincident geometry, causes problems when # probe variable is adjusted, likely due to concident/degenerate # geometry. from __future__ import division, print_function, absolute_import, unicode_literals import pyPolyCSG as csg probe = 0.05 #probe = 0.9 # works #probe = 1.0 # works #probe = 1.1 # fails #probe = 2.0 # fails block = csg.box(6, 2, 4, True) cyl = csg.cylinder(1, 4.5, True) cyl = cyl.translate(0, probe, 0) offset = 4 i = 0 # keep track of which iteration failed while offset > -0.4: print(i) i += 1 tool = cyl.translate(offset, 0, 0) block -= tool offset -= 0.5 block.save_mesh('tmp_%04d.obj' % i) print(offset) block.save_mesh('tmp.obj')
# iterative subtraction of cylinder from box, from Dave Curtis # produces nearly coincident geometry, causes problems when # probe variable is adjusted, likely due to concident/degenerate # geometry. import pyPolyCSG as csg #probe = 0.9 # works #probe = 1.0 # works #probe = 1.1 # fails probe = 2.0 # fails block = csg.box(6,2,4,True) cyl = csg.cylinder(1,4.5,True) cyl = cyl.translate(0,probe,0) offset = 4 i = 0 # keep track of which iteration failed while offset > -0.4: print i i += 1 tool = cyl.translate(offset,0,0) block -= tool offset -= 0.5 print offset block.save_mesh('tmp.obj')
# example of box primitive # James Gregson ([email protected]), March 2013 # import module import pyPolyCSG as csg # create a box, arguments are dimensions in x, y and z, # True centers on origin box = csg.box( 1.0, 2.0, 3.0, True ); # save result as box.obj box.save_mesh( "output/box.obj" )
def __init__(self, pos, dim, mat = None, color = None): polyhedron = csg.box(*dim) CSGObject.__init__(self, pos, polyhedron, mat, color) self.translate(pos) self._dim = dim
from __future__ import division, print_function, absolute_import, unicode_literals import numpy; import pyPolyCSG as csg A = csg.box( 1.0, 1.0, 1.0, True ) print('Mesh vertices:') print(A.get_vertices()) print('Mesh triangles:') print(A.get_triangles())
GL.glEnd() GL.glEndList() return genList def normalizeAngle(self, angle): while angle < 0: angle += 360 * 16 while angle > 360 * 16: angle -= 360 * 16 return angle if __name__ == '__main__': app = QtGui.QApplication(sys.argv) window = Window() # construct a polygon blk = csg.box(6,2,4,True) cyl = csg.cylinder(1,4,True) blk -= cyl cyl = csg.cylinder(.5,8,True) cyl = cyl.rotate(90,0,0) blk -= cyl cyl = cyl.rotate(0,90,0) blk -= cyl # and display it window.csgPolygon = blk window.show() sys.exit(app.exec_())
from __future__ import division, print_function, absolute_import, unicode_literals import numpy import pyPolyCSG as csg A = csg.box(1.0, 1.0, 1.0, True) print('Mesh vertices:') print(A.get_vertices()) print('Mesh triangles:') print(A.get_triangles())