本文整理汇总了Python中panda3d.bullet.BulletWorld.setGroupCollisionFlag方法的典型用法代码示例。如果您正苦于以下问题:Python BulletWorld.setGroupCollisionFlag方法的具体用法?Python BulletWorld.setGroupCollisionFlag怎么用?Python BulletWorld.setGroupCollisionFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.bullet.BulletWorld
的用法示例。
在下文中一共展示了BulletWorld.setGroupCollisionFlag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: App
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setGroupCollisionFlag [as 别名]
class App(ShowBase):
def __init__(self, args):
ShowBase.__init__(self)
headless = args["--headless"]
width = args["--width"]
height = args["--height"]
globalClock.setMode(ClockObject.MNonRealTime)
globalClock.setDt(0.02) # 20ms per frame
self.setBackgroundColor(0.9, 0.9, 0.9)
self.createLighting()
if not headless:
self.setupCamera(width, height, Vec3(200, -200, 0), Vec3(0, 0, 0))
# self.render.setAntialias(AntialiasAttrib.MAuto)
# filters = CommonFilters(self.win, self.cam)
# filters.setAmbientOcclusion(numsamples=16, radius=0.01, amount=1.0, strength=2.0, falloff=0.002)
# filters.setAmbientOcclusion(radius=0.01, amount=0.5, strength=0.5)
self.render.setShaderAuto()
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81 * 100.0))
# self.world.setGravity(Vec3(0, 0, 0))
# self.setupDebug()
self.createPlane(Vec3(0, 0, -100))
self.animated_rig = ExposedJointRig("walking", {"walk": "walking-animation.egg"})
self.animated_rig.reparentTo(self.render)
self.animated_rig.setPos(0, 0, 0)
# self.animated_rig.createLines(VBase4(0.5, 0.75, 1.0, 1.0))
self.physical_rig = RigidBodyRig()
self.physical_rig.reparentTo(self.render)
self.physical_rig.setPos(0, 0, 0)
self.physical_rig.createColliders(self.animated_rig)
self.physical_rig.createConstraints()
self.physical_rig.setCollideMask(BitMask32.bit(1))
self.physical_rig.attachRigidBodies(self.world)
self.physical_rig.attachConstraints(self.world)
self.physical_rig.attachCubes(self.loader)
self.target_physical_rig = RigidBodyRig()
self.target_physical_rig.reparentTo(self.render)
self.target_physical_rig.setPos(0, 0, 0)
self.target_physical_rig.createColliders(self.animated_rig)
self.target_physical_rig.createConstraints()
self.target_physical_rig.setCollideMask(BitMask32.bit(2))
self.target_physical_rig.attachRigidBodies(self.world)
self.target_physical_rig.attachConstraints(self.world)
self.target_physical_rig.clearMasses()
self.disableCollisions()
# self.animated_rig.pose('walk', 0)
self.physical_rig.matchPose(self.animated_rig)
self.target_physical_rig.matchPose(self.animated_rig)
self.world.doPhysics(globalClock.getDt(), 10, 1.0 / 180.0)
self.physical_rig.clearForces()
self.target_physical_rig.clearForces()
self.num_frames = self.animated_rig.getNumFrames("walk")
self.model = load_model("model.json", "weights.hdf5")
self.err_sum = 0.0
self.accept("escape", sys.exit)
self.taskMgr.add(self.update, "update")
def disableCollisions(self):
for i in range(32):
self.world.setGroupCollisionFlag(i, i, False)
self.world.setGroupCollisionFlag(0, 1, True)
self.world.setGroupCollisionFlag(0, 2, True)
def setupDebug(self):
node = BulletDebugNode("Debug")
node.showWireframe(True)
self.world.setDebugNode(node)
np = self.render.attachNewNode(node)
np.show()
def createLens(self, aspect_ratio, fov=60.0, near=1.0, far=1000.0):
lens = PerspectiveLens()
lens.setFov(fov)
lens.setAspectRatio(aspect_ratio)
lens.setNearFar(near, far)
return lens
def setupCamera(self, width, height, pos, look):
self.cam.setPos(pos)
self.cam.lookAt(look)
#.........这里部分代码省略.........
示例2: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setGroupCollisionFlag [as 别名]
#.........这里部分代码省略.........
self.debugNP.hide()
def doScreenshot(self):
base.screenshot('Bullet')
def doSelect(self, i):
self.boxNP = self.boxes[i]
# ____TASK___
def processInput(self, dt):
force = Vec3(0, 0, 0)
torque = Vec3(0, 0, 0)
if inputState.isSet('forward'): force.setY( 1.0)
if inputState.isSet('reverse'): force.setY(-1.0)
if inputState.isSet('left'): force.setX(-1.0)
if inputState.isSet('right'): force.setX( 1.0)
if inputState.isSet('turnLeft'): torque.setZ( 1.0)
if inputState.isSet('turnRight'): torque.setZ(-1.0)
force *= 30.0
torque *= 10.0
self.boxNP.node().setActive(True)
self.boxNP.node().applyCentralForce(force)
self.boxNP.node().applyTorque(torque)
def update(self, task):
dt = globalClock.getDt()
self.processInput(dt)
self.world.doPhysics(dt)
return task.cont
def cleanup(self):
self.world = None
self.worldNP.removeNode()
def setup(self):
self.worldNP = render.attachNewNode('World')
# World
self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
self.debugNP.show()
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNP.node())
# Ground
shape = BulletPlaneShape(Vec3(0, 0, 1), -1)
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
np.node().addShape(shape)
np.setPos(0, 0, -1)
np.setCollideMask(BitMask32.bit(0))
self.world.attachRigidBody(np.node())
# Boxes
self.boxes = [None,]*6
for i in range(6):
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box-1'))
np.node().setMass(1.0)
np.node().addShape(shape)
self.world.attachRigidBody(np.node())
self.boxes[i] = np
visualNP = loader.loadModel('models/box.egg')
visualNP.reparentTo(np)
self.boxes[0].setPos(-3, -3, 0)
self.boxes[1].setPos( 0, -3, 0)
self.boxes[2].setPos( 3, -3, 0)
self.boxes[3].setPos(-3, 3, 0)
self.boxes[4].setPos( 0, 3, 0)
self.boxes[5].setPos( 3, 3, 0)
self.boxes[0].setCollideMask(BitMask32.bit(1))
self.boxes[1].setCollideMask(BitMask32.bit(2))
self.boxes[2].setCollideMask(BitMask32.bit(3))
self.boxes[3].setCollideMask(BitMask32.bit(1))
self.boxes[4].setCollideMask(BitMask32.bit(2))
self.boxes[5].setCollideMask(BitMask32.bit(3))
self.boxNP = self.boxes[0]
self.world.setGroupCollisionFlag(0, 1, True)
self.world.setGroupCollisionFlag(0, 2, True)
self.world.setGroupCollisionFlag(0, 3, True)
self.world.setGroupCollisionFlag(1, 1, False)
self.world.setGroupCollisionFlag(1, 2, True)
示例3: TestApplication
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setGroupCollisionFlag [as 别名]
#.........这里部分代码省略.........
character_obj = self.controlled_objects_[obj_index]
if self.active_sector_ is not None:
self.active_sector_.releaseCharacter()
character_obj.setY(sector,0)
character_obj.setH(sector,0)
self.active_sector_ = sector
self.active_sector_.constrainCharacter(character_obj)
self.active_sector_.enableDetection(False)
sectors = [s for s in self.level_sectors_ if s != self.active_sector_]
for s in sectors:
s.enableDetection(True)
def setupPhysics(self):
# setting up physics world and parent node path
self.physics_world_ = BulletWorld()
self.world_node_ = self.render.attachNewNode('world')
self.cam.reparentTo(self.world_node_)
self.physics_world_.setGravity(Vec3(0, 0, -9.81))
self.debug_node_ = self.world_node_.attachNewNode(BulletDebugNode('Debug'))
self.debug_node_.node().showWireframe(True)
self.debug_node_.node().showConstraints(True)
self.debug_node_.node().showBoundingBoxes(True)
self.debug_node_.node().showNormals(True)
self.physics_world_.setDebugNode(self.debug_node_.node())
self.debug_node_.hide()
# setting up collision groups
self.physics_world_.setGroupCollisionFlag(GAME_OBJECT_BITMASK.getLowestOnBit(),GAME_OBJECT_BITMASK.getLowestOnBit(),True)
self.physics_world_.setGroupCollisionFlag(SECTOR_ENTERED_BITMASK.getLowestOnBit(),SECTOR_ENTERED_BITMASK.getLowestOnBit(),True)
self.physics_world_.setGroupCollisionFlag(GAME_OBJECT_BITMASK.getLowestOnBit(),SECTOR_ENTERED_BITMASK.getLowestOnBit(),False)
# setting up ground
self.ground_ = self.world_node_.attachNewNode(BulletRigidBodyNode('Ground'))
self.ground_.node().addShape(BulletPlaneShape(Vec3(0, 0, 1), 0))
self.ground_.setPos(0,0,0)
self.ground_.setCollideMask(GAME_OBJECT_BITMASK)
self.physics_world_.attachRigidBody(self.ground_.node())
# creating level objects
self.setupLevelSectors()
# creating controlled objects
diameter = 0.4
sphere_visual = loader.loadModel('models/ball.egg')
bounds = sphere_visual.getTightBounds() # start of model scaling
extents = Vec3(bounds[1] - bounds[0])
scale_factor = diameter/max([extents.getX(),extents.getY(),extents.getZ()])
sphere_visual.clearModelNodes()
sphere_visual.setScale(scale_factor,scale_factor,scale_factor) # end of model scaling
sphere_visual.setTexture(loader.loadTexture('models/bowl.jpg'),1)
sphere = NodePath(BulletRigidBodyNode('Sphere'))
sphere.node().addShape(BulletSphereShape(0.5*diameter))
sphere.node().setMass(1.0)
#sphere.node().setLinearFactor((1,0,1))
#sphere.node().setAngularFactor((0,1,0))
sphere.setCollideMask(GAME_OBJECT_BITMASK)
sphere_visual.instanceTo(sphere)