Beispiel #1
0
import os
from payton.scene import Scene
from payton.scene.geometry import Mesh


scene = Scene()
mesh = Mesh()
mesh.add_triangle(
    [[0, 0, 0], [2, 0, 0], [2, 2, 0]], texcoords=[[0, 0], [1, 0], [1, 1]]
)
mesh.add_triangle(
    [[0, 0, 0], [2, 2, 0], [0, 2, 0]], texcoords=[[0, 0], [1, 1], [0, 1]]
)
texture_file = os.path.join(os.path.dirname(__file__), "cube.png")
mesh.material.texture = texture_file
scene.add_object("mesh", mesh)
scene.run()
Beispiel #2
0
            c[0] -= 0.01
        if c[1] >= initial[1]:
            c[1] -= 0.01
        if c[2] >= initial[2]:
            c[2] -= 0.01

        if sum(c) <= sum(initial) + 0.01:
            rise = True
    scene._background.top_color = c


scene = Scene()
scene.create_clock("sun", 0.1, change_background)

hud = Hud()
font_file = os.path.join(os.path.dirname(__file__),
                         "../static/arial_narrow_7.ttf")
hud.set_font(font_file, 15)

info_text = "Hit space to start background animation"

info = Text(label=info_text,
            position=(550, 0),
            color=(1, 1, 1),
            size=(300, 200))

hud.add_child("info", info)
scene.add_object("hud", hud)

scene.run()
Beispiel #3
0
from payton.scene import Scene
from payton.scene.geometry import Cube

scene = Scene()
cube = Cube()
scene.add_object("cube", cube)

scene.run()
import os
from payton.scene import Scene
from payton.scene.geometry import Cube
from payton.scene.observer import Observer
from payton.scene.gui import Hud, Text

scene = Scene()

texture_file = os.path.join(os.path.dirname(__file__), "cube.png")

cube = Cube(width=5.0, height=5.0, depth=5.0)
cube.position = [0, 0, 2.5]
cube.material.texture = texture_file

scene.add_object("cube", cube)

inside_box = Observer(
    position=[-1.7898840267533351, 2.210322695165203, 1.400984730396208],
    target=[0, 0, 1],
    fov=110,
)

scene.add_observer(inside_box)

hud = Hud()
font_file = os.path.join(
    os.path.dirname(__file__), "../static/arial_narrow_7.ttf"
)
hud.set_font(font_file, 15)

info_text = "Cycle through cameras using F2 and F3"
Beispiel #5
0
def logger(name, scene, period, total):
    if scene.objects["ball"].matrix[3][2] < 0:
        # Do not continue simulation if we hit the ground.
        scene.clocks[name].kill()  # We do not need this clock anymore
        return None

    # Log ball location
    logging.debug("Ball position: x:{} y:{} z:{} t={}".format(
        scene.objects["ball"].matrix[3][0],
        scene.objects["ball"].matrix[3][1],
        scene.objects["ball"].matrix[3][2],
        total,
    ))


#  Definitions
pm_scene = Scene()

ball = Sphere(radius=1, track_motion=True)

# Add ball to the scene
pm_scene.add_object("ball", ball)
pm_scene.observers[0].target_object = ball  # Track the ball

pm_scene.grid.resize(30, 30, 2)

pm_scene.create_clock("motion", 0.01, projectile_motion)
pm_scene.create_clock("logger", 0.05, logger)

pm_scene.run()
car_object_file = os.path.join(os.path.dirname(__file__), "lib",
                               "Low-Poly-Racing-Car.obj")

spherical_car_1 = Wavefront(filename=car_object_file)
spherical_car_2 = Wavefront(filename=car_object_file)

aabb_car_1 = Wavefront(filename=car_object_file)
aabb_car_2 = Wavefront(filename=car_object_file)

spherical_car_1.position = [-2, 0, 0]
spherical_car_2.position = [-2, 0, 4]

aabb_car_1.position = [2, 0, 0]
aabb_car_2.position = [2, 0, 4]

scene.add_object("scar1", spherical_car_1)
scene.add_object("scar2", spherical_car_2)

scene.add_object("acar1", aabb_car_1)
scene.add_object("acar2", aabb_car_2)

spherical_collision.add_object(spherical_car_1)
spherical_collision.add_object(spherical_car_2)

aabb_collision.add_object(aabb_car_1)
aabb_collision.add_object(aabb_car_2)

scene.add_collision_test(spherical_collision)
scene.add_collision_test(aabb_collision)

scene.create_clock("motion", 0.01, motion)
Beispiel #7
0
import os
from payton.scene import Scene
from payton.scene.wavefront import Wavefront

object_file = os.path.join(os.path.dirname(__file__), "monkey.obj")

scene = Scene()
monkey = Wavefront(filename=object_file)

scene.add_object("monkey", monkey)
scene.run()
Beispiel #8
0
    scene.objects["nucleus"].children["particle"].children[
        "sub_particle"
    ].position = [sx, sy, 0]
    scene.lights[0].position = [px, py, 0]
    scene.lights[1].position = [-px, -py, 0]


space = Scene()
space.lights.append(Light())
space.observers[0].position = [20, 20, 20]
space.grid.resize(40, 40, 1)

texture_file = os.path.join(os.path.dirname(__file__), "map.png")

nucleus = Sphere(radius=5, parallels=36, meridians=36)
nucleus.material.texture = texture_file
particle = Sphere()
particle.position = [8, 0, 0]

sub_particle = Sphere(radius=0.5)
sub_particle.position = [0, 2, 0]

nucleus.add_child("particle", particle)
particle.add_child("sub_particle", sub_particle)

space.add_object("nucleus", nucleus)

space.create_clock("motion", 0.01, motion)
print("Hit SPACE to continue animation")
space.run()
Beispiel #9
0
from payton.scene import Scene
from payton.scene.geometry import Line


scene = Scene()

line = Line(
    vertices=[
        [0, 0, 0],
        [0, 0, 1],
        [0.5, 0, 1.5],
        [1, 0, 1],
        [0, 0, 1],
        [1, 0, 0],
        [0, 0, 0],
        [1, 0, 1],
        [1, 0, 0],
    ]
)

scene.add_object("line", line)
scene.run()
Beispiel #10
0
from payton.scene import Scene
from payton.scene.geometry import Plane

scene = Scene()
plane = Plane(width=2, height=2)
scene.add_object("plane", plane)
scene.run()
Beispiel #11
0
def hit(collision, pairs):
    for pair in pairs:
        pair[0].material.color = [1.0, 0, 0]
        pair[1].material.color = [1.0, 0, 0]
        # Once there is a hit, system will not check
        # for the same collision, if you want to have the objects
        # back in the collision detection pipeline, you have to do
        # collision.resolve(pair[0], pair[1])


scene = Scene()
collision = CollisionTest(callback=hit)
for i in range(50):
    x = random.randint(-5, 5)
    y = random.randint(-5, 5)
    z = random.randint(-5, 5)
    if i % 2 == 0:
        s = Sphere()
        s.position = [x, y, z]
        scene.add_object("s_{}".format(i), s)
        collision.add_object(s)
    else:
        c = Cube()
        c.position = [x, y, z]
        scene.add_object("c_{}".format(i), c)
        collision.add_object(c)

scene.add_collision_test(collision)
scene.run()
Beispiel #12
0
def generate(name, scene, period, total):
    x = random.randint(-10, 10)
    y = random.randint(-10, 10)
    z = random.randint(-10, 10)
    r = random.randint(0, 255) / 255
    g = random.randint(0, 255) / 255
    b = random.randint(0, 255) / 255
    scene.objects["pc"].add([[x, y, z]], [[r, g, b]])


scene = Scene()

hud = Hud()
text = Text(
    label="Hit Space to create points",
    position=(5, 5),
    size=(200, 35),
    color=(1, 1, 1),
)

hud.add_child("text", text)
scene.add_object("hud", hud)

pc = PointCloud()

scene.add_object("pc", pc)
scene.create_clock("generate", 0.001, generate)

scene.run()
Beispiel #13
0
        score_board += 1
        game.huds["hud"].children[
            "score"].label = f"Number of balloons popped: {score_board}"


game.create_clock("balloon-creator", 1, create_balloon)
game.create_clock("move-balloons", 0.005, move_balloons)
game.on_select = select
hud = Hud()

text = Text(
    label="Hit Space to start popping the balloons!",
    position=(10, 10),
    color=(1, 1, 1),
    size=(300, 100),
)

hud.add_child("info", text)

score = Text(
    label="Number of balloons popped: 0",
    position=(10, 40),
    color=(1, 1, 1),
    size=(300, 100),
)

hud.add_child("score", score)

game.add_object("hud", hud)
game.run()
Beispiel #14
0
    for pair in pairs:
        pair[1].material.color = [1.0, 0, 0]
        collision.resolve(pair[0], pair[1])
    c3.position = [c3.position[0], c3.position[1], c3.position[2] + 0.11]

    moving_part = c3
    myScene.clocks["c2_clocks"].pause()
    print("Collision triggered")


collision = CollisionTest(callback=makeItRed)
collision.add_object(c2)
collision.add_object(c3)
myScene.add_collision_test("test", collision)

myScene.add_object("cylinder_1", c1)
myScene.add_object("cylinder_2", c2)
myScene.add_object("cylinder_3", c3)


def c2Move(period, total):
    pos = moving_part.position
    moving_part.position = [pos[0], pos[1], pos[2] + period]


def c3Move(period, total):
    if moving_part == c3 and myScene.clocks["c2_clocks"]._pause:
        time.sleep(0.5)
        c3.material.color = [1.0, 1.0, 1.0]
        myScene.clocks["c2_clocks"].pause()
Beispiel #15
0
import os
import math
from payton.scene import Scene
from payton.scene.geometry import Cylinder


def rotate(name, scene, period, total):
    scene.objects["cylinder"].rotate_around_z(math.radians(1))


scene = Scene()
cyl = Cylinder(height=2.0)

scene.create_clock("rotate", 0.01, rotate)

texture_file = os.path.join(os.path.dirname(__file__), "barrel.jpg")

cyl.material.texture = texture_file

scene.add_object("cylinder", cyl)
scene.run()
Beispiel #16
0
import random
from payton.scene import Scene
from payton.scene.geometry import Cube


def select(list):
    for obj in list:
        obj.material.color = [1, 1, 1]


scene = Scene(on_select=select)
for i in range(10):
    x = random.randint(-5, 5)
    y = random.randint(-5, 5)
    z = random.randint(-5, 5)
    r = random.randint(0, 255) / 255.0
    g = random.randint(0, 255) / 255.0
    b = random.randint(0, 255) / 255.0
    cube = Cube()
    cube.material.color = [r, g, b]
    cube.position = [x, y, z]
    scene.add_object("cube_{}".format(i), cube)

print("Try clicking on objects")

scene.run()