Ejemplo n.º 1
0
def geometryUpdater(self):
    #These parameters find the static offset which was created during initialization and the current position which is returned by the self._get() method
    positionNow = self._get("position")
    sizeNow = self._get("size")
    hprNow = self._get( "hpr")
    textureNow = self._get("texture")
    colorNow = self._get("color")

    #print("size signal: "+repr(sizeScalar)+"  offset size: "+repr(sizeOffset))
    self._pandaModel.setScale(sizeNow)
    self._pandaModel.setPos(positionNow.x, positionNow.y, positionNow.z)
    self._pandaModel.setHpr(degrees(hprNow.h),
                            degrees(hprNow.p),
                            degrees(hprNow.r))
    if textureNow != "" and textureNow != self._currentTexture:
        texf = FileSearch.findTexture(textureNow)
        self._currentTexture = textureNow
        #print("The texture is: "+repr(texf))
        self._pandaModel.setTexture(texf, 1)

    if colorNow.a != 0:
        self._pandaModel.setColor(colorNow.toVBase4())
    if self._twoSided:
        sideTwoNow = self._get("sideTwo")
        if sideTwoNow != "" and sideTwoNow != self._currentsideTwo:
            tex = FileSearch.findTexture(sideTwoNow)
            self._currentsideTwo = sideTwoNow
            #print("The texture is: "+repr(texf))
            self._sideTwo._pandaModel.setTexture(tex, 1)
    # This is used to keep the model off the screen until the first update happens
    if not self._onScreen:
           self._reparent(self._parent)
           self._onScreen = True
Ejemplo n.º 2
0
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
    positionNow = self._get("position")
    sizeScalar = self._get("size") + 0
    sizeOffset = self._size
    hprOffset = self._hpr

    hprNow = self._get("hpr")

    # print str(positionNow) + " " + str(positionOffset) + " " + str(hprNow)
    # This is the actual updates to position/size/hpr etc.
    # if PandaGlobals.eventSignals is not None:
    #        for signal in PandaGlobals.events:
    #            print repr(signal)

    # print "size signal: "+repr(sizeScalar)+"  offset size: "+repr(sizeOffset)
    self._pandaModel.setScale(sizeScalar * sizeOffset)
    self._pandaModel.setPos(
        positionNow.x + positionOffset.x * sizeScalar,
        positionNow.y + positionOffset.y * sizeScalar,
        positionNow.z + positionOffset.z * sizeScalar,
    )

    self._pandaModel.setHpr(
        degrees(hprNow.h + hprOffset.h), degrees(hprNow.p + hprOffset.p), degrees(hprNow.r + hprOffset.r)
    )
    texture = self._get("texture")
    if texture != "" and texture != self._currentTexture:
        texf = FileSearch.findTexture(texture)
        self._currentTexture = texture
        # print "The texture is: "+repr(texf)
        self._pandaModel.setTexture(texf, 1)
    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)
        self._onScreen = True
Ejemplo n.º 3
0
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
    positionNow = self._get("position")
    sizeScalar = self._get("size") + 0
    sizeOffset = self._size
    hprOffset = self._hpr

    hprNow = self._get("hpr")

    #print(str(positionNow) + " " + str(positionOffset) + " " + str(hprNow))
    #This is the actual updates to position/size/hpr etc.
    #if PandaGlobals.eventSignals is not None:
    #        for signal in PandaGlobals.events:
    #            print(repr(signal))

    #print("size signal: "+repr(sizeScalar)+"  offset size: "+repr(sizeOffset))
    self._pandaModel.setScale(sizeScalar * sizeOffset)
    self._pandaModel.setPos(positionNow.x + positionOffset.x * sizeScalar,
                            positionNow.y + positionOffset.y * sizeScalar,
                            positionNow.z + positionOffset.z * sizeScalar)

    self._pandaModel.setHpr(degrees(hprNow.h + hprOffset.h),
                            degrees(hprNow.p + hprOffset.p),
                            degrees(hprNow.r + hprOffset.r))
    texture = self._get("texture")
    if texture != "" and texture != self._currentTexture:
        texf = FileSearch.findTexture(texture)
        self._currentTexture = texture
        #print("The texture is: "+repr(texf))
        self._pandaModel.setTexture(texf, 1)
    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)
        self._onScreen = True
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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)