Beispiel #1
0
	def setShape( self, matrix4By4 ):
		"Set the shape of this carvable object info."
		self.triangleMesh = triangle_mesh.TriangleMesh()
		vertexElement = self.object.getFirstChildWithClassName( 'vertex' )
		vertexPointElements = vertexElement.getChildrenWithClassName( 'bf:Elem' )
		for vertexPointElement in vertexPointElements:
			coordinateElement = vertexPointElement.getFirstChildWithClassName( 'r' )
			vertex = Vector3( float( coordinateElement.attributeTable[ 'x' ] ), float( coordinateElement.attributeTable[ 'y' ] ), float( coordinateElement.attributeTable[ 'z' ] ) )
			self.triangleMesh.vertices.append( getVector3TransformedByMatrix( matrix4By4.matrix, vertex ) )
		edgeElement = self.object.getFirstChildWithClassName( 'edge' )
		edgeSubelements = edgeElement.getChildrenWithClassName( 'bf:Elem' )
		for edgeSubelementIndex in xrange( len( edgeSubelements ) ):
			edgeSubelement = edgeSubelements[ edgeSubelementIndex ]
			vertexIndexes = [ int( edgeSubelement.attributeTable[ 'v1' ] ), int( edgeSubelement.attributeTable[ 'v2' ] ) ]
			edge = triangle_mesh.Edge().getFromVertexIndexes( edgeSubelementIndex, vertexIndexes )
			self.triangleMesh.edges.append( edge )
		faceElement = self.object.getFirstChildWithClassName( 'face' )
		faceSubelements = faceElement.getChildrenWithClassName( 'bf:Elem' )
		for faceSubelementIndex in xrange( len( faceSubelements ) ):
			faceSubelement = faceSubelements[ faceSubelementIndex ]
			edgeIndexes = [ int( faceSubelement.attributeTable[ 'e1' ] ), int( faceSubelement.attributeTable[ 'e2' ] ), int( faceSubelement.attributeTable[ 'e3' ] ) ]
			face = triangle_mesh.Face().getFromEdgeIndexes( edgeIndexes, self.triangleMesh.edges, faceSubelementIndex )
			self.triangleMesh.faces.append( face )
		self.bottom = getBottom( self.triangleMesh.vertices )
		self.top = getTop( self.triangleMesh.vertices )
Beispiel #2
0
def getCarving(fileName=''):
    "Get the triangle mesh for the stl file."
    if fileName == '':
        unmodified = gcodec.getFilesWithFileTypeWithoutWords('stl')
        if len(unmodified) == 0:
            print("There is no stl file in this folder.")
            return None
        fileName = unmodified[0]
    stlData = gcodec.getFileText(fileName, 'rb')
    if stlData == '':
        return None
    triangleMesh = triangle_mesh.TriangleMesh()
    vertexIndexTable = {}
    binarySolidworksHeaderErrorString = 'solid binary STL from Solid Edge, Unigraphics Solutions Inc.'
    binarySolidworksHeaderError = stlData[:len(
        binarySolidworksHeaderErrorString
    )] == binarySolidworksHeaderErrorString
    if binarySolidworksHeaderError:
        print('The solidworks file has the incorrect header:')
        print(binarySolidworksHeaderErrorString)
        print(
            'A binary stl should never start with the word "solid".  Because this error is common the file is been parsed as binary regardless.'
        )
    if (stlData[:5] == 'solid' and not binarySolidworksHeaderError):
        addFacesGivenText(stlData, triangleMesh, vertexIndexTable)
    else:
        addFacesGivenBinary(stlData, triangleMesh, vertexIndexTable)
    triangleMesh.setEdgesForAllFaces()
    return triangleMesh
Beispiel #3
0
def getCarving( fileName = '' ):
	"Get the triangle mesh for the gts file."
	if fileName == '':
		unmodified = gcodec.getFilesWithFileTypeWithoutWords( 'gts' )
		if len( unmodified ) == 0:
			print( "There is no gts file in this folder." )
			return None
		fileName = unmodified[ 0 ]
	return getFromGNUTriangulatedSurfaceText( gcodec.getFileText( fileName ), triangle_mesh.TriangleMesh() )
Beispiel #4
0
	def setBottomTopTriangleMesh( self, edgeTriples, matrix4By4, vertexPairs, vertices ):
		"Set the bottom, top and triangle mesh of this carvable object info."
		self.triangleMesh = triangle_mesh.TriangleMesh()
		for vertex in vertices:
			self.triangleMesh.vertices.append( getVector3TransformedByMatrix( matrix4By4.matrix, vertex ) )
		for vertexPairsIndex in xrange( len( vertexPairs ) ):
			vertexPair = vertexPairs[ vertexPairsIndex ]
			edge = triangle_mesh.Edge().getFromVertexIndexes( vertexPairsIndex, vertexPair )
			self.triangleMesh.edges.append( edge )
		for edgeTriplesIndex in xrange( len( edgeTriples ) ):
			edgeTriple = edgeTriples[ edgeTriplesIndex ]
			face = triangle_mesh.Face().getFromEdgeIndexes( edgeTriple, self.triangleMesh.edges, edgeTriplesIndex )
			self.triangleMesh.faces.append( face )
		self.bottom = getBottom( self.triangleMesh.vertices )
		self.top = getTop( self.triangleMesh.vertices )
Beispiel #5
0
def getCarving(fileName=''):
    "Get the triangle mesh for the obj file."
    if fileName == '':
        unmodified = gcodec.getFilesWithFileTypeWithoutWords('obj')
        if len(unmodified) == 0:
            print("There is no obj file in this folder.")
            return None
        fileName = unmodified[0]
    objText = gcodec.getFileText(fileName, 'rb')
    if objText == '':
        return None
    triangleMesh = triangle_mesh.TriangleMesh()
    addFacesGivenText(objText, triangleMesh)
    triangleMesh.setEdgesForAllFaces()
    return triangleMesh
Beispiel #6
0
def getCarving( fileName = '' ):
	"Get the triangle mesh for the stl file."
	if fileName == '':
		unmodified = gcodec.getFilesWithFileTypeWithoutWords( 'stl' )
		if len( unmodified ) == 0:
			print( "There is no stl file in this folder." )
			return None
		fileName = unmodified[ 0 ]
	stlData = gcodec.getFileText( fileName, 'rb' )
	if stlData == '':
		return None
	triangleMesh = triangle_mesh.TriangleMesh()
	vertexIndexTable = {}
	numberOfVertexStrings = stlData.count( 'vertex' )
	requiredVertexStringsForText = max( 2, len( stlData ) / 8000 )
	if numberOfVertexStrings > requiredVertexStringsForText:
		addFacesGivenText( stlData, triangleMesh, vertexIndexTable )
	else:
#	A binary stl should never start with the word "solid".  Because this error is common the file is been parsed as binary regardless.
		addFacesGivenBinary( stlData, triangleMesh, vertexIndexTable )
	triangleMesh.setEdgesForAllFaces()
	return triangleMesh