Exemple #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 )
Exemple #2
0
def getFaceGivenLine(line, triangleMesh):
    "Add face given line index and lines."
    face = triangle_mesh.Face()
    face.index = len(triangleMesh.faces)
    splitLine = line.split()
    for vertexStringIndex in xrange(1, 4):
        vertexString = splitLine[vertexStringIndex]
        vertexStringWithSpaces = vertexString.replace('/', ' ')
        vertexStringSplit = vertexStringWithSpaces.split()
        vertexIndex = int(vertexStringSplit[0]) - 1
        face.vertexIndexes.append(vertexIndex)
    return face
Exemple #3
0
def getFaceGivenLines( triangleMesh, vertexStartIndex, vertexIndexTable, vertices ):
	"Add face given line index and lines."
	face = triangle_mesh.Face()
	face.index = len( triangleMesh.faces )
	for vertexIndex in xrange( vertexStartIndex, vertexStartIndex + 3 ):
		vertex = vertices[ vertexIndex ]
		vertexUniqueIndex = len( vertexIndexTable )
		if str( vertex ) in vertexIndexTable:
			vertexUniqueIndex = vertexIndexTable[ str( vertex ) ]
		else:
			vertexIndexTable[ str( vertex ) ] = vertexUniqueIndex
			triangleMesh.vertices.append( vertex )
		face.vertexIndexes.append( vertexUniqueIndex )
	return face
Exemple #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 )
Exemple #5
0
def getFromGNUTriangulatedSurfaceText(gnuTriangulatedSurfaceText,
                                      triangleMesh):
    "Initialize from a GNU Triangulated Surface Text."
    if gnuTriangulatedSurfaceText == '':
        return None
    lines = gcodec.getTextLines(gnuTriangulatedSurfaceText)
    linesWithoutComments = []
    for line in lines:
        if len(line) > 0:
            firstCharacter = line[0]
            if firstCharacter != '#' and firstCharacter != '!':
                linesWithoutComments.append(line)
    splitLine = linesWithoutComments[0].split()
    numberOfVertices = int(splitLine[0])
    numberOfEdges = int(splitLine[1])
    numberOfFaces = int(splitLine[2])
    faceTriples = []
    for vertexIndex in xrange(numberOfVertices):
        line = linesWithoutComments[vertexIndex + 1]
        splitLine = line.split()
        vertex = Vector3(float(splitLine[0]), float(splitLine[1]),
                         float(splitLine[2]))
        triangleMesh.vertices.append(vertex)
    edgeStart = numberOfVertices + 1
    for edgeIndex in xrange(numberOfEdges):
        line = linesWithoutComments[edgeIndex + edgeStart]
        splitLine = line.split()
        vertexIndexes = []
        for word in splitLine[:2]:
            vertexIndexes.append(int(word) - 1)
        edge = triangle_mesh.Edge().getFromVertexIndexes(
            edgeIndex, vertexIndexes)
        triangleMesh.edges.append(edge)
    faceStart = edgeStart + numberOfEdges
    for faceIndex in xrange(numberOfFaces):
        line = linesWithoutComments[faceIndex + faceStart]
        splitLine = line.split()
        edgeIndexes = []
        for word in splitLine[:3]:
            edgeIndexes.append(int(word) - 1)
        face = triangle_mesh.Face().getFromEdgeIndexes(edgeIndexes,
                                                       triangleMesh.edges,
                                                       faceIndex)
        triangleMesh.faces.append(face)
    return triangleMesh