mesh.set_textures(database["textures"])
    mesh.set_scale(6371)
    pos = 6371 + 9000
    mesh.set_pos(Point3(0, pos, 0))
    render_pipeline.setEffect(mesh.node_path, "Effects/Earth.effect")
    mesh.reparent_to(base.render)

    sun_light = DirectionalLight()
    sun_pos = Vec3(10000, pos, 0)
    sun_light.setSunDistance(20000)
    sun_light.setPos(sun_pos)
    sun_light.setPssmTarget(base.cam, base.camLens)
    sun_light.setColor(Vec3(1.0))
    sun_light.setShadowMapResolution(2048)
    sun_light.setCastsShadows(True)
    render_pipeline.addLight(sun_light)

    scattering = render_pipeline.getScattering()
    scattering.adjustSetting("atmosphereOffset", Vec3(0, pos, 0))
    scattering.adjustSetting("atmosphereScale", Vec3(1.0))
    render_pipeline.setScatteringSource(sun_light)

    controller = MovementController(base)
    controller.setup()

    base.accept("f3", toggleSceneWireframe)
    render_pipeline.reloadShaders()
    render_pipeline.onSceneInitialized()

    base.run()
Beispiel #2
0
def main_menu():
    """Main menu management."""
    import sandbox
    from panda3d.core import Vec3
    from spacedrive.renderpipeline import DirectionalLight, PointLight
    import math
    import gui_manager

    spacedrive.gui_system.setup_screen(gui_manager.MainMenu())

    solar_system_db = {'Sol': {
        'Sol': {'spectral': 'G2V', 'absolute magnitude': 4.83,
                'texture': 'sun_1k_tex.jpg', 'mass': 2e+30,
                'radius': 695500000.0,
                'rotation': 25.38, 'temperature': 5778, 'type': 'star',
                'bodies': {
                    'Earth': {'atmosphere': {'height': 10000},
                              'semimajor': 149598261, 'period': 365.256363004,
                              'textures': {
                                  'diffuse': 'Planets/Earth/textures/earth_#.png',
                                  'specular': 'Planets/Earth/textures/earth_spec_#.png',
                                  'night': 'Planets/Earth/textures/earth_night_#.png'},
                              'orbit': {'a': 1.00000018,
                                        'e': 'lambda d: 0.01673163 - 3.661e-07 * d',
                                        'w': 'lambda d: 108.04266274 + 0.0031795260 * d',
                                        'i': 'lambda d: -0.00054346 + -0.0001337178 * d',
                                        'M': 'lambda d: -2.4631431299999917',
                                        'N': 'lambda d: -5.11260389 + -0.0024123856 * d'},
                              'mass': 5.9742e+24, 'radius': 6371000.0,
                              'rotation': 1,
                              'type': 'solid'}}}}}

    def update(task=None):
        """ Main update task """
        if True:
            animationTime = sandbox.base.taskMgr.globalClock.getFrameTime() * 0.6

            # displace every light every frame - performance test!
            for i, light in enumerate(lights):
                lightAngle = float(math.sin(i * 1253325.0)) * \
                             math.pi * 2.0 + animationTime * 1.0
                initialPos = initialLightPos[i]
                light.setPos(initialPos + Vec3(math.sin(lightAngle) * 0.0,
                                               math.cos(lightAngle) * 0.0,
                                               math.sin(animationTime) * 10.0))
        if task is not None:
            return task.cont

    shuttle = sandbox.base.loader.loadModel("Ships/Shuttle MKI/shuttle")
    shuttle.reparent_to(sandbox.base.render)
    shuttle.set_pos(100, 0, 0)
    #shuttle.set_pos(00, 100, 0)
    #shuttle.set_pos(10, 50, 10)
    shuttle.set_hpr(-110, -30, 0)
    '''from direct.interval.LerpInterval import LerpHprInterval
    l = LerpHprInterval(shuttle, 10, Vec3(-110, -30, 360))
    l.loop()'''

    skybox = sandbox.base.loader.loadModel("Skybox/Skybox")
    skybox.set_scale(sandbox.base.camLens.get_far()*0.8)
    skybox.reparent_to(sandbox.base.render)
    sandbox.render_pipeline.reloadShaders()
    skybox.setShader(Shader.load(Shader.SLGLSL,
        "Shader/DefaultShaders/Opaque/vertex.glsl",
        "Shader/Skybox/fragment.glsl"))
    lights = []
    initialLightPos = []
    colors = [
        Vec3(1, 0, 0),
        Vec3(0, 1, 0),
        Vec3(0, 0, 1),
        Vec3(1, 1, 0),

        Vec3(1, 0, 1),
        Vec3(0, 1, 1),
        Vec3(1, 0.5, 0),
        Vec3(0, 0.5, 1.0),
    ]

    # Add some shadow casting lights
    '''for i in xrange(4):
        angle = float(i) / 8.0 * math.pi * 2.0

        pos = Vec3(math.sin(angle) * 10.0, math.cos(angle) * 10.0 + 50, 7)
        light = PointLight()
        light.setRadius(10.0)
        light.setColor(colors[i] * 2.0)
        light.setPos(pos)
        light.setShadowMapResolution(1024)
        light.setCastsShadows(True)

        # add light
        sandbox.base.render_pipeline.addLight(light)
        lights.append(light)
        initialLightPos.append(pos)'''

    import spacedrive.utils.texture as texture_utils
    #texture_utils.prepare_srgb(sandbox.base.render)

    #sandbox.base.addTask(update, "update")

    from spacedrive import orbit_system

    key = 'Sol'
    orbit_system.create_solar_system(name=key, database=solar_system_db)
    import sandbox
    from spacedrive.celestial_components import CelestialComponent
    for component in sandbox.get_components(CelestialComponent):
        if component.name.lower() == 'earth':
            from panda3d.core import Point3D
            spawn = Point3D(component.true_pos)
            #spawn.set_y(spawn.get_y() - (6471000*1.5))
            spawn.set_x(spawn.get_x() - (6471000*2))
            #spawn.set_x(spawn.get_x() + 6471000)
            system = sandbox.get_system(spacedrive.GraphicsSystem)
            system.current_pos = spawn
            print("Spawn point:", spawn)
            print("Spawn delta:", spawn - component.true_pos)
    from spacedrive.renderpipeline.Code.MovementController import MovementController

    controller = MovementController(base)
    controller.setup()
    base.accept('new game screen', start_sp_game)
    base.camera.set_hpr(-90, 0, 0)