2019-11-02 17:27:54 -05:00
|
|
|
from direct.interval.IntervalGlobal import *
|
2019-12-30 00:00:16 -06:00
|
|
|
from .Entity import Entity
|
2022-12-16 18:40:57 -06:00
|
|
|
from panda3d.core import Vec3
|
2019-11-02 17:27:54 -05:00
|
|
|
|
|
|
|
class PropSpinner(Entity):
|
|
|
|
|
|
|
|
def __init__(self, level, entId):
|
|
|
|
Entity.__init__(self, level, entId)
|
|
|
|
self.initProps()
|
|
|
|
|
|
|
|
def destroy(self):
|
|
|
|
self.destroyProps()
|
|
|
|
Entity.destroy(self)
|
|
|
|
|
|
|
|
def initProps(self):
|
|
|
|
topNode = self.getZoneNode()
|
|
|
|
props = topNode.findAllMatches('**/Prop_*')
|
|
|
|
spinTracks = Parallel()
|
|
|
|
for prop in props:
|
|
|
|
name = prop.getName()
|
|
|
|
nameParts = name.split('_')
|
|
|
|
axis = nameParts[2]
|
|
|
|
rate = 0
|
2020-01-08 16:47:17 -06:00
|
|
|
neg = nameParts[3][0].upper() == 'N'
|
2019-11-02 17:27:54 -05:00
|
|
|
if neg:
|
|
|
|
nameParts[3] = nameParts[3][1:]
|
|
|
|
try:
|
|
|
|
rate = int(nameParts[3])
|
|
|
|
except:
|
2019-12-30 00:00:16 -06:00
|
|
|
print('invalid prop rotate string: %s' % name)
|
2019-11-02 17:27:54 -05:00
|
|
|
|
|
|
|
if neg:
|
|
|
|
rate = -rate
|
|
|
|
prop.setHpr(0, 0, 0)
|
|
|
|
if axis == 'X':
|
|
|
|
hpr = Vec3(0, rate * 360, 0)
|
|
|
|
elif axis == 'Y':
|
|
|
|
hpr = Vec3(rate * 360, 0, 0)
|
|
|
|
elif axis == 'Z':
|
|
|
|
hpr = Vec3(0, 0, rate * 360)
|
|
|
|
else:
|
2019-12-30 00:00:16 -06:00
|
|
|
print('error', axis)
|
2019-11-02 17:27:54 -05:00
|
|
|
spinTracks.append(LerpHprInterval(prop, 60, hpr))
|
|
|
|
|
|
|
|
spinTracks.loop()
|
|
|
|
self.spinTracks = spinTracks
|
|
|
|
|
|
|
|
def destroyProps(self):
|
|
|
|
if hasattr(self, 'spinTracks'):
|
|
|
|
self.spinTracks.pause()
|
|
|
|
del self.spinTracks
|
|
|
|
|
|
|
|
if __dev__:
|
|
|
|
|
|
|
|
def attribChanged(self, *args):
|
|
|
|
self.destroyProps()
|
|
|
|
self.initProps()
|