Skip to content

Commit

Permalink
annimation added in
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAwesomePossum committed Jun 24, 2015
1 parent 346ef00 commit af4bf4d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 22 deletions.
50 changes: 45 additions & 5 deletions PandaModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"localSize" : 1,
"localOrientation" : SHPR(0,0,0),
"joints" : [], # jointed models not currently supported
"animations" : None,
"animation" : None,
"defaultAnimation" : None,
"frame" : None,
"cRadius" : 1,
Expand All @@ -39,11 +39,11 @@ def getModel(x):
x = x._pandaModel
return x

def pandaModel(fileName = None, name = "PandaModel", size = None, hpr = None, position = None, tag = [], color = None, texture = None, parent = render, duration = 0):
return PandaModel( fileName, size, hpr, position, tag, color, texture, name, parent, duration)
def pandaModel(fileName = None, name = "PandaModel", size = None, hpr = None, position = None, tag = [], color = None, texture = None, parent = render, duration = 0, frame = None, joints = [], animation = None):
return PandaModel( fileName, size, hpr, position, tag, color, texture, name, parent, duration, frame, joints, animation)

class PandaModel(Proxy.Proxy):
def __init__(self, fileName, size, hpr, position, tag, color, texture, name, parent, duration):
def __init__(self, fileName, size, hpr, position, tag, color, texture, name, parent, duration, frame, joints, animation):
Proxy.Proxy.__init__(self, name = str(name) + ":" + str(PandaGlobals.nextModelId), updater = modelUpdater,
types = {"position": p3Type, "hpr": hprType , "size": numType,
"color": colorType, "texture": stringType})
Expand Down Expand Up @@ -75,9 +75,28 @@ def __init__(self, fileName, size, hpr, position, tag, color, texture, name, par
print("No .model for " + str(fileName))
self._mParams = defaultModelParameters
parameterCache[fileName] = self._mParams
self._pandaModel = loader.loadModel(self._mFile)
self._hasJoints = len(joints) != 0
self._joints = joints
self._jointNodes = {}

if animation != None:
self._pandaModel = Actor.Actor(fileName, animation)
if frame != None:
self._frame = frame
else: # Not animated
self._pandaModel = loader.loadModel(self._mFile)
if self._pandaModel == None:
print 'Model not found: ' + fileName
exit()
if self._hasJoints:
for j,pj in joints:
self._jointNodes[j] = self._pandaModel.controlJoint(None, "modelRoot", pj)
if self._jointNodes[j] == None:
print 'joint not found: ' + j
exit()
self._pandaModel.setTag('rpandaid', str(self._name))
self._onScreen = False
self._animPlaying = False
self._size=self._mParams['localSize']
self._hpr=self._mParams['localOrientation']
self._position=self._mParams['localPosition']
Expand Down Expand Up @@ -132,6 +151,13 @@ def _remove(self):
def _reparent(self, m):
# print "reparent " + repr(self) + " to " + repr(m)
self._pandaModel.reparentTo(m)
def play(self,anim):
if not self._animPlaying:
self._pandaModel.loop(anim)
self._animPlaying = True
def stop(self):
if self._animPlaying:
self._animPlaying = False
def _touches(self, handle, trace = False):
if trace:
print("Touch: " + repr(self) + " (" + self._cType + ") " + repr(handle) + " (" + handle._cType + ")")
Expand Down Expand Up @@ -187,6 +213,7 @@ def _touches(self, handle, trace = False):
#print ("*****"+repr(res))
return res


def modelUpdater(self):
#These parameters find the static offset which was created during initialization and the current position which is returned by the self._get() method
positionOffset = self._position
Expand Down Expand Up @@ -222,6 +249,19 @@ def modelUpdater(self):
color = self._get("color")
if color.a != 0:
self._pandaModel.setColor(color.toVBase4())

#animations
#if self._hasJoints:
# if self._animPlaying:
# for j,pj in self._joints:
# sig = self.j
# print sig
# hpr = sig.now()
# print hpr
# self._jointNodes[j].setH(degrees(hpr.h))
# self._jointNodes[j].setP(degrees(hpr.p))
# self._jointNodes[j].setR(degrees(hpr.r))
# self._pandaModel.loop('walk', fromFrame = self._frame, toFrame = self._frame)
# This is used to keep the model off the screen until the first update happens
if not self._onScreen:
self._reparent(self._parent)
Expand Down
34 changes: 17 additions & 17 deletions PandaModels.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from . PandaModel import *
import PandaGlobals as Globals

# Characters/Creatures

Expand Down Expand Up @@ -34,12 +34,12 @@ def penguin(**a):
return pandaModel("Penguin/Penguin.egg", name = "Penguin", **a)

def ralph(**a):
return pandaModel("Ralph/ralph.egg", name = "Ralph", **a)
return pandaModel(Globals.pandaPath + "/models/Ralph/ralph.egg", name = "Ralph",
# joints = [('neck', 'Neck'), ('leftWrist', 'LeftWrist'),
# ('rightWrist', 'RightWrist'),
# ('jaw', 'Jaw'), ('leftElbow', 'LeftElbow'),
# ('rightShoulder', 'RightShoulder'), ('leftShoulder', 'LeftShoulder'), ('leftKnee', 'LeftKnee'),
# ('rightKnee', 'RightKnee')], animations = {"walk" : g.pandaPath + "/models/Ralph/ralph-walk.egg"}, frame = 4, **a )
# ('rightShoulder', 'RightShoulder'), ('leftShoulder', 'LeftShoulder'), ('leftKnee', 'LeftKnee'),('rightKnee', 'RightKnee')],
animation = {"walk" : Globals.pandaPath + "/models/Ralph/ralph-walk.egg","run" : Globals.pandaPath + "/models/Ralph/ralph-run.egg"}, frame = 4, **a )

def bee (**a):
return pandaModel("Bee/Bee.egg", name = "Bee", **a)
Expand Down Expand Up @@ -82,19 +82,19 @@ def bowlingPins(**a):
return pandaModel ("bowlingpins/bowlingpins.egg", name = "BowlingPins", **a)

def sonic(**a):#Works as of 6-23-08 ~ Kendric
return pandaModel("sonic/sonic.egg", name = "Sonic", **a)
# joints = [('neck', 'Neck'), ('leftEyeBrow', 'LeftEyeBrow'), ('rightEyeBrow', 'RightEyeBrow'),
# ('leftLowerSpike', 'LeftLowerSpike'), ('lowerRightSpike', 'LowerRightSpike'),
# ('topSpike', 'TopSpike'), ('leftMiddleSpike', 'LeftMiddleSpike'),
# ('rightMiddleSpike', 'RightMiddleSpike'), ('lowerSpike', 'LowerSpike'),
# ('jaw', 'Jaw'),
# ('leftShoulder', 'LeftShoulder'), ('rightShoulder', 'LeftShoulder1'),
# ('leftElbow', 'LeftElbow'), ('rightElbow', 'LeftElbow1'),
# ('leftWrist', 'LeftWrist'), ('rightWrist', 'LeftWrist1'),
# ('leftHip', 'LeftHip'), ('rightHip', 'RightHip'),
# ('leftKnee', 'LeftKnee'), ('rightKnee', 'RightKnee'),
# ('leftAnkle', 'LeftAnkle'), ('rightAnkle', 'RightAnkle'), ], animations = {"walk" : g.pandaPath + "/models/sonic/sonic-run.egg"},
# defaultAnimation = "walk", frame = 11, **a)
return pandaModel("sonic/sonic.egg", name = "Sonic",
joints = [('neck', 'Neck'), ('leftEyeBrow', 'LeftEyeBrow'), ('rightEyeBrow', 'RightEyeBrow'),
('leftLowerSpike', 'LeftLowerSpike'), ('lowerRightSpike', 'LowerRightSpike'),
('topSpike', 'TopSpike'), ('leftMiddleSpike', 'LeftMiddleSpike'),
('rightMiddleSpike', 'RightMiddleSpike'), ('lowerSpike', 'LowerSpike'),
('jaw', 'Jaw'),
('leftShoulder', 'LeftShoulder'), ('rightShoulder', 'LeftShoulder1'),
('leftElbow', 'LeftElbow'), ('rightElbow', 'LeftElbow1'),
('leftWrist', 'LeftWrist'), ('rightWrist', 'LeftWrist1'),
('leftHip', 'LeftHip'), ('rightHip', 'RightHip'),
('leftKnee', 'LeftKnee'), ('rightKnee', 'RightKnee'),
('leftAnkle', 'LeftAnkle'), ('rightAnkle', 'RightAnkle'), ], animation = {"walk" : Globals.pandaPath + "/models/sonic/sonic-run.egg"},
frame = 11, **a)

# Jointed Models

Expand Down

0 comments on commit af4bf4d

Please sign in to comment.