Пример #1
0
def SetLight():
    global light, scene
    #placing light over the duel
    light = soya.Light(scene)
    #~ light.set_xyz(-10, 45,45)
    light.set_xyz(2, 100, 2)
    #~ light.directional=True #like the sun; BUT The position of a directional light doesn't matter
    light.cast_shadow = 1
    light.shadow_color = (0.0, 0.0, 0.0, 0.5)
    light2 = soya.Light(scene)
    #~ light.set_xyz(-10, 45,45)
    light2.set_xyz(20, 15, -4)
    light2.cast_shadow = 0
    light2.constant = 0.0
    light2.linear = 0.5
    light2.diffuse = (0.7, 0.7, 0.7, 1.0)
Пример #2
0
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()
Пример #3
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)
Пример #4
0
    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)
Пример #5
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()
Пример #6
0
    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)

    # 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
Пример #7
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()
Пример #8
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()