def generate_renderable_array_object(self) -> RenderableArray: """Generates RenderableArray object for a portal""" # Hard coded triangle indices as file format only specifies 4 indices triangleIndices: List[IntIterable] = [[0, 1, 2], [0, 2, 3]] currentRenderable = RenderableArray() currentRenderable.materialIndex = R6Constants.UINT_MAX for vertex in self.vertices: currentRenderable.vertices.append(vertex.copy()) #calculate the normal of the first triangle line1 = Vector.subtract_vector(self.vertices[0], self.vertices[1]) line2 = Vector.subtract_vector(self.vertices[1], self.vertices[2]) crossProductNormal = Vector.cross(line1, line2) #use the same normal for all vertices currentRenderable.normals = [] for _ in range(len(currentRenderable.vertices)): currentRenderable.normals.append(crossProductNormal.copy()) #Explicitly state that there are no values for these attributes currentRenderable.UVs = None currentRenderable.vertexColors = None currentRenderable.triangleIndices = triangleIndices return currentRenderable
def generate_renderable_arrays_for_mesh( self, mesh: R6MeshDefinition) -> List[RenderableArray]: """ Generates a list of RenderableArray objects from the internal data structure """ renderables: List[RenderableArray] = [] uniqueMaterials = set() for faceIdx in mesh.faceIndices: currentFace = self.faces[faceIdx] uniqueMaterials.add(currentFace.materialIndex) for materialIdx in uniqueMaterials: attribList: List[Tuple[int, int]] = [] triangleIndices: List[IntIterable] = [] #build list of sets of vertices and associated params, and list of new triangle indices for faceIdx in mesh.faceIndices: currentFace = self.faces[faceIdx] if currentFace.materialIndex == materialIdx: # Add this face to the current renderable currentTriangleIndices = [] for vertIndex in range(len(currentFace.vertexIndices)): #Build a list of attributes paired with a vertex, which we can use to reduce total array length in the RenderableArray currentAttribs = (currentFace.vertexIndices[vertIndex], currentFace.paramIndices[vertIndex]) if currentAttribs in attribList: currentTriangleIndices.append( attribList.index(currentAttribs)) else: attribList.append(currentAttribs) currentTriangleIndices.append( attribList.index(currentAttribs)) triangleIndices.append(currentTriangleIndices) currentRenderable = RenderableArray() currentRenderable.normals = [] currentRenderable.UVs = [] currentRenderable.vertexColors = [] # fill out new renderable by unravelling and expanding the vertex and param pairs for currentAttribSet in attribList: # Make sure to copy any arrays so any transforms don't get interferred with in other renderables currentVertex = self.vertices[currentAttribSet[0]] currentVertexParams = self.vertexParams[currentAttribSet[1]] currentRenderable.vertices.append(currentVertex.copy()) currentRenderable.normals.append( currentVertexParams.normal.copy()) currentRenderable.UVs.append(currentVertexParams.UV.copy()) # Convert color to RenderableArray standard format, RGBA 0.0-1.0 range importedColorCopy = currentVertexParams.color.copy() # convert the color to 0.0-1.0 range, rather than 0-255 importedColor = normalize_color(importedColorCopy) # pad with an alpha value so it's RGBA importedColor = pad_color(importedColor) currentRenderable.vertexColors.append(importedColor) # Assign the specified material currentRenderable.materialIndex = materialIdx # set the triangle indices currentRenderable.triangleIndices = triangleIndices renderables.append(currentRenderable) return renderables