Ejemplo n.º 1
0
 def refresh(self):
     res = []
     l1 = getCollection(self.m1).allModels()
     l2 = getCollection(self.m2).allModels()
     if self.trace:
             print repr(l1)
             print repr(l2)
     for m1 in l1:
         if m1.d.initialized:
             for m2 in l2:
                 if not (m1 is m2) and m2.d.initialized and not m1.d.zombie and not m2.d.zombie:
                     if m1.touches(m2, self.trace):
                         res = maybeAddModelToResult(res, m1, m2)
     if res == []:
         return None
     else:
         return res
Ejemplo n.º 2
0
    def __init__(self, fileName, name, size, hpr, position, color,
                 control, texture, duration, kind, joints,  animations, defaultAnimation, frame):
        if name is None:
            name = fileName  #  Should parse off the directories
        Handle.__init__(self, name = name, duration = duration)
        mFile = fileSearch(fileName, "models",["egg"])
        if mFile is None:
            print "Can't find model" + str(fileName)
            mFile = Filename("panda-model.egg.pz")
            mParams = pandaParameters
        elif fileName in parameterCache:
            mParams = parameterCache[fileName]
        else:
            mParamFile = Filename(mFile)
            mParamFile.setExtension("model")
            if mParamFile.exists():
                mParams = loadDict(mParamFile, modelParameters, defaultModelParameters)
            else:
                print "No .model for " + str(fileName)
                mParams = defaultModelParameters
            parameterCache[fileName] = mParams
        localPosition = mParams["localPosition"]
        localSize = mParams["localSize"]
        localOrientation = mParams["localOrientation"]
        cRadius = mParams["cRadius"]
        cTop = mParams["cTop"]
        cFloor = mParams["cFloor"]
        cType = mParams["cType"]

        self.d.fileName = mFile
        self.d.hasJoints = len(joints) != 0
        expandedJoints = []
        for x in joints:
            if isinstance(x, basestring):
                    j = x
                    pj = x
            else:
                    j, pj = x
            expandedJoints.add((j, pj))
        self.d.joints = expandedJoints
        self.d.jointNodes = {}
        self.cRadius = static(cRadius)
        self.cFloor = static(cFloor)
        self.cTop = static(cTop)
        self.cType = static(cType)
        self.d.noHPR = False
        self.d.defaultAnimation = defaultAnimation
        ctl = newSignalRefd(self, "control", controlType, scEmptyControl)
        self.__dict__["control"] = ctl
        for j,pj in joints:
            self.__dict__[j] = newSignalRefd(self, j, HPRType, HPR(0,0,0), ctl)

        if self.d.hasJoints:
            if animations != None:
                self.d.model = Actor.Actor(self.d.fileName, animations)
                #self.d.model.reparentTo(render)
                if frame != None:
                    self.d.frame = frame
                else:
                    undefinedSignal(self, 'frame') # ????  Bad error message ...
            else:
                self.d.model = Actor.Actor(self.d.fileName)
         
                print "joint "+str(j)+" "+ str(pj)
                self.d.jointNodes[j] = self.d.model.controlJoint(None, "modelRoot", pj)
                if self.d.jointNodes[j] == None:
                    print 'joint not found: ' + j
                    exit()
        else:   #  Not jointed
            self.d.model = loader.loadModel(self.d.fileName)
            if self.d.model == None:
                print 'Model not found: ' + fileName  # Shouldn't happen - file was found
                exit()
        g.nextModelId = g.nextModelId + 1
        self.d.model.setTag('rpandaid', str(g.nextModelId))
        self.d.localSize = localSize
        self.d.localPosition = localPosition
        self.d.localOrientation = localOrientation
        self.d.onScreen = False
        self.d.currentTexture = ""
        self.__dict__['position'] = newSignalRefd(self, 'position', P3Type, P3(0,0,0), ctl)
        self.__dict__['hpr']   = newSignalRefd(self, 'hpr', HPRType, HPR(0,0,0), ctl)
        self.__dict__['color'] = newSignalRefd(self, 'color', ColorType, noColor, ctl)
        self.__dict__['size'] = newSignalRefd(self, 'size', numType, 1, ctl)
        self.__dict__['texture'] = newSignalRefd(self, 'texture', stringType, "", ctl)
        if size is not None:
             self.size.setBehavior(size)
        if position is not None:
             self.position.setBehavior(position)
        if control is not None:
             # print "Setting control", control
             self.control.setBehavior(control)
#        print hpr
#        print self.hpr.signal
        if hpr is not None:
             self.hpr.setBehavior(hpr)
#        print "HPR: "
#        print self.hpr.signal
        if color is not None:
             self.color.setBehavior(color)
        self.d.animPlaying = False # This initializes it so there is no animation playing.
        if texture is not None:
            print "Texture for model " + name
            tex = findTexture(texture)
            self.d.currentTexture = texture
            self.d.model.setTexture(tex, 1)
        if kind is not None:
            getCollection(kind).add(self)