本文整理汇总了Python中panda3d.bullet.BulletRigidBodyNode.notifyCollisions方法的典型用法代码示例。如果您正苦于以下问题:Python BulletRigidBodyNode.notifyCollisions方法的具体用法?Python BulletRigidBodyNode.notifyCollisions怎么用?Python BulletRigidBodyNode.notifyCollisions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.bullet.BulletRigidBodyNode
的用法示例。
在下文中一共展示了BulletRigidBodyNode.notifyCollisions方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Track2
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import notifyCollisions [as 别名]
class Track2(object):
def __init__(self, bulletWorld):
self.env = loader.loadModel("models/env")
self.env.reparentTo(render)
self.env.setPos(0,0,-6)
self.env.setScale(400)
self.environ_tex = loader.loadTexture("models/tex/env_sky.jpg")
self.env.setTexture(self.environ_tex, 1)
self.period_cloud = self.env.hprInterval(400, (360, 0, 0))
self.period_cloud.loop()
self.ground = loader.loadModel("models/Ground2")
self.ground.reparentTo(render)
self.ground.setPos(0,0,-5)
self.ground.setScale(0.5,0.5,0)
self.ground_tex = loader.loadTexture("models/tex/ground.tif")
self.ground.setTexture(self.ground_tex, 1)
# model used as collision mesh
collisionModel = loader.loadModel('models/Track2')
# model used as display model
model = loader.loadModel('models/Track2')
tex = loader.loadTexture("models/tex/Main.png")
model.setTexture(tex)
# renders track from two camera views
model.setTwoSided(True)
collisionModel.setScale(1, 1, 100)
mesh = BulletTriangleMesh()
for geomNP in collisionModel.findAllMatches('**/+GeomNode'):
geomNode = geomNP.node()
ts = geomNP.getTransform(collisionModel)
for geom in geomNode.getGeoms():
mesh.addGeom(geom, ts)
shape = BulletTriangleMeshShape(mesh, dynamic=False)
self.rigidNode = BulletRigidBodyNode('Heightfield')
self.rigidNode.notifyCollisions(False)
np = render.attachNewNode(self.rigidNode)
np.node().addShape(shape)
model.setScale(1, 1, .1)
model.reparentTo(np)
np.setScale(.7)
np.setPos(0, 0, -5)
np.setCollideMask(BitMask32(0xf0))
np.node().notifyCollisions(False)
bulletWorld.attachRigidBody(np.node())
self.hf = np.node() # To enable/disable debug visualisation
示例2: __init__
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import notifyCollisions [as 别名]
def __init__(self, main, base, render, type = "heightMap"):
if type == "heightMap":
self.terrainFromHeightMap(main)
elif type == "model":
self.terrainFromModel(main)
# Plane
shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
universeNode = BulletRigidBodyNode('UniverseNode')
universeNode.notifyCollisions(True)
universeNode.addShape(shape)
np = self.parentNodePath.attachNewNode(universeNode)
np.setPos(0, 0, -150)
np.hide()
main.world.attachRigidBody(universeNode)
self.parentNodePath.reparentTo(main.worldNP)
self.hf = self.rigidNodePath.node() # To enable/disable debug visualisation
# Sky Dome
universeBackground = UniverseBackground()
示例3: Track
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import notifyCollisions [as 别名]
class Track(object):
def __init__(self, bulletWorld):
self.sky = SkyDome()
# model used as collision mesh
collisionModel = loader.loadModel('models/walledTrack')
# model used as display model
model = loader.loadModel('models/FullTrack')
tex = loader.loadTexture("models/tex/Main.png")
ts = TextureStage('ts')
ts.setMode(TextureStage.MBlend)
model.setTexture(ts, tex, 2)
#model.setTexScale(ts, 70)
# renders track from two camera views
model.setTwoSided(True)
mesh = BulletTriangleMesh()
for geomNP in collisionModel.findAllMatches('**/+GeomNode'):
geomNode = geomNP.node()
ts = geomNP.getTransform(collisionModel)
for geom in geomNode.getGeoms():
mesh.addGeom(geom, ts)
shape = BulletTriangleMeshShape(mesh, dynamic=False)
self.rigidNode = BulletRigidBodyNode('Track')
self.rigidNode.notifyCollisions(False)
np = render.attachNewNode(self.rigidNode)
np.node().addShape(shape)
model.reparentTo(np)
np.setScale(70)
np.setPos(0, 0, -5)
np.setCollideMask(BitMask32(0xf0))
np.node().notifyCollisions(False)
bulletWorld.attachRigidBody(np.node())
self.hf = np.node() # To enable/disable debug visualisation
示例4: Flame
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import notifyCollisions [as 别名]
class Flame(Entity):
"""
The thing that comes out the end of the thing you hold
"""
animspeed = 0.1
depth = 20
playerWidth = 3
speed = 20
def __init__(self, world, pos, hpr):
super(Flame, self).__init__()
self.shape = BulletBoxShape(Vec3(0.1,0.05,0.05))
self.bnode = BulletRigidBodyNode()
self.bnode.setMass(1.0)
self.bnode.addShape(self.shape)
self.np = utilities.app.render.attachNewNode(self.bnode)
self.world =world
self.anim = list()
self.anim.append(utilities.loadObject("flame1", depth=0))
self.anim.append(utilities.loadObject("flame2", depth=0))
self.anim.append(utilities.loadObject("flame3", depth=0))
world.bw.attachRigidBody(self.bnode)
self.curspr = 0
self.obj = self.anim[self.curspr]
self.obj.show()
self.livetime = 0
self.delta = 0
self.pos = pos
self.pos.y = Flame.depth
#self.pos.z -= 0.2
self.hpr = hpr
self.vel = Point2()
self.vel.x = cos(world.player.angle)*Flame.speed
self.vel.y = sin(world.player.angle)*Flame.speed
tv = Vec3(self.vel.x, 0, self.vel.y)
# this makes the shot miss the target if the player has any velocity
tv += world.player.bnode.getLinearVelocity()
self.bnode.setLinearVelocity(tv)
tv.normalize()
# initial position of RB and draw plane
self.np.setHpr(hpr)
self.np.setPos(pos+tv/2)
self.bnode.setAngularFactor(Vec3(0,0,0))
self.bnode.setLinearFactor(Vec3(1,0,1))
self.bnode.setGravity(Vec3(0,0,0))
self.bnode.setCcdMotionThreshold(1e-7)
self.bnode.setCcdSweptSphereRadius(0.10)
self.bnode.notifyCollisions(True)
self.bnode.setIntoCollideMask(BitMask32.bit(1))
self.bnode.setPythonTag("Entity", self)
self.noCollideFrames = 4
for a in self.anim:
a.hide()
a.reparentTo(self.np)
a.setScale(0.25, 1, 0.25)
a.setPos(0, -0.1,0)
def update(self, timer):
#animation
self.delta += timer
self.livetime += timer
if self.noCollideFrames == 0:
self.bnode.setIntoCollideMask(BitMask32.allOn())
if self.noCollideFrames > -1:
self.noCollideFrames -= 1
if self.delta > Flame.animspeed:
self.delta = 0
self.obj.hide()
self.curspr += 1
if self.curspr > len(self.anim)-1:
self.curspr = 0
self.obj = self.anim[self.curspr]
self.obj.show()
示例5: Terrain
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import notifyCollisions [as 别名]
class Terrain(object):
def __init__(self, main, base, render, type = "heightMap"):
if type == "heightMap":
self.terrainFromHeightMap(main)
elif type == "model":
self.terrainFromModel(main)
# Plane
shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
universeNode = BulletRigidBodyNode('UniverseNode')
universeNode.notifyCollisions(True)
universeNode.addShape(shape)
np = self.parentNodePath.attachNewNode(universeNode)
np.setPos(0, 0, -150)
np.hide()
main.world.attachRigidBody(universeNode)
self.parentNodePath.reparentTo(main.worldNP)
self.hf = self.rigidNodePath.node() # To enable/disable debug visualisation
# Sky Dome
universeBackground = UniverseBackground()
def terrainFromModel(self, main):
self.parentNodePath = NodePath("FloorNodePath")
self.parentNodePath.setPos(0, 0, -1)
self.parentNodePath.setScale(2.0, 2.0, 1.0)
# self.parentNodePath.setP(90)
self.loadModelAndTexture()
self.setupCollisionMeshAndRigidNodeFromModel()
main.world.attachRigidBody(self.rigidNodePath.node())
def loadModelAndTexture(self, path={"model": "models/map", "texture": "models/tex/floor.jpg"}):
self.floorModel = loader.loadModel(path["model"])
# floor_tex = loader.loadTexture(path["texture"])
# self.floorModel.setTexture(floor_tex)
self.parentNodePath.attachNewNode(self.floorModel.node())
def setupCollisionMeshAndRigidNodeFromModel(self):
mesh = BulletTriangleMesh()
for geomNP in self.floorModel.findAllMatches('**/+GeomNode'):
geomNode = geomNP.node()
ts = geomNP.getTransform(self.floorModel)
for geom in geomNode.getGeoms():
mesh.addGeom(geom, ts)
shape = BulletTriangleMeshShape(mesh, dynamic=False)
self.rigidNode = BulletRigidBodyNode('Floor')
self.rigidNode.notifyCollisions(False)
self.rigidNodePath = self.parentNodePath.attachNewNode(self.rigidNode)
self.rigidNodePath.node().addShape(shape)
self.rigidNodePath.setScale(12, 12, 1.5)
self.rigidNodePath.setCollideMask(BitMask32.allOn())
self.rigidNodePath.node().notifyCollisions(False)
def toggleHeightfield(self):
self.hf.setDebugEnabled(not self.hf.isDebugEnabled())
def terrainFromHeightMap(self, main):
self.parentNodePath = NodePath("FloorNodePath")
self.parentNodePath.setPos(0, 0, -2)
self.parentNodePath.setScale(5, 5, 0.75)
# Heightfield (static)
height = 8.0
img = PNMImage(Filename('models/elevation.png'))
xdim = img.getXSize()
ydim = img.getYSize()
shape = BulletHeightfieldShape(img, height, ZUp)
shape.setUseDiamondSubdivision(True)
self.rigidNode = BulletRigidBodyNode('Heightfield')
self.rigidNode.notifyCollisions(False)
self.rigidNodePath = self.parentNodePath.attachNewNode(self.rigidNode)
self.rigidNodePath.node().addShape(shape)
self.rigidNodePath.setPos(0, 0, 0)
self.rigidNodePath.setCollideMask(BitMask32.allOn())
self.rigidNodePath.node().notifyCollisions(False)
main.world.attachRigidBody(self.rigidNodePath.node())
self.hf = self.rigidNodePath.node() # To enable/disable debug visualisation
self.terrain = GeoMipTerrain('terrain')
self.terrain.setHeightfield(img)
self.terrain.setBlockSize(32)
self.terrain.setNear(50)
self.terrain.setFar(100)
self.terrain.setFocalPoint(base.camera)
rootNP = self.terrain.getRoot()
rootNP.reparentTo(self.parentNodePath)
rootNP.setSz(8.0)
offset = img.getXSize() / 2.0 - 0.5
rootNP.setPos(-offset, -offset, -height / 2.0)
self.terrain.generate()
#.........这里部分代码省略.........