Ejemplo n.º 1
0
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())))
Ejemplo n.º 2
0
class Grid(GeometryNode):
    __identifier__ = 'Primitives'
    NODE_NAME = 'Grid'

    def __init__(self):
        super(Grid, self).__init__()
        params = [{'name': 'Size', 'type': 'vector2', 'value': [10, 10]},
                  {'name': 'Resolution', 'type': 'vector2i', 'value': [10, 10]}]
        self.set_parameters(params)
        self.cook()

    def run(self):
        size = self.get_property("Size")
        resolution = self.get_property("Resolution")
        x = size[0] * 0.5
        z = size[1] * 0.5
        fx = resolution[0]
        fz = resolution[1]

        if fx < 2 or fz < 2:
            self.geo = None
            return

        x_range = np.linspace(-x, x, fx)
        z_range = np.linspace(-z, z, fz)
        vertices = np.dstack(np.meshgrid(x_range, z_range, np.array([0.0]))).reshape(-1, 3)
        a = np.add.outer(np.array(range(fx - 1)), fx * np.array(range(fz - 1)))
        faces = np.dstack([a, a + 1, a + fx + 1, a + fx]).reshape(-1, 4)

        nms = np.zeros((vertices.shape[0], 3), dtype=float)
        nms[..., 1] = 1
        self.geo = Mesh()
        self.geo.addVertices(vertices[:, [0, 2, 1]])
        self.geo.addFaces(faces)
        self.geo.setVertexAttribData('normal', nms, attribType='vector3', defaultValue=[0, 0, 0])
Ejemplo n.º 3
0
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)