コード例 #1
0
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 = 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)

    def update(self):

        self.renderer.render(self.scene, self.camera)
コード例 #2
0
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;
        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)

    def update(self):

        self.time += 1/60
        self.mesh.material.uniforms["time"].data = self.time
        self.renderer.render(self.scene, self.camera)
コード例 #3
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)
コード例 #4
0
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, 4)

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

        self.scene.add(self.mesh)

    def update(self):

        self.renderer.render(self.scene, self.camera)
コード例 #5
0
class Test(Base):
    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)

    def update(self):

        self.mesh.rotateX(-0.03)
        self.mesh.rotateY(0.03)
        self.mesh.rotateZ(-0.03)

        self.backdrop.rotateZ(0.03)
        self.renderer.render(self.scene, self.camera)