本文整理汇总了Python中panda3d.bullet.BulletWorld.setDebugNode方法的典型用法代码示例。如果您正苦于以下问题:Python BulletWorld.setDebugNode方法的具体用法?Python BulletWorld.setDebugNode怎么用?Python BulletWorld.setDebugNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.bullet.BulletWorld
的用法示例。
在下文中一共展示了BulletWorld.setDebugNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PhysicsMgr
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
class PhysicsMgr():
def __init__(self, _game, _gravity=(0, 0, -9)):
self.game = _game
self.physicsWorld = BulletWorld()
self.physicsWorld.setGravity(Vec3(_gravity))
def startPhysics(self):
taskMgr.add(self.updatePhysics, "update-physics")
def stopPhysics(self):
taskMgr.remove("update-physics")
def setPhysicsDebug(self, _bool=False):
debugNode = BulletDebugNode('Debug')
self.debugNP = render.attachNewNode(debugNode)
if _bool:
debugNode = BulletDebugNode('Debug')
debugNode.showWireframe(True)
debugNode.showConstraints(True)
debugNode.showBoundingBoxes(False)
debugNode.showNormals(False)
self.debugNP = render.attachNewNode(debugNode)
self.physicsWorld.setDebugNode(self.debugNP.node())
self.debugNP.show()
else:
self.debugNP.hide()
#debugNode = None
def updatePhysics(self, task):
dt = globalClock.getDt()
self.physicsWorld.doPhysics(dt, 5, 1.0/240.0)
return task.cont
示例2: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
#.........这里部分代码省略.........
self.processInput(dt)
self.world.doPhysics(dt)
#pairs = [(mf.getNode0().getName(),
# mf.getNode1().getName())
# for mf in self.world.getManifolds() if mf.getNumManifoldPoints() > 0]
#print pairs
return task.cont
def cleanup(self):
self.world = None
self.worldNP.removeNode()
#def doAdded(self, node1, node2):
# print 'added:', node1.getName(), node2.getName()
#def doDestroyed(self, node1, node2):
# print 'destroyed:', node1.getName(), node2.getName()
def setup(self):
self.worldNP = render.attachNewNode('World')
# World
self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
self.debugNP.show()
self.debugNP.node().showWireframe(True)
self.debugNP.node().showConstraints(True)
self.debugNP.node().showBoundingBoxes(False)
self.debugNP.node().showNormals(True)
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNP.node())
# Plane (static)
shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
np.node().addShape(shape)
np.setPos(0, 0, -1)
np.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(np.node())
# Box (dynamic)
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
np.node().setMass(1.0)
np.node().addShape(shape)
np.setPos(0, 0, 4)
np.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(np.node())
self.boxNP = np # For applying force & torque
#np.node().notifyCollisions(True)
#self.accept('bullet-contact-added', self.doAdded)
#self.accept('bullet-contact-destroyed', self.doRemoved)
# Sphere (dynamic)
shape = BulletSphereShape(0.6)
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Sphere'))
示例3: App
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [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)
#.........这里部分代码省略.........
示例4: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
#.........这里部分代码省略.........
force = self.hLeg.getTotalForce()
t = self.hLeg.getTotalTorque()
self.hLegText.setText("High Leg:\nForce: %0.2f,%0.2f,%0.2f\nTorque: %0.2f,%0.2f,%0.2f" % (force.x, force.y, force.z, t.x,t.y,t.z))
force = self.lLeg.getTotalForce()
t = self.lLeg.getTotalTorque()
self.lLegText.setText("Low Leg:\nForce: %0.2f,%0.2f,%0.2f\nTorque: %0.2f,%0.2f,%0.2f" % (force.x, force.y, force.z, t.x,t.y,t.z))
f = self.foot.getTotalForce()
t = self.foot.getTotalTorque()
self.footText.setText("Foot:\nForce: %0.2f,%0.2f,%0.2f\nTorque: %0.2f,%0.2f,%0.2f" % (f.x,f.y,f.z, t.x,t.y,t.z))
dt = globalClock.getDt()
self.world.doPhysics(dt, 20, 1.0/180.0)
return task.cont
def cleanup(self):
self.worldNP.removeNode()
self.worldNP = None
self.world = None
def setup(self):
self.worldNP = render.attachNewNode('World')
# World
self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
self.debugNP.show()
self.debugNP.node().showWireframe(True)
self.debugNP.node().showConstraints(True)
self.debugNP.node().showBoundingBoxes(False)
self.debugNP.node().showNormals(True)
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNP.node())
# Box 0
shape = BulletBoxShape(Vec3(1, 1, 1))
body0 = BulletRigidBodyNode('Box 0')
bodyNP = self.worldNP.attachNewNode(body0)
bodyNP.node().addShape(shape)
bodyNP.setCollideMask(BitMask32.allOn())
bodyNP.setPos(0, 0, 12.2)
visNP = loader.loadModel('models/box.egg')
visNP.clearModelNodes()
visNP.reparentTo(bodyNP)
self.world.attachRigidBody(body0)
# Box A
shape = BulletBoxShape(Vec3(0.1, 0.1, 5))
self.hLeg = BulletRigidBodyNode('Box A')
bodyNP = self.worldNP.attachNewNode(self.hLeg)
bodyNP.node().addShape(shape)
bodyNP.node().setMass(1.0)
bodyNP.node().setDeactivationEnabled(False)
bodyNP.setCollideMask(BitMask32.allOn())
bodyNP.setPos(0, 0, 5.1)
visNP = loader.loadModel('models/box.egg')
visNP.clearModelNodes()
visNP.setScale(Vec3(0.2, 0.2, 10))
visNP.reparentTo(bodyNP)
self.world.attachRigidBody(self.hLeg)
示例5: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
class Game(DirectObject):
def __init__(self):
base.setBackgroundColor(0.1, 0.1, 0.8, 1)
base.setFrameRateMeter(True)
base.cam.setPos(0, -60, 20)
base.cam.lookAt(0, 0, 0)
# Light
alight = AmbientLight('ambientLight')
alight.setColor(Vec4(0.5, 0.5, 0.5, 1))
alightNP = render.attachNewNode(alight)
dlight = DirectionalLight('directionalLight')
dlight.setDirection(Vec3(1, 1, -1))
dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
dlightNP = render.attachNewNode(dlight)
render.clearLight()
render.setLight(alightNP)
render.setLight(dlightNP)
# Input
self.accept('escape', self.doExit)
self.accept('r', self.doReset)
self.accept('f1', self.toggleWireframe)
self.accept('f2', self.toggleTexture)
self.accept('f3', self.toggleDebug)
self.accept('f5', self.doScreenshot)
# Task
taskMgr.add(self.update, 'updateWorld')
# Physics
self.setup()
# _____HANDLER_____
def doExit(self):
self.cleanup()
sys.exit(1)
def doReset(self):
self.cleanup()
self.setup()
def toggleWireframe(self):
base.toggleWireframe()
def toggleTexture(self):
base.toggleTexture()
def toggleDebug(self):
if self.debugNP.isHidden():
self.debugNP.show()
else:
self.debugNP.hide()
def doScreenshot(self):
base.screenshot('Bullet')
# ____TASK___
def update(self, task):
dt = globalClock.getDt()
self.world.doPhysics(dt, 10, 0.008)
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.debugNP.showTightBounds()
#self.debugNP.showBounds()
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNP.node())
# Ground
p0 = Point3(-20, -20, 0)
p1 = Point3(-20, 20, 0)
p2 = Point3(20, -20, 0)
p3 = Point3(20, 20, 0)
mesh = BulletTriangleMesh()
mesh.addTriangle(p0, p1, p2)
mesh.addTriangle(p1, p2, p3)
shape = BulletTriangleMeshShape(mesh, dynamic=False)
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Mesh'))
#.........这里部分代码省略.........
示例6: TestApplication
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
#.........这里部分代码省略.........
def switchToSector(self,sector):
obj_index = self.controlled_obj_index_
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)
示例7: level_1
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
#.........这里部分代码省略.........
def update(self, task):
dt = globalClock.getDt()
self.player.processInput(dt)
self.world.doPhysics(dt, 4, 1./240.)
# Call camera function in player class
self.player.cameraFollow(self.floater)
# Identifying player collecting items
self.collectLetters()
# Start from beginning position if player falls off track
if self.player.characterNP.getZ() < -10.0:
if self.onLevelTwo:
self.player.startPosLevel2()
else:
self.player.startPosLevel1()
# If player gets too close to enemy, enemy attacks
self.enemyAttackDecision()
return task.cont
def setup(self):
# Debug (useful to turn on for physics)
self.debugNP = self.render.attachNewNode(BulletDebugNode('Debug'))
self.debugNP.hide()
# Physics World
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNP.node())
# Main Character
self.player = Player()
self.player.createPlayer(render, self.world)
# Enemies
self.createEnemies()
# Music
self.backgroundMusic = loader.loadSfx('../sounds/elfman-piano-solo.ogg')
self.backgroundMusic.setLoop(True)
self.backgroundMusic.stop()
self.backgroundMusic.setVolume(0.9) # lower this when I add sound effects
# Sound Effects
self.collect = base.loader.loadSfx("../sounds/collect-sound.wav")
self.collect.setVolume(1)
self.damage = base.loader.loadSfx("../sounds/damage.wav")
self.damage.setVolume(0.5)
self.winner = base.loader.loadSfx("../sounds/win-yay.wav")
self.winner.setVolume(1)
self.dead = base.loader.loadSfx("../sounds/severe-damage.wav")
self.dead.setVolume(1)
# Level 1 Skybox
self.skybox = loader.loadModel('../models/skybox_galaxy.egg')
self.skybox.setScale(1000) # make big enough to cover whole terrain
self.skybox.setBin('background', 1)
self.skybox.setDepthWrite(0)
self.skybox.setLightOff()
self.skybox.reparentTo(render)
示例8: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
#.........这里部分代码省略.........
self.box.applyTorque(torque)
def processContacts(self):
if not self.box or not self.sphere:
return
result = self.world.contactTestPair(self.box, self.sphere)
#result = self.world.contactTest(self.box)
#print '-->', result.getNumContacts()
for contact in result.getContacts():
cp = contact.getManifoldPoint()
node0 = contact.getNode0()
node1 = contact.getNode1()
print node0.getName(), node1.getName(), cp.getLocalPointA()
#print contact.getNode0(), cp.getPositionWorldOnA()
#print contact.getIdx0(), contact.getIdx1(), \
# contact.getPartId0(), contact.getPartId1()
self.removeNode(node1)
def removeNode(self, node):
self.world.removeRigidBody(node)
if node == self.sphere: self.sphere = None
if node == self.box: self.box = None
np = NodePath(node)
np.removeNode()
def update(self, task):
dt = globalClock.getDt()
self.processInput(dt)
self.world.doPhysics(dt, 10, 0.008)
self.processContacts()
return task.cont
def cleanup(self):
self.world = None
self.worldNP.removeNode()
#def onContactAdded(self, node1, node2):
# print 'contact added:', node1, node2
#def onContactDestroyed(self, node1, node2):
# print 'contact destroyed:', node1, node2
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())
# Plane
shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
np.node().addShape(shape)
np.setPos(0, 0, -1)
np.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(np.node())
# Box
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
np.node().setMass(1.0)
np.node().addShape(shape)
np.node().addShape(shape, TransformState.makePos(Point3(0, 1, 0)))
np.node().setDeactivationEnabled(False)
np.setPos(2, 0, 4)
np.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(np.node())
visualNP = loader.loadModel('models/box.egg')
visualNP.reparentTo(np)
self.box = np.node()
# Sphere
shape = BulletSphereShape(0.6)
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Sphere'))
np.node().setMass(1.0)
np.node().addShape(shape)
np.node().addShape(shape, TransformState.makePos(Point3(0, 1, 0)))
np.setPos(-2, 0, 4)
np.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(np.node())
self.sphere = np.node()
示例9: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
class Game(DirectObject):
def __init__(self):
base.setBackgroundColor(0.1, 0.1, 0.8, 1)
base.setFrameRateMeter(True)
base.cam.setPos(0, -80, 40)
base.cam.lookAt(0, 0, 10)
# Light
alight = AmbientLight('ambientLight')
alight.setColor(Vec4(0.5, 0.5, 0.5, 1))
alightNP = render.attachNewNode(alight)
dlight = DirectionalLight('directionalLight')
dlight.setDirection(Vec3(0, 0, -1))
dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
dlightNP = render.attachNewNode(dlight)
render.clearLight()
render.setLight(alightNP)
render.setLight(dlightNP)
# Input
self.accept('escape', self.doExit)
self.accept('r', self.doReset)
self.accept('f1', self.toggleWireframe)
self.accept('f2', self.toggleTexture)
self.accept('f3', self.toggleDebug)
self.accept('f5', self.doScreenshot)
# Task
taskMgr.add(self.update, 'updateWorld')
# Physics
self.setup()
# _____HANDLER_____
def doExit(self):
self.cleanup()
sys.exit(1)
def doReset(self):
self.cleanup()
self.setup()
def toggleWireframe(self):
base.toggleWireframe()
def toggleTexture(self):
base.toggleTexture()
def toggleDebug(self):
if self.debugNP.isHidden():
self.debugNP.show()
else:
self.debugNP.hide()
def doScreenshot(self):
base.screenshot('Bullet')
# ____TASK___
def update(self, task):
dt = globalClock.getDt()
self.world.doPhysics(dt, 10, 0.008)
return task.cont
def cleanup(self):
self.world = None
self.worldNP.removeNode()
@staticmethod
def Vec3Rand():
x = 2 * random.random() - 1
y = 2 * random.random() - 1
z = 2 * random.random() - 1
return Vec3(x, y, z)
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
p0 = Point3(-20, -20, 0)
p1 = Point3(-20, 20, 0)
p2 = Point3(20, -20, 0)
p3 = Point3(20, 20, 0)
mesh = BulletTriangleMesh()
mesh.addTriangle(p0, p1, p2)
#.........这里部分代码省略.........
示例10: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
#.........这里部分代码省略.........
def toggleTexture(self):
base.toggleTexture()
def toggleDebug(self):
if self.debugNP.isHidden():
self.debugNP.show()
else:
self.debugNP.hide()
def doScreenshot(self):
base.screenshot('Bullet')
# ____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
force = render.getRelativeVector(self.boxNP, force)
torque = render.getRelativeVector(self.boxNP, torque)
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)
self.world.doPhysics(dt, 5, 1.0/180.0)
return task.cont
def cleanup(self):
self.world.removeRigidBody(self.groundNP.node())
self.world.removeRigidBody(self.boxNP.node())
self.world = None
self.debugNP = None
self.groundNP = None
self.boxNP = None
self.worldNP.removeNode()
def setup(self):
self.worldNP = render.attachNewNode('World')
# World
self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
self.debugNP.show()
self.debugNP.node().showWireframe(True)
self.debugNP.node().showConstraints(True)
self.debugNP.node().showBoundingBoxes(False)
self.debugNP.node().showNormals(True)
#self.debugNP.showTightBounds()
#self.debugNP.showBounds()
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNP.node())
# Ground (static)
shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
self.groundNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
self.groundNP.node().addShape(shape)
self.groundNP.setPos(0, 0, -2)
self.groundNP.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(self.groundNP.node())
# Box (dynamic)
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
self.boxNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
self.boxNP.node().setMass(1.0)
self.boxNP.node().addShape(shape)
self.boxNP.setPos(0, 0, 2)
#self.boxNP.setScale(2, 1, 0.5)
self.boxNP.setCollideMask(BitMask32.allOn())
#self.boxNP.node().setDeactivationEnabled(False)
self.world.attachRigidBody(self.boxNP.node())
visualNP = loader.loadModel('models/box.egg')
visualNP.clearModelNodes()
visualNP.reparentTo(self.boxNP)
示例11: RonnieRacer
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
#.........这里部分代码省略.........
self.steeringIncrement = 60
#spin the flag
self.rot += 1
self.flagNP.setHpr(self.rot,0,0)
#time
self.time += dt
self.timeText.setText('Time: ' + str(int(self.time)))
if(self.score > 0):
self.score -= dt
self.scoreText.setText('Score: '+str(int(self.score)))
return task.cont
def cleanup(self):
self.world = None
self.worldNP.removeNode()
def setup(self):
# Steering info
self.steering = 0.0 # degree
self.steeringClamp = 30.0 # degree
self.steeringIncrement = 80.0 # degree per second
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())
if(self.gameLevel == 1):
#set score
print('GameLevel')
self.score = 1000
self.distanceTravelled = 0
self.time = 0
# Plane
img = PNMImage(Filename('media/terrain/SIMP_Assignment_2_Terrain_1.png'))
shape = BulletHeightfieldShape(img, 50.0, ZUp)
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
np.node().addShape(shape)
np.setPos(0, 0, 0)
np.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(np.node())
#skybox
skybox = loader.loadModel('media/models/skybox/skybox_01.X')
skybox.reparentTo(render)
# Chassis
shape = BulletBoxShape(Vec3(0.6, 1.4, 0.5))
ts = TransformState.makePos(Point3(0, 0, 1.0))
self.vehicleNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Vehicle'))
self.vehicleNP.node().addShape(shape, ts)
self.vehicleNP.setPos(-93, -88, -7)#-93, -88, -7) #(-82,65.8,-8) #(55,8.38,-6)#(45, -19, -8)#(-93, -88, -7)
self.vehicleNP.setHpr(-90,0,0)
self.vehicleNP.node().setMass(5.0)
self.vehicleNP.node().setDeactivationEnabled(False)
示例12: SMWorld
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
#.........这里部分代码省略.........
#------------------------------------------------------------------------------------------------------------------------------------------------------------
# Sets up the world and returns a NodePath of the BulletWorld
#------------------------------------------------------------------------------------------------------------------------------------------------------------
def setupWorld(self):
self.worldBullet = BulletWorld()
self.worldBullet.setGravity(Vec3(0, 0, -GRAVITY))
self.terrSteepness = -1
wNP = render.attachNewNode('WorldNode')
self.audioMgr.loadSFX("snowCrunch01")
self.audioMgr.loadBGM("snowmanWind")
return wNP
#------------------------------------------------------------------------------------------------------------------------------------------------------------
# Prints all nodes that are a child of render.
#------------------------------------------------------------------------------------------------------------------------------------------------------------
def printSceneGraph(self):
print(render.ls())
#------------------------------------------------------------------------------------------------------------------------------------------------------------
# Initializes and returns a DebugNode NodePath.
#------------------------------------------------------------------------------------------------------------------------------------------------------------
def setupDebug(self):
debug = BulletDebugNode()
debug.showWireframe(False) # Yeah, don't set this to true unless you want to emulate an 80's computer running Crysis on Ultra settings.
debug.showConstraints(True)
debug.showBoundingBoxes(True) # This is the main use I have for it.
debug.showNormals(True)
debugNP = render.attachNewNode(debug)
self.worldBullet.setDebugNode(debugNP.node())
debugNP.hide()
return debugNP
#------------------------------------------------------------------------------------------------------------------------------------------------------------
# Initializes and returns a BulletRigidBodyNode of the terrain, which loads the map with the specified name.
#------------------------------------------------------------------------------------------------------------------------------------------------------------
def setupHeightmap(self, name):
# Automatically generate a heightmap mesh from a monochrome image.
self.hmHeight = 120
hmPath = "../maps/map" + name + "/map" + name + "-h.png"
imPath = "../maps/map" + name + "/map" + name + "-i.png"
smPath = "../maps/map" + name + "/map" + name + "-s.png"
scmPath = "../maps/map" + name + "/map" + name + "-sc.png"
print(hmPath)
print(imPath)
print(smPath)
print(scmPath)
hmImg = PNMImage(Filename(hmPath))
hmShape = BulletHeightfieldShape(hmImg, self.hmHeight, ZUp)
hmNode = BulletRigidBodyNode('Terrain')
hmNode.addShape(hmShape)
hmNode.setMass(0)
self.hmNP = render.attachNewNode(hmNode)
self.worldBullet.attachRigidBody(hmNode)
self.hmOffset = hmImg.getXSize() / 2.0 - 0.5
self.hmTerrain = GeoMipTerrain('gmTerrain')
self.hmTerrain.setHeightfield(hmImg)
# Optimizations and fixes
self.hmTerrain.setBruteforce(True) # I don't think this is actually needed.
示例13: BallInMaze
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
class BallInMaze(DirectObject):
def __init__(self):
base.setBackgroundColor(0.1, 0.1, 0.8, 1)
base.setFrameRateMeter(True)
base.cam.setPosHpr(0, 0, 25, 0, -90, 0)
base.disableMouse()
# Input
self.accept('escape', self.exitGame)
self.accept('f1', self.toggleWireframe)
self.accept('f2', self.toggleTexture)
self.accept('f3', self.toggleDebug)
self.accept('f5', self.doScreenshot)
# Setup scene 1: World
self.debugNP = render.attachNewNode(BulletDebugNode('Debug'))
self.debugNP.node().showWireframe(True)
self.debugNP.node().showConstraints(True)
self.debugNP.node().showBoundingBoxes(True)
self.debugNP.node().showNormals(True)
self.debugNP.show()
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNP.node())
# Setup scene 2: Ball
visNP = loader.loadModel('models/ball.egg')
visNP.clearModelNodes()
bodyNPs = BulletHelper.fromCollisionSolids(visNP, True)
self.ballNP = bodyNPs[0]
self.ballNP.reparentTo(render)
self.ballNP.node().setMass(1.0)
self.ballNP.setPos(4, -4, 1)
self.ballNP.node().setDeactivationEnabled(False)
visNP.reparentTo(self.ballNP)
# Setup scene 3: Maze
visNP = loader.loadModel('models/maze.egg')
visNP.clearModelNodes()
visNP.reparentTo(render)
self.holes = []
self.maze = []
self.mazeNP = visNP
bodyNPs = BulletHelper.fromCollisionSolids(visNP, True);
for bodyNP in bodyNPs:
bodyNP.reparentTo(render)
if isinstance(bodyNP.node(), BulletRigidBodyNode):
bodyNP.node().setMass(0.0)
bodyNP.node().setKinematic(True)
self.maze.append(bodyNP)
elif isinstance(bodyNP.node(), BulletGhostNode):
self.holes.append(bodyNP)
# Lighting and material for the ball
ambientLight = AmbientLight('ambientLight')
ambientLight.setColor(Vec4(0.55, 0.55, 0.55, 1))
directionalLight = DirectionalLight('directionalLight')
directionalLight.setDirection(Vec3(0, 0, -1))
directionalLight.setColor(Vec4(0.375, 0.375, 0.375, 1))
directionalLight.setSpecularColor(Vec4(1, 1, 1, 1))
self.ballNP.setLight(render.attachNewNode(ambientLight))
self.ballNP.setLight(render.attachNewNode(directionalLight))
m = Material()
m.setSpecular(Vec4(1,1,1,1))
m.setShininess(96)
self.ballNP.setMaterial(m, 1)
# Startup
self.startGame()
def exitGame(self):
sys.exit()
def toggleWireframe(self):
base.toggleWireframe()
def toggleTexture(self):
base.toggleTexture()
def toggleDebug(self):
if self.debugNP.isHidden():
self.debugNP.show()
else:
self.debugNP.hide()
def doScreenshot(self):
base.screenshot('Bullet')
def startGame(self):
self.ballNP.setPos(4, -4, 1)
#.........这里部分代码省略.........
示例14: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
class Game(DirectObject):
def __init__(self):
base.setBackgroundColor(0.1, 0.1, 0.8, 1)
base.setFrameRateMeter(True)
base.cam.setPos(0, -40, 10)
base.cam.lookAt(0, 0, 0)
# Light
alight = AmbientLight('ambientLight')
alight.setColor(Vec4(0.5, 0.5, 0.5, 1))
alightNP = render.attachNewNode(alight)
dlight = DirectionalLight('directionalLight')
dlight.setDirection(Vec3(5, 0, -2))
dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
dlightNP = render.attachNewNode(dlight)
render.clearLight()
render.setLight(alightNP)
render.setLight(dlightNP)
# Input
self.accept('escape', self.doExit)
self.accept('r', self.doReset)
self.accept('f1', self.toggleWireframe)
self.accept('f2', self.toggleTexture)
self.accept('f3', self.toggleDebug)
self.accept('f5', self.doScreenshot)
# Task
taskMgr.add(self.update, 'updateWorld')
# Physics
self.setup()
# _____HANDLER_____
def doExit(self):
self.cleanup()
sys.exit(1)
def doReset(self):
self.cleanup()
self.setup()
def toggleWireframe(self):
base.toggleWireframe()
def toggleTexture(self):
base.toggleTexture()
def toggleDebug(self):
if self.debugNP.isHidden():
self.debugNP.show()
else:
self.debugNP.hide()
def doScreenshot(self):
base.screenshot('Bullet')
# ____TASK___
def update(self, task):
dt = globalClock.getDt()
self.world.doPhysics(dt, 10, 0.004)
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())
# Box
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5) * 2.0)
boxNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
boxNP.node().setMass(150.0)
boxNP.node().addShape(shape)
boxNP.setPos(0, 0, 2)
boxNP.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(boxNP.node())
visualNP = loader.loadModel('models/box.egg')
visualNP.clearModelNodes()
visualNP.setScale(2.0)
#.........这里部分代码省略.........
示例15: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setDebugNode [as 别名]
#.........这里部分代码省略.........
self.debugNP.hide()
def doScreenshot(self):
base.screenshot("Bullet")
# def doJump(self):
# self.player.setMaxJumpHeight(5.0)
# self.player.setJumpSpeed(8.0)
# self.player.doJump()
# def doCrouch(self):
# self.crouching = not self.crouching
# sz = self.crouching and 0.6 or 1.0
# self.playerNP2.setScale(Vec3(1, 1, sz))
# ____TASK___
def processInput(self, dt):
speed = Vec3(0, 0, 0)
omega = 0.0
if inputState.isSet("forward"):
speed.setY(2.0)
if inputState.isSet("reverse"):
speed.setY(-2.0)
if inputState.isSet("left"):
speed.setX(-2.0)
if inputState.isSet("right"):
speed.setX(2.0)
if inputState.isSet("turnLeft"):
omega = 120.0
if inputState.isSet("turnRight"):
omega = -120.0
self.player.setAngularMovement(omega)
self.player.setLinearMovement(speed, True)
def update(self, task):
dt = globalClock.getDt()
self.processInput(dt)
self.world.doPhysics(dt, 4, 1.0 / 240.0)
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), 0)
# img = PNMImage(Filename('models/elevation2.png'))
# shape = BulletHeightfieldShape(img, 1.0, ZUp)
np = self.worldNP.attachNewNode(BulletRigidBodyNode("Ground"))
np.node().addShape(shape)
np.setPos(0, 0, -1)
np.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(np.node())
# Box
shape = BulletBoxShape(Vec3(1.0, 3.0, 0.3))
np = self.worldNP.attachNewNode(BulletRigidBodyNode("Box"))
np.node().setMass(50.0)
np.node().addShape(shape)
np.setPos(3, 0, 4)
np.setH(0)
np.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(np.node())
# Character
h = 1.75
w = 0.4
shape = BulletCapsuleShape(w, h - 2 * w, ZUp)
self.player = BulletCharacterNode(shape, 0.4, "Player")
self.player.setMass(20.0)
self.player.setMaxSlope(45.0)
self.player.setGravity(9.81)
self.playerNP = self.worldNP.attachNewNode(self.player)
self.playerNP.setPos(-2, 0, 10)
self.playerNP.setH(-90)
self.playerNP.setCollideMask(BitMask32.allOn())
self.world.attachCharacter(self.player)