Пример #1
0
    def __init__(self):
        ShowBase.__init__(self)

        # Load the environment model.
        self.environ = self.loader.loadModel("models/environment")
        # Reparent the model to render.
        self.environ.reparentTo(self.render)
        # Apply scale and position transforms on the model.
        self.environ.setScale(0.25, 0.25, 0.25)
        self.environ.setPos(-8, 42, 0)

        # Add the spinCameraTask procedure to the task manager.
        self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
Пример #2
0
    def initPanda(self):
        if hasattr(self, 'panda'):
            # Allow multiple entry
            return
        if self.do is None:
            self.do = DirectObject()

        # The undecorated config option can't be changed at runtime, so we need
        # to set it before the panda object is created.
        if self.displaySettings.displayMode == NO_BORDER:
            loadPrcFileData('', 'undecorated 1')

        # The resolution /can/ be changed at runtime, but there's a split second
        # flash of the window at the defualt resolution when first opening the
        # game which looks quite ugly.
        loadPrcFileData('', 'win-size %d %d' % self.displaySettings.size)

        loadPrcFile(data.getPandaPath(data, 'config/config.prc'))
        self.panda = ShowBase.ShowBase()
        self.pandaScene = None

        # See https://www.panda3d.org/manual/index.php/Mouse_Support
        self.panda.disableMouse()  # Name is misleading

        self.displaySettings.applyTimings()

        self.initPlaque()

        self.displaySettings.onDetailLevelChanged.addListener(self.setShader)
        self.setShader()
Пример #3
0
    def __init__(self):
        #init panda3d showbase
        base = ShowBase.ShowBase()

        builtins.print_to_screen = print_to_screen

        base.setBackgroundColor(0, 0, 0)
        base.disableMouse()
        base.win.set_close_request_event('exit-event')
        self.accept('exit-event', self.on_exit)
        self.accept('f10', print_to_screen)

        #hacking the event menager
        eventMgr.doEvents = self.doEvents
        #hasking interval manager
        IntervalManager.ivalMgr._step = IntervalManager.ivalMgr.step
        IntervalManager.ivalMgr.step = self.ivalMgr_step
        #hacking task manager
        taskMgr._step = taskMgr.step
        taskMgr.step = self.tsk_step

        try:
            #init game
            self.game = Game(self)
            #start plugins
            for plugin in plugins.values():
                try:
                    plugin.start()
                except:
                    pass
        except Exception as err:
            trbck = traceback.format_exc(limit=1)
            txt = 'Oops, something went wrong!\n\n' + trbck + '\nPlease report this error to the game developers.'
            print_to_screen(txt)
Пример #4
0
    def __init__(self):
        #init ShowBase
        base = ShowBase.ShowBase()

        #base.disableMouse()

        #load all the config vars
        builtins.cfg = Configer(path + 'config.txt')

        #log/print all messages
        builtins.log = Logger(out_file=cfg['log-file'])

        #print the msg (as needed from the configer
        for msg in cfg.debug:
            log.debug(msg)
        for msg in cfg.warning:
            log.warning(msg)

        #make the path a builtin
        builtins.path = path
        log.debug('Curent working directory is: ' + path)

        if cfg['want-pstats']:
            PStatClient.connect()

        #config vars can also be passed as command line arguments
        if len(sys.argv) > 1:
            names = sys.argv[1:][::2]
            values = sys.argv[2:][::2]
            for name, value in dict(zip(names, values)).items():
                log.debug('cmd option: ' + name + ' ' + value)
                cfg.setCfgValueFromString(name, value)
                log.debug(name + ':' + str(cfg[name]))
        #start the game
        self.startGame(path + cfg['source-dir'])
Пример #5
0
    def __init__(self):
        base = ShowBase.ShowBase()

        base.trackball.node().setHpr(0, 40, 0)
        base.trackball.node().setPos(0, 10, 0)

        grid = loader.load_model('grid1')
        grid.reparent_to(render)
        grid.set_scale(0.1)

        self.accept('space', self.run)
Пример #6
0
    def __init__(self):
        base = ShowBase.ShowBase()

        self.helptxt = OnscreenText(
            text="Click on the mesh to make Frowney move",
            parent=base.a2dTopLeft,
            fg=(1, 0, 0, 1),
            pos=(0.06, -0.1),
            align=TextNode.ALeft,
            scale=0.1,
        )

        base.trackball.node().setHpr(0, 40, 0)
        base.trackball.node().setPos(0, 100, 0)

        mesh = loader.loadModel("mesh")
        mesh.reparentTo(render)
        mesh.setRenderModeFilledWireframe((0, 1, 0, 1))

        self.frowney = loader.loadModel("frowney")
        self.frowney.reparentTo(render)
        self.frowney.setH(180.0)  # pathfallower walks backwards...
        self.frowney.setZ(0.5)
        self.frowney.setScale(0.5)
        self.frowney.flattenStrong()
        # Pathfollower is the class that moves a node along a path
        self.seeker = PathFollower(node=self.frowney,
                                   min_distance=1.0,
                                   draw_line=False)
        # NavGraph is the class that finds a path between two points
        self.graph = NavGraph(mesh,
                              smooth=0.5,
                              max_moves=2000,
                              debug=True,
                              draw_graph=False)

        self.start = Point3(0, 0, 0)
        self.end = None

        # mouse picking/collision detection
        self.world_node = render.attachNewNode("World")
        self.world = BulletWorld()
        triMeshData = BulletTriangleMesh()
        triMeshData.addGeom(mesh.getChild(0).node().getGeom(0))
        shape = BulletTriangleMeshShape(triMeshData, dynamic=False)
        geometry = self.world_node.attachNewNode(
            BulletRigidBodyNode("StaticGeometry"))
        geometry.node().addShape(shape)
        geometry.node().setMass(0.0)
        self.world.attachRigidBody(geometry.node())

        self.accept("mouse1", self.set_target)
    def __init__(self):
        ShowBase.__init__(self)
        FSM.__init__(self, "FSM-Game")
        # self.win
        base.enableParticles()
        self.playerName = ""
        self.IsFullScreen = False
        self.blade_runner = player.Player(self.playerName)
        self.disableMouse()
        self.plight = PointLight("plight")
        self.plight.setColor((1, 1, 1, 1))
        self.plnp = self.render.attachNewNode(self.plight)
        self.render.setLight(self.plnp)
        self.windowProps = WindowProperties()

        self.intro = logoscreen.Logoscreen()
        self.intro.start()

        self.crawl = crawl.testCrawl()
        self.accept('1', self.crawl.start)

        self.menu = menu.Menu(self.windowProps, self)
        self.accept('2', self.menu.start)

        self.l1 = level1.Level1()
        self.accept('3', self.l1.start)

        self.l2 = level2.Level2()
        self.accept('4', self.l2.start)

        self.l3 = level3.Level3()
        self.accept('5', self.l3.start)

        self.l4 = level4.Level4()
        self.accept('6', self.l4.start)

        #ENDGAME SCREEN WITH REPORT
        self.end = endgame.Endgame()
        self.accept('7', self.end.start)
Пример #8
0
 def __init__(self):
     base = ShowBase.ShowBase()
     #stress test
     for x in range(32):
         for y in range(32):
             DirectButton(
                         frameSize=(32, 0, 0, -32),
                         pos=(x*32, 0, -y*32),
                         scale=32,
                         command=self.print_id,
                         extraArgs=[x, y],
                         parent=pixel2d
                         )
Пример #9
0
    def __init__(self):
        base = ShowBase.ShowBase()

        self.gui=Gui()
        #debug
        self.accept('tab', base.bufferViewer.toggleEnable)

        #make some sample data
        self.gui.make_group('test')
        #stress test, make 1000 buttons - may not fit screen
        for x in range(50):
            for y in range(20):
                Button(gui=self.gui, width=32, group='test', pos=(-16+x*32, y*32), on_click_cmd='print("button id:{0} clicked!".format(self.id))')

        self.gui.close_group('test')
Пример #10
0
    def __init__(self):
        base = ShowBase.ShowBase()

        base.trackball.node().setHpr(0, 40, 0)
        base.trackball.node().setPos(0, 20, 0)

        DeferredRenderer(preset='full')
        #uncomment is AO is a mess
        #deferred_renderer.set_filter_define('compose', 'DISABLE_AO, 1)

        column=loader.loadModel("models/column")
        column.reparentTo(deferred_render)
        column2=column.copyTo(deferred_render)
        column2.set_pos(10.0, 0, 0)
        column3=column.copyTo(deferred_render)
        column3.set_pos(20.0, 0, 0)
        column4=column.copyTo(deferred_render)
        column4.set_pos(30.0, 0, 0)
        column5=column.copyTo(deferred_render)
        column5.set_pos(40.0, 0, 0)
        column6=column.copyTo(deferred_render)
        column6.set_pos(50.0, 0, 0)
        box=loader.loadModel("models/box2")
        box.set_pos(2,2,0)
        box.setH(45)
        box.reparentTo(deferred_render)

        frowney=loader.loadModel('frowney')
        frowney.set_pos(-2, -1, 1)
        frowney.setH(90)
        frowney.reparentTo(deferred_render)

        #lights will vanish once out of scope, so keep a reference!
        #... but you can also remove lights by doing 'del self.light_1' or 'self.light_1=None'
        #also use keywords! else you'll never know what SphereLight((0.4,0.4,0.6), (0.9,0.0,2.0), 8.0, 256) is!!!
        self.light_0 = SceneLight(color=(0.1, 0.1, 0.3), direction=(-0.5, 0.5, 1.0))
        #self.light_0.add_light(color=(0.0, 0.0, 0.2), direction=(0.5, -0.5, -1.0), name='ambient') #not recomended but working
        self.light_1 = SphereLight(color=(0.9,0.9,0.3), pos=(2,3,2), radius=8.0, shadow_size=256)
        self.light_2 = ConeLight(color=(0.9, 0.9, 0.3), pos=(4,0,5), look_at=(12, 0, 0), radius=16.0, fov=50.0, shadow_size=256)

        self.light_2.set_color((1, 0, 0, 0))

        self.accept('space', self.do_debug)
        self.accept('1', self.change_shadow_bias, [0.001])
        self.accept('2', self.change_shadow_bias, [-0.001])

        self.minimal=False
        self.bias=0.01
    def __init__(self, fStartDirect=False):
        base = getattr(ShowBaseGlobal, 'base', None)
        if not base:
            base = ShowBase(False, windowType='none')

        fDirect = (base.config.GetBool('want-directtools', 0)
                   or (base.config.GetString("cluster-mode", '') != ''))

        self.fStartDirect = fStartDirect or fDirect

        # Create the Wx app
        self.wxApp = wx.App(redirect=False)
        self.wxApp.SetAppName(self.appname)
        WxAppShell.__init__(self,
                            size=wx.Size(self.frameWidth, self.frameHeight))
        self.initialize()
Пример #12
0
    def __init__(self):
        #init ShowBase
        base = ShowBase.ShowBase()
        #make the path a builtin
        builtins.path = path

        cfg = {
            'simple-shaders': False,
            'shadow-size': 1024,
            'shadow-area': 50,
            'srgb': True,
            'hardware-skinning': True
        }

        cfg['hardware-skinning'] = ConfigVariableBool('hardware-skinning',
                                                      True).getValue()
        cfg['srgb'] = ConfigVariableBool('framebuffer-srgb', False).getValue()
        cfg['win-size'] = [
            ConfigVariableInt('win-size', '640 480').getWord(0),
            ConfigVariableInt('win-size', '640 480').getWord(1)
        ]
        cfg['music-volume'] = ConfigVariableInt('music-volume',
                                                '50').getValue()
        cfg['sound-volume'] = ConfigVariableInt('sound-volume',
                                                '100').getValue()
        cfg['key-forward'] = ConfigVariableString('key-forward',
                                                  'w').getValue()
        cfg['key-back'] = ConfigVariableString('key-back', 's').getValue()
        cfg['key-left'] = ConfigVariableString('key-left', 'a').getValue()
        cfg['key-right'] = ConfigVariableString('key-right', 'd').getValue()
        cfg['key-jump'] = ConfigVariableString('key-jump', 'space').getValue()
        cfg['key-cut-grass'] = ConfigVariableString('key-cut-grass',
                                                    'shift').getValue()
        cfg['key-enter-exit-car'] = ConfigVariableString(
            'key-enter-exit-car', 'tab').getValue()
        cfg['shadow-size'] = ConfigVariableInt('shadow-size', 1024).getValue()
        cfg['shadow-area'] = ConfigVariableInt('shadow-area', 50).getValue()

        builtins.cfg = cfg

        self.info_level = DEBUG

        self.startGame()
Пример #13
0
    def __init__(self):
        base = ShowBase.ShowBase()

        scene = loader.loadModel('editor/scene/vol_shp')
        scene.reparentTo(render)

        #movable emitter
        #give it something to move around
        axis = render.attachNewNode('axis')
        self.emitter = loader.loadModel('smiley')
        self.emitter.reparentTo(axis)
        self.emitter.setPos(100, 0, 0)
        interval = axis.hprInterval(15, (360, 0, 0), startHpr=(0, 0, 0))
        interval.loop()
        #emitter.hide()
        #scene.reparentTo(axis)

        #load particles and link them to a moving emitter
        self.particle = Wfx(vector_field='vol_shp.txo.mf',
                            velocity_constant=0.05,
                            collision_depth=0.5,
                            voxel_size=Vec3(128, 128, 128))
        #self.particle2=Wfx(update_speed=60.0, heightmap_resolution=512, world_size=200.0, velocity_constant=0.05)
        self.particle.load("snow3.wfx")
        #self.particle2.load("snow3.wfx")
        #self.particle.set_emitter_node(emitter_id=0, node=self.emitter)
        self.particle.start()
        #self.particle2.start()

        #self.particle.set_emitter_force(0, Vec3(0.1, 0, 0))

        #space stops the fx animation

        self.particle.global_force = Vec3(0, 0, -1)

        self.active = 1

        self.accept("space", self.flip_active)

        taskMgr.add(self.do_wind, 'do_wind')
Пример #14
0
Файл: demo.py Проект: wezu/gpui
    def __init__(self):
        base = ShowBase.ShowBase()

        self.gui=Gui()
        #debug
        self.accept('tab', base.bufferViewer.toggleEnable)

        #make some sample data
        self.gui.make_group('test')

        b=Button(gui=self.gui, width=128, group='test', on_click_cmd='print("button id:{0} clicked!".format(self.id))')
        b.set_pos(0, 32)

        s=Slider(gui=self.gui, parent=None, group='test', name='slider', width=128, pos=(0, 128), on_move_cmd='print("slider value: {0:.2f}".format(*self.value))')

        f=MovableFrame(gui=self.gui, parent=None, group='test', name='frame', size=(256,256))
        f.set_pos(200, 0)

        b2=Button(gui=self.gui, width=128, group='test', parent='frame', pos=(0, 32), on_click_cmd='print("button id:{0} clicked!".format(self.id))')


        self.gui.close_group('test')
Пример #15
0
    def __init__(self):
        #init ShowBase
        base = ShowBase.ShowBase()
        #make the path a builtin
        builtins.path = path

        if exists(path + 'setup.json'):
            #the setup dict can be loaded from
            #-a json file
            #-a pickeled dict
            #-xml
            #-yaml
            #-any other file that can serialize a python dict
            #-or it could be here as a python dict
            #I used object_pairs_hook=OrderedDict to perserve the order of options
            with open(path + 'setup.json') as f:
                setup_data = json.load(f, object_pairs_hook=OrderedDict)
            #if some custom functions are needed you can add them here
            # and set the func value in the setup data e.g "func":"someCustomFunction(42)"
            functions = {'someCustomFunction': self.someCustomFunction}

            #launch the Launcher
            self.launcher = Launcher(self, setup_data, functions)
Пример #16
0
def init():
    """Initialize ShowBase and Panda3D globals."""
    # pylint: disable=global-statement
    global base, cam, cam_node, camera, lens, loader, messenger, \
           mouse_watcher, render, render2d, aspect2d, pixel2d, task_mgr, \
           win, ttf

    load_prc_file(resource_filename('tsim', 'data/config.prc'))

    base = ShowBase.ShowBase()
    cam = base.cam
    cam_node = base.camNode
    camera = base.camera
    lens = base.cam.node().get_lens()
    loader = base.loader
    messenger = base.messenger
    mouse_watcher = base.mouseWatcherNode
    render = base.render
    render2d = base.render2d
    aspect2d = base.aspect2d
    pixel2d = base.pixel2d
    task_mgr = base.task_mgr
    win = base.win
    ttf = loader.load_font('cmtt12.egg')
Пример #17
0
    def __init__(self):
        base = ShowBase.ShowBase()
        base.set_background_color(0, 0, 0)
        base.disable_mouse()

        self.game = Game()
Пример #18
0
if __name__ == "__main__":
    #import Arrow
    #from direct.directbase import DirectStart
    #from showbase.DirectObject import DirectObject
    from direct.showbase import ShowBase
    sb = ShowBase.ShowBase()

    sb.userExit()
    
    
    print "done"
Пример #19
0
print 'TestStart: Starting up test environment.'

from pandac.PandaModules import *

from direct.showbase.PythonUtil import *
from direct.showbase import ShowBase
ShowBase.ShowBase()

# Put an axis in the world:
loader.loadModel("models/misc/xyzAxis").reparentTo(render)

if 0:
    # Hack:
    # Enable drive mode but turn it off, and reset the camera
    # This is here because ShowBase sets up a drive interface, this
    # can be removed if ShowBase is changed to not set that up.
    base.useDrive()
    base.disableMouse()
    if base.mouseInterface:
        base.mouseInterface.reparentTo(base.dataUnused)
    if base.mouse2cam:
        base.mouse2cam.reparentTo(base.dataUnused)
    # end of hack.

camera.setPosHpr(0, -10.0, 0, 0, 0, 0)
base.camLens.setFov(52.0)
base.camLens.setNearFar(1.0, 10000.0)

globalClock.setMaxDt(0.2)
base.enableParticles()
Пример #20
0
    def __init__(self):
        builtins.app=self
        builtins.Config = Config
        #basic stuff
        self.base = ShowBase.ShowBase()
        self.base.disableMouse()
        self.base.set_background_color(0, 0, 0)
        # listen to window events
        self.accept("window-event", self._on_window_event)

        #set some shader inputs
        screen_size = Vec2(base.win.get_x_size(), base.win.get_y_size())
        render.set_shader_input('screen_size', screen_size)
        render.set_shader_input("camera_pos", base.cam.get_pos(render))

        with loading():
            #make the gui
            self.gui=UI('gui/anonymous.ttf',
                       'gui/moonhouse.ttf',
                       'gui/monosb.ttf' )
            self.gui.load_from_file('gui/gui.json')
            self.gui.show_hide('main_menu')

            #load the music
            self.music=loader.load_music('music/starflash.ogg')
            self.music.set_loop(True)

            #load sounds
            self.sfx={}
            self.sfx['up']=loader.load_sfx('sounds/up.ogg')
            self.sfx['down']=loader.load_sfx('sounds/down.ogg')
            self.sfx['yay']=loader.load_sfx('sounds/yay.ogg')

            #set volume
            self.music_volume=Config.getfloat('audio', 'music-volume')
            self.sound_volume=Config.getfloat('audio', 'sound-volume')
            base.musicManager.setVolume(self.music_volume)
            base.sfxManagerList[0].setVolume(self.sound_volume)
            self.gui['sound-volume1']['value']=self.sound_volume
            self.gui['music-volume1']['value']=self.music_volume
            self.gui['sound-volume2']['value']=self.sound_volume
            self.gui['music-volume2']['value']=self.music_volume

            #setup key binds for the camera
            self.key_binds={}
            self.key_binds['rotate']=Config.get('keys', 'camera-rotate')
            self.key_binds['pan']=Config.get('keys', 'camera-pan')
            self.key_binds['zoom_in']=Config.get('keys', 'camera-zoom-in')
            self.key_binds['zoom_out']=Config.get('keys', 'camera-zoom-out')
            self.key_binds['left']=Config.get('keys', 'camera-left')
            self.key_binds['right']=Config.get('keys', 'camera-right')
            self.key_binds['forward']=Config.get('keys', 'camera-forward')
            self.key_binds['back']=Config.get('keys', 'camera-back')
            cam_speed=Config.getfloat('control', 'camera-speed')
            cam_zoom_speed=Config.getfloat('control', 'zoom-speed')
            self.cam_driver=CameraControler(pos=(0,0,0), offset=(0, 20, 0),
                                            speed=cam_speed, zoom_speed=cam_zoom_speed)
            self.cam_driver.bind_keys(**self.key_binds)

            #setup clicking on 3d objects
            self.ray_trav = CollisionTraverser()
            self.ray_handler = CollisionHandlerQueue()
            picker_np = base.camera.attach_new_node(CollisionNode('mouseRay'))
            self.mouse_ray = CollisionRay()
            picker_np.node().add_solid(self.mouse_ray)
            self.ray_trav.add_collider(picker_np, self.ray_handler)

            #skybox
            self.skybox=loader.load_model('models/stars')
            self.skybox.reparent_to(render)
            self.skybox.set_scale(0.8)
            self.skybox.set_bin('background', 0)
            self.skybox.set_depth_write(0)
            self.skybox.set_light_off()
            self.skybox.set_transparency(TransparencyAttrib.M_none)

            self.stars0=self.make_stars(number=1000, size=8, color_variation=0.5, sigma=2.0, spread=10)
            self.stars1=self.make_stars(number=800, size=8, texture='tex/star2.png', sigma=3.0, spread=20)
            self.stars2=self.make_stars(number=300, size=24, spread=50)
            self.stars3=self.make_stars(number=100, size=32, color_variation=0.4, spread=100)
            self.stars4=self.make_stars(number=100, size=56, color_variation=0.2, spread=150)
            self.stars5=self.make_stars(number=10, size=120, color_variation=0.1, spread=100)

            LerpHprInterval(nodePath=self.stars0,duration=2000.0, hpr=(360,360,360), startHpr=(0,0,0)).loop()
            LerpHprInterval(nodePath=self.stars1,duration=2400.0, hpr=(360,360,360), startHpr=(0,0,0)).loop()
            LerpHprInterval(nodePath=self.stars2,duration=2700.0, hpr=(360,360,360), startHpr=(0,0,0)).loop()
            LerpHprInterval(nodePath=self.stars3,duration=3100.0, hpr=(360,360,360), startHpr=(0,0,0)).loop()
            LerpHprInterval(nodePath=self.stars4,duration=3700.0, hpr=(360,360,360), startHpr=(0,0,0)).loop()

            self.accept('mouse1', self.on_click)
            self.accept('mouse3', self.on_click, [True])
            self.time=0
            taskMgr.add(self.update, 'update_tsk')
            self.clock_tsk=taskMgr.doMethodLater(1.0, self.clock, 'clock_tsk')

        #everything is loaded, show it and start the music
        self.gui.fade_screen(0.5, base.get_background_color())
        self.music.play()
Пример #21
0
    def __init__(self):       
        #setup
        self.size=1024
        self.edit_mode=False
        terrain_type='simple'        
        self.terrain_node=None 
        preset='hills'
        
        commands=sys.argv[1:]
        if '-res' in commands:
            try:
                self.size=int(commands[commands.index('-res')+1])
            except Exception as e:
                print e   
        if '-prev' in commands:
            try:
                terrain_type=commands[commands.index('-prev')+1]
            except Exception as e:
                print e 
        if '-edit' in commands:  
            self.edit_mode=True
        else:
            loadPrcFileData("", "window-type offscreen")  
        if '-preset' in commands:
            try:
                preset=commands[commands.index('-preset')+1]
            except Exception as e:
                print e 
                      
        base = ShowBase.ShowBase()
        if self.edit_mode:
            base.cam.set_pos(128, -128, 80)
            base.cam.look_at(128, 128, 0)
               
        self.height_map=self.make_buffer(Shader.load(Shader.SL_GLSL,'shaders/noise_v.glsl','shaders/noise_f.glsl'), self.size, rgbBits=(16, 0, 0, 0))
        
        self.erosion_map=self.make_buffer(Shader.load(Shader.SL_GLSL,'shaders/erode_v.glsl','shaders/erode_f.glsl'), self.size,rgbBits=(16, 0, 0, 0))
        self.erosion_map['quad'].set_shader_input('height_map', self.height_map['tex'])        
        
        self.atr_map=self.make_buffer(Shader.load(Shader.SL_GLSL,'shaders/atr_v.glsl','shaders/atr_f.glsl'), self.size,)
        self.atr_map['quad'].set_shader_input('height_map', self.erosion_map['tex'])
        
        #some starting inputs
        self.inputs={'seed1':random.random(),
                    'seed2':random.random(),
                    'seed3':random.random(),
                    'seed4':random.random(),
                    'seed5':random.random(),
                    'seed6':random.random()                    
                    }
        self.presets={
                    'moutains':{
                        'parm6': Vec2(21.5, 0.007),
                        'parm5': Vec2(1.2, -0.08),
                        'parm4': Vec2(1.95, 0.58),
                        'parm3': Vec2(1.58, -0.93),
                        'parm2': Vec2(7.4, 0.25),
                        'parm1': Vec2(1.85, 0.95),                   
                        'sharpness': [0.5],
                        'erosion': [0.4]
                        },
                    'hills':{
                        'parm3': LVector2f(1.15895, -0.93), 
                        'parm6': LVector2f(21.5, 0.0112105),
                        'parm5': LVector2f(1.2, -0.0315789),
                        'parm4': LVector2f(1.17807, 0.334386),
                        'parm3': LVector2f(1.15895, -0.93),       
                        'parm2': LVector2f(2.48772, 0.355263),
                        'parm1': LVector2f(0.902631, 0.957018),
                        'erosion': [0.4912281036376953],
                        'sharpness': [0.2719298005104065]
                        },
                    'dunes':{
                        'parm3': LVector2f(0.66772, 0.564737), 
                        'parm6': LVector2f(100, 0.00559648),
                        'parm5': LVector2f(1.2, -0.0119299),
                        'parm4': LVector2f(1.95, 0.334386), 
                        'parm2': LVector2f(0, 0.13772),
                        'parm1': LVector2f(0.130702, 0.599123),
                        'erosion': [0.9052631855010986],
                        'sharpness': [0.3070174753665924]    
                        },
                     'ridge':{
                        'parm3': LVector2f(0.842104, -0.221228),
                        'sharpness': [0.2175438106060028],
                        'parm6': LVector2f(1.75438, 0.0126141),
                        'parm5': LVector2f(0.350877, -0.0701754),
                        'parm4': LVector2f(0.491228, 0.15193),
                        'erosion': [0.9473683834075928],
                        'parm2': LVector2f(4.2807, 0.151754),
                        'parm1': LVector2f(0.376315, 0.852632)
                        },
                     'foothills':{
                        'parm3': LVector2f(0.210526, -0.375439),
                        'sharpness': [0.0],
                        'parm6': LVector2f(55.7895, 0.00770173),
                        'parm5': LVector2f(2.25263, 0.0126316),
                        'parm4': LVector2f(0.616668, 0.713333),
                        'erosion': [0.8631577491760254],
                        'parm2': LVector2f(1.71579, 0.579825),
                        'parm1': LVector2f(0.0605269, 0.621053)
                        },
                     'plains':{
                        'parm3': LVector2f(1.12281, 0.403334),
                        'sharpness': [1.0], 
                        'parm6': LVector2f(0.440877, 0.1),
                        'parm5': LVector2f(0.09, -0.1),
                        'parm4': LVector2f(1.12281, 0.341403),
                        'erosion': [0.23508775234222412],
                        'parm2': LVector2f(0.982455, 0.235965),
                        'parm1': LVector2f(0.105263, -0.522807)
                        },
                      'spikes':{
                            'parm3': LVector2f(1.58, -0.93),
                            'sharpness': [0.0],
                            'parm6': LVector2f(93.7807, -0.0063158),
                            'parm5': LVector2f(4.35789, 0.00491222),
                            'parm4': LVector2f(1.73947, 0.692281),
                            'erosion':[1.0],
                            'parm2': LVector2f(15.5403, 0.102631),
                            'parm1': LVector2f(1.85, 1)        
                        },
                      'canyon':{
                        'parm3': LVector2f(0.597547, -0.726316),
                        'sharpness': [0.0],
                        'parm6': LVector2f(1.50001, -0.0333333),
                        'parm5': LVector2f(0.881757, 0.0245614),
                        'parm4': LVector2f(1.04088, 0.880701),
                        'erosion': [1.0],
                        'parm2': LVector2f(1.57544, 1),
                        'parm1': LVector2f(1.21842, 1)
                        }      
                    }
        if preset in self.presets:
            self.inputs.update(self.presets[preset])
        else:
            self.inputs.update(self.presets['moutains'])    

        if self.edit_mode:
            #sliders        
            self.sliders=[]
            self.make_slider('parm1',0, [-0.8, 0.9],min_max=(0.0, 10.0))        
            self.make_slider('parm2',0, [-0.8, 0.8],min_max=(0.0, 20.0))
            self.make_slider('parm3',0, [-0.8, 0.7],min_max=(0.0, 20.0))
            self.make_slider('parm4',0, [-0.8, 0.6],min_max=(0.0, 20.0))
            self.make_slider('parm5',0, [-0.8, 0.5])
            self.make_slider('parm6',0, [-0.8, 0.4])
            
            self.make_slider('parm1',1, [0.3, 0.9], min_max=(-1.0, 1.0))
            self.make_slider('parm2',1, [0.3, 0.8], min_max=(-1.0, 1.0))
            self.make_slider('parm3',1, [0.3, 0.7], min_max=(-1.0, 1.0))
            self.make_slider('parm4',1, [0.3, 0.6], min_max=(-1.0, 1.0))
            self.make_slider('parm5',1, [0.3, 0.5], min_max=(-0.1, 0.1))
            self.make_slider('parm6',1, [0.3, 0.4], min_max=(-0.1, 0.1))
            
            self.make_slider('erosion',0, [-0.5, 0.3], min_max=(0.0, 1.0))
            self.make_slider('sharpness',0, [-0.5, 0.2], min_max=(0.0, 1.0))
            
            #save button
            self.save_button = DirectButton(text='SAVE',scale=0.1, pos=(-0.5,0.0,0.06), command=self.write )
            #reseed button
            self.save_button = DirectButton(text='RANDOM',scale=0.1, pos=(-0.5,0.0,-0.06), command=self.re_seed )
            
            self.preset_buttons=[]
            i=0
            for mode in self.presets:
                b=DirectButton(text=str(mode).upper(),scale=0.1, pos=(1.05,0.0,0.9-i*0.12), command=self.set_preset, extraArgs=[mode] )
                self.preset_buttons.append(b)
                i+=1
        else:
            self.send_inputs()
            base.graphicsEngine.renderFrame() 
            self.write()
            base.userExit()

        if terrain_type=='simple':
            self.terrain_node=None
            self.mesh=loader.loadModel('mesh/mesh80k')
            self.mesh.reparent_to(render)
            self.mesh.set_pos(-256, -256, -50)
            #shader
            terrain_shader=Shader.load(Shader.SL_GLSL, "shaders/terrain_v.glsl", "shaders/terrain_f.glsl")
            self.mesh.set_shader(terrain_shader)
            self.mesh.set_shader_input("height", self.erosion_map['tex'])
            self.mesh.set_shader_input("atr1", self.atr_map['tex'])
            self.mesh.set_shader_input("camera", base.camera)
            
            # Set some texture on the terrain
            grass_tex1 = base.loader.loadTexture("textures/grass.jpg")
            grass_tex1.set_minfilter(SamplerState.FT_linear_mipmap_linear)
            grass_tex1.set_anisotropic_degree(4)            
            dirt_tex1 = base.loader.loadTexture("textures/dirt.jpg")
            dirt_tex1.set_minfilter(SamplerState.FT_linear_mipmap_linear)
            dirt_tex1.set_anisotropic_degree(4)            
            rock_tex1 = base.loader.loadTexture("textures/rock.jpg")
            rock_tex1.set_minfilter(SamplerState.FT_linear_mipmap_linear)
            rock_tex1.set_anisotropic_degree(4)                        
            self.mesh.set_shader_input("grass1",grass_tex1)
            self.mesh.set_shader_input("dirt1",dirt_tex1)
            self.mesh.set_shader_input("rock1",rock_tex1)
            grass_tex1n = base.loader.loadTexture("textures/grass_n.jpg")
            grass_tex1n.set_minfilter(SamplerState.FT_linear_mipmap_linear)
            grass_tex1n.set_anisotropic_degree(4)            
            dirt_tex1n = base.loader.loadTexture("textures/dirt_n.jpg")
            dirt_tex1n.set_minfilter(SamplerState.FT_linear_mipmap_linear)
            dirt_tex1n.set_anisotropic_degree(4)            
            rock_tex1n = base.loader.loadTexture("textures/rock_n.jpg")
            rock_tex1n.set_minfilter(SamplerState.FT_linear_mipmap_linear)
            rock_tex1n.set_anisotropic_degree(4)                        
            self.mesh.set_shader_input("grass1n",grass_tex1n)
            self.mesh.set_shader_input("dirt1n",dirt_tex1n)
            self.mesh.set_shader_input("rock1n",rock_tex1n)
            
        elif terrain_type=='flat':
            cm = CardMaker("plane")
            cm.setFrame(0, 256, 0, 256)
            self.preview_plane=render.attachNewNode(cm.generate())
            self.preview_plane.setTexture(self.erosion_map['tex'])
            self.preview_plane.lookAt(0, 0, -1)     
            self.terrain_node=None
Пример #22
0
 def __init__(self):       
     #setup
     size=512 #size of the wave buffer
     self.update_speed=1.0/60.0 #the waves only look good when generated at this constant rate (1/60=60fps)
    
     
     base = ShowBase.ShowBase()   
     base.setBackgroundColor(0.1,0.25,0.4) 
     #I don't know what I'm doin'...
     base.trackball.node().setPos(-128, 150, -50)    
     base.trackball.node().setHpr(0, 40, 0) 
     
     #wave source buffer
     self.wave_source=self.makeBuffer(size=256, texFilter=Texture.FTNearest)
     self.wave_source['quad'].setColor(0,0,0, 0)
     self.wave_source['quad'].setZ(-10)
     
     #a normal, animated actor
     visible_panda=self.makeWalkingPanda(render)
     
     #a copy of the panda, but rendered offscreen
     phantom_panda=self.makeWalkingPanda(self.wave_source['root']) 
     #do the magic       
     self.setWaveCaster(phantom_panda)
     
     #make the ping-pong buffer to draw the water waves
     #shader 2 makes no use of the wave_source texture, appart from that they are identical
     shader1=Shader.load(Shader.SL_GLSL,'v.glsl', 'make_wave_f.glsl')
     shader2=Shader.load(Shader.SL_GLSL,'v.glsl', 'make_wave2_f.glsl')        
     self.ping=self.makeBuffer(shader1, size)
     self.pong=self.makeBuffer(shader2, size)
     self.ping['quad'].setShaderInput("size",float(size))
     self.pong['quad'].setShaderInput("size",float(size))        
     self.ping['quad'].setTexture(self.pong['tex'])
     self.pong['quad'].setTexture(self.ping['tex'])        
     self.ping['quad'].setShaderInput('startmap', self.wave_source['tex'])        
     self.ping['buff'].setActive(True)
     self.pong['buff'].setActive(False)   
     
     #some vars to track the state of things
     self.time=0
     self.state=0
     
     #set lights
     #reusing some of my old stuff, no mind the light manager
     l=LightManager()
     self.sun=l.addLight(pos=(128.0, 300.0, 50.0), color=(0.9, 0.9, 0.9), radius=500.0)
     
     #skybox
     skybox=loader.loadModel('skybox/skybox')
     skybox.reparentTo(render)
     skybox.setPos(128, 128, 64)
     skybox.setScale(300)
     #preview         
     cm = CardMaker("plane")
     cm.setFrame(0, 256, 0, 256)
     self.water_plane=render.attachNewNode(cm.generate())
     self.water_plane.lookAt(0, 0, -1)
     self.water_plane.setPos(0,0,1.0)
     self.water_plane.flattenStrong()
     self.water_plane.setShader(Shader.load(Shader.SL_GLSL,'water_v.glsl','water_f.glsl'))
     self.water_plane.setShaderInput("size",float(size))
     self.water_plane.setShaderInput("normal_map",loader.loadTexture("normal.png"))
     self.water_plane.setTexture(self.pong['tex'])           
     self.water_plane.hide(BitMask32.bit(1))
     self.makeWaterBuffer()  
     #self.water_plane.hide()
  
     #update task
     taskMgr.add(self.update, 'update') 
Пример #23
0
import os
import sys
#C:\Users\Vadim\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\panda3d\models
from direct.gui.DirectGui import *
from direct.showbase import DirectObject
from direct.showbase.ShowBase import *
from direct.task import Task
from panda3d.core import *

base = ShowBase()

dir = os.path.abspath(__file__).strip('Solar System v2.py')


def lightIntensive():
    return 100, 100, 100, 0.00001


class World(DirectObject.DirectObject):
    def __init__(self):
        self.title = OnscreenText(
            text=
            u"Simple model of the Solar System\nDeveloped by students from 465 group:\n Tatarincev V.P.\n Vinokurov N.A.",
            parent=base.a2dBottomRight,
            align=TextNode.A_right,
            style=1,
            fg=(1, 1, 1, 1),
            pos=(-0.1, 0.25),
            scale=.07)

        self.title2 = OnscreenText(
Пример #24
0
    def __init__(self, directory):
        #init ShowBase
        base = ShowBase.ShowBase()
        base.setBackgroundColor(1, 1, 1)
        #PStatClient.connect()
        self.lManager = LightManager()
        self.skyimg = PNMImage("data/sky_grad.png")

        #manager for post process filters (fxaa, soft shadows, dof)
        manager = FilterManager(base.win, base.cam)
        self.filters = setupFilters(manager, path, fxaa_only=False)

        #load a level
        self.level = loadLevel(path=path, from_dir=directory)

        self.startpos = None

        #process properties
        functions = {
            'coll_mask': self.setCollideMaskOn,
            'hide': self.hideNode,
            'startpos': self.setStratPos,
            'alpha': self.setAlpha
        }
        processProps(self.level, functions)

        #lights and shadows
        self.sun = setupLights(self.lManager)
        self.shadows = setupShadows(buffer_size=1024)

        #camera controll
        base.disableMouse()
        self.controler = CameraControler(shadows=self.shadows)
        #point and click interface
        self.pointer = PointAndClick()
        self.accept('mouse1', self.onMouseClick)

        #player model
        #could be another class.... well next time
        self.pcNode = render.attachNewNode('pcNode')
        self.actor = Actor(
            "demo_models/male", {
                "attack1": "demo_models/male_attack1",
                "attack2": "demo_models/male_attack2",
                "walk": "demo_models/male_run",
                "block": "demo_models/male_block",
                "die": "demo_models/male_die",
                "strafe": "demo_models/male_strafe2",
                "hit": "demo_models/male_hit",
                "idle": "demo_models/male_ready2"
            })
        self.actor.setBlend(frameBlend=True)
        self.actor.reparentTo(self.pcNode)
        self.actor.setScale(.1)
        self.actor.setShader(
            Shader.load(Shader.SLGLSL, path + "shaders/player_v.glsl",
                        path + "shaders/player_f.glsl"))
        self.actor.loop("idle")
        self.pcNode.setPos(self.startpos)
        #collisions
        self.coll_ray = self.pcNode.attachNewNode(CollisionNode('collRay'))
        self.coll_ray.node().addSolid(CollisionRay(0, 0, 20, 0, 0, -180))
        self.coll_ray.node().setIntoCollideMask(BitMask32.allOff())
        self.coll_ray.node().setFromCollideMask(BitMask32.bit(1))
        #self.coll_ray.show()
        self.traverser = CollisionTraverser()
        self.queue = CollisionHandlerQueue()
        self.traverser.addCollider(self.coll_ray, self.queue)

        #pathfinding
        self.navi = Navigator(path + directory + '/navmesh.csv', self.pcNode,
                              self.actor)
        self.target = render.attachNewNode('target')
        self.setTime(7.5)
        #tasks
        taskMgr.add(self.update, 'update_task', sort=45)
        self.clock = 7.5
        taskMgr.doMethodLater(1.0, self.clockTick, 'clock_task', sort=10)
        self.accept('window-event', self.windowEventHandler)
Пример #25
0
import wx
import os
from wx.lib.agw import fourwaysplitter as FWS

from pandac.PandaModules import *
from direct.showbase.ShowBase import *
from direct.directtools.DirectGlobals import *

try:
    base
except NameError:
    base = ShowBase(False, windowType = 'none')

from WxAppShell import *
from ViewPort import *

ID_FOUR_VIEW = 401
ID_TOP_VIEW = 402
ID_FRONT_VIEW = 403
ID_LEFT_VIEW = 404
ID_PERSP_VIEW = 405

class WxPandaShell(WxAppShell):
    """ Class for Panda3D LevelEditor """ 
    frameWidth = 800
    frameHeight = 600
    appversion      = '1.0'
    appname         = 'Panda3D Generic WX Frame'
    copyright       = ('Copyright 2010 Disney Online Studios.' +
                       '\nAll Rights Reserved.')
    
Пример #26
0
print 'DirectStart: Starting the game.'

from direct.showbase import ShowBase
base = ShowBase.ShowBase()
Пример #27
0
import wx
import os
from wx.lib.agw import fourwaysplitter as FWS

from pandac.PandaModules import *
from direct.showbase.ShowBase import *
from direct.directtools.DirectGlobals import *

try:
    base
except NameError:
    base = ShowBase(False)

from WxAppShell import *
from ViewPort import *

ID_FOUR_VIEW = 401
ID_TOP_VIEW = 402
ID_FRONT_VIEW = 403
ID_LEFT_VIEW = 404
ID_PERSP_VIEW = 405


class WxPandaShell(WxAppShell):
    """ Class for Panda3D LevelEditor """
    frameWidth = 800
    frameHeight = 600
    appversion = '1.0'
    appname = 'Panda3D Generic WX Frame'
    copyright = ('Copyright 2010 Disney Online Studios.' +
                 '\nAll Rights Reserved.')