def getPhysBody(self):
        from panda3d.bullet import BulletRigidBodyNode, BulletBoxShape
        from panda3d.core import TransformState

        bnode = BulletRigidBodyNode('entity-phys')
        bnode.setMass(self.mass)

        bnode.setCcdMotionThreshold(1e-7)
        bnode.setCcdSweptSphereRadius(0.5)

        if self.solidType == self.SOLID_MESH:
            convexHull = PhysicsUtils.makeBulletConvexHullFromCollisionSolids(
                self.model.find("**/+CollisionNode").node())
            bnode.addShape(convexHull)
        elif self.solidType == self.SOLID_BBOX:
            mins = Point3()
            maxs = Point3()
            self.calcTightBounds(mins, maxs)
            extents = PhysicsUtils.extentsFromMinMax(mins, maxs)
            tsCenter = TransformState.makePos(
                PhysicsUtils.centerFromMinMax(mins, maxs))
            shape = BulletBoxShape(extents)
            bnode.addShape(shape, tsCenter)

        return bnode
Beispiel #2
0
 def load(self):
     Entity.load(self)
     loader = self.cEntity.getLoader()
     entnum = self.cEntity.getEntnum()
     rbnode = BulletRigidBodyNode('func_physics')
     mass = loader.getEntityValueFloat(entnum, "mass")
     rbnode.setMass(100)
     min = Point3(0)
     max = Point3(0)
     self.cEntity.getModelBounds(min, max)
     center = PhysicsUtils.centerFromMinMax(min, max)
     extents = PhysicsUtils.extentsFromMinMax(min, max)
     shape = BulletBoxShape(extents)
     rbnode.addShape(shape)
     self.assign(base.bspLoader.getResult().find(
         "**/brushroot").attachNewNode(rbnode))
     self.setPos(center)
     self.cEntity.getModelNp().wrtReparentTo(self)
     base.physicsWorld.attachRigidBody(rbnode)
Beispiel #3
0
    def load(self, physName='useableObject'):
        if self.autoPhysBox:
            min = Point3(0)
            max = Point3(0)
            self.getUseableBounds(min, max)

            min -= Point3(0.1, 0.1, 0.1)
            max += Point3(0.1, 0.1, 0.1)

            extents = PhysicsUtils.extentsFromMinMax(min, max)

            shape = BulletBoxShape(extents)
            # Use the box as a trigger and collision geometry.
            if self.hasPhysGeom:
                bodyNode = BulletGhostNode(physName)
            else:
                bodyNode = BulletRigidBodyNode(physName)
            bodyNode.setKinematic(True)

            if not self.underneathSelf:
                center = PhysicsUtils.centerFromMinMax(min, max)
                bodyNode.addShape(shape, TransformState.makePos(center))
            else:
                bodyNode.addShape(shape)

            self.setupPhysics(bodyNode)
        else:
            for np in self.findAllMatches("**/+BulletRigidBodyNode"):
                if (np.getCollideMask() & CIGlobals.WallGroup) != 0:
                    np.setCollideMask(np.getCollideMask()
                                      | CIGlobals.UseableGroup)
                    self.bodyNP = np
                    self.bodyNode = np.node()

        if self.bodyNP:
            self.bodyNP.setPythonTag('useableObject', self)
    def load(self):
        if self.autoPhysBox:
            min = Point3(0)
            max = Point3(0)
            self.getUseableBounds(min, max)

            min -= Point3(0.1, 0.1, 0.1)
            max += Point3(0.1, 0.1, 0.1)

            center = PhysicsUtils.centerFromMinMax(min, max)
            extents = PhysicsUtils.extentsFromMinMax(min, max)

            shape = BulletBoxShape(extents)
            # Use the box as a trigger and collision geometry.
            if self.hasPhysGeom:
                bodyNode = BulletGhostNode('useableObject')
            else:
                bodyNode = BulletRigidBodyNode('useableObject')
            bodyNode.setKinematic(True)
            bodyNode.addShape(shape, TransformState.makePos(center))

            self.setupPhysics(bodyNode)
        if self.bodyNP:
            self.bodyNP.setPythonTag('useableObject', self)