本文整理汇总了Python中panda3d.bullet.BulletRigidBodyNode.addShape方法的典型用法代码示例。如果您正苦于以下问题:Python BulletRigidBodyNode.addShape方法的具体用法?Python BulletRigidBodyNode.addShape怎么用?Python BulletRigidBodyNode.addShape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.bullet.BulletRigidBodyNode
的用法示例。
在下文中一共展示了BulletRigidBodyNode.addShape方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ball
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
class Ball(object):
def __init__(self, render, world, loader, player):
self.render = render
self.world = world
self.loader = loader
self.player = player
self.dropHeight = 5
self.createItem()
def createItem(self):
self.collisionShape = BulletSphereShape(0.5)
self.actor = BulletRigidBodyNode('Ball')
self.actor.setMass(5.0)
self.actor.addShape(self.collisionShape)
self.np = self.render.attachNewNode(self.actor)
self.np.setCollideMask(BitMask32.allOff())
self.x = self.player.getCharacterNP().getX()
self.y = self.player.getCharacterNP().getY()
self.z = self.player.getCharacterNP().getZ() + self.dropHeight
self.np.setPos(self.x, self.y, self.z)
self.world.attachRigidBody(self.actor)
self.actorModelNP = self.loader.loadModel('models/sphere/ball.egg')
self.actorModelNP.reparentTo(self.np)
self.actorModelNP.setScale(0.5)
self.actorModelNP.setPos(0, 0, 0)
def getActor(self):
return self.actor
def getNP(self):
return self.np
示例2: genHand
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
def genHand(self, handz=100.0):
# fgr0
boxx = 5.0
boxy = 2.0
boxz = 20.0
boxpx = 0.0
boxpy = 10.0
boxpz = handz
shape = BulletBoxShape(Vec3(boxx, boxy, boxz)) # the parameters are half extends
node = BulletRigidBodyNode('fgr0')
node.addShape(shape)
node.setTransform(TransformState.makePos(VBase3(boxpx, boxpy, boxpz)))
self.bltWorld.attachRigidBody(node)
pg.plotBox(self.base.render, pos=[boxpx, boxpy, boxpz], x=boxx * 2.0, y=boxy * 2.0, z=boxz * 2.0, rgba=None)
# fgr1
boxx = 5.0
boxy = 2.0
boxz = 20.0
boxpx = 0.0
boxpy = -10.0
boxpz = handz
shape = BulletBoxShape(Vec3(boxx, boxy, boxz)) # the parameters are half extends
node = BulletRigidBodyNode('fgr1')
node.addShape(shape)
node.setTransform(TransformState.makePos(VBase3(boxpx, boxpy, boxpz)))
self.bltWorld.attachRigidBody(node)
pg.plotBox(self.base.render, pos=[boxpx, boxpy, boxpz], x=boxx * 2.0, y=boxy * 2.0, z=boxz * 2.0, rgba=None)
示例3: create_object
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
def create_object(self):
from panda3d.core import Filename, NodePath, BitMask32
from direct.actor.Actor import Actor
from panda3d.bullet import BulletRigidBodyNode, BulletCapsuleShape
from game_system.resources import ResourceManager
f = Filename.fromOsSpecific(ResourceManager.get_absolute_path(ResourceManager["TestAI"]["lp_char_bs.egg"]))
model = Actor(f)
bullet_node = BulletRigidBodyNode("TestAIBulletNode")
bullet_nodepath = NodePath(bullet_node)
bullet_node.set_angular_factor((0, 0, 1))
shape = BulletCapsuleShape(0.3, 1.4, 2)
bullet_node.addShape(shape)
bullet_node.setMass(1.0)
model.reparentTo(bullet_nodepath)
model.set_hpr(180, 0, 0)
model.set_pos(0, 0, -1)
bullet_nodepath.set_collide_mask(BitMask32.bit(0))
bullet_nodepath.set_python_tag("actor", model)
return bullet_nodepath
示例4: StaticModel
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
class StaticModel(BulletObject):
def __init__(self, name, modelPath, displayModelPath, game, pos):
self.name = name
self.modelPath = modelPath
self.game = game
self.model = self.game.loader.loadModel(self.modelPath)
geomNodes = self.model.findAllMatches('**/+GeomNode')
self.geomNode = geomNodes.getPath(0).node()
self.geom = self.geomNode.getGeom(0)
#self.shape = BulletConvexHullShape()
#self.shape.addGeom(self.geom)
mesh = BulletTriangleMesh()
mesh.addGeom(self.geom)
self.shape = BulletTriangleMeshShape(mesh, dynamic=False)
self.node = BulletRigidBodyNode(self.name)
self.node.addShape(self.shape)
self.np = self.game.render.attachNewNode(self.node)
self.np.setPos(pos)
self.game.world.attachRigidBody(self.node)
#self.model.reparentTo(self.np)
self.displayModel = self.game.loader.loadModel(displayModelPath)
self.displayModel.reparentTo(self.np)
self.displayModel.setTwoSided(True)
self.slice_able = False
示例5: DynamicModel
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
class DynamicModel(DynamicObject):
def __init__(self, name, modelPath, game, pos):
self.name = name
self.modelPath = modelPath
self.game = game
self.model = self.game.loader.loadModel(self.modelPath)
geomNodes = self.model.findAllMatches('**/+GeomNode')
self.geomNode = geomNodes.getPath(0).node()
self.geom = self.geomNode.getGeom(0)
self.shape = BulletConvexHullShape()
self.shape.addGeom(self.geom)
self.node = BulletRigidBodyNode(self.name)
self.node.setMass(10.0)
self.node.addShape(self.shape)
self.np = self.game.render.attachNewNode(self.node)
self.np.setPos(pos)
self.game.world.attachRigidBody(self.node)
self.model.reparentTo(self.np)
self.node.setCcdMotionThreshold(1e-7)
self.node.setCcdSweptSphereRadius(0.5)
self.slice_able = True
示例6: StaticTerrain
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
class StaticTerrain(BulletObject):
def __init__(self, game, imgPath, height):
self.game = game
self.img = PNMImage(Filename(imgPath))
self.shape = BulletHeightfieldShape(self.img, height, 2)
self.node = BulletRigidBodyNode('Ground')
self.node.addShape(self.shape)
self.np = self.game.render.attachNewNode(self.node)
self.np.setPos(0, 0, 0)
self.np.setScale(1, 1, 1)
self.game.world.attachRigidBody(self.node)
self.terrain = GeoMipTerrain('terrain')
self.terrain.setHeightfield(self.img)
self.terrain.generate()
self.terrainNP = self.terrain.getRoot()
self.offset = self.img.getXSize() / 2.0 - 0.5
self.terrainNP.setSz(height)
self.terrainNP.setPos(-self.offset,-self.offset,-height/2.0)
#self.terrainNP.flattenStrong()
self.terrainNP.reparentTo(self.np)
self.terrainNP.show()
self.debugOff()
self.slice_able = False
self.terrain.setBlockSize(32)
self.terrain.setNear(100)
self.terrain.setFar(400)
self.terrain.setFocalPoint(self.game.playerNp)
def update(self, dt=0.1):
self.terrain.update()
示例7: DynamicPlatform
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
class DynamicPlatform(DynamicObject):
def __init__(self, name, game, x, y, z, pos):
self.name = name
self.game = game
self.shape = BulletBoxShape(Vec3(x, y, z))
self.node = BulletRigidBodyNode(self.name)
self.node.addShape(self.shape)
self.np = self.game.render.attachNewNode(self.node)
self.np.setPos(pos)
self.game.world.attachRigidBody(self.node)
#self.model = self.game.loader.loadModel("models/crate.egg")
#self.model.reparentTo(self.np)
self.node.setCcdMotionThreshold(1e-7)
self.node.setCcdSweptSphereRadius(0.5)
#self.node.setFriction(5)
#self.debugOff()
self.speedVec = Vec3(0,0,0)
self.lastPos = Vec3(self.getPos())
self.slice_able = False
#self.node.setCcdMotionThreshold(1e-7)
#self.node.setCcdSweptSphereRadius(0.5)
def update(self, dt):
return
示例8: DynamicNp
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
class DynamicNp(DynamicObject):
def __init__(self, name, model, game, pos):
self.name = name
self.game = game
self.model = model
self.geomNode = self.model.node()
self.geom = self.geomNode.getGeom(0)
# with triangle mesh it crashes
#mesh = BulletTriangleMesh()
#mesh.addGeom(self.geom)
#self.shape = BulletTriangleMeshShape(mesh, dynamic=True)
# with convex hull
self.shape = BulletConvexHullShape()
self.shape.addGeom(self.geom)
self.node = BulletRigidBodyNode(self.name)
self.node.setMass(10.0)
self.node.addShape(self.shape)
self.np = self.game.render.attachNewNode(self.node)
self.np.setPos(pos)
self.game.world.attachRigidBody(self.node)
self.model.reparentTo(self.np)
self.node.setCcdMotionThreshold(1e-7)
self.node.setCcdSweptSphereRadius(0.5)
self.slice_able = True
示例9: rayHit
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
def rayHit(pfrom, pto, geom):
"""
NOTE: this function is quite slow
find the nearest collision point between vec(pto-pfrom) and the mesh of nodepath
:param pfrom: starting point of the ray, Point3
:param pto: ending point of the ray, Point3
:param geom: meshmodel, a panda3d datatype
:return: None or Point3
author: weiwei
date: 20161201
"""
bulletworld = BulletWorld()
facetmesh = BulletTriangleMesh()
facetmesh.addGeom(geom)
facetmeshnode = BulletRigidBodyNode('facet')
bullettmshape = BulletTriangleMeshShape(facetmesh, dynamic=True)
bullettmshape.setMargin(0)
facetmeshnode.addShape(bullettmshape)
bulletworld.attachRigidBody(facetmeshnode)
result = bulletworld.rayTestClosest(pfrom, pto)
if result.hasHit():
return result.getHitPos()
else:
return None
示例10: setupPlayer
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
def setupPlayer(self, x, y, z):
yetiHeight = 7
yetiRadius = 2
yetiShape = BulletCapsuleShape(yetiRadius, yetiHeight - 2 * yetiRadius, ZUp)
modelPrefix = "../res/models/yeti_"
self.yetiModel = Actor("../res/models/yeti.egg", {"idle":"../res/models/yeti_idle.egg", "walk":"../res/models/yeti_walking.egg"})
self.yetiModel.setH(90)
self.yetiModel.setPos(0, 0, SNOW_HEIGHT)
playerNode = BulletRigidBodyNode("Player")
playerNode.setMass(MASS)
playerNode.addShape(yetiShape)
# Without this set to 0,0,0, the Yeti would wobble like a Weeble but not fall down.
playerNode.setAngularFactor(Vec3(0,0,0))
# Without this disabled, things will weld together after a certain amount of time. It's really annoying.
playerNode.setDeactivationEnabled(False)
playerNP = self.worldNP.attachNewNode(playerNode)
playerNP.setPos(x, y, z)
playerNP.setH(270)
self.yetiModel.reparentTo(playerNP)
self.bulletWorld.attachRigidBody(playerNP.node())
# Hopefully Brandon will get those animation files to me so I can convert them.
# self.setAnimation('idle')
return playerNP
示例11: genCollisionMeshMultiNp
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
def genCollisionMeshMultiNp(nodepath, basenodepath=None, name='autogen'):
"""
generate the collision mesh of a nodepath using nodepath
this function suppose the nodepath has multiple models with many geomnodes
use genCollisionMeshMultiNp instead of genCollisionMeshNp for generality
:param nodepath: the panda3d nodepath of the object
:param basenodepath: the nodepath to compute relative transform, identity if none
:param name: the name of the rigidbody
:return: bulletrigidbody
author: weiwei
date: 20161212, tsukuba
"""
gndcollection = nodepath.findAllMatches("**/+GeomNode")
geombullnode = BulletRigidBodyNode(name)
for gnd in gndcollection:
geom = gnd.node().getGeom(0)
geomtf = gnd.getTransform(base.render)
if basenodepath is not None:
geomtf = gnd.getTransform(basenodepath)
geombullmesh = BulletTriangleMesh()
geombullmesh.addGeom(geom)
bullettmshape = BulletTriangleMeshShape(geombullmesh, dynamic=True)
bullettmshape.setMargin(0)
geombullnode.addShape(bullettmshape, geomtf)
return geombullnode
示例12: demoContinue
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
def demoContinue(self):
if self.newObjects < self.NrObjectToDrop:
node = BulletRigidBodyNode('Box')
node.setMass(1.0)
node.addShape(self.shape)
np = self.rbcnp.attachNewNode(node)
np.setPos(self.spawnNP.getPos(render))
np.setHpr(randint(-45, 45), randint(-45, 45), randint(-45, 45))
self.world.attachRigidBody(node)
bNP = self.model.copyTo(np)
#bNP.setPos(self.spawnNP.getPos())
#bNP.setColor(random(), random(), random(), 1)
#bNP.setHpr(randint(-45, 45), randint(-45, 45), randint(-45, 45))
#self.setUntextured(bNP)
#bNP.setTexureOff()
#np.setScale(10)
np.flattenStrong()
self.objects.append(np)
self.newObjects += 1
self.rbcnp.node().collect()
if self.newObjects < self.NrObjectToDrop:
return False
else:
self.running = False
return True
示例13: genBulletBoxes
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
def genBulletBoxes(env,world):
boxes = list()
for np in listNodes(env,"Collision_box_"):
geom = np.node().getGeom(0)
# get the minimum and maximum points
vdata = geom.getVertexData()
vertices = GeomVertexReader(vdata,'vertex')
vmin = LPoint3()
vmax = LPoint3()
np.calcTightBounds(vmin,vmax)
#Create the bullet box with center at (0,0)
norm = vmax-vmin
hnorm = LVecBase3(norm[0]*.5,norm[1]*.5,norm[2]*.5)
shape = BulletBoxShape(hnorm)
# create the surrounding nodes
node = BulletRigidBodyNode('env')
node.addShape(shape)
enp = env.attachNewNode(node)
enp.setPos(vmin+hnorm)
# attach it to the world and save it for later
world.attachRigidBody(node)
boxes.append(enp.node())
# clean up the environment higherarchy
np.removeNode()
return boxes
示例14: __init__
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
def __init__(self,mainReference):
super(Player, self).__init__(mainReference)
# setting player HP
self.healthPoints = 100
# fine tuning the camera properties
self.mainRef.camLens.setFov(50)
self.mainRef.camLens.setNear(0.02)
self.mainRef.camLens.setFar(80.0)
self.currentRegionID = 1
# dummy nodepath for our player; we will attach everything to it
# player bullet node - NOTE: for detecting collision with attacks, only
playerNode = BulletRigidBodyNode('Player_NP')
playerNode.addShape( BulletCapsuleShape(0.3, 1, ZUp) ) # adicionar node no lugar da string
self.mainRef.world.attachRigidBody(playerNode)
self.playerNP = self.mainRef.render.attachNewNode(playerNode)
# this collision mask will only avoid CharacterBody collision on itself
self.playerNP.setCollideMask(BitMask32(0x7FFFFFFF))
# notify collision contacts
self.playerNP.node().notifyCollisions(True)
self.playerHeadNP = NodePath("empty") # This node is intended to be a placeholder for the camera (maintainability only)
self.playerHeadNP.reparentTo( self.playerNP )
self.playerHeadNP.setPos(0, 0, 1.35)
# self.mainRef.camera.setPos(0, -4, 0)
self.mainRef.camera.reparentTo( self.playerHeadNP )
# NodePath position
self.playerNP.setPos(0,0,1.0)
# setting player's character body
self.playerBody = CharacterBody(self.mainRef, self.playerNP.getPos(), 0.38, 0.5)
self.playerBody.charBodyNP.reparentTo(self.playerNP)
# setting our movementHandler
self.movementHandler = MovementHandler(self.mainRef)
self.movementHandler.registerFPSMovementInput()
# attach default weapon
self.activeWeapon = Glock(self.mainRef.camera)
# adding the shoot event
self.mainRef.accept("mouse1", self.shootBullet)
# adding the reload event
self.mainRef.accept("mouse3", self.reloadWeapon)
# player boolean to authorize player HP decrease when zombie contact happens
self.canLoseHP = True
示例15: setupDeathzone
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import addShape [as 别名]
def setupDeathzone(self, height):
planeShape = BulletPlaneShape(Vec3(0, 0, 1), 1)
planeNode = BulletRigidBodyNode('DeathZone')
planeNode.addShape(planeShape)
planeNP = render.attachNewNode(planeNode)
planeNP.setPos(0, 0, height)
self.worldBullet.attachRigidBody(planeNode)
return planeNP