Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Quake 2 Model Test"""
import os
import sdl2
from payton.scene import Scene
from payton.scene.controller import Controller
from payton.scene.geometry import MD2, Plane
from payton.scene.gui import info_box
scene = Scene()
ground = Plane(width=20, height=20)
object_file = os.path.join(os.path.dirname(__file__), "infantry", "tris.md2")
model = MD2(filename=object_file)
class CustomKeyboardControls(Controller):
def keyboard(self, event, scene):
super().keyboard(event, scene)
if event.type == sdl2.SDL_KEYUP:
key = event.key.keysym.sym
if key == sdl2.SDLK_UP:
model.animate("walk", 0, 52)
if key == sdl2.SDLK_DOWN:
model.animate("death", 0, 76, False)
label = """
import random
from payton.scene import Scene
from payton.scene.geometry import Cube, Plane
scene = Scene()
ground = Plane(20, 20)
scene.add_object("ground", ground)
for i in range(100):
x = random.randint(-10, 10)
y = random.randint(-10, 10)
z = random.randint(0, 10)
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.material.opacity = random.randint(0, 255) / 255.0
cube.position = [x, y, z]
scene.add_object("cube_{}".format(i), cube)
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()
scene = Scene()
scene.shadow_quality = SHADOW_HIGH
def move(period, total):
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)
from payton.scene.gui import info_box
def rotate(period, total):
global scene
y = math.radians(period * 100)
y = -y if int(total) % 2 == 0 else y
scene.objects["cube"].rotate_around_x(math.radians(period * 50))
scene.objects["cube"].rotate_around_y(y)
scene.objects["cube"].rotate_around_z(math.radians(period * 150))
scene = Scene()
cube = Cube()
ground = Plane(10, 10)
cube.position = [0, 0, 1.0]
texture_file = os.path.join(os.path.dirname(__file__), "cube.png")
scene.observers[0].distance_to_target(5)
cube.material.texture = texture_file
scene.add_object("cube", cube)
scene.add_object("ground", ground)
scene.create_clock("rotate", 0.01, rotate)
scene.add_object(
"info", info_box(left=10, top=10, width=220, height=100, label="Hit SPACE\nto start animation",),
)
scene.run()
scene = Scene()
scene.shadow_quality = SHADOW_HIGH
def move(period, total):
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
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()
def __init__(self, **kwargs):
super().__init__(**kwargs)
ground = Plane(20, 20)
self.lights[0].position = [10.0, 10.0, 10]
model_file = os.path.join(os.path.dirname(__file__), "forgottenone2", "tris.md2")
weapon_file = os.path.join(os.path.dirname(__file__), "forgottenone2", "weapon.md2")
model = MD2(model_file, "ForgottenOne.pcx", track_motion=True)
model.track_motion = True
model._motion_path_line.material.color = [1.0, 0.0, 0.0]
weapon = MD2(weapon_file, "weapon.pcx")
model.bake_animation("run", 0, 5, 3)
weapon.bake_animation("run", 0, 5, 3)
model.add_child("weapon", weapon)
print(model.animations)
print(weapon.animations)
from payton.scene import Scene
from payton.scene.geometry import Line, Plane
from payton.scene.gui import info_box
def draw(hit):
global scene
scene.objects["line"].append([hit])
scene = Scene()
scene.add_click_plane([0, 0, 0.5], [0, 0, 1], draw)
scene.add_object("line", Line())
scene.objects["line"].material.color = [1.0, 0.0, 0.0]
ground = Plane(30, 30)
ground.position = [0, 0, 0.48]
scene.add_object("ground", ground)
scene.add_object(
"info", info_box(left=10, top=10, width=220, height=100, label="Start Clicking \nto draw lines",),
)
scene.run()
import os
from payton.scene import Scene
from payton.scene.geometry import Cylinder, Plane
from payton.scene.gui import info_box
def rotate(period, total):
global scene
scene.objects["cylinder"].rotate_around_z(math.radians(1))
scene = Scene()
cyl = Cylinder(height=2.0)
cyl.position = [0, 0, 1.0]
ground = Plane(10, 10)
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.add_object(
"info", info_box(left=10, top=10, width=220, height=100, label="Hit SPACE\nto start animation",),
)
scene.add_object("ground", ground)
scene.run()