Exemplo n.º 1
0
class Demo(ShowBase):
    def __init__(self):
        from rpcore import RenderPipeline, PointLight
        from rpcore.util.movement_controller import MovementController

        self.render_pipeline = RenderPipeline()
        self.render_pipeline.create(self)

        self.render_pipeline.daytime_mgr.time = '08:00'

        self.point_light = PointLight()
        self.point_light.set_color(1, 1, 0.9)
        self.point_light.set_energy(10)
        self.point_light.set_pos(0, 5, 2)
        self.point_light.set_radius(20)
        self.render_pipeline.add_light(self.point_light)

        self.ruby = Actor('ruby.egg', {'idle': 'ruby_anim.egg'})
        self.ruby.reparent_to(self.render)
        self.ruby.set_h(180)
        self.ruby.loop('idle')

        self.controller = MovementController(self)
        self.controller.set_initial_position_hpr(
            Vec3(0, 5, 1.75),  # position
            Vec3(180, -10, 0))  # hpr
        self.controller.setup()
Exemplo n.º 2
0
class Demo(ShowBase):
    def __init__(self):
        from rpcore import RenderPipeline, PointLight
        from rpcore.util.movement_controller import MovementController

        self.render_pipeline = RenderPipeline()
        self.render_pipeline.create(self)

        self.render_pipeline.daytime_mgr.time = '08:00'

        self.point_light = PointLight()
        self.point_light.set_color(1, 1, 0.9)
        self.point_light.set_energy(10)
        self.point_light.set_pos(0, 5, 2)
        self.point_light.set_radius(20)
        self.render_pipeline.add_light(self.point_light)

        # load animations from EGG, because glTF animations aren't supported
        self.ruby_scene = self.loader.load_model('ruby.gltf')
        self.ruby = Actor(self.ruby_scene.find('+Character'), {'idle': 'ruby_anim.egg'})
        self.ruby.reparent_to(self.render)
        self.ruby.set_h(180)
        self.ruby.loop('idle')

        self.controller = MovementController(self)
        self.controller.set_initial_position_hpr(
            Vec3(0, 5, 1.75),  # position
            Vec3(180, -10, 0))  # hpr
        self.controller.setup()
class Demo(ShowBase):
    def __init__(self):
        from rpcore import RenderPipeline, PointLight
        from rpcore.util.movement_controller import MovementController

        self.render_pipeline = RenderPipeline()
        self.render_pipeline.create(self)

        self.render_pipeline.daytime_mgr.time = '08:00'

        self.point_light = PointLight()
        self.point_light.set_color(1, 1, 0.9)
        self.point_light.set_energy(10)
        self.point_light.set_pos(0, 5, 2)
        self.point_light.set_radius(20)
        self.render_pipeline.add_light(self.point_light)

        self.ruby = Actor('ruby_mesh.gltf', {'idle': 'ruby_anim.egg'})
        self.ruby.reparent_to(self.render)
        self.ruby.set_h(180)
        self.ruby.loop('idle')

        self.render_pipeline.set_effect(self.ruby, 'hardware_skinning.yaml', options={}, sort=25)
        sattrib = self.ruby.get_attrib(ShaderAttrib)
        sattrib = sattrib.set_flag(ShaderAttrib.F_hardware_skinning, True)
        self.ruby.set_attrib(sattrib)

        self.controller = MovementController(self)
        self.controller.set_initial_position_hpr(
            Vec3(0, 5, 1.75),  # position
            Vec3(180, -10, 0))  # hpr
        self.controller.setup()
Exemplo n.º 4
0
class MainApp(ShowBase):
    """ Main Testing Showbase """
    def __init__(self):

        # Setup window size, title and so on
        load_prc_file_data(
            "", """
        win-size 1600 900
        window-title Render Pipeline - Lights demo
        """)

        # ------ Begin of render pipeline code ------

        # Insert the pipeline path to the system path, this is required to be
        # able to import the pipeline classes
        pipeline_path = "../../"

        # Just a special case for my development setup, so I don't accidentally
        # commit a wrong path. You can remove this in your own programs.
        if not os.path.isfile(os.path.join(pipeline_path, "setup.py")):
            pipeline_path = "../../RenderPipeline/"

        sys.path.insert(0, pipeline_path)

        from rpcore import RenderPipeline, SpotLight
        self.render_pipeline = RenderPipeline()
        self.render_pipeline.create(self)

        # This is a helper class for better camera movement - its not really
        # a rendering element, but it included for convenience
        from rpcore.util.movement_controller import MovementController

        # ------ End of render pipeline code, thats it! ------

        # Set time of day
        self.render_pipeline.daytime_mgr.time = "4:50"

        self.half_energy = 5000
        self.lamp_fov = 70
        self.lamp_radius = 10
        # Load the scene
        model = loader.loadModel("scene/Scene.bam")
        model.reparent_to(render)

        # Animate balls, this is for testing the motion blur
        blend_type = "noBlend"

        np = model.find("**/MBRotate")
        np.hprInterval(1.5,
                       Vec3(360, 360, 0),
                       Vec3(0, 0, 0),
                       blendType=blend_type).loop()

        np = model.find("**/MBUpDown")
        np_pos = np.get_pos() - Vec3(0, 0, 2)
        Sequence(
            np.posInterval(0.15,
                           np_pos + Vec3(0, 0, 6),
                           np_pos,
                           blendType=blend_type),
            np.posInterval(0.15,
                           np_pos,
                           np_pos + Vec3(0, 0, 6),
                           blendType=blend_type)).loop()

        np = model.find("**/MBFrontBack")
        np_pos = np.get_pos() - Vec3(0, 0, 2)
        Sequence(
            np.posInterval(0.15,
                           np_pos + Vec3(0, 6, 0),
                           np_pos,
                           blendType=blend_type),
            np.posInterval(0.15,
                           np_pos,
                           np_pos + Vec3(0, 6, 0),
                           blendType=blend_type)).loop()

        np = model.find("**/MBScale")
        Sequence(
            np.scaleInterval(0.2, Vec3(1.5), Vec3(1), blendType=blend_type),
            np.scaleInterval(0.2, Vec3(1), Vec3(1.5),
                             blendType=blend_type)).loop()

        # Generate temperature lamps
        # This shows how to procedurally create lamps. In this case, we
        # base the lights positions on empties created in blender.
        self._lights = []
        light_key = lambda light: int(light.get_name().split("LampLum")[-1])
        lumlamps = sorted(model.find_all_matches("**/LampLum*"), key=light_key)
        for lumlamp in lumlamps:
            lum = float(lumlamp.get_name()[len("LampLum"):])
            light = SpotLight()
            light.direction = (0, -1.5, -1)
            light.fov = self.lamp_fov
            light.set_color_from_temperature(lum * 1000.0)
            light.energy = self.half_energy
            light.pos = lumlamp.get_pos(self.render)
            light.radius = self.lamp_radius
            light.casts_shadows = False
            light.shadow_map_resolution = 256
            self.render_pipeline.add_light(light)

            # Put Pandas on the edges
            if lumlamp in lumlamps[0:2] + lumlamps[-2:]:
                panda = loader.loadModel("panda")
                panda.reparent_to(render)
                panda_mat = Material("default")
                panda_mat.emission = 0
                panda.set_material(panda_mat)
                panda.set_pos(light.pos)
                panda.set_z(0.65)
                panda.set_h(180 + randint(-60, 60))
                panda.set_scale(0.2)
                panda.set_y(panda.get_y() - 3.0)

            self._lights.append(light)

        self.render_pipeline.prepare_scene(model)

        # Init movement controller
        self.controller = MovementController(self)
        self.controller.set_initial_position(Vec3(23.9, 42.5, 13.4),
                                             Vec3(23.8, 33.4, 10.8))
        self.controller.setup()

        self.day_time = 0.3
        self.time_direction = 0

        # Keys to modify the time, disabled in the demo
        self.accept("k", self.reset)
        self.accept("p", self.set_time_direction, [
            1,
        ])
        self.accept("p-up", self.set_time_direction, [
            0,
        ])
        self.accept("i", self.set_time_direction, [
            -1,
        ])
        self.accept("i-up", self.set_time_direction, [
            0,
        ])

        self.addTask(self.update, "update")

    def reset(self):
        self.day_time = 0.209

    def set_time_direction(self, direction):
        self.time_direction = direction

    def update(self, task):
        """ Update method """
        frame_time = globalClock.get_frame_time()
        # Make the lights glow
        for i, light in enumerate(self._lights):
            brightness = math.sin(0.4 * i + frame_time * 1.0)
            light.energy = max(
                0, self.half_energy / 2 + brightness * self.half_energy)
        return task.cont
Exemplo n.º 5
0
class MainApp(ShowBase):

    """ Main Testing Showbase """

    def __init__(self):

        # Setup window size, title and so on
        load_prc_file_data("", """
        win-size 1600 900
        window-title Render Pipeline - Benchmark
        """)

        # ------ Begin of render pipeline code ------

        # Insert the pipeline path to the system path, this is required to be
        # able to import the pipeline classes
        pipeline_path = "../../"

        # Just a special case for my development setup, so I don't accidentally
        # commit a wrong path. You can remove this in your own programs.
        if not os.path.isfile(os.path.join(pipeline_path, "setup.py")):
            pipeline_path = "../../RenderPipeline/"

        sys.path.insert(0, pipeline_path)

        from rpcore import RenderPipeline, PointLight
        self.render_pipeline = RenderPipeline()
        self.render_pipeline.create(self)

        # This is a helper class for better camera movement - its not really
        # a rendering element, but it included for convenience
        from rpcore.util.movement_controller import MovementController

        # ------ End of render pipeline code, thats it! ------

        # Set time of day
        self.render_pipeline.daytime_mgr.time = "17:41"

        self.camLens.set_fov(90)

        model = self.loader.load_model("scene/Scene.bam")
        model.reparent_to(self.render)

        model.flatten_strong()
        num_rows = 255

        img = PNMImage("scene/lights.png")

        for x in range(num_rows):
            for y in range(num_rows):
                light = PointLight()
                # light.direction = (0, 0, -1)
                # light.fov = 60
                # light.set_color_from_temperature(randint(2000, 20000))
                light.color = img.get_xel(x * 1, y * 1)
                light.energy = 5000 * (x / num_rows)
                light.pos = Vec3(-(x - num_rows // 2) / num_rows * 1000.0,
                                 (y - num_rows // 2) / num_rows * 1000.0, 2)
                light.radius = 4
                light.inner_radius = 0.5
                light.casts_shadows = False
                light.shadow_map_resolution = 256
                self.render_pipeline.add_light(light)

        self.render_pipeline.prepare_scene(model)

        # Init movement controller
        self.controller = MovementController(self)
        self.controller.set_initial_position(Vec3(0, 450, 200), Vec3(0))
        self.controller.setup()

        self.accept("l", self.benchmark)

    def benchmark(self):
        mopath = (
            (Vec3(0.0, 450.0, 200.0), Vec3(180.0, -23.9624938965, 0.0)),
            (Vec3(-190.848297119, 304.510772705, 90.5852050781), Vec3(209.767547607, -19.2802791595, 0.0)),
            (Vec3(-220.74269104, 10.6886262894, 38.7188148499), Vec3(278.595062256, -16.6669464111, -0.00123210949823)),
            (Vec3(-51.2080802917, -188.072463989, 50.2380104065), Vec3(364.747375488, -22.7647132874, 0.0)),
            (Vec3(211.633651733, -190.621276855, 216.169631958), Vec3(413.887451172, -40.1869468689, -0.000118153897347)),
            (Vec3(320.780090332, 303.404388428, 341.834014893), Vec3(495.000030518, -41.1669464111, 0.00174981483724)),
            (Vec3(125.150436401, 294.57989502, 218.834960938), Vec3(444.363800049, 3.80416536331, 0.0)),
            (Vec3(-355.501434326, 153.010559082, 68.0701370239), Vec3(611.234924316, -11.5491724014, 0.000359044410288)),
            (Vec3(-118.283355713, -115.640907288, 6.09887886047), Vec3(637.222473145, -8.82695007324, 0.0)),
            (Vec3(80.3096160889, 12.4637413025, 26.0630741119), Vec3(676.439758301, -24.3980617523, 0.0)),
            (Vec3(69.6195449829, 152.581176758, 14.8633785248), Vec3(881.898925781, -15.3602952957, 0.0)),
            (Vec3(-202.29776001, 109.818962097, 94.7222290039), Vec3(962.381530762, -27.7736206055, 0.00155594921671)),
            (Vec3(6.89826059341, -412.195037842, 221.591659546), Vec3(1080.42749023, -31.1491756439, 0.0)),
            (Vec3(362.657867432, -34.1290054321, 216.362884521), Vec3(1166.81677246, -35.0691833496, 0.0)),
            (Vec3(-0.339450836182, 452.040649414, 199.996627808), Vec3(180.0, -23.9624938965, 0.0)),
        )
        self.controller.play_motion_path(mopath, 3.0)
Exemplo n.º 6
0
class MainApp(ShowBase):

    """ Main Testing Showbase """

    def __init__(self):

        # Setup window size, title and so on
        load_prc_file_data("", """
        win-size 1600 900
        window-title Render Pipeline - Lights demo
        """)

        # ------ Begin of render pipeline code ------

        # Insert the pipeline path to the system path, this is required to be
        # able to import the pipeline classes
        pipeline_path = "../../"

        # Just a special case for my development setup, so I don't accidentally
        # commit a wrong path. You can remove this in your own programs.
        if not os.path.isfile(os.path.join(pipeline_path, "setup.py")):
            pipeline_path = "../../RenderPipeline/"

        sys.path.insert(0, pipeline_path)

        from rpcore import RenderPipeline, SpotLight
        self.render_pipeline = RenderPipeline()
        self.render_pipeline.create(self)

        # This is a helper class for better camera movement - its not really
        # a rendering element, but it included for convenience
        from rpcore.util.movement_controller import MovementController

        # ------ End of render pipeline code, thats it! ------

        # Set time of day
        self.render_pipeline.daytime_mgr.time = "4:50"

        self.half_energy = 5000
        self.lamp_fov = 70
        self.lamp_radius = 10
        # Load the scene
        model = loader.loadModel("scene/Scene.bam")
        model.reparent_to(render)

        # Animate balls, this is for testing the motion blur
        blend_type = "noBlend"

        np = model.find("**/MBRotate")
        np.hprInterval(1.5, Vec3(360, 360, 0), Vec3(0, 0, 0), blendType=blend_type).loop()

        np = model.find("**/MBUpDown")
        np_pos = np.get_pos() - Vec3(0, 0, 2)
        Sequence(
            np.posInterval(0.15, np_pos + Vec3(0, 0, 6), np_pos, blendType=blend_type),
            np.posInterval(0.15, np_pos, np_pos + Vec3(0, 0, 6), blendType=blend_type)).loop()

        np = model.find("**/MBFrontBack")
        np_pos = np.get_pos() - Vec3(0, 0, 2)
        Sequence(
            np.posInterval(0.15, np_pos + Vec3(0, 6, 0), np_pos, blendType=blend_type),
            np.posInterval(0.15, np_pos, np_pos + Vec3(0, 6, 0), blendType=blend_type)).loop()

        np = model.find("**/MBScale")
        Sequence(
            np.scaleInterval(0.2, Vec3(1.5), Vec3(1), blendType=blend_type),
            np.scaleInterval(0.2, Vec3(1), Vec3(1.5), blendType=blend_type)).loop()


        # Generate temperature lamps
        # This shows how to procedurally create lamps. In this case, we
        # base the lights positions on empties created in blender.
        self._lights = []
        light_key = lambda light: int(light.get_name().split("LampLum")[-1])
        lumlamps = sorted(model.find_all_matches("**/LampLum*"), key=light_key)
        for lumlamp in lumlamps:
            lum = float(lumlamp.get_name()[len("LampLum"):])
            light = SpotLight()
            light.direction = (0, -1.5, -1)
            light.fov = self.lamp_fov
            light.set_color_from_temperature(lum * 1000.0)
            light.energy = self.half_energy
            light.pos = lumlamp.get_pos(self.render)
            light.radius = self.lamp_radius
            light.casts_shadows = False
            light.shadow_map_resolution = 256
            self.render_pipeline.add_light(light)

            # Put Pandas on the edges
            if lumlamp in lumlamps[0:2] + lumlamps[-2:]:
                panda = loader.loadModel("panda")
                panda.reparent_to(render)
                panda_mat = Material("default")
                panda_mat.emission = 0
                panda.set_material(panda_mat)
                panda.set_pos(light.pos)
                panda.set_z(0.65)
                panda.set_h(180 + randint(-60, 60))
                panda.set_scale(0.2)
                panda.set_y(panda.get_y() - 3.0)

            self._lights.append(light)

        self.render_pipeline.prepare_scene(model)

        # Init movement controller
        self.controller = MovementController(self)
        self.controller.set_initial_position(Vec3(23.9, 42.5, 13.4), Vec3(23.8, 33.4, 10.8))
        self.controller.setup()

        self.day_time = 0.3
        self.time_direction = 0

        # Keys to modify the time, disabled in the demo
        self.accept("k", self.reset)
        self.accept("p", self.set_time_direction, [1,])
        self.accept("p-up", self.set_time_direction, [0,])
        self.accept("i", self.set_time_direction, [-1,])
        self.accept("i-up", self.set_time_direction, [0,])

        self.addTask(self.update, "update")

    def reset(self):
        self.day_time = 0.209

    def set_time_direction(self, direction):
        self.time_direction = direction

    def update(self, task):
        """ Update method """
        frame_time = globalClock.get_frame_time()
        # Make the lights glow
        for i, light in enumerate(self._lights):
            brightness = math.sin(0.4 * i + frame_time * 1.0)
            light.energy = max(0, self.half_energy / 2 + brightness * self.half_energy)
        return task.cont
Exemplo n.º 7
0
class Application(ShowBase):
    def __init__(self):
        sys.path.insert(0, "../../")
        load_prc_file_data("", "win-size 512 512")
        load_prc_file_data("", "textures-power-2 none")
        load_prc_file_data("", "print-pipe-types #f")
        load_prc_file_data("", "notify-level-glgsg error")
        # load_prc_file_data("", "win-size 1024 1024")

        from rpcore import RenderPipeline, PointLight

        self.render_pipeline = RenderPipeline()
        self.render_pipeline.mount_mgr.config_dir = "config/"
        self.render_pipeline.set_empty_loading_screen()
        self.render_pipeline.create(self)

        sphere = loader.loadModel("res/sphere.bam")
        sphere.reparent_to(render)

        self.disableMouse()
        self.camLens.setFov(40)
        self.camLens.setNearFar(0.03, 2000.0)
        self.camera.set_pos(0, -3.5, 0)
        self.camera.look_at(0, -2.5, 0)

        self.render2d.hide()
        self.aspect2d.hide()

        light = PointLight()
        light.pos = 10, -10, 10
        light.radius = 1e20
        light.color = (1, 1, 1)
        light.inner_radius = 4.0
        light.energy = 3
        self.render_pipeline.add_light(light)

        light = PointLight()
        light.pos = -10, -10, 10
        light.radius = 1e20
        light.color = (1, 1, 1)
        light.inner_radius = 4.0
        light.energy = 3
        self.render_pipeline.add_light(light)

        for mat in sphere.find_all_materials():
            mat.roughness = material.roughness
            mat.base_color = Vec4(*(list(material.basecolor) + [1]))
            mat.refractive_index = material.ior

            mat.metallic = 1.0 if material.mat_type == "metallic" else 0.0

            if material.mat_type == "clearcoat":
                mat.emission = (2, 0, 0, 0)
                mat.metallic = 1.0
                mat.refractive_index = 1.51

            if material.mat_type == "foliage":
                mat.emission = (5, 0, 0, 0)
                mat.metallic = 0.0
                mat.refractive_index = 1.51

        for i in range(10):
            self.taskMgr.step()

        self.win.save_screenshot("scene-rp.png")

        base.accept("r", self.reload)

    def reload(self):
        print("Reloading")
        self.render_pipeline.reload_shaders()

        for i in range(4):
            self.taskMgr.step()

        self.win.save_screenshot("scene-rp.png")
class Application(ShowBase):

    def __init__(self):
        sys.path.insert(0, "../../")
        load_prc_file_data("", "win-size 512 512")
        load_prc_file_data("", "textures-power-2 none")
        load_prc_file_data("", "print-pipe-types #f")
        load_prc_file_data("", "notify-level-glgsg error")
        # load_prc_file_data("", "win-size 1024 1024")

        from rpcore import RenderPipeline, PointLight

        self.render_pipeline = RenderPipeline()
        self.render_pipeline.mount_mgr.config_dir = "config/"
        self.render_pipeline.set_empty_loading_screen()
        self.render_pipeline.create(self)

        sphere = loader.loadModel("res/sphere.bam")
        sphere.reparent_to(render)

        self.disableMouse()
        self.camLens.setFov(40)
        self.camLens.setNearFar(0.03, 2000.0)
        self.camera.set_pos(0, -3.5, 0)
        self.camera.look_at(0, -2.5, 0)

        self.render2d.hide()
        self.aspect2d.hide()

        light = PointLight()
        light.pos = 10, -10, 10
        light.radius = 1e20
        light.color = (1, 1, 1)
        light.inner_radius = 4.0
        light.energy = 3
        self.render_pipeline.add_light(light)

        light = PointLight()
        light.pos = -10, -10, 10
        light.radius = 1e20
        light.color = (1, 1, 1)
        light.inner_radius = 4.0
        light.energy = 3
        self.render_pipeline.add_light(light)

        for mat in sphere.find_all_materials():
            mat.roughness = material.roughness
            mat.base_color = Vec4(*(list(material.basecolor) + [1]))
            mat.refractive_index = material.ior

            mat.metallic = 1.0 if material.mat_type == "metallic" else 0.0

            if material.mat_type == "clearcoat":
                mat.emission = (2, 0, 0, 0)
                mat.metallic = 1.0
                mat.refractive_index = 1.51

            if material.mat_type == "foliage":
                mat.emission = (5, 0, 0, 0)
                mat.metallic = 0.0
                mat.refractive_index = 1.51

        for i in range(10):
            self.taskMgr.step()

        self.win.save_screenshot("scene-rp.png")

        base.accept("r", self.reload)

    def reload(self):
        print("Reloading")
        self.render_pipeline.reload_shaders()

        for i in range(4):
            self.taskMgr.step()

        self.win.save_screenshot("scene-rp.png")