예제 #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()

        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
    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)
예제 #4
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)
예제 #5
0
    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)
예제 #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, 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)
예제 #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
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)
예제 #9
0
    def render_task(self, task_index: int,
                    bucket_index: int,
                    bucket_order_info: BucketOrderInfo, sample, renderer: Renderer):

        sampler = self.main_sampler.get_sub_sampler(bucket_index, bucket_order_info)

        if sampler is None:
            return

        print("start render task : id(" + str(task_index) + ") (" + str(sampler.bucket_extend.start_x) + "," + str(
            sampler.bucket_extend.start_y) + ") " + "(" + str(sampler.bucket_extend.end_x - 1) + "," + str(
            sampler.bucket_extend.end_y - 1) + ")")

        self.draw_bucket_extend(sampler.bucket_extend)

        pixels = []

        maxSamples = sampler.get_maximum_sample_count()
        samples = []
        rays = []
        Ls = []
        Ts = []
        intersections = []
        for n in range(maxSamples):
            samples.append(deepcopy(sample))
            rays.append(Ray())
            Ls.append(Spectrum(0.0))
            Ts.append(Spectrum(0.0))
            intersections.append(Intersection())

            # preallocate array for each pixels
        # rays = [Ray()]*maxSamples
        # Ls = [Spectrum(0.0)]*maxSamples
        # Ts = [Spectrum(0.0)]*maxSamples
        #        intersections = [Intersection()]*maxSamples

        while True:

            if sampler.get_more_samples(samples) == 0:
                break

            for i in range(len(samples)):
                rays[i] = self.camera.generate_ray(samples[i])
                Ls[i] = renderer.get_li(self.scene, rays[i], intersections[i], samples[i])

            s = Spectrum(0.0)
            for i in range(len(samples)):
                s += Ls[i]

            s /= float(len(samples))
            s = s.get_clamp(0.0, 1.0)
            pixels.append(s)

        print("end render task " + str(task_index))

        return pixels, sampler.bucket_extend
예제 #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))
예제 #11
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)
예제 #12
0
def main():

    config = pyglet.gl.Config(double_buffer=True, sample_buffers=1, samples=4)

    win = pyglet.window.Window(config=config)

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

    camera.translate(0, 0, 2)

    particleSystem = ParticleSystem()

    scene.add(particleSystem.boundBoxMesh)
    scene.add(particleSystem.particleMesh)

    def update(dt: float):
        particleSystem()
        # mesh.rotate(0, 0.1, 0.1)

    clock = pyglet.clock.schedule_interval(update, 1 / 120)

    @win.event
    def on_draw():
        win.clear()
        renderer.render(scene, camera)

    @win.event
    def on_mouse_drag(x, y, dx, dy, buttons, modifiers):
        if buttons & pyglet.window.mouse.RIGHT:
            scene.rotate(-dy / 10, dx / 10, 0)

    @win.event
    def on_mouse_scroll(x, y, scroll_x, scroll_y):
        camera.translate(0, 0, -scroll_y)

    # @win.event
    # def on_key_press(symbol, modifiers):
    #     if symbol == pyglet.window.key.A:
    #         camera.translate(-0.1, 0, 0)
    #     if symbol == pyglet.window.key.D:
    #         camera.translate(0.1, 0, 0)
    #     if symbol == pyglet.window.key.W:
    #         camera.translate(0, 0.1, 0)
    #     if symbol == pyglet.window.key.S:
    #         camera.translate(0,-0.1, 0)

    pyglet.app.run()
예제 #13
0
import sys, random
import pygame

from core.renderer import Renderer

ren = Renderer()


class SceneError(Exception):
    pass
    """When a error in a custom script is made."""


class Scene():
    def __init__(self):
        self.renderer = Renderer
        self.objs = {}
        self.events = {
            "OnDraw": {},
            "OnMouseMove": {},
            "OnKey": {},
            "OnQuit": {}
        }

    def addObj(self, obj, pos, name):
        obj.verts = [(x + pos[0], y + pos[1], z + pos[2])
                     for x, y, z in obj.verts]
        self.objs[name] = obj
        print(obj.events)
        for key, value in obj.events.items():
            self.addEvent(