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}) modelTypes = {"localOrientation": hprType, "localSize": numType, "localPosition": p3Type, "cRadius": numType, "cType": stringType, "cFloor": numType, "cTop": numType} #(p3Type, SP3(0,0,0)), "hpr": (hprType, SHPR(0,0,0)), "size": (numType, 1)}) PandaGlobals.nextModelId = PandaGlobals.nextModelId + 1 self._parent = getModel(parent) self._mFile = FileSearch.fileSearch(fileName, "models", ["egg"]) #print("Object Name: "+ str(fileName)+"-gID: "+str(PandaGlobals.nextModelId)) if type(tag) == type("s"): collections = [tag] else: collections = tag self._collections = collections if fileName in parameterCache: self._mParams = parameterCache[fileName] elif self._mFile is None: print("Can't find model " + repr(fileName)) #should substitute pandafor unknown models #self._mFile = Filename("/c/Panda3D-1.8.1/models/"+fileName) #print("File Path: " + repr(mFile)) else: mParamFile = Filename(self._mFile) #print(repr(mParamFile)) mParamFile.setExtension("model") if mParamFile.exists(): self._mParams = FileIO.loadDict(mParamFile, types = modelTypes, defaults = defaultModelParameters) else: print("No .model for " + str(fileName)) self._mParams = defaultModelParameters parameterCache[fileName] = self._mParams self._hasJoints = len(joints) != 0 self._joints = joints self._jointNodes = {} self._animation = animation 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._fileName = fileName self._onScreen = False self._animPlaying = False self._size=self._mParams['localSize'] self._hpr=self._mParams['localOrientation'] self._position=self._mParams['localPosition'] self._cRadius = float(self._mParams['cRadius']) self._cType = self._mParams['cType'] self._cFloor = float(self._mParams['cFloor']) self._cTop = float(self._mParams['cTop']) self._currentTexture = "" self._onscreen = False # This defers the reparenting until the model has been updated the first time self._parent = getModel(parent) if position is not None: self.position = position else: self.position = P3(0,0,0) if hpr is not None: self.hpr = hpr else: self.hpr = SHPR(0,0,0) if size is not None: self.size = size else: self.size = 1 if texture is not None: self.texture = texture else: self.texture = "" if color is not None: self.color = color else: self.color = noColor for tag in collections: if tag not in frpGlobals.collections: frpGlobals.collections[tag] = [self] frpGlobals.collections[tag].append(self) #Get saved reaction functions for this collection for t, v in frpGlobals.collectionReactions.items(): for tag in collections: if tag in v: for args in v[tag]: getattr(Functions, t)(self, args[0], what = args[1]) if duration > 0: react(self, delay(duration), exitScene)
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 }) modelTypes = { "localOrientation": hprType, "localSize": numType, "localPosition": p3Type, "cRadius": numType, "cType": stringType, "cFloor": numType, "cTop": numType } #(p3Type, SP3(0,0,0)), "hpr": (hprType, SHPR(0,0,0)), "size": (numType, 1)}) PandaGlobals.nextModelId = PandaGlobals.nextModelId + 1 self._parent = getModel(parent) self._mFile = FileSearch.fileSearch(fileName, "models", ["egg"]) #print("Object Name: "+ str(fileName)+"-gID: "+str(PandaGlobals.nextModelId)) if type(tag) == type("s"): collections = [tag] else: collections = tag self._collections = collections if fileName in parameterCache: self._mParams = parameterCache[fileName] elif self._mFile is None: print("Can't find model " + repr(fileName)) #should substitute pandafor unknown models #self._mFile = Filename("/c/Panda3D-1.8.1/models/"+fileName) #print("File Path: " + repr(mFile)) else: mParamFile = Filename(self._mFile) #print(repr(mParamFile)) mParamFile.setExtension("model") if mParamFile.exists(): self._mParams = FileIO.loadDict( mParamFile, types=modelTypes, defaults=defaultModelParameters) else: print("No .model for " + str(fileName)) self._mParams = defaultModelParameters parameterCache[fileName] = self._mParams self._hasJoints = len(joints) != 0 self._joints = joints self._jointNodes = {} self._animation = animation 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._fileName = fileName self._onScreen = False self._animPlaying = False self._size = self._mParams['localSize'] self._hpr = self._mParams['localOrientation'] self._position = self._mParams['localPosition'] self._cRadius = float(self._mParams['cRadius']) self._cType = self._mParams['cType'] self._cFloor = float(self._mParams['cFloor']) self._cTop = float(self._mParams['cTop']) self._currentTexture = "" self._onscreen = False # This defers the reparenting until the model has been updated the first time self._parent = getModel(parent) if position is not None: self.position = position else: self.position = P3(0, 0, 0) if hpr is not None: self.hpr = hpr else: self.hpr = SHPR(0, 0, 0) if size is not None: self.size = size else: self.size = 1 if texture is not None: self.texture = texture else: self.texture = "" if color is not None: self.color = color else: self.color = noColor for tag in collections: if tag not in frpGlobals.collections: frpGlobals.collections[tag] = [self] frpGlobals.collections[tag].append(self) #Get saved reaction functions for this collection for t, v in frpGlobals.collectionReactions.items(): for tag in collections: if tag in v: for args in v[tag]: getattr(Functions, t)(self, args[0], what=args[1]) if duration > 0: react(self, delay(duration), exitScene)