-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_mesh.py
131 lines (106 loc) · 5.05 KB
/
test_mesh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import pyggel
from pyggel import *
import random, time
def main():
pyggel.view.init(screen_size=(800,600), screen_size_2d=(640, 480))
pyggel.view.set_debug(False)
my_light = pyggel.light.Light((0,100,0), (0.5,0.5,0.5,1),
(1,1,1,1), (50,50,50,10),
(0,0,0), True)
camera = pyggel.camera.LookAtCamera((0,0,0), distance=10)
camera.roty = 180
obj = pyggel.mesh.OBJ("data/bird_plane.obj")
root = obj.get_obj_by_name("cylinder1")
tail = obj.get_obj_by_name("sphere2")
head = obj.get_obj_by_name("sphere2_copy3")
wings = obj.get_obj_by_name("cube4")
skel = pyggel.mesh.Skeleton()
skel.add_bone(root.name, (0,0,root.side("back")), (0,0,root.side("front")))
skel.add_bone(tail.name, (0,0,tail.side("front")), (0,0,tail.side("back")), root.name)
skel.add_bone(head.name, (0,0,head.side("back")), (0,0,head.side("front")), root.name, 0.25)
skel.add_bone(wings.name, (wings.side("left"),0,0), (wings.side("right"),0,0), root.name, 0.5)
action = pyggel.mesh.Action(2, [pyggel.mesh.RotateTo(wings.name, (0,0,45),0,.5),
pyggel.mesh.RotateTo(wings.name, (0,0,-45),.5,1.5),
pyggel.mesh.RotateTo(wings.name, (0,0,0),1.5,2),
pyggel.mesh.ScaleTo(tail.name, (1.25,1.25,1.25), 0, 1),
pyggel.mesh.ScaleTo(tail.name, (1,1,1), 1, 2),
pyggel.mesh.RotateTo(head.name, (0,15,0),0,.25),
pyggel.mesh.RotateTo(head.name, (0,-15,0),.25,.75),
pyggel.mesh.RotateTo(head.name, (0,0,0),.75,1),
pyggel.mesh.RotateTo("weapon_right", (0,0,-45),0,.5),
pyggel.mesh.RotateTo("weapon_right", (0,0,45),.5,1.5),
pyggel.mesh.RotateTo("weapon_right", (0,0,0),1.5,2),
pyggel.mesh.RotateTo("weapon_left", (0,0,-45),0,.5),
pyggel.mesh.RotateTo("weapon_left", (0,0,45),.5,1.5),
pyggel.mesh.RotateTo("weapon_left", (0,0,0),1.5,2)])
head_left = pyggel.mesh.Action(1, [pyggel.mesh.RotateTo(head.name, (0,45,0),0,1)])
head_right = pyggel.mesh.Action(1, [pyggel.mesh.RotateTo(head.name, (0,-45,0), 0,1)])
head_up = pyggel.mesh.Action(1, [pyggel.mesh.RotateTo(head.name, (45,0,0),0,1)])
head_down = pyggel.mesh.Action(1, [pyggel.mesh.RotateTo(head.name, (-45,0,0),0,1)])
head_test = pyggel.mesh.Action(5, [pyggel.mesh.RotateTo(head.name, (0,0,45),0,1),
pyggel.mesh.RotateTo(head.name, (0,-45,0),2,3),
pyggel.mesh.RotateTo(head.name, (0,0,0),4,5),
pyggel.mesh.RotateTo(tail.name, (0,0,360), 0,5),
pyggel.mesh.RotateTo(wings.name, (0,0,720),0,5)])
ani = pyggel.mesh.Animation(obj, skel, {"1":head_left,
"2":head_right,
"3":head_up,
"4":head_down,
"5":action,
"6":head_test})
#Let's make some connections here:
new_obj = wings.copy()
new_obj.name = "weapon_right"
skel.add_bone(new_obj.name, (wings.side("right"),0,0), (wings.side("right")+new_obj.side("width"),0,0), wings.name)
ani.mesh.objs.append(new_obj)
new_obj2 = wings.copy()
new_obj2.name = "weapon_left"
skel.add_bone(new_obj2.name, (wings.side("left"),0,0), (wings.side("left")-new_obj2.side("width"),0,0), wings.name)
ani.mesh.objs.append(new_obj2)
ani2 = ani.copy()
ani2.do("5", True)
ani2.pos = (0,0,-10)
my_scene = pyggel.scene.Scene()
my_scene.add_3d(ani)
my_scene.add_3d(ani2)
my_scene.add_light(my_light)
clock = pygame.time.Clock()
meh = pyggel.event.Handler()
meh.bind_to_event(" ", lambda a,b: pyggel.misc.save_screenshot("Test.png"))
last = None
while 1:
clock.tick(60)
pyggel.view.set_title("FPS: %s"%clock.get_fps())
meh.update()
if meh.quit:
pyggel.quit()
return None
if K_LEFT in meh.keyboard.active:
camera.roty -= .5
if K_RIGHT in meh.keyboard.active:
camera.roty += .5
if K_DOWN in meh.keyboard.active:
camera.rotx -= .5
if K_UP in meh.keyboard.active:
camera.rotx += .5
if "=" in meh.keyboard.active:
camera.distance -= .1
if "-" in meh.keyboard.active:
camera.distance += .1
if "a" in meh.keyboard.active:
camera.posx -= .1
if K_d in meh.keyboard.active:
camera.posx += .1
if K_s in meh.keyboard.active:
camera.posz -= .1
if K_w in meh.keyboard.active:
camera.posz += .1
nums = ("1", "2", "3", "4", "5", "6")
for i in nums:
if i in meh.keyboard.hit:
ani.do(i, False)
pyggel.view.clear_screen()
pyggel.view.set3d()
my_scene.render(camera)
pyggel.view.refresh_screen()
main()