Ejemplo n.º 1
0
 def __init__(self, pos, radius, height, mat = None, color = None):
     polyhedron = csg.cylinder(radius, height, True)
     polyhedron = polyhedron.translate(0, height/2.0, 0)
     CSGObject.__init__(self, pos, polyhedron, mat, color)
     self.translate(pos)
     self._radius = radius
     self._height = height
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
# 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')
Ejemplo n.º 6
0
# 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')
Ejemplo n.º 7
0
                
        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_())
Ejemplo n.º 8
0
# example of cylinder primitive
# James Gregson ([email protected]), March 2013

# import module
import pyPolyCSG as csg

# create a cylinder with radius 0.5 and height 2, centered on origin
# with 100 sides
cyl = csg.cylinder( 0.5, 2.0, True, 100 )

tmp = csg.polyhedron()
tmp.make_cylinder( 0.5, 2.0, True, 50 )
tmp.save_mesh("output/cylinder2.obj")

# save result as box.obj
cyl.save_mesh( "output/cylinder.obj" )