コード例 #1
0
    def _create_models(self):
        rhomb_world = soya.World()
        centerVerticesLeft = []
        centerVerticesRight = []
        for i in range(self.rhomb_n):
            l = soya.Vertex(
                rhomb_world,
                self.rhomb_radius * math.sin(2.0 * math.pi * i / self.rhomb_n),
                0.0,
                self.rhomb_radius * math.cos(2.0 * math.pi * i / self.rhomb_n))
            r = soya.Vertex(
                rhomb_world,
                self.rhomb_radius * math.sin(2.0 * math.pi * i / self.rhomb_n),
                0.0,
                self.rhomb_radius * math.cos(2.0 * math.pi * i / self.rhomb_n))
            l.diffuse = self.rhomb_color1
            r.diffuse = self.rhomb_color2
            centerVerticesLeft.append(l)
            centerVerticesRight.append(r)
        for i in range(self.rhomb_n):
            leftVertex = soya.Vertex(rhomb_world, 0.0, -self.rhomb_left_size,
                                     0.0)
            rightVertex = soya.Vertex(rhomb_world, 0.0, self.rhomb_right_size,
                                      0.0)
            leftVertex.diffuse = self.rhomb_color1
            rightVertex.diffuse = self.rhomb_color2
            f = soya.Face(rhomb_world, [
                leftVertex, centerVerticesLeft[(i + 1) % self.rhomb_n],
                centerVerticesLeft[i]
            ])
            f.smooth_lit = 1
            f = soya.Face(rhomb_world, [
                rightVertex, centerVerticesRight[i],
                centerVerticesRight[(i + 1) % self.rhomb_n]
            ])
            f.smooth_lit = 1
        model_builder = soya.SimpleModelBuilder()
        model_builder.shadow = 1
        rhomb_world.model_builder = model_builder

        self.rhomb_model = rhomb_world.to_model()
        self.rhomb = MovingRotatingBody(self.scene, self.rhomb_model)
        self.rhomb.rotate_z(90)
        self.rhomb.current = RIGHT
        self.rhomb.speed = soya.Vector(self.scene, *self.rhomb_speed_xyz)

        self.rhomb.angle_x = 0
        self.rhomb.angle_y = 0
        self.rhomb.angle_z = 0

        self.rhomb.rotating = 0
        self.rhomb.angle = 0
コード例 #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
ファイル: plot.py プロジェクト: maciekswat/dolfin_python_deps
def UnitTriangle(color=(0.0, 1.0, 0.0, 0.5)):
    "Return model for unit tetrahedron."

    info("Plotting unit triangle")

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

    # Create vertice
    v0 = soya.Vertex(scene, 0.0, 0.0, 0.0, diffuse=color)
    v1 = soya.Vertex(scene, 1.0, 0.0, 0.0, diffuse=color)
    v2 = soya.Vertex(scene, 0.0, 1.0, 0.0, diffuse=color)

    # Create edges
    e0 = Cylinder(scene, v0, v1, 0.007)
    e1 = Cylinder(scene, v0, v2, 0.007)
    e2 = Cylinder(scene, v1, v2, 0.007)

    # Create face
    f = soya.Face(scene, (v0, v1, v2))

    # Make face double sided
    f.double_sided = 1

    # Extract model
    model = scene.to_model()

    return model
コード例 #4
0
ファイル: plot.py プロジェクト: maciekswat/dolfin_python_deps
def Cylinder(scene, p0, p1, r, color=(0.0, 0.0, 0.0, 1.0)):
    "Return model for cylinder from p0 to p1 with radius r."

    # Convert to NumPy array
    if isinstance(p0, soya.Vertex):
        p0 = array((p0.x, p0.y, p0.z))
        p1 = array((p1.x, p1.y, p1.z))
    else:
        p0 = array(p0)
        p1 = array(p1)

    # Get tangent vectors for plane
    n = p0 - p1
    n = n / norm(n)
    t0, t1 = tangents(n)

    # Traverse the circles
    num_steps = 10
    dtheta = 2.0*pi / float(num_steps)
    for i in range(num_steps):

        # Compute coordinates for square
        dx0 = cos(i*dtheta)*t0 + sin(i*dtheta)*t1
        dx1 = cos((i + 1)*dtheta)*t0 + sin((i + 1)*dtheta)*t1
        x0 = p0 + r*dx0
        x1 = p0 + r*dx1
        x2 = p1 + r*dx0
        x3 = p1 + r*dx1

        # Cover square by two triangles
        v0 = soya.Vertex(scene, x0[0], x0[1], x0[2], diffuse=color)
        v1 = soya.Vertex(scene, x1[0], x1[1], x1[2], diffuse=color)
        v2 = soya.Vertex(scene, x2[0], x2[1], x2[2], diffuse=color)
        v3 = soya.Vertex(scene, x3[0], x3[1], x3[2], diffuse=color)
        f0 = soya.Face(scene, (v0, v1, v2))
        f1 = soya.Face(scene, (v1, v2, v3))
        f0.double_sided = 1
        f1.double_sided = 1

    # Extract model
    model = scene.to_model()

    return model
コード例 #5
0
ファイル: plot.py プロジェクト: maciekswat/dolfin_python_deps
def UnitTetrahedron(color=(0.0, 1.0, 0.0, 0.5)):
    "Return model for unit tetrahedron."

    info("Plotting unit tetrahedron")

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

    # Create vertices
    v0 = soya.Vertex(scene, 0.0, 0.0, 0.0, diffuse=color)
    v1 = soya.Vertex(scene, 1.0, 0.0, 0.0, diffuse=color)
    v2 = soya.Vertex(scene, 0.0, 1.0, 0.0, diffuse=color)
    v3 = soya.Vertex(scene, 0.0, 0.0, 1.0, diffuse=color)

    # Create edges
    e0 = Cylinder(scene, v0, v1, 0.007)
    e1 = Cylinder(scene, v0, v2, 0.007)
    e2 = Cylinder(scene, v0, v3, 0.007)
    e3 = Cylinder(scene, v1, v2, 0.007)
    e4 = Cylinder(scene, v1, v3, 0.007)
    e5 = Cylinder(scene, v2, v3, 0.007)

    # Create faces
    f0 = soya.Face(scene, (v1, v2, v3))
    f1 = soya.Face(scene, (v0, v2, v3))
    f2 = soya.Face(scene, (v0, v1, v3))
    f3 = soya.Face(scene, (v0, v1, v2))

    # Make faces double sided
    f0.double_sided = 1
    f1.double_sided = 1
    f2.double_sided = 1
    f3.double_sided = 1

    # Extract model
    model = scene.to_model()

    return model