Пример #1
0
 def test_mesh_collision(self):
     a = Cube()
     b = Cube(width=2.0, height=1.23, depth=1.0)
     b.position = [1.0, 0.2, 0.1]
     c = CollisionTest(callback=dummy, objects=[a, b])
     check = c._mesh_collision(a, b)
     self.assertTrue(check)
Пример #2
0
def fetch_instagram(name, scene, period, total):
    """This method runs once and continues to build the scene"""
    global y, z
    scene.clocks["fetch_instagram"].pause()
    url = "https://www.instagram.com/nasa/?__a=1"
    data = requests.get(url)
    images = data.json()["graphql"]["user"]["edge_owner_to_timeline_media"][
        "edges"
    ]
    for image in images:
        node = image["node"]
        for thum in node["thumbnail_resources"]:
            if thum["config_width"] == 640:
                src = thum["src"]
                print(f"Downloading {src}")
                f = requests.get(src, allow_redirects=True)
                with open(f"/tmp/{node['id']}.jpg", "wb") as fi:
                    fi.write(f.content)

                cube = Cube()
                cube.position = [0, y - 1, z]
                y += 1
                if y == 3:
                    y = 0
                    z += 1
                cube.material.texture = f"/tmp/{node['id']}.jpg"
                cube.info = node["edge_media_to_caption"]["edges"][0]["node"][
                    "text"
                ]
                scene.add_object(node["id"], cube)
Пример #3
0
from payton.scene import Scene
from payton.scene.geometry import Cube

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

scene.run()
Пример #4
0
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"
Пример #5
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()
Пример #6
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()