forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEffects.py
More file actions
134 lines (111 loc) · 4.86 KB
/
Effects.py
File metadata and controls
134 lines (111 loc) · 4.86 KB
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
""" Showutil Effects module: contains code for useful showcode effects. """
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
# bounce types
SX_BOUNCE = 0
SY_BOUNCE = 1
SZ_BOUNCE = 2
TX_BOUNCE = 3
TY_BOUNCE = 4
TZ_BOUNCE = 5
H_BOUNCE = 6
P_BOUNCE = 7
R_BOUNCE = 8
# convenience funcs
#
def createScaleXBounce(nodeObj, numBounces, startValues, totalTime, amplitude):
return createBounce(nodeObj, numBounces, startValues, totalTime,
amplitude, SX_BOUNCE)
def createScaleYBounce(nodeObj, numBounces, startValues, totalTime, amplitude):
return createBounce(nodeObj, numBounces, startValues, totalTime,
amplitude, SY_BOUNCE)
def createScaleZBounce(nodeObj, numBounces, startValue, totalTime, amplitude):
return createBounce(nodeObj, numBounces, startValue, totalTime,
amplitude, SZ_BOUNCE)
def createXBounce(nodeObj, numBounces, startValues, totalTime, amplitude):
return createBounce(nodeObj, numBounces, startValues, totalTime,
amplitude, TX_BOUNCE)
def createYBounce(nodeObj, numBounces, startValues, totalTime, amplitude):
return createBounce(nodeObj, numBounces, startValues, totalTime,
amplitude, TY_BOUNCE)
def createZBounce(nodeObj, numBounces, startValues, totalTime, amplitude):
return createBounce(nodeObj, numBounces, startValues, totalTime,
amplitude, TZ_BOUNCE)
def createHBounce(nodeObj, numBounces, startValues, totalTime, amplitude):
return createBounce(nodeObj, numBounces, startValues, totalTime,
amplitude, H_BOUNCE)
def createPBounce(nodeObj, numBounces, startValues, totalTime, amplitude):
return createBounce(nodeObj, numBounces, startValues, totalTime,
amplitude, P_BOUNCE)
def createRBounce(nodeObj, numBounces, startValues, totalTime, amplitude):
return createBounce(nodeObj, numBounces, startValues, totalTime,
amplitude, R_BOUNCE)
def createBounce(nodeObj, numBounces, startValues, totalTime, amplitude,
bounceType=SZ_BOUNCE):
"""
createBounce: create and return a list of intervals to make a
given nodePath bounce a given number of times over a give total time.
"""
if not nodeObj or numBounces < 1 or totalTime == 0:
self.notify.warning(
"createBounceIvals called with invalid parameter")
return
result = Sequence()
# calculate how long, in seconds, each bounce should last
bounceTime = totalTime/float(numBounces)
currTime = bounceTime
currAmplitude = amplitude
# determine the how much of a change in value the first bounce
# will produce based on the given start value and amplitude
#
if ((bounceType == SX_BOUNCE) or (bounceType == TX_BOUNCE) or
(bounceType == H_BOUNCE)):
index = 0
elif ((bounceType == SY_BOUNCE) or (bounceType == TY_BOUNCE) or
(bounceType == P_BOUNCE)):
index = 1
elif ((bounceType == SZ_BOUNCE) or (bounceType == TZ_BOUNCE) or
(bounceType == R_BOUNCE)):
index = 2
currBounceVal = startValues[index]
# create a lerp interval for each bounce, making sure to
# figure out the new value, which progressively gets closer
# to our start value
#
for bounceNum in range(numBounces*2):
# determine the direction that this value should go,
# alternating for each lerp interval to simulate
# a spring effect
#
if bounceNum % 2:
# bounce down
currBounceVal = startValues[index]
blend = 'easeIn'
else:
# bounce up
currBounceVal = startValues[index] + currAmplitude
blend = 'easeOut'
newVec3 = Vec3(startValues)
newVec3.setCell(index, currBounceVal)
print "### newVec3 = ", newVec3
# create the right type of lerp
if ((bounceType == SX_BOUNCE) or (bounceType == SY_BOUNCE) or
(bounceType == SZ_BOUNCE)):
result.append(LerpScaleInterval(
nodeObj, currTime, newVec3, blendType=blend))
elif ((bounceType == TX_BOUNCE) or (bounceType == TY_BOUNCE) or
(bounceType == TZ_BOUNCE)):
result.append(LerpPosInterval(
nodeObj, currTime, newVec3, blendType=blend))
elif ((bounceType == H_BOUNCE) or (bounceType == P_BOUNCE) or
(bounceType == R_BOUNCE)):
result.append(LerpHprInterval(
nodeObj, currTime, newVec3, blendType=blend))
# the value diff from the base gets smaller for each
# consecutive bounce, and make sure to update for
# possibly a new amount of time the next bounce will
# take
#
currAmplitude *= 0.5
currTime = bounceTime
return result