-
Notifications
You must be signed in to change notification settings - Fork 24
/
vfx.py
291 lines (265 loc) · 10 KB
/
vfx.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
'''
VFX for Panda3D (c) by Wezu
This file is licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported License.
See http://creativecommons.org/licenses/by-sa/3.0/ for full license text.
'''
from panda3d.core import *
from direct.task import Task
from direct.interval.IntervalGlobal import *
class short_vfx():
def __init__(self, parent, texture=None, scale=1.0, Z=0.0, depthTest=False, depthWrite=False):
self.vfx=loader.loadModel('vfx/short_vfx')
if texture != None:
self.vfx.setTexture(TextureStage.getDefault(), loader.loadTexture(texture), 1)
self.vfx.reparentTo(render)
self.vfx.setBin('fixed', 40)
self.vfx.setDepthWrite(depthWrite)
self.vfx.setDepthTest(depthTest)
self.vfx.setLightOff()
self.vfx.setScale(scale)
self.vfx.setHpr(-90, 0, 0)
self.vfx.flattenLight()
self.Z=Z
self.parent=parent
self.vfxU=-0.5
self.vfxV=0
def start(self, speed=0.04):
taskMgr.doMethodLater(speed, self.run,'vfx')
def run(self, task):
if not self.parent:
self.vfx.removeNode()
return task.done
self.vfx.setPos(self.parent.getPos(render))
self.vfx.setZ(self.vfx.getZ()+self.Z)
self.vfxU=self.vfxU+0.5
if self.vfxU>=1.0:
self.vfxU=0
self.vfxV=self.vfxV-0.5
if self.vfxV <=-1:
self.vfx.removeNode()
return task.done
self.vfx.lookAt(base.camera)
self.vfx.setTexOffset(TextureStage.getDefault(), self.vfxU, self.vfxV)
return task.again
class vfx():
def __init__(self, parent, texture=None, scale=1.0, Z=0.0, depthTest=False, depthWrite=False, pos=None):
self.vfx=loader.loadModel('vfx/vfx2')
if texture != None:
self.vfx.setTexture(TextureStage.getDefault(), loader.loadTexture(texture), 1)
self.vfx.reparentTo(render)
self.vfx.setBin('fixed', 40)
self.vfx.setDepthWrite(depthWrite)
self.vfx.setDepthTest(depthTest)
self.vfx.setLightOff()
self.vfx.setScale(scale)
self.vfx.setHpr(-90, 0, 0)
self.vfx.flattenLight()
self.Z=Z
self.parent=None
self.pos=(0,0,0)
if parent:
self.parent=parent
else:
self.pos=pos
self.vfxU=-0.125
self.vfxV=0
self.auto_destruct=False
self.auto_stop=False
self.vfx.hide()
self.frame=0
self.stopAtFrame=-1
def hide(self):
self.vfx.hide()
def show(self):
self.vfx.show()
def stop(self):
self.vfx.hide()
self.auto_stop=True
def step(self):
if not self.parent:
self.vfx.removeNode()
return task.done
if self.auto_destruct:
self.vfx.removeNode()
return task.done
if self.auto_stop:
return task.done
if self.parent:
self.vfx.setPos(self.parent.getPos(render))
else:
self.vfx.setPos(self.pos)
self.vfx.setZ(self.vfx.getZ()+self.Z)
self.vfxU=self.vfxU+0.125
if self.vfxU>=1.0:
self.vfxU=0
self.vfxV=self.vfxV-0.125
self.vfx.lookAt(base.camera)
self.vfx.setTexOffset(TextureStage.getDefault(), self.vfxU, self.vfxV)
def remove_loop(self):
self.auto_destruct=True
def loop(self, speed=0.015):
self.auto_stop=False
taskMgr.doMethodLater(speed, self.run_loop,'vfx')
def run_loop(self,task):
if self.auto_destruct:
self.vfx.removeNode()
return task.done
if self.auto_stop:
self.hide()
return task.done
if self.parent:
self.vfx.setPos(self.parent.getPos(render))
else:
self.vfx.setPos(self.pos)
self.vfx.setZ(self.vfx.getZ()+self.Z)
self.vfxU=self.vfxU+0.125
if self.vfxU>=1.0:
self.vfxU=0
self.vfxV=self.vfxV-0.125
self.vfx.lookAt(base.camera)
self.vfx.setTexOffset(TextureStage.getDefault(), self.vfxU, self.vfxV)
return task.again
def start(self, speed=0.015, stopAtFrame=-1):
self.stopAtFrame=stopAtFrame
self.auto_stop=False
self.vfx.show()
taskMgr.doMethodLater(speed, self.run,'vfx')
def run(self, task):
if self.frame==self.stopAtFrame:
self.vfx.removeNode()
return task.done
self.frame+=1
if self.parent:
self.vfx.setPos(self.parent.getPos(render))
else:
self.vfx.setPos(self.pos)
self.vfx.setZ(self.vfx.getZ()+self.Z)
self.vfxU=self.vfxU+0.125
if self.vfxU>=1.0:
self.vfxU=0
self.vfxV=self.vfxV-0.125
if self.vfxV <=-1:
self.vfx.removeNode()
return task.done
self.vfx.lookAt(base.camera)
self.vfx.setTexOffset(TextureStage.getDefault(), self.vfxU, self.vfxV)
return task.again
class vfxGui():
def __init__(self, parent, texture=None, scale=32.0, Z=0.0, depthTest=False, depthWrite=False):
self.vfx=loader.loadModel('vfx/vfx2')
if texture != None:
self.vfx.setTexture(TextureStage.getDefault(), loader.loadTexture(texture), 1)
self.vfx.reparentTo(pixel2d)
self.vfx.setBin('fixed', 40)
self.vfx.setDepthWrite(depthWrite)
self.vfx.setDepthTest(depthTest)
self.vfx.setLightOff()
self.vfx.setScale(scale)
self.vfx.setHpr(-90, 0, 0)
self.vfx.flattenLight()
self.Z=Z
self.parent=parent
self.vfxU=-0.125
self.vfxV=0
def start(self, speed=0.015):
taskMgr.doMethodLater(speed, self.run,'vfx')
def run(self, task):
self.vfx.setPos(self.parent.getPos(pixel2d))
self.vfx.setZ(self.vfx.getZ()+self.Z)
self.vfxU=self.vfxU+0.125
if self.vfxU>=1.0:
self.vfxU=0
self.vfxV=self.vfxV-0.125
if self.vfxV <=-1:
self.vfx.removeNode()
return task.done
self.vfx.lookAt(base.camera)
self.vfx.setTexOffset(TextureStage.getDefault(), self.vfxU, self.vfxV)
return task.again
class P2Pvfx():
def __init__(self, from_target, to_target, texture, scale=1.0, Z=0.0, depthTest=False, depthWrite=False):
self.vfx=loader.loadModel('vfx/vfx1')
if texture != None:
self.vfx.setTexture(TextureStage.getDefault(), loader.loadTexture(texture), 1)
self.vfx.reparentTo(render)
self.vfx.setBin('fixed', 40)
self.vfx.setDepthWrite(depthWrite)
self.vfx.setDepthTest(depthTest)
self.vfx.setLightOff()
self.vfx.setScale(scale)
self.vfx.flattenLight()
self.Z=Z
self.vfxU=-0.125
self.vfxV=0
length =from_target.getDistance(to_target)
#print length
self.vfx.setScale(length,1,1)
self.parent=from_target
oldHPR=from_target.getHpr()
from_target.lookAt(to_target)
self.vfx.setHpr(from_target.getHpr())
self.vfx.setH(self.vfx,90)
from_target.setHpr(oldHPR)
self.vfx.hide()
def start(self, speed=0.030):
taskMgr.doMethodLater(speed, self.run,'vfx')
def run(self, task):
if not self.parent:
self.vfx.removeNode()
return task.done
self.vfx.setPos(self.parent.getPos(render))
self.vfx.show()
self.vfx.setZ(self.vfx.getZ()+self.Z)
self.vfxU=self.vfxU+0.5
if self.vfxU>=1.0:
self.vfxU=0
self.vfxV=self.vfxV-0.125
if self.vfxV <=-1:
self.vfx.removeNode()
return task.done
self.vfx.setTexOffset(TextureStage.getDefault(), self.vfxU, self.vfxV)
return task.again
class MovingVfx():
def __init__(self, from_target, to_target, texture=None, scale=1.0, Z=0.0, time=1.0, gravity=1.0, depthTest=False, depthWrite=False):
self.vfx=loader.loadModel('vfx/vfx2')
if texture != None:
self.vfx.setTexture(TextureStage.getDefault(), loader.loadTexture(texture), 1)
self.vfx.reparentTo(render)
self.vfx.setBin('fixed', 40)
self.vfx.setDepthWrite(depthWrite)
self.vfx.setDepthTest(depthTest)
self.vfx.setLightOff()
self.vfx.setScale(scale)
self.vfx.setHpr(-90, 0, 0)
#self.vfx.setPos(from_target.getPos(render))
self.vfx.flattenLight()
self.Z=Z
self.vfxU=-0.125
self.vfxV=0
self.target=to_target
self.from_target=from_target
self.time=time
self.gravity=gravity
self.interval=None
def start(self):
speed=self.time/64
taskMgr.doMethodLater(speed, self.run,'vfx')
self.interval=ProjectileInterval(self.vfx, startPos=self.from_target.getPos(render), endPos=self.target.getPos(render), duration=self.time, gravityMult=self.gravity).start()
def run(self, task):
if not self.target:
self.vfx.removeNode()
if self.interval:
self.interval.pause()
self.interval=None
return task.done
self.vfxU=self.vfxU+0.125
if self.vfxU>=1.0:
self.vfxU=0
self.vfxV=self.vfxV-0.125
if self.vfxV <=-1:
self.vfx.removeNode()
return task.done
self.vfx.lookAt(base.camera)
self.vfx.setTexOffset(TextureStage.getDefault(), self.vfxU, self.vfxV)
return task.again