class Face(GeometryNode): __identifier__ = 'OpenGL' NODE_NAME = 'Face' def __init__(self): super(Face, self).__init__() self.add_input("Points", multi_input=True) def run(self): self.geo = Mesh() geos = [ port.node().get_data(port) for port in self.get_port(0).connected_ports() ] points = [] pscales = [] colors = [] for geo in geos: points.append(geo.getVertexAttrib('pos', 0)) pscales.append(geo.getVertexAttrib('pscale', 0)) colors.append(geo.getVertexAttrib('color', 0)) self.geo.addVertices(points) self.geo.setVertexAttribData('color', colors, attribType='vector3', defaultValue=[1, 1, 1]) self.geo.setVertexAttribData('pscale', pscales, attribType='float', defaultValue=1.0) if self.geo.getNumVertexes() > 2: self.geo.addFace(list(range(self.geo.getNumVertexes())))
class File(GeometryNode): __identifier__ = 'Geometry' NODE_NAME = 'File' def __init__(self): super(File, self).__init__() ext = "*." + ";*.".join(imports) self.add_file_input("file", "file", ext=ext) def load(self, filePath): self.geo = Mesh() scene = pyassimp.load(filePath, processing=import_flags) norms = None uvs = None for mesh in scene.meshes: offset = self.geo.getNumVertexes() self.geo.addVertices(mesh.vertices) for vts in mesh.faces: self.geo.mesh.add_face([self.geo.mesh.vertex_handle(i + offset) for i in vts if i >= 0]) normals = mesh.normals if normals.shape[0] > 0: if norms is None: norms = [normals] else: norms.append(normals) elif norms is not None: norms.append(np.zeros((len(mesh.vertices), 3))) texcoords = mesh.texturecoords if texcoords.shape[0] > 0: if uvs is None: uvs = [texcoords[0]] else: uvs.append(texcoords[0]) elif uvs is not None: uvs.append(np.zeros((len(mesh.vertices), 3))) if norms is not None: self.geo.setVertexAttribData('normal', np.vstack(norms), attribType='vector3', defaultValue=[0, 0, 0]) if uvs is not None: self.geo.setVertexAttribData('uv', np.vstack(uvs), attribType='vector3', defaultValue=[0, 0, 0]) pyassimp.release(scene) def run(self): file = self.get_property("file") self.geo = None if os.path.exists(file): self.load(file)