-
Notifications
You must be signed in to change notification settings - Fork 29
/
tour3d.py
294 lines (258 loc) · 9.45 KB
/
tour3d.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.scatter import Scatter
from kivy.uix.image import Image
from kivy.animation import Animation
from kivy.clock import Clock
from kivy3dgui.layout3d import Node
class Note(Scatter):
def __init__(self, **kwargs):
wpos = self.pos = kwargs.pop("pos")
try:
self.create_image = kwargs.pop("create_image")
super(Note, self).__init__(**kwargs)
except:
print(kwargs)
self.opacity = 0
#Show
anim = Animation(opacity=1.0, duration=0.3)
anim.start(self)
create_image = kwargs.get('create_image', False)
self.request_del = False
text_editor = TextInput(size = (120, 90))
close = Button(size = (20, 20), text="x")
image = Image(source="./data/imgs/background.jpg", allow_stretch=True, keep_ratio=False)
self.add_widget(image)
self.add_widget(text_editor)
self.add_widget(close)
if create_image:
image_front = Image(source="./data/imgs/faust_github.jpg", size=(120,70), allow_stretch=True, keep_ratio=False)
self.add_widget(image_front)
self.size = (120, 120)
self.size_hint = (None, None)
image.size = (120, 120)
text_editor.pos = (0, 10)
close.pos = (100, 100)
self.pos = wpos
close.bind(on_release=self.close_request)
def close_request(self, *args):
if not self.request_del:
anim = Animation(opacity=0.0, duration=0.3)
anim.bind(on_complete=self.on_complete)
anim.start(self)
self.request_del = True
def on_complete(self, *args):
self.parent.remove_widget(self)
class Tour3DApp(App):
def create_note(self, args):
self.create_image = not self.create_image
return Note(pos=(args[0]-4, args[1]-102), create_image = self.create_image)
def speed_event(self):
self.show_speed_control = not self.show_speed_control
if self.show_speed_control:
Animation(translate=(16, 15, -10), scale=(0.07, 0.07, 0.07), duration=0.4).start(self.layout3d.ids["SpeedInc"])
Animation(translate=(12, 15, -10), scale=(0.07, 0.07, 0.07), duration=0.4).start(self.layout3d.ids["SpeedDec"])
else:
Animation(translate=(14, 15, -10), scale=(0.07, 0.07, 0.07), duration=0.4).start(self.layout3d.ids["SpeedInc"])
Animation(translate=(14, 15, -10), scale=(0.07, 0.07, 0.07), duration=0.4).start(self.layout3d.ids["SpeedDec"])
self.rot_speed = 14.0
def add_speed(self, value):
self.rot_speed += value
def build(self):
from kivy.lang import Builder
self.create_image = False
self.rot_speed = 14.0
self.show_speed_control = False
self.rotating = True
self.delay = 8.0
self.red_n = []
self.green_n = []
self.layout3d = Builder.load_string('''
#:kivy 1.0
#: import Layout3D kivy3dgui.layout3d
#: import Animation kivy.animation.Animation
<Note>
Layout3D:
id: par
size_hint: (1.0, 1.0)
canvas_size: (1366, 768)
post_processing: False
shadow: False
canvas.before:
Color:
rgb: 1, 1, 1,0.1
Rectangle:
size: self.size
pos: self.pos
#source: "./data/imgs/checkerb.png"
Node:
rotate: (90.0, 1.0, 0, 0)
scale: (80.0,80.0,0.1)
translate: (0, -25, -110)
effect: True
picking: False
meshes: ("./data/obj/box.obj", )
FloatLayout:
size_hint: (1.0, 1.0)
Button:
background_normal: "./data/imgs/checkerb.png"
Node:
#rotate: (-90.0, 1.0, 0, 0)
scale: (0.1,0.1,0.1)
translate: (0, -18, -12)
effect: True
picking: False
meshes: ("./data/obj/sphere.obj", )
FloatLayout:
size_hint: (1.0, 1.0)
Button:
background_normal: "./data/imgs/green.png"
Node:
#rotate: (30.0, 0.0, 0, 1.0)
id: FarSphere
scale: (0.3,0.3,0.3)
translate: (-10, 10, -170)
effect: True
meshes: ("./data/obj/sphere.obj", )
FloatLayout:
size_hint: (1.0, 1.0)
id: NoteLayout
Button:
size_hint: (1.0, 1.0)
background_normal: "./data/imgs/worldtex.png"
on_touch_down:
Animation(translate=(2, 8, -17), scale=(0.45, 0.45, 0.45), duration=2.3).start(FarSphere)
Animation(look_at = [0, 15, 20, 0, 14, -20, 0, 1, 0], duration=2.3).start(root)
NoteLayout.add_widget(app.create_note((args[1].x, args[1].y)))
Animation(translate= (20, -10, -48),duration=2.3).start(Drawer2)
Slider:
size_hint: (1.0, 0.05)
pos_hint: {"x": 0.0, "y":0.5}
opacity: 0.3
Node:
rotate: (310.0, 0.0, 1, 0)
id: Sheet1
scale: (0.15,0.15,0.15)
translate: (-10, 14, -10)
effect: True
meshes: ("./data/obj/sphere.obj", )
FloatLayout:
size_hint: (1.0, 1.0)
Button:
text: "Rotate"
size_hint: (0.3, 0.2)
font_size: 80
pos_hint: {"x": 0, "y":0.4}
on_release:
anim = Animation(rotate=(310, 0, 1, 0), duration=0.3)
anim.start(Sheet1)
app.rotating = True
Button:
text: "Stop"
size_hint: (0.3, 0.2)
font_size: 80
pos_hint: {"x": 0.5, "y":0.4}
on_release:
anim = Animation(rotate=(130, 0, 1, 0), duration=0.3)
anim.start(Sheet1)
app.rotating = False
Node:
rotate: (290.0, 0.0, 1, 0)
id: Speed
scale: (0.11,0.11,0.11)
translate: (14, 14, -10)
effect: True
meshes: ("./data/obj/sphere.obj", )
FloatLayout:
size_hint: (1.0, 1.0)
Button:
text: "Speed"
size_hint: (0.3, 0.2)
font_size: 80
pos_hint: {"x": 0.5, "y":0.4}
on_release:
app.speed_event()
Node:
rotate: (290.0, 0.0, 1, 0)
id: SpeedInc
scale: (0.07,0.07,0.07)
translate: (14, 15, -10)
effect: True
meshes: ("./data/obj/sphere.obj", )
FloatLayout:
size_hint: (1.0, 1.0)
Button:
text: ">>"
size_hint: (0.3, 0.2)
font_size: 80
pos_hint: {"x": 0.5, "y":0.4}
on_release:
app.add_speed(14.0)
Node:
rotate: (290.0, 0.0, 1, 0)
id: SpeedDec
scale: (0.07,0.07,0.07)
translate: (14, 15, -10)
effect: True
meshes: ("./data/obj/sphere.obj", )
FloatLayout:
size_hint: (1.0, 1.0)
Button:
text: "<<"
size_hint: (0.3, 0.2)
font_size: 80
pos_hint: {"x": 0.5, "y":0.4}
on_release:
app.add_speed(-14.0)
Node:
#rotate: (-90.0, 1.0, 0, 0)
scale: (8.4,8.4,8.4)
translate: (0, -10, -40)
effect: True
meshes: ("./data/obj/table.obj", )
FloatLayout:
size_hint: (1.0, 1.0)
Button:
background_normal: "./data/imgs/table.png"
Node:
#rotate: (-90.0, 1.0, 0, 0)
scale: (8.4,8.4,8.4)
translate: (0, -10, -48)
effect: True
picking: False
meshes: ("./data/obj/drawer.obj", )
FloatLayout:
size_hint: (1.0, 1.0)
Button:
background_normal: "./data/imgs/drawer.png"
Node:
#rotate: (-90.0, 1.0, 0, 0)
scale: (8.4,8.4,8.4)
id: Drawer2
translate: (20, -10, -48)
effect: True
picking: False
meshes: ("./data/obj/drawer.obj", )
FloatLayout:
size_hint: (1.0, 1.0)
id: SelfDrawer
Button:
background_normal: "./data/imgs/drawer.png"
on_release:
Animation(look_at = [0, 15, 16, 0, 12, 0, 0, 1, 0], duration=2.3).start(root)
Animation(translate= (20, -10, -40),duration=2.3).start(Drawer2)
''')
"""rotate= (120.0, 0.0, 1.0, 0.4),"""
self.layout3d.look_at = [0, 15, 86, 0, 8, 0, 0, 1, 0]
self.y_rotate = 0.0
Clock.schedule_interval(self.update_time, 1 / 60.)
return self.layout3d
def update_time(self, delta):
if self.rotating:
self.y_rotate += delta * self.rot_speed
self.layout3d.ids["FarSphere"].rotate = [self.y_rotate, 0.0, 1.0, 0.0]
if __name__ == '__main__':
Tour3DApp().run()