Esempio n. 1
0
def GetMaterials():
    global blue_mat, gnd_mat, wht_mat
    # Creates the material
    blue_mat = soya.Material()

    # 0.0 is the most metallic / shiny, and 128.0 is the most plastic.
    blue_mat.shininess = 0.5

    # Sets the material's diffuse color. The diffuse color is the basic color.
    # In Soya 3D, colors are tuples of 4 floats: (red, green, blue, alpha),
    blue_mat.diffuse = (0.0, 0.2, 0.7, 1.0)

    # The specular color is the one used for the specular / shiny effects.
    blue_mat.specular = (0.2, 0.7, 1.0, 1.0)

    # Activates the separate specular. This results in a brighter specular effect.
    blue_mat.separate_specular = 1

    gnd_mat = soya.Material()
    gnd_mat.shininess = 0.5
    gnd_mat.diffuse = (0.25, 0.2, 0.1, 1.0)
    gnd_mat.specular = (0.25, 0.2, 0.1, 1.0)

    wht_mat = soya.Material()
    wht_mat.shininess = 0.5
    wht_mat.diffuse = (0.5, 0.5, 0.5, 0.99)
    wht_mat.specular = (0.5, 0.5, 0.5, 0.99)
Esempio n. 2
0
File: editor.py Progetto: 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()
Esempio n. 3
0
File: panel.py Progetto: 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
Esempio n. 4
0
def PointSecondDerivative(x):
    "Return model for evaluation of second derivatives at given point."

    info("Plotting dof: point derivative at x = %s" % str(x))

    # Make sure point is 3D
    x = to3d(x)

    # Create separate scene (since we will extract a model, not render)
    scene = soya.World()

    # Define material (color) for the sphere
    material = soya.Material()
    material.diffuse = (0.0, 0.0, 0.0, 0.05)

    # Create sphere
    sphere = Sphere(scene, material=material)

    # Scale and moveand move to coordinate
    sphere.scale(0.15, 0.15, 0.15)
    p = sphere.position()
    p.set_xyz(x[0], x[1], x[2])
    sphere.move(p)

    # Extract model
    model = scene.to_model()

    return model
Esempio n. 5
0
 def begin_round(self):
     soya.MainLoop.begin_round(self)
     if STOP:
         reader.running = False
         sys.exit()
     if not PAUSE:
         swarms = reader.get_round()
         if not len(swarms):
             return
         cube_keys = self.cubes.keys()
         for name, swarm in swarms.items():
             if not name in self.cubes.keys():
                 color = soya.Material()
                 color.diffuse = [
                     int(swarm['color'][x:x + 2], 16) / 255.0
                     for x in range(0, len(swarm['color']), 2)
                 ]
                 cube = soya.cube.Cube(None, color, size=0.08).shapify()
                 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))
Esempio n. 6
0
 def create_atmosphere(self):
     self.items['atmosphere'] = soya.SkyAtmosphere()
     self.items['atmosphere'].bg_color = self.theme_file.theme_items[
         'atmosphere']['background_color']
     self.items['atmosphere'].sky_color = self.theme_file.theme_items[
         'atmosphere']['sky_color']
     try:
         self.items['atmosphere'].cloud = soya.Material( \
             soya.Image.get(self.theme_file.theme_items['atmosphere']['clouds']))
     except:
         pass  # does this work at all!?
Esempio n. 7
0
def IntegralMoment(cellname, num_moments, x=None):
    "Return model for integral moment for given element."

    info("Plotting dof: integral moment")

    # Set position
    if x is None and cellname == "triangle":
        a = 1.0 / (2 + sqrt(2)) # this was a fun exercise
        x = (a, a, 0.0)
    elif x is None:
        a = 1.0 / (3 + sqrt(3)) # so was this
        x = (a, a, a)

    # Make sure point is 3D
    x = to3d(x)

    # Fancy scaling of radius and color
    r = 1.0 / (num_moments + 5)
    if num_moments % 2 == 0:
        c = 1.0
    else:
        c = 0.0

    # Create separate scene (since we will extract a model, not render)
    scene = soya.World()

    # Define material (color) for the sphere
    material = soya.Material()
    material.diffuse = (c, c, c, 0.7)

    # Create sphere
    sphere = Sphere(scene, material=material)

    # Scale and moveand move to coordinate
    sphere.scale(r, r, r)
    p = sphere.position()
    p.set_xyz(x[0], x[1], x[2])
    sphere.move(p)

    # Extract model
    model = scene.to_model()

    return model
Esempio n. 8
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()
Esempio n. 9
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'])
Esempio n. 10
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)
Esempio n. 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