コード例 #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())))
コード例 #2
0
ファイル: primitives.py プロジェクト: ArnoChenFx/Node3D
class Box(GeometryNode):
    __identifier__ = 'Primitives'
    NODE_NAME = 'Box'

    def __init__(self):
        super(Box, self).__init__()
        self.create_property("Size", value=[1, 1, 1], widget_type=NODE_PROP_VECTOR3)
        self.cook()

    def run(self):
        size = self.get_property("Size")
        x = size[0] * 0.5
        y = size[1] * 0.5
        z = size[2] * 0.5
        self.geo = Mesh()
        v1 = self.geo.addVertex([x, -y, -z])
        v2 = self.geo.addVertex([x, -y, z])
        v3 = self.geo.addVertex([x, y, z])
        v4 = self.geo.addVertex([x, y, -z])
        v5 = self.geo.addVertex([-x, -y, -z])
        v6 = self.geo.addVertex([-x, -y, z])
        v7 = self.geo.addVertex([-x, y, z])
        v8 = self.geo.addVertex([-x, y, -z])

        self.geo.addFace([v1, v2, v3, v4])
        self.geo.addFace([v2, v6, v7, v3])
        self.geo.addFace([v6, v5, v8, v7])
        self.geo.addFace([v5, v1, v4, v8])
        self.geo.addFace([v4, v3, v7, v8])
        self.geo.addFace([v5, v6, v2, v1])
        self.geo.mesh.update_normals()