Example #1
0
class Test(Base):
    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))

    def update(self):

        if self.input.isKeyDown("p"):
            self.mesh.material.settings[
                "wireframe"] = not self.mesh.material.settings["wireframe"]
        self.rig.update(self.input, 1 / 60)
        self.renderer.render(self.scene, self.camera)
Example #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 = 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)
Example #3
0
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)
Example #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, 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)
Example #5
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;
        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)
Example #6
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)
Example #7
0
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 = 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)

    def update(self):

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

        self.rig.update(self.input, 1 / 60)

        self.backdrop.rotateZ(0.03)
        self.renderer.render(self.scene, self.camera)
Example #8
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)