How to use the payton.scene.geometry.Cube function in Payton

To help you get started, we’ve selected a few Payton examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sinanislekdemir / payton / payton / scene / test_geometry.py View on Github external
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)
github sinanislekdemir / payton / examples / basics / 30_near_far_plane.py View on Github external
direction = 0


scene.active_observer.far = 20
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("test", collision)
scene.create_clock("plane", 0.01, change_near_plane)
scene.run()
github sinanislekdemir / payton / examples / tools / 05_subdivide.py View on Github external
import os

from payton.scene import Scene
from payton.scene.geometry import Cube
from payton.scene.material import WIREFRAME
from payton.tools.mesh.geometry import subdivide

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

cube = Cube()
cube = subdivide(cube, 4)
cube.material.texture = texture_file
cube.material.display = WIREFRAME

normal_cube = Cube()
normal_cube.material = cube.material
normal_cube.position = [2, 0, 0]

scene = Scene()
scene.add_object("cube", cube)
scene.add_object("normal_cube", normal_cube)
scene.run()
github sinanislekdemir / payton / examples / tools / 05_subdivide.py View on Github external
import os

from payton.scene import Scene
from payton.scene.geometry import Cube
from payton.scene.material import WIREFRAME
from payton.tools.mesh.geometry import subdivide

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

cube = Cube()
cube = subdivide(cube, 4)
cube.material.texture = texture_file
cube.material.display = WIREFRAME

normal_cube = Cube()
normal_cube.material = cube.material
normal_cube.position = [2, 0, 0]

scene = Scene()
scene.add_object("cube", cube)
scene.add_object("normal_cube", normal_cube)
scene.run()
github sinanislekdemir / payton / examples / basics / 24_object_oriented.py View on Github external
def __init__(self, **kwargs):
        super().__init__(**kwargs)
        cube = Cube()
        self.add_object("cube", cube)
        self.create_clock("rotator", 0.01, self.timer)
        self.add_object(
            "info", info_box(left=10, top=10, width=220, height=100, label="Hit SPACE\nto start animation",),
        )
github sinanislekdemir / payton / examples / basics / 27_json.py View on Github external
import os

from payton.scene.geometry import Cube, Sphere, Wavefront
from payton.scene.geometry.export import export_json, import_json
from payton.scene.scene import Scene

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

monkey = Wavefront(filename=object_file)
monkey.add_child("cube", Cube())
monkey.children["cube"].position = [0, 0, 3]
monkey.children["cube"].add_child("sphere", Sphere())
monkey.children["cube"].children["sphere"].position = [1, 0, 0]

export_json(monkey, "test.json")
new = import_json("test.json")

scene = Scene()
scene.add_object("monkey", new)
scene.run()
github sinanislekdemir / payton / examples / basics / 23_motion.py View on Github external
forward = 0.02
            if key == sdl2.SDLK_DOWN:
                forward = -0.02
            if key == sdl2.SDLK_LEFT:
                rotate = -1
            if key == sdl2.SDLK_RIGHT:
                rotate = 1
        if event.type == sdl2.SDL_KEYUP:
            key = event.key.keysym.sym
            if key == sdl2.SDLK_UP or key == sdl2.SDLK_DOWN:
                forward = 0
            if key == sdl2.SDLK_LEFT or key == sdl2.SDLK_RIGHT:
                rotate = 0


cube = Cube()
cube.track_motion = True
scene.controller = CustomKeyboardControls()
scene.add_object("cube", cube)
scene.create_clock("motion", 0.01, motion)

label = """This demo uses clock\n hit SPACE to start

Key Up = forward
Key Down = back
Key Left = turn left
Key Right = turn right
"""

scene.add_object("info", info_box(left=10, top=10, width=220, height=200, label=label))

scene.run()
github sinanislekdemir / payton / examples / basics / 19_multiple_cameras.py View on Github external
import os

from payton.scene import Scene
from payton.scene.geometry import Cube
from payton.scene.gui import info_box
from payton.scene.observer import Observer

scene = Scene()
scene.background.top_color = [0, 0, 0, 1]
scene.background.bottom_color = [0, 0, 0, 1]

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)

scene.add_object(
    "info", info_box(left=10, top=10, width=220, height=100, label="Hit F2/F3 to\nswitch between cameras",),
)

scene.run()
github sinanislekdemir / payton / examples / basics / 02_cube.py View on Github external
angle = (total * 60) % 360
    px = math.cos(math.radians(angle)) * 8
    py = math.sin(math.radians(angle)) * 8
    scene.lights[0].position = [px, py, 4.0]


cube = Cube()
cube.position = [2, 1, 0.5]

ground = Plane(width=30, height=30)
wall1 = Plane(width=30, height=10)
wall1.rotate_around_x(math.radians(90))
wall1.position = [0, -10, 5]

scene.lights[0].position = [5.0, 5.0, 6.0]
cube_by_corners = Cube(from_corner=[-3, -3, 1], to_corner=[-1, -1, 3])
scene.create_clock("mm", 0.001, move)

texture_file = os.path.join(os.path.dirname(__file__), "barrel.jpg")
cube_by_corners.material.texture = texture_file
ground.material.texture = texture_file

scene.add_object("wall", wall1)
scene.add_object("cube", cube)
scene.add_object("cube_by_corners", cube_by_corners)
scene.add_object("ground", ground)
scene.grid.visible = False

scene.run()
github sinanislekdemir / payton / examples / basics / 07_picking.py View on Github external
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)

scene.add_object(
    "info", info_box(left=10, top=10, width=220, height=100, label="Try clicking cubes"),
)


scene.run()