def initGear(self):
        if hasattr(self, 'in_initGear'):
            return
        self.in_initGear = True
        self.destroyGear()
        model = loader.loadModel(GearEntity.ModelPaths[self.modelType])
        self.gearParent = self.attachNewNode('gearParent-%s' % self.entId)
        if self.orientation == 'horizontal':
            vertNodes = model.findAllMatches('**/VerticalCollisions')
            for node in vertNodes:
                node.stash()

            mPlat = MovingPlatform.MovingPlatform()
            mPlat.setupCopyModel(self.getParentToken(), model, 'HorizontalFloor')
            model = mPlat
        else:
            horizNodes = model.findAllMatches('**/HorizontalCollisions')
            for node in horizNodes:
                node.stash()

            model.setZ(0.15)
            model.flattenLight()
        model.setScale(self.gearScale)
        model.flattenLight()
        model.setScale(self.getScale())
        self.setScale(1)
        model.flattenLight()
        if self.orientation == 'vertical':
            self.gearParent.setP(-90)
        self.model = model
        self.model.reparentTo(self.gearParent)
        self.startRotate()
        del self.in_initGear
 def loadModel(self):
     self.notify.debug('loadModel')
     model = loader.loadModel('phase_9/models/cogHQ/platform1')
     self.platform = MovingPlatform.MovingPlatform()
     self.platform.setupCopyModel(self.getParentToken(), model, 'platformcollision')
     self.platform.reparentTo(self)
     self.platform.setPos(0, 0, 0)
Beispiel #3
0
 def loadModel(self):
     crateModel = loader.loadModel(
         DistributedCrate.ModelPaths[self.modelType])
     self.crate = MovingPlatform.MovingPlatform()
     self.crate.setupCopyModel(self.getParentToken(), crateModel, 'floor')
     self.setScale(1.0)
     self.crate.setScale(self.scale)
     self.crate.reparentTo(self)
     self.crate.flattenLight()
Beispiel #4
0
    def initPlatform(self):
        model = loader.loadModel(self.modelPath)
        if model is None:
            return
        model.setScale(self.modelScale)
        if self.floorName is None:
            return
        self.platformModel = MovingPlatform.MovingPlatform()
        self.platformModel.setupCopyModel(self.getParentToken(), model,
                                          self.floorName)
        self.accept(self.platformModel.getEnterEvent(), self.localToonEntered)
        self.accept(self.platformModel.getExitEvent(), self.localToonLeft)
        self.startGuard = None
        self.endGuard = None
        zoneNp = self.getZoneNode()
        if len(self.startGuardName):
            self.startGuard = zoneNp.find('**/%s' % self.startGuardName)
        if len(self.endGuardName):
            self.endGuard = zoneNp.find('**/%s' % self.endGuardName)
        side2srch = {
            'front': '**/wall_front',
            'back': '**/wall_back',
            'left': '**/wall_left',
            'right': '**/wall_right'
        }
        for side in side2srch.values():
            np = self.platformModel.find(side)
            if not np.isEmpty():
                np.setScale(1.0, 1.0, 2.0)
                np.setZ(-10)
                np.flattenLight()

        self.startBoardColl = NodePathCollection()
        self.endBoardColl = NodePathCollection()
        for side in self.startBoardSides:
            np = self.platformModel.find(side2srch[side])
            if np.isEmpty():
                DistributedLift.warning("couldn't find %s board collision" %
                                        side)
            else:
                self.startBoardColl.addPath(np)

        for side in self.endBoardSides:
            np = self.platformModel.find(side2srch[side])
            if np.isEmpty():
                DistributedLift.warning("couldn't find %s board collision" %
                                        side)
            else:
                self.endBoardColl.addPath(np)

        self.platformModel.reparentTo(self.platform)
        return
Beispiel #5
0
    def createNewBlock(self, model, blockAttribs):
        (initX, initY, initZ, initH, initP, initR) = (0, 0, 0, 0, 0, 0)
        (finalX, finalY, finalZ, finalH, finalP, finalR) = (0, 0, 0, 0, 0, 0)
        blockType = blockAttribs[0]
        typeAttribs = ToonBlitzGlobals.BlockTypes[blockType]
        blockName = blockType + '-' + str(self.index)
        self.model = NodePath(blockName)
        (typeX, typeY, typeZ) = typeAttribs[1]
        (typeH, typeP, typeR) = typeAttribs[2]
        (scaleX, scaleY, scaleZ) = typeAttribs[3]
        model.setScale(scaleX, scaleY, scaleZ)
        blockPosAttribs = blockAttribs[1]
        (initX, initY, initZ) = blockPosAttribs[0]
        if len(blockPosAttribs) == 3:
            self.isMovingBlock = True
            (finalX, finalY, finalZ) = blockPosAttribs[1]
            posIvalDuration = blockPosAttribs[2]

        if len(blockAttribs) == 3:
            blockHprAttribs = blockAttribs[2]
            (initH, initP, initR) = blockHprAttribs[0]
            if len(blockHprAttribs) == 3:
                self.isMovingBlock = True
                (finalH, finalP, finalR) = blockHprAttribs[1]
                hprIvalDuration = blockHprAttribs[2]

        if self.isMovingBlock:
            self.platform = MovingPlatform.MovingPlatform()
            self.platform.setupCopyModel(blockName, model)
            self.platform.reparentTo(self.model)
            self.clearMoveIval()
            forwardIval = LerpPosInterval(self.model,
                                          posIvalDuration,
                                          pos=Point3(finalX, finalY, finalZ),
                                          startPos=Point3(initX, initY, initZ),
                                          name='%s-moveFront' %
                                          self.platform.name,
                                          fluid=1)
            backwardIval = LerpPosInterval(
                self.model,
                posIvalDuration,
                pos=Point3(initX, initY, initZ),
                startPos=Point3(finalX, finalY, finalZ),
                name='%s-moveBack' % self.platform.name,
                fluid=1)
            self.moveIval = Sequence(forwardIval, backwardIval)
        else:
            self.platform = model.copyTo(self.model)
        self.model.flattenLight()
        self.model.setPos(typeX + initX, typeY + initY, typeZ + initZ)
        self.model.setHpr(typeH + initH, typeP + initP, typeR + initR)
Beispiel #6
0
    def initBelt(self):
        treadModel = loader.loadModel(self.treadModelPath)
        treadModel.setSx(self.widthScale)
        treadModel.flattenLight()
        self.numTreads = int(self.length / self.treadLength) + 3
        self.beltNode = self.attachNewNode('belt')
        self.treads = []
        for i in xrange(self.numTreads):
            mp = MovingPlatform.MovingPlatform()
            mp.parentingNode = render.attachNewNode('parentTarget')
            mp.setupCopyModel('conv%s-%s' % (self.getParentToken(), i), treadModel, self.floorName, parentingNode=mp.parentingNode)
            mp.parentingNode.reparentTo(mp)
            mp.reparentTo(self.beltNode)
            self.treads.append(mp)

        self.start()
Beispiel #7
0
 def start(self):
     model = loader.loadModel(self.modelPath)
     if model is None:
         return
     if len(self.floorName) == 0:
         return
     model.setScale(self.modelScale)
     model.flattenMedium()
     self.platform = MovingPlatform.MovingPlatform()
     self.platform.setupCopyModel(self.getParentToken(), model,
                                  self.floorName)
     self.platform.reparentTo(self)
     startPos = Point3(0, 0, 0)
     endPos = self.offset
     distance = Vec3(self.offset).length()
     waitDur = self.period * self.waitPercent
     moveDur = self.period - waitDur
     self.moveIval = Sequence(
         WaitInterval(waitDur * 0.5),
         LerpPosInterval(self.platform,
                         moveDur * 0.5,
                         endPos,
                         startPos=startPos,
                         name='platformOut%s' % self.entId,
                         blendType=self.motion,
                         fluid=1),
         WaitInterval(waitDur * 0.5),
         LerpPosInterval(self.platform,
                         moveDur * 0.5,
                         startPos,
                         startPos=endPos,
                         name='platformBack%s' % self.entId,
                         blendType=self.motion,
                         fluid=1),
         name=self.getUniqueName('platformIval'))
     self.moveIval.loop()
     self.moveIval.setT(globalClock.getFrameTime() - self.level.startTime +
                        self.period * self.phaseShift)
Beispiel #8
0
    def createNewBlock(self, model, blockAttribs):
        # Do this when you have different block models in one maya file.
        initX, initY, initZ, initH, initP, initR = 0, 0, 0, 0, 0, 0
        finalX, finalY, finalZ, finalH, finalP, finalR = 0, 0, 0, 0, 0, 0

        blockType = blockAttribs[0]
        typeAttribs = ToonBlitzGlobals.BlockTypes[blockType]
        # Setting block name
        blockName = blockType + '-' + str(self.index)
        self.model = NodePath(blockName)

        # Setting type attributes
        # Note: Scale can only be a attribute of a block type.
        # Individual blocks cannot be scaled as when you like.
        typeX, typeY, typeZ = typeAttribs[1]
        typeH, typeP, typeR = typeAttribs[2]
        scaleX, scaleY, scaleZ = typeAttribs[3]
        model.setScale(scaleX, scaleY, scaleZ)

        # Setting block attributes
        blockPosAttribs = blockAttribs[1]
        initX, initY, initZ = blockPosAttribs[0]
        if (len(blockPosAttribs) == 3):
            self.isMovingBlock = True
            finalX, finalY, finalZ = blockPosAttribs[1]
            posIvalDuration = blockPosAttribs[2]

        if (len(blockAttribs) == 3):
            # Block has hpr mentioned in it
            blockHprAttribs = blockAttribs[2]
            initH, initP, initR = blockHprAttribs[0]
            if (len(blockHprAttribs) == 3):
                self.isMovingBlock = True
                finalH, finalP, finalR = blockHprAttribs[1]
                hprIvalDuration = blockHprAttribs[2]

        if self.isMovingBlock:
            # Create moving platform
            self.platform = MovingPlatform.MovingPlatform()
            self.platform.setupCopyModel(blockName, model)
            self.platform.reparentTo(self.model)

            # Setup the interval that makes the block move back and forth between initPos and finalPos
            self.clearMoveIval()
            forwardIval = LerpPosInterval(self.model,
                                          posIvalDuration,
                                          pos=Point3(finalX, finalY, finalZ),
                                          startPos=Point3(initX, initY, initZ),
                                          name='%s-moveFront' %
                                          self.platform.name,
                                          fluid=1)
            backwardIval = LerpPosInterval(
                self.model,
                posIvalDuration,
                pos=Point3(initX, initY, initZ),
                startPos=Point3(finalX, finalY, finalZ),
                name='%s-moveBack' % self.platform.name,
                fluid=1)
            self.moveIval = Sequence(forwardIval, backwardIval)

            # @TODO: Make a self.rotateIval with a LerpHprInterval using initH, initP, initR, finalH, finalP, finalR
            # So far we don't have any rotating blocks
        else:
            # Create stationary block
            self.platform = model.copyTo(self.model)

        self.model.flattenLight()
        self.model.setPos(typeX + initX, typeY + initY, typeZ + initZ)
        self.model.setHpr(typeH + initH, typeP + initP, typeR + initR)
    def loadModel(self):
        self.loaded = 1
        self.stomperModels = ['phase_9/models/cogHQ/square_stomper']
        if self.cogStyle == 1:
            self.stomperModels = ['phase_11/models/lawbotHQ/LB_square_stomper']
        self.notify.debug('loadModel')
        shadow = None
        self.sound = self.sounds[self.soundPath]
        self.rotateNode = self.attachNewNode('rotate')
        stomperModel = loader.loadModel(self.stomperModels[self.modelPath])
        if self.style == 'vertical':
            model = stomperModel
            self.rotateNode.setP(-90)
            sideList = model.findAllMatches('**/collSide')
            for side in sideList:
                side.stash()

            upList = model.findAllMatches('**/collUp')
            for up in upList:
                up.stash()

            head = model.find('**/head')
            shaft = model.find('**/shaft')
            self.crushSurface = head.find('**/collDownWalls')
            self.shadow = None
            if self.wantShadow:
                shadow = loader.loadModel(
                    'phase_3/models/props/square_drop_shadow').getChild(0)
                shadow.setScale(0.3 * self.headScale[0],
                                0.3 * self.headScale[2], 1)
                shadow.setAlphaScale(0.8)
                shadow.flattenMedium()
                shadow.reparentTo(self)
                shadow.setPos(0, 0, 0.025)
                shadow.setTransparency(1)
                self.shadow = shadow
            floorHeadNp = model.find('**/head_collisions/**/collDownFloor')
            floorHead = floorHeadNp.node()
            if self.removeHeadFloor:
                floorHeadNp.stash()
            else:
                for i in xrange(floorHead.getNumSolids()):
                    floorHead.modifySolid(i).setEffectiveNormal(
                        Vec3(0.0, -1.0, 0.0))

            floorShaft = model.find(
                '**/shaft_collisions/**/collDownFloor').node()
            for i in xrange(floorShaft.getNumSolids()):
                floorShaft.modifySolid(i).setEffectiveNormal(
                    Vec3(0.0, -1.0, 0.0))

            self.accept(self.crushMsg, self.checkSquashedToon)
        elif self.style == 'horizontal':
            model = MovingPlatform.MovingPlatform()
            model.setupCopyModel(self.getParentToken(), stomperModel,
                                 'collSideFloor')
            head = model.find('**/head')
            head.node().setPreserveTransform(0)
            head.setZ(1.0)
            for child in head.findAllMatches('+ModelNode'):
                child.node().setPreserveTransform(ModelNode.PTNet)

            model.flattenLight()
            upList = model.findAllMatches('**/collUp')
            for up in upList:
                up.stash()

            downList = model.findAllMatches('**/collDown')
            for down in downList:
                down.stash()

            self.crushSurface = model.find(
                '**/head_collisions/**/collSideWalls')
        if self.removeCamBarrierCollisions:
            walls = model.findAllMatches('**/collDownWalls')
            for wall in walls:
                node = wall.node()
                bitmask = node.getIntoCollideMask()
                invBitmask = BitMask32(ToontownGlobals.CameraBitmask)
                invBitmask.invertInPlace()
                bitmask &= invBitmask
                node.setIntoCollideMask(bitmask)

        shaft = model.find('**/shaft')
        shaft.setScale(self.shaftScale)
        head.setScale(self.headScale)
        model.find('**/shaft').node().setPreserveTransform(0)
        model.flattenLight()
        self.model = model
        if self.motion == MotionSwitched:
            self.model.setPos(0, -self.range, 0)
        self.model.reparentTo(self.rotateNode)
        if self.wantSmoke:
            self.smoke = loader.loadModel('phase_4/models/props/test_clouds')
            self.smoke.setColor(0.8, 0.7, 0.5, 1)
            self.smoke.setBillboardPointEye()