Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 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])
return True
scene = Scene(width=600, height=600)
spherical_collision = CollisionTest(callback=hit_sphere, level=CollisionTest.SPHERICAL)
aabb_collision = CollisionTest(callback=hit_aabb, level=CollisionTest.AABB)
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)
scene.objects["dir"].forward(0.1)
def set_target(hit):
global target
scene.objects["dir"].direct_to(hit)
target = hit
scene.add_click_plane([0, 0, 0], [0, 0, 1], set_target)
scene.create_clock("move", 0.05, move_to_target)
obj_file = os.path.join(os.path.dirname(__file__), "director.obj")
tex_file = os.path.join(os.path.dirname(__file__), "checkers.jpg")
odir = Wavefront(filename=obj_file)
ground = Plane(width=20, height=20)
ground.material.texture = tex_file
scene.add_object("dir", odir)
scene.add_object("ground", ground)
print("Hit space to start then click on the scene")
scene.run()
global total_angles, amount
scene.objects["lamp"].rotate_around_x(math.radians(amount))
total_angles += amount
if total_angles >= 30:
amount = -0.5
if total_angles <= -60:
amount = 0.5
light_pos = scene.objects["lamp"].to_absolute([0, 0, -3.4])
scene.lights[0].position = light_pos
table_file = os.path.join(os.path.dirname(__file__), "scene", "table.obj")
lamp_file = os.path.join(os.path.dirname(__file__), "scene", "lamp.obj")
table = Wavefront(table_file)
lamp = Wavefront(lamp_file)
lamp.fix_normals(reverse=True)
lamp.position = [0, 0, 12]
scene.create_clock("swing", 0.01, swing)
scene.active_observer.position = [
8.261520800759284,
8.259030103723475,
17.54799562339614,
]
scene.lights[0].position = [0, 0, 8.6]
scene.add_object("table", table)
scene.add_object("lamp", lamp)
scene.run()
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()
import os
from payton.scene import Scene
from payton.scene.geometry import Plane, Wavefront
from payton.scene.geometry.wavefront import export
object_file = os.path.join(os.path.dirname(__file__), "monkey.obj")
scene = Scene()
ground = Plane(10, 10)
monkey = Wavefront(filename=object_file)
export(monkey, "output.obj")
exported_mesh = Wavefront(filename="output.obj")
exported_mesh.position = [0, 0, 1.0]
scene.add_object("monkey", exported_mesh)
scene.add_object("ground", ground)
scene.run()
import os
from payton.scene import Scene
from payton.scene.geometry import Plane, Wavefront
from payton.scene.geometry.wavefront import export
object_file = os.path.join(os.path.dirname(__file__), "monkey.obj")
scene = Scene()
ground = Plane(10, 10)
monkey = Wavefront(filename=object_file)
export(monkey, "output.obj")
exported_mesh = Wavefront(filename="output.obj")
exported_mesh.position = [0, 0, 1.0]
scene.add_object("monkey", exported_mesh)
scene.add_object("ground", ground)
scene.run()
def swing(period, total):
global total_angles, amount
scene.objects["lamp"].rotate_around_x(math.radians(amount))
total_angles += amount
if total_angles >= 30:
amount = -0.5
if total_angles <= -60:
amount = 0.5
light_pos = scene.objects["lamp"].to_absolute([0, 0, -3.4])
scene.lights[0].position = light_pos
table_file = os.path.join(os.path.dirname(__file__), "scene", "table.obj")
lamp_file = os.path.join(os.path.dirname(__file__), "scene", "lamp.obj")
table = Wavefront(table_file)
lamp = Wavefront(lamp_file)
lamp.fix_normals(reverse=True)
lamp.position = [0, 0, 12]
scene.create_clock("swing", 0.01, swing)
scene.active_observer.position = [
8.261520800759284,
8.259030103723475,
17.54799562339614,
]
scene.lights[0].position = [0, 0, 8.6]
scene.add_object("table", table)
scene.add_object("lamp", lamp)
scene.run()
# back in the collision detection pipeline, you have to do
collision.resolve(pair[0], pair[1])
return True
scene = Scene(width=600, height=600)
spherical_collision = CollisionTest(callback=hit_sphere, level=CollisionTest.SPHERICAL)
aabb_collision = CollisionTest(callback=hit_aabb, level=CollisionTest.AABB)
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)
pair[1].material.color = [0.0, 1.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])
return True
scene = Scene(width=600, height=600)
spherical_collision = CollisionTest(callback=hit_sphere, level=CollisionTest.SPHERICAL)
aabb_collision = CollisionTest(callback=hit_aabb, level=CollisionTest.AABB)
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)
pair[0].material.color = [0.0, 1.0, 0]
pair[1].material.color = [0.0, 1.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])
return True
scene = Scene(width=600, height=600)
spherical_collision = CollisionTest(callback=hit_sphere, level=CollisionTest.SPHERICAL)
aabb_collision = CollisionTest(callback=hit_aabb, level=CollisionTest.AABB)
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)