def control_lost(self): super(Mobile, self).control_lost() if self.control_keys == CONTROL_KEYS[0]: soya.MAIN_LOOP.camera.parent.remove(soya.MAIN_LOOP.camera) soya.MAIN_LOOP.camera = None soya.set_root_widget(None)
def main(): soya.init() #soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data")) # Creates the scene. scene = soya.World() # Creates a camera. camera = soya.Camera(scene) camera.set_xyz(0.0, 0.0, 4.0) camera.fov = 100.0 # Creates a dragdrop world. world = Editor(scene, camera) # Adds some bodys with different models, at different positions. red = soya.Material(); red .diffuse = (1.0, 0.0, 0.0, 1.0) green = soya.Material(); green.diffuse = (0.0, 1.0, 0.0, 1.0) blue = soya.Material(); blue .diffuse = (0.0, 0.0, 1.0, 1.0) soya.Body(world, soya.cube.Cube(None, red ).to_model()).set_xyz(-1.0, -1.0, 1.0) soya.Body(world, soya.cube.Cube(None, green).to_model()).set_xyz( 0.0, -1.0, 0.0) soya.Body(world, soya.cube.Cube(None, blue ).to_model()).set_xyz( 1.0, -1.0, -1.0) soya.Body(world, soya.sphere.Sphere().to_model()).set_xyz(1.0, 1.0, 0.0) # Adds a light. light = soya.Light(scene) light.set_xyz(0.0, 0.2, 1.0) soya.set_root_widget(camera) # Main loop soya.MainLoop(scene).main_loop()
def setup_scene(self): self.scene = scene = soya.World() self.light = soya.Light(scene) self.camera = soya.Camera(scene) soya.set_root_widget(self.camera) self.main_loop = soya.MainLoop(scene) self.run_soya_rounds() # XXX dismiss init events (a big mouse one)
def activate(self, event = None): if not self.active: self.active = 1 soya.set_root_widget(self.camera) self.render() self.cancel = self.dialog.after(50, self.rotate)
def begin_guiloop(callbackround=None, callbackadvance=None ): global root, mainloop global scene, callback_round, callback_advance, camera, scene_body callback_round = callbackround callback_advance = callbackadvance soya.set_root_widget(root) scene_body = SceneBody(scene,None) mainloop.main_loop()
def setUp(self): self.scene = scene = soya.World() light = soya.Light(scene) light.set_xyz(15, 15, -15) camera = soya.Camera(scene) camera.set_xyz(0, 0,-10) camera.look_at(soya.Point(scene, 0, 0, 0)) soya.set_root_widget(camera) self.main_loop = soya.MainLoop(scene)
def test_render_front(self): soya.set_root_widget(self.blue_camera) soya.render() screenshot = soya.screenshot() self.assertEquals(screenshot.getpixel((0,0)), (0, 0, 255)) soya.set_root_widget(self.red_camera) soya.render() screenshot = soya.screenshot() self.assertEquals(screenshot.getpixel((0,0)),(255, 0, 0))
def __init__(self): super(GUIManager, self).__init__() #Graphics setup self.__setDataDir() #self.scene = self.__createScene() self.camera = self.__createCamera(self) self.__setLights(self) self.level = self.__createLevel(self) soya.set_root_widget(self.camera) self.game = None
def control_owned(self): tofu_enet.Mobile.control_owned(self) if not getattr(soya.MAIN_LOOP, "camera", None): soya.MAIN_LOOP.camera = soya.TravelingCamera(soya.MAIN_LOOP.scenes[0]) soya.MAIN_LOOP.camera.back = 70.0 soya.set_root_widget(soya.MAIN_LOOP.camera) traveling = soya.ThirdPersonTraveling(self) traveling.distance = 5.0 soya.MAIN_LOOP.camera.add_traveling(traveling) soya.MAIN_LOOP.camera.zap()
def test_render_back_read(self): """Test that rendering made without switching back buffer are accessible with screenshot""" # Screenshot in front buffer soya.set_root_widget(self.blue_camera) soya.render() screenshot = soya.screenshot() self.assertEquals(screenshot.getpixel((0,0)),(0, 0, 255)) # Screenshot in back buffer soya.set_root_widget(self.red_camera) soya.render(swap_buffer=False) screenshot = soya.screenshot(use_back_buffer=True) self.assertEquals(screenshot.getpixel((0,0)),(255, 0, 0))
def control_owned(self): tofu_udp.InterpolatedAnimatedMobile.control_owned(self) if not getattr(soya.MAIN_LOOP, "camera", None): soya.MAIN_LOOP.camera = soya.TravelingCamera(soya.MAIN_LOOP.scenes[0]) soya.MAIN_LOOP.camera.back = 70.0 group = soya.widget.Group() group.add(soya.MAIN_LOOP.camera) soya.widget.FPSLabel(group) soya.set_root_widget(group) traveling = soya.ThirdPersonTraveling(self) traveling.distance = 5.0 soya.MAIN_LOOP.camera.add_traveling(traveling) soya.MAIN_LOOP.camera.zap()
def begin_loop(callbackround=None, callbackadvance=None, engine="soya" ): global scene, callback_round, callback_advance, camera,mainloop import soya.pudding as pudding callback_round = callbackround callback_advance = callbackadvance if engine=="soya": soya.set_root_widget(camera) elif engine=="pudding": pass else: print "error engine %s unknown" % engine #soya.set_root_widget(soya.widget.Group()) #soya.root_widget.add(camera) #if enable_fps: soya.root_widget.add(soya.widget.FPSLabel()) return mainloop.main_loop()
def _init_widget_engine(self): """Initialize the pudding widget system, create a root widget. """ pudding.init(style=Style(self.widget_properties)) # Create a pudding root widget: self.root_widget = pudding.core.RootWidget( \ width=self.screen_res_x, height=self.screen_res_y, \ top=0, left=0) self.widget_properties['root_widget'] = self.root_widget self.root_widget.add_child(self.camera) soya.set_root_widget(self.root_widget) pudding.main_loop.MainLoop(self.root_world).update()
def _create_camera_and_light(self): self.light = soya.Light(self.scene) self.light.set_xyz(*self.light_xyz) self.camera = soya.Camera(self.scene) self.camera.z = self.camera_z self.camera.fov = self.camera_fov self.camera.ortho = True # calculate the "border" of the field p = self.camera.coord2d_to_3d(0.0, 0.0, 0.0) self.rhomb.left = p.x self.rhomb.right = -p.x self.rhomb.top = p.y self.rhomb.bottom = -p.y soya.set_root_widget(self.camera)
def init_pudding(width = 1020,height = 760,title="PyWorlds (Soya3D)", options = {}): global root,viewport,camera,scene,mainloop, pyworlds_engine soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data")) pyworlds_engine = "pudding" import soya.pudding as pudding soya.init(width=width, height= height, title=title) pudding.init() scene = pyworlds.basics.scene.scene mainloop=pudding.main_loop.MainLoop(scene) scene.mainloop=mainloop scene.round_duration=.04 mainloop.round_duration=.04 if 'nobasics' not in options: init_basicscene() soya.set_root_widget(pudding.core.RootWidget(width = width,height = height)) if 'nochild' not in options: soya.root_widget.add_child(camera)
def __init__(self, material, dialog): self.active = 0 self.dialog = dialog self.material = material self.scene = soya.World() self.camera = soya.Camera(self.scene) soya.set_root_widget(self.camera) soya.Light(self.scene).set_xyz(0.2, 2.0, 0.2) #self.cube = cube.Cube(self.scene, material) cube_world = cube.Cube(None, material) self.cube = soya.Body(self.scene, cube_world.to_model()) self.cube.set_xyz(0.0, 0.0, -2.0) self.cube.rotate_x(30.0)
def control_owned(self): super(Mobile, self).control_owned() local_mobiles = [mobile for mobile in self.level.mobiles if mobile.local] self.control_keys = CONTROL_KEYS[min(len(local_mobiles), len(CONTROL_KEYS)) - 1] if len(local_mobiles) == 1: soya.MAIN_LOOP.camera = soya.TravelingCamera(soya.MAIN_LOOP.scenes[0]) soya.MAIN_LOOP.camera.back = 70.0 group = soya.widget.Group() group.add(soya.MAIN_LOOP.camera) soya.widget.FPSLabel(group) soya.set_root_widget(group) traveling = soya.ThirdPersonTraveling(self) traveling.distance = 5.0 soya.MAIN_LOOP.camera.add_traveling(traveling) soya.MAIN_LOOP.camera.zap()
def main(): DEBUG = 1 import sys import os import soya.cube # init soya in resizable window: soya.init('MovableCamera Module', 1024, 768, 0) soya.path.append( os.path.join(os.path.dirname(sys.argv[0]), '..', '..', 'media', 'themes', 'kiddy', 'media')) # set the root scene: scene = soya.World() # set up the light: light = soya.Light(scene) light.set_xyz(0.0, 0.7, 1.0) # set up the camera: camera = MovableCamera(app_dir='.', parent_world=scene, debug=DEBUG) camera.set_xyz(0.0, 0, 10.0) # a test cube in the background: test_cube_world = soya.cube.Cube() test_cube_world.model_builder = soya.SolidModelBuilder() test_cube = soya.Body(scene, test_cube_world.to_model()) test_cube.rotate_y(45.0) test_cube.rotate_x(45.0) atmosphere = soya.SkyAtmosphere() atmosphere.bg_color = (1.0, 0.0, 0.0, 1.0) atmosphere.ambient = (0.5, 0.5, 0.0, 1.0) atmosphere.skyplane = 1 atmosphere.sky_color = (1.0, 1.0, 0.0, 1.0) atmosphere.cloud = soya.Material(soya.Image.get('cloud.png')) scene.atmosphere = atmosphere # set our root widget: soya.set_root_widget(camera) # start soya main loop: soya.MainLoop(scene).main_loop()
def __init__(self): tofu4soyapudding.GameInterface.__init__(self) soya.init() pudding.init() self.player_character = None # Creates a traveling camera in the scene, with a default look-toward-nothing # traveling. self.camera = soya.TravelingCamera(scene) self.camera.back = 70.0 self.camera.add_traveling(soya.FixTraveling(soya.Point(), soya.Vector(None, 0.0, 0.0, 10.0))) self.root = pudding.core.RootWidget(width = 640, height = 480) soya.set_root_widget(self.root) soya.root_widget.add_child(self.camera) pudding.ext.fpslabel.FPSLabel(soya.root_widget, position = pudding.TOP_RIGHT)
def _init_widget_engine(self): """Initialize the pudding widget system, create a root widget. """ pudding.init(style=Style(self.widget_properties)) # Create a pudding root widget: self.root_widget = pudding.core.RootWidget( \ width=self.config['screen'].as_int('resolution_x'), height=self.config['screen'].as_int('resolution_y'), \ top=0, left=0) self.widget_properties['root_widget'] = self.root_widget # Loading Label: # This should come immediatly, but it comes too late (after # the models are loaded). lc_top = self.config['screen'].as_int('resolution_x') / 2 lc_left = self.config['screen'].as_int('resolution_x') / 2 - 100 self.loading_cont = pudding.container.HorizontalContainer( \ self.root_widget, \ top=lc_top, left=lc_left, width=10, height=10, z_index=1) self.loading_cont.anchors = pudding.ANCHOR_RIGHT \ | pudding.ANCHOR_TOP | \ pudding.ANCHOR_LEFT self.loading_cont.add_child(pudding.control.SimpleLabel( label=_(u'Loading, please wait...'), font=self.widget_properties['font']['p']['obj'], top=10, left=10, color=self.widget_properties['font']['p']['color'] ), pudding.EXPAND_HORIZ) self.root_widget.add_child(self.camera) soya.set_root_widget(self.root_widget) if self.config['screen'].as_bool('fps_label'): pudding.ext.fpslabel.FPSLabel(soya.root_widget, \ position = pudding.TOP_RIGHT) pudding.main_loop.MainLoop(self.root_world).update()
def main(): DEBUG = 1 import sys import os import soya.cube # init soya in resizable window: soya.init('MovableCamera Module', 1024, 768, 0) soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..', '..', 'media', 'themes', 'kiddy', 'media')) # set the root scene: scene = soya.World() # set up the light: light = soya.Light(scene) light.set_xyz(0.0, 0.7, 1.0) # set up the camera: camera = MovableCamera(app_dir = '.', parent_world = scene, debug = DEBUG) camera.set_xyz(0.0, 0, 10.0) # a test cube in the background: test_cube_world = soya.cube.Cube() test_cube_world.model_builder = soya.SolidModelBuilder() test_cube = soya.Body(scene, test_cube_world.to_model()) test_cube.rotate_y(45.0) test_cube.rotate_x(45.0) atmosphere = soya.SkyAtmosphere() atmosphere.bg_color = (1.0, 0.0, 0.0, 1.0) atmosphere.ambient = (0.5, 0.5, 0.0, 1.0) atmosphere.skyplane = 1 atmosphere.sky_color = (1.0, 1.0, 0.0, 1.0) atmosphere.cloud = soya.Material(soya.Image.get('cloud.png')) scene.atmosphere = atmosphere # set our root widget: soya.set_root_widget(camera) # start soya main loop: soya.MainLoop(scene).main_loop()
def __init__(self): # in theory this shouldnt need to be overriden # create the scene. for simple menus this can probably be left alone self.create_scene() # create the camera self.create_camera() # set the root widget to our local class with the modified resize event soya.set_root_widget(self.RootWidget()) # add the camera soya.root_widget.add(self.camera) # create all our widgets. subclasses will override this self.create_widgets() # resize all our widgets initially. the same function will be called for # video resize events. subclasses will override this self.resize() soya.Idler.__init__(self,self.scene)
def __init__(self, world, dialog): self.active = 0 self.dialog = dialog self.handles = [] self.vertex_handles = [] self.children_visibility = {world: 1} self.world = self.current = world self.scene = soya.World() self.scene.name = "__scene__" self.scene.atmosphere = soya.Atmosphere() self.scene.atmosphere.ambient = (0.5, 0.5, 0.5, 1.0) self.camera = soya.Camera(self.scene) self.camera.set_xyz(0.0, 0.0, 5.0) self.camera.rotate_y(45) soya.set_root_widget(self.camera) self.light = soya.Light(self.scene) self.light.set_xyz(0.2, 2.0, 2.2) self.light.top_level = 1 self.light.cast_shadow = 0 self.cursor = Cursor(self.scene, self.camera, self.handles, self.light) self.cursor.name = "cursor" self.content = soya.World(self.scene) self.content.name = "__content__" self.content.append(world) self.add_handles_for(world) observe_tree(world, self.on_changed) self.last_click = 0 self.camera_mode = 0
def test_render_does_not_alter(self): """Test that rendering in the back buffer doesn't alter the front one.""" # Screenshot in front buffer soya.set_root_widget(self.blue_camera) soya.render() # Screenshot in back buffer soya.set_root_widget(self.red_camera) soya.render(swap_buffer=False) # Front buffer didn't changed screenshot = soya.screenshot() self.assertEquals(screenshot.getpixel((0,0)),(0, 0, 255)) # Everything still work fine soya.set_root_widget(self.blue_camera) soya.render() screenshot = soya.screenshot() self.assertEquals(screenshot.getpixel((0,0)),(0, 0, 255))
# instanciate: test_guipanel = GuiPanel(scene, name, position, scale, rotation, color, DEBUG) # set up the camera: camera = soya.Camera(scene) camera.set_xyz(0.0, 0, 10.0) # set up the light: light = soya.Light(scene) light.set_xyz(0.0, 0.7, 1.0) # a test cube in the background: test_cube_world = soya.cube.Cube() test_cube_world.builder = soya.SolidModelBuilder() test_cube = soya.Body(scene, test_cube_world.to_model()) test_cube.rotate_y(45.0) test_cube.rotate_x(45.0) test_cube.y = 2.3 # a test atmosphere: #atmosphere = soya.SkyAtmosphere() #atmosphere.sky_color = (1, 1, 0.8, 1) #scene.atmosphere = atmosphere # set our root widget: soya.set_root_widget(camera) # start soya main loop: soya.MainLoop(scene).main_loop()
scene.add(level) if THIRD_PERSON: print "Third person mode !" character = ThirdPersonCharacter(scene, KeyboardController()) else: print "First person mode !" character = FirstPersonCharacter(scene, KeyboardController()) print "Use arrow keys to move and shift to jump." if SCALE: character.set_xyz(-128.0/20., 40.0/20., 8.0/20.) else: character.set_xyz(-128.0, 40.0, 8.0) if SCALE: character.camera.back = 80.0 else: character.camera.back = 1500.0 #scene.add(character.camera) # Creates a widget group, containing the camera and a label showing the FPS. soya.set_root_widget(widget.Group()) soya.root_widget.add(character.camera) soya.root_widget.add(widget.FPSLabel()) soya.MainLoop(scene).main_loop()
def activate(self, event=None): if not self.active: self.active = 1 soya.set_root_widget(self.camera) soya.cursor_set_visible(0) self.auto_render()
def render(models, title, num_moments, is3d, rotate): "Render given list of models." # Note that we view from the positive z-axis, and not from the # negative y-axis. This should make no difference since the # element dofs are symmetric anyway and it plays better with # the default camera settings in Soya. # Initialize Soya soya.init(title) # Create scene scene = soya.World() scene.atmosphere = soya.Atmosphere() if title == "Notation": scene.atmosphere.bg_color = (0.0, 1.0, 0.0, 1.0) else: scene.atmosphere.bg_color = (1.0, 1.0, 1.0, 1.0) # Not used, need to manually handle rotation #label = Label3D(scene, text=str(num_moments), size=0.005) #label.set_xyz(1.0, 1.0, 1.0) #label.set_color((0.0, 0.0, 0.0, 1.0)) # Define rotation if is3d: class RotatingBody(soya.Body): def advance_time(self, proportion): self.rotate_y(2.0 * proportion) else: class RotatingBody(soya.Body): def advance_time(self, proportion): self.rotate_z(2.0 * proportion) # Select type of display, rotating or not if rotate: Body = RotatingBody else: Body = soya.Body # Add all models for model in models: body = Body(scene, model) # Set light light = soya.Light(scene) if is3d: light.set_xyz(1.0, 5.0, 5.0) else: light.set_xyz(0.0, 0.0, 1.0) light.cast_shadow = 1 light.shadow_color = (0.0, 0.0, 0.0, 0.5) # Set camera camera = soya.Camera(scene) camera.ortho = 0 p = camera.position() if is3d: if rotate: camera.set_xyz(-20, 10, 50.0) camera.fov = 2.1 p.set_xyz(0.0, 0.4, 0.0) else: camera.set_xyz(-20, 10, 50.0) camera.fov = 1.6 p.set_xyz(0.3, 0.42, 0.5) else: if rotate: camera.set_xyz(0, 10, 50.0) camera.fov = 2.6 p.set_xyz(0.0, 0.0, 0.0) else: camera.set_xyz(0, 10, 50.0) camera.fov = 1.7 p.set_xyz(0.5, 0.4, 0.0) camera.look_at(p) soya.set_root_widget(camera) # Handle exit class Idler(soya.Idler): def end_round(self): for event in self.events: if event[0] == QUIT: print("Closing plot, bye bye") sys.exit(0) # Main loop idler = Idler(scene) idler.idle()
def render(models, title, num_moments, is3d, rotate): "Render given list of models." # Note that we view from the positive z-axis, and not from the # negative y-axis. This should make no difference since the # element dofs are symmetric anyway and it plays better with # the default camera settings in Soya. # Initialize Soya soya.init(title) # Create scene scene = soya.World() scene.atmosphere = soya.Atmosphere() if title == "Notation": scene.atmosphere.bg_color = (0.0, 1.0, 0.0, 1.0) else: scene.atmosphere.bg_color = (1.0, 1.0, 1.0, 1.0) # Not used, need to manually handle rotation #label = Label3D(scene, text=str(num_moments), size=0.005) #label.set_xyz(1.0, 1.0, 1.0) #label.set_color((0.0, 0.0, 0.0, 1.0)) # Define rotation if is3d: class RotatingBody(soya.Body): def advance_time(self, proportion): self.rotate_y(2.0 * proportion) else: class RotatingBody(soya.Body): def advance_time(self, proportion): self.rotate_z(2.0 * proportion) # Select type of display, rotating or not if rotate: Body = RotatingBody else: Body = soya.Body # Add all models for model in models: body = Body(scene, model) # Set light light = soya.Light(scene) if is3d: light.set_xyz(1.0, 5.0, 5.0) else: light.set_xyz(0.0, 0.0, 1.0) light.cast_shadow = 1 light.shadow_color = (0.0, 0.0, 0.0, 0.5) # Set camera camera = soya.Camera(scene) camera.ortho = 0 p = camera.position() if is3d: if rotate: camera.set_xyz(-20, 10, 50.0) camera.fov = 2.1 p.set_xyz(0.0, 0.4, 0.0) else: camera.set_xyz(-20, 10, 50.0) camera.fov = 1.6 p.set_xyz(0.3, 0.42, 0.5) else: if rotate: camera.set_xyz(0, 10, 50.0) camera.fov = 2.6 p.set_xyz(0.0, 0.0, 0.0) else: camera.set_xyz(0, 10, 50.0) camera.fov = 1.7 p.set_xyz(0.5, 0.4, 0.0) camera.look_at(p) soya.set_root_widget(camera) # Handle exit class Idler(soya.Idler): def end_round(self): for event in self.events: if event[0] == QUIT: print "Closing plot, bye bye" sys.exit(0) # Main loop idler = Idler(scene) idler.idle()
# initialise pudding pudding.init() scene = soya.World() sword_model = soya.Model.get("sword") sword = soya.Body(scene, sword_model) sword.x = 1 sword.rotate_y(90.) # one line rotation :) sword.advance_time = lambda p: sword.rotate_y(5.*p) light = soya.Light(scene) light.set_xyz( .5, 0., 2.) camera = soya.Camera(scene) camera.z = 3. w = pudding.core.RootWidget(width = 1024,height = 768) i = pudding.control.Input(w, 'sometext', top = 10, left = 10, width = 100, height = 50) w.add_child(camera) soya.set_root_widget(w) pudding.main_loop.MainLoop(scene).main_loop()
#~ j2.attach(ball, pend) #~ j2.anchor = Point(scene, 3, 7.4, 0) #.setAnchor( (3,2,0) ) # '_soya.FixedJoint' object has no attribute 'anchor' j2 = soya.FixedJoint(ball, pend) j2.setFixed() j2.setFeedback(flag=True) # for getFeedback # these seem irrelevant after hinge? ground.pushable = False ground.gravity_mode = False hing.pushable = False hing.gravity_mode = False pole.pushable = False pole.gravity_mode = False print(pole.num_joints, pole.joints) # dir(pole), dir(pole.joints[0])) #~ print(joint1.anchor, joint1.anchor2, joint2.anchor, joint2.anchor2) # bump with init force #~ ball.add_force(soya.Vector(scene,0,ball_density*3000,0)) ball.add_force(soya.Vector(scene, 0, 0, 10000)) #~ pend.add_force(soya.Vector(scene,0,0,5000)) SetLight() SetCamera() SetWindowOverlay() #running soya soya.set_root_widget(root) #(camera); must be root for overlays ml = soya.MainLoop(scene) ml.main_loop()
# Creates a character in the level, with a keyboard controler character = Character(level, KeyboardControler()) character.set_xyz(216.160568237, -7.93332195282, 213.817764282) # Creates a Tomb Raider-like camera in the scene camera = soya.TravelingCamera(scene) traveling = soya.ThirdPersonTraveling(character) traveling.distance = 5.0 camera.add_traveling(traveling) camera.zap() camera.back = 70.0 # Creates a widget group, containing the camera and a label showing the FPS. soya.set_root_widget(pudding.core.RootWidget()) soya.root_widget.add_child(camera) pudding.ext.fpslabel.FPSLabel(soya.root_widget, position = pudding.TOP_RIGHT) health_bar = pudding.ext.meter.MeterValueLabel(soya.root_widget, "health:", left = 10, top = 10, width = 200, height = 20) health_bar.anchors = pudding.ANCHOR_TOP_LEFT health_bar.meter.user_change = False health_bar.meter.border_color = (0, 0, 0, 1) health_bar.label.color = health_bar.meter.border_color logo = pudding.control.Logo(soya.root_widget, 'little-dunk.png') button = pudding.control.Button(soya.root_widget, 'Quit', left = 10, width = 50, height = 40)
def video(pairs,hosts): soya.init() scene = soya.World() light = soya.Light(scene) light.set_xyz(5.5,5.0,5.0) camera = soya.Camera(scene) camera.z = 10.0 root = soya.widget.Group() root.add(camera) #soya.set_root_widget(camera) times = [x[2] for x in pairs] timee = [x[3] for x in pairs] global time global endtime time = min(times) endtime = max(timee) print "Start time: ", time print "End time: ", endtime swo = soya.sphere.Sphere() timekeep = soya.sphere.Sphere() mpair = list() def managePairs(): #print "Managing pairs: ",len(pairs) removepairs = list() for pair in pairs: if(pair[2] >= time and pair[3] >= time): #print "Added pair" #mpair.append(data(mhosts[pair[0]][0],mhosts[pair[0]][1],mhosts[pair[1]][0],mhosts[pair[1]][1],pair[2],pair[3],scene,swo.to_model())) d = data(mhosts[pair[0]][0],mhosts[pair[0]][1],mhosts[pair[1]][0],mhosts[pair[1]][1],pair[2],pair[3],scene,swo.to_model()) if(d not in mpair): mpair.append(d) removepairs.append(pair) else: del d dele = list() for x in mpair: if x.end > time: dele.append(x) for x in dele: mpair.remove(x) for pair in removepairs: pairs.remove(pair) def addtime(*args): global time #time = time + datetime.timedelta(milliseconds=1) #managePairs() #test #time = time + datetime.timedelta(milliseconds=100) #time = time + datetime.timedelta(microseconds=10) time = time + timescale print "\rTime: ", str(time), if(time >= endtime): j = raw_input("\nSimulation finished.") timebody = soya.Body(scene,timekeep.to_model()) timebody.begin_scene = addtime timebody.advance_time = addtime timebody.set_xyz(1,1,1) timebody.scale(.001,.001,.001) #hosts curdegree = 0 degreediff = 360 / len(hosts) - 1 rad = 5 mhosts = dict() for host in hosts: mhosts[host] = (rad*math.cos(curdegree),rad*math.sin(curdegree)) #(x,y) curdegree += degreediff for mhost in mhosts: sw = soya.sphere.Sphere() sp = soya.Body(scene,sw.to_model()) sp.x = mhosts[mhost][0] sp.y = mhosts[mhost][1] print "Host at %d,%d" % (sp.x,sp.y) #lab = soya.widget.Label(root,mhost) lab = soya.label3d.Label3D(scene,mhost) lab.set_xyz(sp.x,sp.y-1.5,0) lab.set_color((1.0,1.0,1.0,1.0)) #lab.lit = 1 #lab.set_xyz(sp.x,sp.y,0) #lab.set_align((int(sp.x),int(sp.y),0)) #lab.set_align(-1) #soya.Body(scene,lab) def modpos(dataobj): def adda(prop): dataobj.calcpos() dataobj.set_xyz(dataobj.x,dataobj.y,0) return adda def modlabel(timel): def changeitup(blah): timel.set_text(str(time)) return changeitup timelab = soya.label3d.Label3D(scene,str(time)) timelab.set_color((1.0,1.0,1.0,1.0)) timelab.advance_time = modlabel(timelab) timelab.set_size(.035) timelab.set_xyz(0,-5,0) soya.set_root_widget(root) SIXZERO = 1000000 THOUS = 1000 class data(soya.Body): def __init__(self,sx,sy,ex,ey,start,end,scene,model): self.start = start self.end = end self.sx = sx self.sy = sy self.ex = ex self.ey = ey self.x = sx self.y = sy self.plusy = False self.plusx = False if ey >= sy: self.plusy = True if ex >= sx: self.plusx = True super(data,self).__init__(scene,model) diff = end - start #timetot = diff.seconds*THOUS+ diff.microseconds*THOUS timetot = (diff.seconds*SIXZERO)+ diff.microseconds # print timetot self.vox = (ex - sx) / (timetot) self.voy = (ey - sy) / (timetot) # self.nstart = self.start.second*THOUS+ self.start.microsecond*THOUS # self.nend = self.end.second*THOUS+ self.end.microsecond*THOUS #self.nstart = self.start.second #self.nend = self.end.second self.advance_time = modpos(self) #self.begin_round = addtime # print "Diff: " ,diff self.mnormal = (diff.seconds * SIXZERO ) + diff.microseconds #self.mnormal = diff.seconds def calcpos(self): global time #halfn = time.second - self.start.second if(self.start<= time and self.end >= time): #print "Actually rendering" halfn = ((time.second - self.start.second) * SIXZERO) + (time.microsecond - self.start.microsecond) self.x = self.sx + (self.vox * halfn) self.y = self.sy + (self.voy * halfn) else: self.x = -10 self.y = 0 swo.scale(.2,.2,.2) #j = data(2.0,4.0,5.0,0,time,endtime,scene,swo.to_model()) for pair in pairs: d = data(mhosts[pair[0]][0],mhosts[pair[0]][1],mhosts[pair[1]][0],mhosts[pair[1]][1],pair[2],pair[3],scene,swo.to_model()) #print '%s -> %s (%s)' % (pair[2],pair[3],pair[3] - pair[2]) #sph.advance_time = gadd(sph) soya.MainLoop(scene).main_loop()
def main(): DEBUG = 1 import sys import os #import MovableCamera # init soya in resizable window: soya.init('Canta', 1024, 768, 0) # append our data path: soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..', 'data')) # disable soya's auto exporter: soya.AUTO_EXPORTERS_ENABLED = 0 # set the root scene: scene = soya.World() # set up the light: light = soya.Light(scene) #light.set_xyz(1.0, 0.7, 1.0) light.set_xyz(0.0, 0.7, 1.0) # set up the camera: # (uncomment for static camera): camera = soya.Camera(scene) camera.set_xyz(0.0, 0, 10.0) # (uncomment for movable camera): #camera = MovableCamera.MovableCamera(scene) # create 5 animated objects (CANTA letters): # Letter 'C': name = 'Logo_0' position = (-4.0, 0.0, 0.0) scale = (4.0, 3.0, 3.0) rotation = (0.0, 0.0, 0.0) shadow = 1 action = 'Logo_0Damping' test_animodel0 = AniModel( parent_world = scene, name = name, position = position, scale = scale, rotation = rotation, shadow = shadow, action = action, debug = DEBUG ) # Letter 'A': name = 'Logo_1' position = (-3.0, -0.2, 0.0) scale = (1.0, 1.0, 1.0) rotation = (0.0, 0.0, 0.0) shadow = 1 action = 'Logo_1Damping' test_animodel1 = AniModel( parent_world = scene, name = name, position = position, scale = scale, rotation = rotation, shadow = shadow, action = action, debug = DEBUG ) # Letter 'N': name = 'Logo_2' position = (-1.5, 0.9, 0.0) scale = (1.0, 1.0, 1.0) rotation = (0.0, 0.0, 0.0) shadow = 1 action = 'Logo_2Damping' test_animodel2 = AniModel( parent_world = scene, name = name, position = position, scale = scale, rotation = rotation, shadow = shadow, action = action, debug = DEBUG ) # Letter 'T': name = 'Logo_3' position = (0.0, -0.5, 0.5) scale = (1.0, 1.0, 1.0) rotation = (0.0, 0.0, 0.0) shadow = 1 action = 'Logo_3Damping' test_animodel3 = AniModel( parent_world = scene, name = name, position = position, scale = scale, rotation = rotation, shadow = shadow, action = action, debug = DEBUG ) # Letter 'A': name = 'Logo_4' position = (2.0, 0.0, -0.3) scale = (1.5, 1.5, 1.5) rotation = (0.0, 0.0, 0.0) shadow = 1 action = 'Logo_4Damping' test_animodel1 = AniModel( parent_world = scene, name = name, position = position, scale = scale, rotation = rotation, shadow = shadow, action = action, debug = DEBUG ) # set our root widget: soya.set_root_widget(camera) # start soya main loop: soya.MainLoop(scene).main_loop()
cube_model = cube_world.to_model() # Creates several semi-transparent cubes. cube1 = soya.Body(scene, cube_model) cube1.set_xyz(-0.3, 0.3, 0.0) cube1.rotate_y(30.0) cube2 = soya.Body(scene, cube_model) cube2.set_xyz(0.0, 0.0, -1.5) cube2.rotate_y(30.0) cube3 = soya.Body(scene, cube_model) cube3.set_xyz(0.6, -0.4, 0.5) cube3.rotate_y(30.0) # Creates a light. light = soya.Light(scene) light.set_xyz(1.0, 0.7, 1.0) # Creates a camera. camera = soya.Camera(scene) camera.set_xyz(0.0, 0.0, 3.0) soya.set_root_widget(camera) soya.MainLoop(scene).main_loop()
slider = widget.add_child( Slider(slider_label, test_filter, 288, colors, DEBUG)) # set up the camera: camera = soya.Camera(scene) camera.set_xyz(0.0, 0, 10.0) # set up the light: light = soya.Light(scene) light.set_xyz(1.0, 0.7, 1.0) # a test cube in the background: test_cube_world = soya.cube.Cube() test_cube_world.model_builder = soya.SolidModelBuilder() test_cube = soya.Body(scene, test_cube_world.to_model()) test_cube.rotate_y(45.0) test_cube.rotate_x(45.0) # add the camera to the root widget: widget.add_child(camera) # set our root widget: soya.set_root_widget(widget) # add a FPS Label: pudding.ext.fpslabel.FPSLabel(soya.root_widget, position=pudding.BOTTOM_RIGHT) # start pudding main loop: pudding.main_loop.MainLoop(scene).idle()