コード例 #1
0
    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()

        geometry = BoxGeometry()
        material = SurfaceBasicMaterial({"useVertexColors": 1})
        self.mesh = Mesh(geometry, material)
        self.mesh.rotateX(0.6)
        self.mesh.rotateY(-0.6)
        self.mesh.rotateZ(-0.4)

        self.scene.add(self.mesh)

        # pull camera towards viewer
        self.camera.setPosition(0, 0, 4)

        # add a backdrop
        backGeometry = BoxGeometry(width=2, height=2, depth=0.01)
        backMaterial = SurfaceBasicMaterial({"baseColor": [1, 1, 0]})
        self.backdrop = Mesh(backGeometry, backMaterial)
        self.backdrop.rotateX(1.57)
        self.backdrop.setPosition(0, -1, 0)
        self.scene.add(self.backdrop)
コード例 #2
0
ファイル: test-36.py プロジェクト: Frixiol/GraphicsFramework
class Test(Base):

    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()

        self.rig = MovementRig()
        self.rig.add(self.camera)
        self.scene.add(self.rig)
        self.rig.setPosition(0, 0, 4)

        geometry = PlaneGeometry(width=100, height=100,widthResolution=100, heightResolution=100)
        material = SurfaceBasicMaterial({"useVertexColors":1})
        self.terrain = Mesh(geometry, material)
        self.terrain.rotateX(3.14/2)
        self.scene.add(self.terrain)





        self.scene.add(AxesHelper(axisLength=3))




    def update(self):

        self.rig.update(self.input, 1/60)
        self.renderer.render(self.scene, self.camera)
コード例 #3
0
ファイル: test-35.py プロジェクト: Frixiol/GraphicsFramework
    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()

        self.rig = MovementRig()
        self.rig.add(self.camera)
        self.scene.add(self.rig)
        self.rig.setPosition(0, 0, 4)

        geometry = BoxGeometry()
        material = SurfaceBasicMaterial({"useVertexColors": 1})
        self.mesh = Mesh(geometry, material)
        self.mesh.rotateX(0.6)
        self.mesh.rotateY(-0.6)
        self.mesh.rotateZ(-0.4)

        self.scene.add(self.mesh)

        # add a backdrop
        backGeometry = PolygonGeometry(sides=64, radius=2)
        backMaterial = SurfaceBasicMaterial({"baseColor": [1, 1, 0]})
        self.backdrop = Mesh(backGeometry, backMaterial)
        self.backdrop.rotateX(1.57)
        self.backdrop.setPosition(0, -1, 0)
        self.scene.add(self.backdrop)
コード例 #4
0
def main():

    renderer, scene, camera = Renderer(), Scene(), Camera()

    geometry = TorusGeometry()
    material = SurfaceMaterial()
    mesh = Mesh(geometry, material)

    scene.add(mesh)
    mesh.translate(0, 0, -5)

    win = Window(renderer, scene, camera)
コード例 #5
0
ファイル: test-34C.py プロジェクト: Frixiol/GraphicsFramework
class Test(Base):

    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()
        # pull camera towards viewer
        self.camera.setPosition(0, 0, 7)

        geometry = SphereGeometry(radius=3)

        vsCode = """
        in vec3 vertexPosition;
        out vec3 position;
        uniform mat4 modelMatrix;
        uniform mat4 viewMatrix;
        uniform mat4 projectionMatrix;
        
        void main()
        {
            
            vec4 pos = vec4(vertexPosition, 1);
            gl_Position = projectionMatrix * viewMatrix * modelMatrix * pos;
            position = vertexPosition;
        }
        """

        fsCode = """
        in vec3 position;
        out vec4 fragColor;
        
        void main()
        {
            vec3 color = fract(position);
            fragColor = vec4(color,1);
        }
        """
        material = Material(vsCode, fsCode)
        material.locateUniforms()

        self.mesh = Mesh(geometry, material)

        self.scene.add(self.mesh)

    def update(self):

        self.mesh.rotateY(0.01)
        self.renderer.render(self.scene, self.camera)
コード例 #6
0
    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()
        # pull camera towards viewer
        self.camera.setPosition(0, 0, 7)

        geometry = SphereGeometry(radius=3)

        vsCode = """
        in vec3 vertexPosition;
        in vec3 vertexColor;
        uniform mat4 modelMatrix;
        uniform mat4 viewMatrix;
        uniform mat4 projectionMatrix;
        out vec3 color;
        uniform float time;
        
        void main()
        {
            float offset = 0.2 * sin(2.0 * vertexPosition.x + time);
            vec3 pos = vertexPosition + vec3(0, offset, 0);
            gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(pos, 1);
            color = vertexColor;
        }
        """

        fsCode = """
        in vec3 color;
        uniform float time;
        out vec4 fragColor;
        
        void main()
        {
            float r = abs(sin(time));
            vec4 c = vec4(r, -0.5*r, -0.5*r, 0);
            fragColor = vec4(color , 1) + c;
        }
        """

        material = Material(vsCode, fsCode)
        material.addUniform("float", "time", 0)
        material.locateUniforms()

        self.time = 0

        self.mesh = Mesh(geometry, material)

        self.scene.add(self.mesh)
コード例 #7
0
    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()
        # pull camera towards viewer
        self.camera.setPosition(0, 0, 4)

        geometry = BoxGeometry()
        material = SurfaceBasicMaterial({"useVertexColors": 1})
        self.mesh = Mesh(geometry, material)

        self.scene.add(self.mesh)
コード例 #8
0
    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()
        # pull camera towards viewer
        self.camera.setPosition(0, 0, 7)

        geometry = Geometry()
        posData = []
        for x in range(-32, 32, 3):
            posData.append([x/10, sin(x/10), 0])
        geometry.addAttribute("vec3", "vertexPosition", posData)
        geometry.countVertices()

        pointMaterial = PointBasicMaterial({"baseColor": [1,1,0]})
        self.pointMesh = Mesh(geometry, pointMaterial)

        lineMaterial = LineBasicMaterial({"baseColor": [1,0,1]})
        self.lineMesh = Mesh(geometry,lineMaterial)

        self.scene.add(self.pointMesh)
        self.scene.add(self.lineMesh)
コード例 #9
0
ファイル: objreader.py プロジェクト: stolyaroleh/renderer
def read_obj(filename):
    start = default_timer()

    if not os.path.isfile(filename):
        print('File does not exist: {0}'.format(filename))
        return None

    vertices = []
    indices = []
    uvs = []
    uv_indices = []
    normals = []
    normal_indices = []

    def v(args):
        vertices.extend(islice(map(float, args.split()), 0, 3))

    def vt(args):
        uvs.extend(islice(map(float, args.split()), 0, 2))

    def vn(args):
        normals.extend(islice(map(float, args.split()), 0, 2))

    def f(args):
        for a in args.split():
            i = list(map(int, [x or 0 for x in a.split('/')] + [0, 0]))
            indices.append(i[0] - 1)
            uv_indices.append(i[1] - 1)
            normal_indices.append(i[2] - 1)

    actions = {'v': v, 'vt': vt, 'vn': vn, 'f': f}

    with open(filename) as file:
        for tokens in map(lambda x: x.strip().split(' ', 1), file):
            if len(tokens) < 2:
                continue
            action, args = tokens[0], tokens[1]
            actions.get(action, lambda x: None)(args)

    end = default_timer()

    if vertices and indices:
        print('Mesh loaded successfully. Triangle count: {0} \nTime: {1:.2} s'.
              format(len(vertices) // 3, end - start))
        return Mesh(filename, vertices, indices, normals, normal_indices)

    return None
コード例 #10
0
    def initialize(self):
        print("Initializing program...")

        self.renderer = Renderer()
        self.scene = Scene()
        self.camera = Camera()
        self.rig = MovementRig(unitsPerSecond=25, degreesPerSecond=90)
        self.rig.add(self.camera)
        self.scene.add(self.rig)
        self.rig.setPosition(0, 0, 4)

        geometry = GridDotGeometry(width=1000,
                                   height=1000,
                                   heightResolution=300,
                                   widthResolution=300)
        material = SurfaceBasicMaterial({"useVertexColors": 1})
        self.mesh = Mesh(geometry, material)

        self.scene.add(self.mesh)
        self.scene.add(AxesHelper(axisLength=3, lineWidth=2))