示例#1
0
文件: editor.py 项目: tewe/canta
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()
示例#2
0
def main():
	soya.init()
	soya.path.append(os.path.abspath(os.path.dirname(sys.argv[0])))
	print soya.path
	
	filename = sys.argv[1]
	
	world = decode_ms3d(open(filename))
	model = world.to_model()
	model.filename=sys.argv[2]
	model.save()
示例#3
0
文件: worlds.py 项目: deavid/pyworlds
def init(width = 1020,height = 760,title="PyWorlds (Soya3D)",create_basic=True):
	global scene,mainloop,pyworlds_engine
	pyworlds_engine = "soya"
	soya.init(width=width, height= height,title=title)
	soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
	scene = pyworlds.basics.scene.scene
	mainloop=soya.MainLoop(scene)
	scene.mainloop=mainloop
	scene.round_duration=.04
	mainloop.round_duration=.04
	if create_basic:
		init_basicscene()
示例#4
0
    def _init_game_engine(self):
        """Initialize soya game engine, append our paths to soya's paths,
            create the scene and set up a camera.
        """

        # Hide window manager's resizability
        # features (maximise, resize, ...):
        RESIZEABLE = False

        soya.init(title=self.window_title, \
                width=self.config['screen'].as_int('resolution_x'),
                height=self.config['screen'].as_int('resolution_y'), \
                fullscreen=int(self.config['screen'].as_bool('fullscreen')), \
                resizeable=RESIZEABLE, sound=False)

        # Enable/disable soya's auto (blender model) importer:
        soya.AUTO_EXPORTERS_ENABLED = True

        # Append some paths:
        #	* themes/[selected theme name]/media
        #	TODO: append paths for all themes in themes/,
        #	so we can change the theme at runtime (?)...
        #	* songs/[song name]/media
        default_path = os.path.join(self.app_dir, 'media', 'themes', \
            'default', 'media')
        soya.path.append(default_path)
        theme_path = os.path.join(self.app_dir, 'media', 'themes', \
            self.widget_properties['theme']['main'], 'media')
        soya.path.append(theme_path)

        self.root_world = soya.World()
        self.widget_properties['root_world'] = self.root_world
        # set up a camera:
        self.camera = soya.Camera(self.root_world)

        ### CAMERA TESTS ###
        moveable = False
        rotating = False
        if moveable:
            from lib.cameras.movable_camera import MovableCamera
            self.camera = MovableCamera(self.app_dir, self.parent_world)
        if rotating:
            from lib.cameras.spinning_camera import SpinningCamera
            cube = soya.Body(self.root_world, soya.cube.Cube().to_model())
            cube.visible = 0
            self.camera = SpinningCamera(self.root_world, cube)
        ### END CAMERA TESTS ###

        self.camera.set_xyz(0.0, 0.0, 15.0)

        self.light = soya.Light(self.root_world)
        self.light.set_xyz(0.0, 7.7, 17.0)
示例#5
0
def edit_material(self, window):
	if not soya.inited: soya.init("Soya Editor")
	
	ed = soya.editor.material.MaterialEditor(self, window)
	
	def on_activate(event = None):
		global CURRENT
		
		if CURRENT: CURRENT.deactivate()
		ed.activate()
		CURRENT = ed
		
	window.bind("<FocusIn>" , on_activate)
示例#6
0
def edit_world(self, window):
	if not self.parent:
		if not soya.inited: soya.init("Soya Editor")
		
		ed = soya.editor.world.WorldEditor(self, window)
		
		def on_activate(event = None):
			global CURRENT
			
			if CURRENT: CURRENT.deactivate()
			ed.activate()
			CURRENT = ed
			
		window.bind("<FocusIn>" , on_activate)
示例#7
0
    def setup(self):
        soya.init("Loopy Demo", *self.resolution)
        soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
        scene = soya.World()

        sword_model = soya.Shape.get("sword")
        sword = soya.Volume(scene, sword_model)
        sword.x = 1.0
        sword.rotate_lateral(90.0)

        light = soya.Light(scene)
        light.set_xyz(0.5, 0.0, 2.0)

        self.camera = soya.Camera(scene)
        self.camera.z = 2.0
示例#8
0
文件: worlds.py 项目: deavid/pyworlds
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)
示例#9
0
 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)
示例#10
0
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()
示例#11
0
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()
示例#12
0
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import sys, os, os.path, random
import soya, soya.gui
import soya.widget

soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))

soya.init(width = 640, height = 480)


red = soya.Material()
red.diffuse = (1.0, 0.0, 0.0, 1.0)

root  = soya.gui.RootLayer(None)
import soya.cube
scene = soya.World()
light = soya.Light(scene)
light.set_xyz(0.5, 0.0, 2.0)
camera = soya.Camera(scene)
camera.z = 2.0
camera.partial = 1
cube = soya.cube.Cube(scene, red)
cube.advance_time = lambda proportion: cube.rotate_lateral(proportion)
示例#13
0
文件: gui.py 项目: haldean/headtrack
#!/usr/bin/env python

import os, soya, sys

soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
soya.init(title='Head Tracking')


class TrackModel(soya.Body):
    def __init__(self, scene, model):
        soya.Body.__init__(self, scene, model)
        self.move = None

    def set_headtracker(self, track):
        self.track = track

    def set_move(self, dx, dy, dz):
        self.move = soya.Vector(self, dx, dy, dz)

    def advance_time(self, proportion):
        soya.Body.advance_time(self, proportion)

        if self.move:
            self.add_mul_vector(proportion, self.move)


scene = soya.World()

model = soya.Model.get('cube')
body = TrackModel(scene, model)
示例#14
0
文件: demo.py 项目: deavid/soyamirror
    
cerealizer.register(Action)
cerealizer.register(Mobile)
cerealizer.register(Level , soya.cerealizer4soya.SavedInAPathHandler(Level ))
cerealizer.register(Player, soya.cerealizer4soya.SavedInAPathHandler(Player))


if   mode == "server":
  try: os.mkdir("/tmp/tofu_data")
  except: pass
  try: os.mkdir("/tmp/tofu_data/players")
  except: pass
  try: os.mkdir("/tmp/tofu_data/levels")
  except: pass
  
  soya.path.insert(0, "/tmp/tofu_data")
  
  LEVEL = Level()
  LEVEL.filename = "demo"
  LEVEL.save()
  
elif mode == "client":
  soya.init("Soya & Tofu demo", 320, 240)
  tofu_enet.HOST = "127.0.0.1"
  tofu_enet.LOGIN = sys.argv[2]
  

main_loop = tofu_enet.MainLoop(soya.World())
main_loop.main_loop()

示例#15
0
                    self.cubes[name] = SwarmEntity(scene, cube)
                else:
                    cube_keys.remove(name)
                p = soya.Point(scene)
                p.set_xyz(*swarm['coords'])
                self.cubes[name].state2.move(p)
            for swarm in cube_keys:
                scene.remove(self.cubes.pop(swarm))


if __name__ == '__main__':
    args = argparser()
    args['resolution'] = map(int, args['resolution'].split('x'))
    FPS = args['fps']
    soya.init(title='SwarmViewer',
              fullscreen=args['full_screen'],
              width=args['resolution'][0],
              height=args['resolution'][1])
    soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))

    # Creates the scene.

    scene = soya.World()

    light = soya.Light(scene)
    light.set_xyz(10.0, 10.2, 11.0)

    soya.cursor_set_visible(0)

    #scene.atmosphere = soya.Atmosphere()
    #scene.atmosphere.ambient = (0.0, 1.0, 1.0, 1.0)
# -*- indent-tabs-mode: t -*-

INTRO = """
  This tutorial show the use of the hit function.
  If define, this function is called when the body collide with another (pushable or not)
  It usefull to trigger action when body hit's each other
"""

import sys, os
import soya



soya.init("collision-5-hit_func",width=1024,height=768)
soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))

print INTRO

class SpeakingHead(soya.Body):
	head_model = soya.Model.get("caterpillar_head")
	def __init__(self,parent,name):
		soya.Body.__init__(self,parent,self.head_model)
		self.name = name
	def hit(self,*args,**kargs):
		print "<%s> outch I'm hit !"%self.name



# create world
scene = soya.World()
# getting the head model
示例#17
0
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()
示例#18
0
	def test_verbose(self):
		if soya.inited:
			self.skip('Soya is already initialised')
		soya.init("test verbose init", quiet=False)
		self.assertNotEqual(self.stdout.getvalue(), '')
		self.assertEqual(self.stderr.getvalue(), '')
示例#19
0
        r = RacingLevelReader(options.filename, verbose=options.verbose, level=racing.Level)
        setModuleScene = racing
    elif options.snowballz:
        import snowballz

        r = SnowballzLevelReader(options.filename, verbose=options.verbose, level=snowballz.Level)
        setModuleScene = snowballz
    else:
        r = LevelReader(options.filename, verbose=options.verbose)

    r.save(options.output)

    if not options.view:
        print "done."
    else:
        soya.init(title="LevelXML", width=1024, height=768)

        soya.set_use_unicode(1)

        scene = soya.World()

        if setModuleScene:
            setModuleScene.scene = scene

        level = soya.World.get(options.output)
        scene.add(level)

        camera = r.get_camera(scene=scene)
        camera.back = 500.0

        soya.set_root_widget(widget.Group())
示例#20
0
文件: panel.py 项目: tewe/canta
    def update_texture(self, texture):
        self.material.texture = None
        self.material.texture = soya.Image.get(texture)


if __name__ == '__main__':

    DEBUG = 1

    import sys
    import os
    import soya.cube

    # init soya in resizable window:
    soya.init('Canta', 1024, 768, 0)

    soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..', 'data'))

    # set the root scene:
    scene = soya.World()

    # create the test object:
    # the name:
    name = 'testpanel'
    # position, scale and rotation with (x, y, z):
    position = (0.0, 0.0, 1.0)
    scale = (5.0, 2.0, 5.0)
    rotation = (0.5, 0.5, 0.5)
    # color:
    color = (0.8, 0.4, 0.2, 0.7)
示例#21
0
    global camera, scene, pole
    # adding camera
    camera = soya.Camera(scene)
    camera.set_xyz(25, 15, 0)  #(15,15,30)
    camera.partial = 1
    #~ camera.rotate_z(180)
    camera.look_at(pole)  #(v_orig)
    #~ camera.back=300


################## MAIN

#evil hack

# Initializes Soya (creates and displays the 3D window).
soya.init("soya-pend", width=600, height=480)

soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
# careful: sys.path instead of sys.argv - and hack to avoid images subdir only
soya.path.append(sys.path[0])  #soya.path.append(os.path.dirname(sys.path[0]))
print(soya.path)

# for window overlay
root = soya.gui.RootLayer(None)

# Creates a simple model model_builder object. (that does  include shadows).
model_builder = soya.SimpleModelBuilder()

# Sets the 'shadow' model_builder property to true.
model_builder.shadow = 1
示例#22
0
 def _init_soya(self):
     soya.path.append("data")
     soya.init()
     self.scene = soya.World()
示例#23
0
	def test_default_with_args(self):
		if soya.inited:
			self.skip('Soya is already initialised')
		soya.init("test default init", width=640, height=480)
		self.assertNotEqual(self.stdout.getvalue(), '')
		self.assertEqual(self.stderr.getvalue(), '')
示例#24
0
	def test_default(self):
		if soya.inited:
			self.skip('Soya is already initialised')
		soya.init("test default init")
		self.assertNotEqual(self.stdout.getvalue(), '')
		self.assertEqual(self.stderr.getvalue(), '')
INTRO = """
  You can also collide with terrain
"""

import sys, os
from random import choice, gauss as normalvariate, randint, random, expovariate
import soya
import soya.widget
from soya import Vector






soya.init("ode-collision-8-terrain",width=1024,height=768)
soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))

print INTRO

scene = soya.World()

# Gets the image "map1.png" from the tutorial data dir, and create the terrain
# from this image. The image dimension must be power of 2 plus 1 : (2 ** n) + 1.
terrain = soya.Terrain(scene)
print "setting terrain's image"
terrain.from_image(soya.Image.get("map3.png"))

# By default, the terrain height ranges from 0.0 (black pixels) to 1.0 (white pixels).
# Here, we multiply the height by 4.0 so it ranges from 0.0 to 4.0.
示例#26
0
文件: demo.py 项目: deavid/soyamirror
  def generate_action(self):
    self.counter += 1
    if   self.counter == 35: self.plan_action(Action(self, ACTION_MOVE_FORWARD))
    elif self.counter == 55: self.plan_action(Action(self, ACTION_MOVE_BACKWARD)); self.counter = 0
    

cerealizer.register(Mobile)
cerealizer.register(Bot)
cerealizer.register(Level , soya.cerealizer4soya.SavedInAPathHandler(Level ))
cerealizer.register(Player, soya.cerealizer4soya.SavedInAPathHandler(Player))

if   mode == "server":
  create_demo_level()
  
elif mode == "client":
  soya.init("Soya & Tofu demo", 640, 480)
  tofu_udp.LOGIN    = sys.argv[2]
  tofu_udp.PASSWORD = "******"
  if len(sys.argv) >= 4: tofu_udp.HOST = sys.argv[3]
  
elif mode == "single":
  create_demo_level()
  
  soya.init("Soya & Tofu demo", 640, 480)
  tofu_udp.LOGIN = sys.argv[2]
  tofu_udp.PASSWORD = "******"


main_loop = tofu_udp.MainLoop(soya.World())
main_loop.main_loop()
示例#27
0
# -*- indent-tabs-mode: t -*-

#!/usr/bin/env python

import sys, os

import soya
import soya.pudding as pudding

soya.init(width = 1024, height = 768)
soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))

# 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.
示例#28
0
	def test_quiet(self):
		if soya.inited:
			self.skip('Soya is already initialised')
		soya.init("test quiet init", quiet=True)
		self.assertEqual(self.stdout.getvalue(), '')
		self.assertEqual(self.stderr.getvalue(), '')
示例#29
0
			time.sleep(0.01)
			try:
				self.motion = False
				motion = watch.getMotion()
				self.motion = motion
			except (RuntimeError):
				print "Watch not connected ?"

	def stop(self):
		self.running = False

motionThread = MotionThread()
motionThread.start()

# Initialisation
soya.init(width = 1024, height = 768, sound = 0, title = "ez430 Demo")
soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))

# Creates a scene.
scene = soya.World()

class AbsDegree:
	def __init__(self):
		self.absdegree = 0

	def update(self, new):
		r = new - self.absdegree
		self.absdegree = new
		return r

#Classe Demo
示例#30
0
 def __init__(self, w, h, fullscreen, title):
     openglBase.OpenGLBase.__init__(self, w, h, fullscreen, title)
     soya.init()
     self.scene = soya3d.World()
示例#31
0
    def append_line(self,line):
        self._lines.append(line)
        self.update()

    def write(self,line):
        self.append_line(line)

    lines=property(get_lines,set_lines)


clientplayer = ClientPlayer()
factory = pb.PBClientFactory()

if __name__=='__main__':
  soya.init(width=800,height=600,title="Balazar Bomber")
  
  #soya.init_audio()

  # play our music file on loop forever :D
  #music=soya.MusicFile(os.path.join(SOUNDS,'test.mod'))
  #music.play(-1)
  
  # we load this for later
  #explosion_sound=soya.AudioFile(os.path.join(SOUNDS,'explosion.wav'))
  #bonus_sound=soya.AudioFile(os.path.join(SOUNDS,'arcade.wav'))
  
  # turn on unicode key events for better text input
  soya.set_use_unicode(True)
  
  # the global state machine object
示例#32
0
 def setup(self):
     soya.init("Loopy Demo", self.resolution[0], self.resolution[1])
     pudding.init()
     self.puddingRoot = self.createPuddingWidgets()
     self.createScene()
     self.idler = soya.Idler(self.scene)
示例#33
0
文件: plot.py 项目: doru1004/FFC
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()
示例#34
0
 def __init__(self, w, h, fullscreen, title):
     openglBase.OpenGLBase.__init__(self, w, h, fullscreen, title)
     soya.init()
     self.scene = soya3d.World()
示例#35
0
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()
示例#36
0
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()
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


# modeling-transparency-1: Transparency : semi-transparent cubes

# In this lesson, we'll build a semi-transparent cube.


# Imports and inits Soya.

import sys, os, os.path, soya, soya.cube

soya.init()
soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))

# Creates the scene.

scene = soya.World()

# Creates a material, and set its diffuse color to a semi-transparent white (alpha = 0.5).
# See lesson modeling-material-1.py about materials and material colors.
# Similarly, you can use per-vertex semi-transparent colors.

material = soya.Material()
material.diffuse = (1.0, 1.0, 1.0, 0.5)

# Creates a cube using our material.
示例#38
0
	def setUp(self):
		soya.init("Soya Test", width=640, height=480, quiet=True)
		if self.pre_build:
			self.setup_scene()