示例#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
文件: panel.py 项目: tewe/canta
    def __init__(self, parent_world, name='default', \
            position=(0., 0., 0.), scale=(1., 1., 1.),\
            rotation=(0., 0., 0.), color=None,
            texture=None, animation=None, shadow=False, debug=False):

        self.debug = debug

        Model.__init__(self, parent_world, name, position, \
                    scale, rotation)

        self.animation = animation
        self.color = color
        self.texture = texture
        self.environment_mapping = False
        self.shadow = shadow
        self.material = soya.Material()

        if self.texture:
            self.material.texture = soya.Image.get(self.texture)

        if self.color:
            self.material.diffuse = self.color

        if self.environment_mapping:
            self.material.environment_mapping = True

        # create a world for the model:
        world = soya.World()

        face = soya.Face(world, [
            soya.Vertex(world, 1.0, 1.0, 0.0, 1.0, 0.0),
            soya.Vertex(world, -1.0, 1.0, 0.0, 0.0, 0.0),
            soya.Vertex(world, -1.0, -1.0, 0.0, 0.0, 1.0),
            soya.Vertex(world, 1.0, -1.0, 0.0, 1.0, 1.0)
        ])

        # set the color of the face:
        face.material = self.material

        # set face double sided:
        face.double_sided = 1

        # create a model from the world:
        model = world.to_model()

        # create a body from the model:
        if self.animation is not None:
            self.body = RotatingBody(self.parent_world,
                                     model,
                                     rotation=self.animation)
        else:
            self.body = soya.Body(self.parent_world, model)

        # position, scale and rotate the body:
        self.set_position(self.position)
        self.set_scale(self.scale)
        self.set_rotation(self.rotation)

        # set name of the body:
        self.body.name = self.name
示例#3
0
    def draw_grid(self, words):
        # 12 balken + 13 falschbalken = 25 einheiten, jeder balken
        #10pixel hoch also insgesamt 250 pixel
        #resolution_y = 768.
        count_right_bar = self.max - self.min
        count_wrong_bar = count_right_bar + 1.
        #count_bar = count_right_bar + count_wrong_bar
        size_y = 0.2
        size_x = 0.3
        range_x = words[-1].timeStamp + words[-1].duration - words[0].timeStamp

        # create a new cube with the new coordinates:
        for i in range(count_right_bar):
            bar = soya.cube.Cube()
            bar.scale(size_x * range_x, size_y/10, 0.5)
            model = bar.to_model()
            # 2 ist für den abstand zwischen den noten
            position_y = ((i) - (count_right_bar / 2.) ) * size_y * 1
            position_x =  0 #( range_x -(range_x)/2 ) * 0.3
            if self.debug: print 'position: ', position_x

            #if i == pos:
            #	pos_z = 3

            #else:
            pos_z = 0
            x = soya.Body(self.world, model).set_xyz(position_x, position_y, pos_z)
示例#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 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
    def add(self, properties):

        material = soya.Material()
        if properties['diffuse']:
            material.diffuse = properties['diffuse']

        #material.diffuse = (0.0, 0.2, 0.7, 1.0)
        # We use here a light blue, to get metallic reflexions.
        if properties['specular']:
            material.specular = properties['specular']

        # Activates the separate specular. This results in a brighter specular effect.
        if properties['seperate_specular']:
            material.separate_specular = 1



        self.use_pil = False
        self.use_shadows = False

        bar = soya.cube.Cube(material=material)
        bar.scale(self.size_x * properties['length'], self.size_y, 0.5)

        if self.use_pil:
            for face in bar.children:
                face.material = self.material

            model_builder = soya.SimpleModelBuilder()
            if self.use_shadows:
                model_builder.shadow = 1
            bar.model_builder = model_builder

        model = bar.to_model()

        if self.use_pil:
            self.material.environment_mapping = 1
            self.material.texture = soya.Image.get('env_map.jpeg')
        if properties['rotate']:
            body = RotatingBody(self.world, model)
        else:
            body = soya.Body(self.world, model)
        body.set_xyz(properties['x'], properties['y'], properties['z'])
示例#7
0
    def __init__(self, parent_world=None, name='', position=(0.0, 0.0, 0.0), \
            scale=(1.0, 1.0, 1.0), rotation=(0.0, 0.0, 0.0), shadow=0, \
            action='', debug=0):

        self.debug = debug

        # call constructor of super class:
        Model.__init__(self, parent_world, name, position, scale, \
                rotation, self.debug)

        # set shadow:
        # TODO: get shadow state from config file.
        self.shadow = shadow

        # set action:
        self.action = action

        # create an animated model:
        animated_model = soya.AnimatedModel.get(self.name)

        # set shadow of the animated model:
        animated_model.shadow = self.shadow

        # create a body from the animated model:
        self.body = soya.Body(self.parent_world, animated_model)

        # start the animation cycle:
        self.body.animate_blend_cycle(self.action)

        # position, scale and rotate the body:
        self.set_position(self.position)
        self.set_scale(self.scale)
        self.set_rotation(self.rotation)

        # set name of the body:
        self.body.name = self.name
示例#8
0
    def __init__(self, parent_world, color, debug=0):
        #CubeList.__init__(self, parent_world, min, max, debug)
        CubeObserver.__init__(self, parent_world, debug)

        self.distance_from_side = 0  # could be problematic must be sync with the other observers
        self.debug = debug
        self.parent_world = parent_world
        self.world = soya.World()
        self.parent_world.add(self.world)

        self.model_builder = soya.SimpleModelBuilder()
        self.model_builder.shadow = 1

        self.material = soya.Material()
        self.material.environment_mapping = 1
        self.material.diffuse = color
        #(1.0, 1.0, 1.0, 0.3)

        ### SHINYNESS ^^ ###
        #self.material.texture = soya.Image.get("env_map.jpeg")
        ### END SHINYNESS ^^ ###

        self.size_of_window_x = 15

        self.range_x = 5

        # For the pos cube.
        self.size_x = 0.1
        bar = soya.cube.Cube(material=self.material)
        bar.scale(self.size_x, 1, 1)

        #bar.model_builder = self.model_builder

        model = bar.to_model()

        self.pos_cube = soya.Body(self.world, model)
示例#9
0
文件: panel.py 项目: tewe/canta
    # 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()
示例#10
0
m_ball.model_builder = model_builder
m_pole.model_builder = model_builder

# Compiles the models (ball) model to a shadowed model.
ball_model = m_ball.to_model()
pole_model = m_pole.to_model()

m_ball_s = m_ball.shapify(
)  # no need to shapify the ball_model - just the above is enough for casting shadows; and can keep m_ball here!
m_ground_s = m_ground.shapify()
m_pole_s = m_pole.shapify()
m_pend_s = m_pend.shapify()
m_hing_s = m_hing.shapify()

#creating Body
ground = soya.Body(scene, m_ground_s)
pole = soya.Body(scene, m_pole_s)
pend = soya.Body(scene, m_pend_s)
ball = soya.Body(
    scene, m_ball_s
)  # dissapears w m_pend parent; unless it is parent during instant: 'Sphere(m_pole' (in which case, scene as parent here will double the object)
# however, that kind of parenting doesn't help with ode! the ball will simply stay still, while pendulum will move .. so must add joint - and  with m_pend parent: RuntimeError: two body must be into the same world to be jointed
hing = soya.Body(scene, m_hing_s)

# set shadows
ball.shadow = 1  # enable shadow
pole.shadow = 1  # enable shadow
ground.shadow = 1  # enable shadow

# set up for collisions:
# GeomSphere/GeomBox must be there for collisions!
示例#11
0
    def __init__(self, parent_world=None, name='', position=(0.0, 0.0, 0.0), \
            scale=(1.0, 1.0, 1.0), rotation=(0.0, 0.0, 0.0), shadow=False, \
            animation=False, cellshading=False, envmap=False, debug=False):

        self.debug = debug

        # call constructor of super class:
        Model.__init__(self, parent_world, name, position, scale, \
                rotation, self.debug)

        self.shadow = shadow
        self.animation = animation
        self.cellshading = cellshading
        self.envmap = envmap

        if self.cellshading:
            # create a cellshading model builder:
            model_builder = soya.CellShadingModelBuilder()

        else:
            # create a simple model builder:
            model_builder = soya.SimpleModelBuilder()

        # set the 'shadow' model_builder attribute:
        model_builder.shadow = self.shadow

        # create a world for the model:
        model_world = soya.World.get(self.name)

        if self.cellshading:
            #print 'CELLSHADING! Creating Material!'
            # modify the material for a better effect:
            #material = model_world.children[0].material
            #material.texture = soya.Image.get("grass.png")
            #material.separate_specular = 1
            #material.shininess = 15.0
            #material.specular = (1.0, 1.0, 1.0, 1.0)

            # creates the shader (a normal material with a texture):
            #shader = soya.Material()
            #shader.texture = soya.Image.get("shader.png")

            # Sets the model_builder properties. These properties can also be passed to the constructor,
            # see docstrings for more info.
            # The shader property is (obviously) the shader :-)
            # outline_color specifies the color of the outline (default : black)
            # outline_width specifies the width of the outline (default 4.0) ; set to 0.0 for no outline
            # outline_attenuation specifies how the distance affects the outline_width (default 0.3).
            #model_builder.shader              = shader
            model_builder.outline_color = (0.0, 0.0, 0.0, 1.0)
            model_builder.outline_width = 7.0
            model_builder.outline_attenuation = 1.0

        elif self.envmap:
            material = soya.Material()
            material.environment_mapping = True  # Specifies environment mapping is active
            material.texture = soya.Image.get(
                self.envmap)  # The textured sphere map

        # set the model_builder of the world:
        model_world.model_builder = model_builder

        if self.envmap:
            for face in model_world.children:
                face.smooth_lit = 0
                face.material = material

        # create a model from the world:
        model = model_world.to_model()

        # create a body from the model:
        if self.animation is not None:
            self.body = RotatingBody(parent_world,
                                     model,
                                     rotation=self.animation)
        else:
            self.body = soya.Body(parent_world, model)

        # position, scale and rotate the body:
        self.set_position(self.position)
        self.set_scale(self.scale)
        self.set_rotation(self.rotation)

        # set name of the body:
        self.body.name = self.name