本文整理汇总了Python中panda3d.bullet.BulletWorld类的典型用法代码示例。如果您正苦于以下问题:Python BulletWorld类的具体用法?Python BulletWorld怎么用?Python BulletWorld使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BulletWorld类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, objpath, handpkg, gdb):
self.objtrimesh=trimesh.load_mesh(objpath)
self.objcom = self.objtrimesh.center_mass
self.objtrimeshconv=self.objtrimesh.convex_hull
# oc means object convex
self.ocfacets, self.ocfacetnormals = self.objtrimeshconv.facets_over(.9999)
# for dbaccess
self.dbobjname = os.path.splitext(os.path.basename(objpath))[0]
# use two bulletworld, one for the ray, the other for the tabletop
self.bulletworldray = BulletWorld()
self.bulletworldhp = BulletWorld()
# plane to remove hand
self.planebullnode = cd.genCollisionPlane(offset=0)
self.bulletworldhp.attachRigidBody(self.planebullnode)
self.handpkg = handpkg
self.handname = handpkg.getHandName()
self.hand = handpkg.newHandNM(hndcolor=[0,1,0,.1])
# self.rtq85hnd = rtq85nm.Rtq85NM(hndcolor=[1, 0, 0, .1])
# for dbsave
# each tpsmat4 corresponds to a set of tpsgripcontacts/tpsgripnormals/tpsgripjawwidth list
self.tpsmat4s = None
self.tpsgripcontacts = None
self.tpsgripnormals = None
self.tpsgripjawwidth = None
# for ocFacetShow
self.counter = 0
self.gdb = gdb
self.loadFreeAirGrip()
示例2: rayHit
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
示例3: PhysicsSystem
class PhysicsSystem(sandbox.EntitySystem):
"""System that interacts with the Bullet physics world"""
def init(self):
self.accept("addSpaceship", self.addSpaceship)
self.world = BulletWorld()
def begin(self):
dt = globalClock.getDt()
self.world.doPhysics(dt)
#world.doPhysics(dt, 10, 1.0/180.0)
def process(self, entity):
pass
def addSpaceship(self, component, shipName, position, linearVelcocity):
component.bulletShape = BulletSphereShape(5)
component.node = BulletRigidBodyNode(shipName)
component.node.setMass(1.0)
component.node.addShape(component.bulletShape)
component.nodePath = universals.solarSystemRoot.attachNewNode(component.node)
addBody(component.node)
position = sandbox.get_system(solarSystem.SolarSystemSystem).solarSystemRoot.find("**/Earth").getPos()
#component.nodePath.setPos(position + Point3(6671, 0, 0))
component.nodePath.setPos(position)
#component.node.setLinearVelocity(Vec3(0, 7.72983, 0))
component.node.setLinearVelocity(linearVelcocity)
示例4: TerrainPhysics
class TerrainPhysics():
def __init__(self, ):
# World
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
def setup(self, terrain, player):
"""Bullet has to be started before some things in the program to avoid crashes."""
self.terrain = terrain
self.player = player
# Demo
spawn = player.attachNewNode("spawnPoint")
spawn.setPos(0, -5, 7)
self.demo = TerrainPhysicsDemo2(self.world, spawn)
taskMgr.add(self.update, 'physics')
def test(self):
self.demo.start()
def update(self, task):
dt = globalClock.getDt()
self.world.doPhysics(dt)
return task.cont
示例5: genAvailableFAGsSgl
def genAvailableFAGsSgl(base, basepath, baseMat4, objpath, objMat4, gdb, handpkg):
"""
find the collision freeairgrips of objpath without considering rotation
:param base: panda base
:param basepath: the path of base object
:param objpath: the path of obj object, the object to be assembled
:param baseMat4, objMat4: all in world coordinates, not relative
:param gdb: grasp db
:param handpkg: hand package
:return: [assgripcontacts, assgripnormals, assgriprotmat4s, assgripjawwidth, assgripidfreeair]
author: weiwei
date: 20170307
"""
bulletworld = BulletWorld()
robothand = handpkg.newHandNM(hndcolor=[1, 0, 0, .1])
basetrimesh = trimesh.load_mesh(basepath)
basenp = pg.packpandanp(basetrimesh.vertices, basetrimesh.face_normals, basetrimesh.faces)
basenp.setMat(baseMat4)
basebullnode = cd.genCollisionMeshNp(basenp, base.render)
bulletworld.attachRigidBody(basebullnode)
dbobjname = os.path.splitext(os.path.basename(objpath))[0]
objfag = Fag(gdb, dbobjname, handpkg)
assgripcontacts = []
assgripnormals = []
assgriprotmat4s = []
assgripjawwidth = []
assgripidfreeair = []
for i, rotmat in enumerate(objfag.freegriprotmats):
assgrotmat = rotmat*objMat4
robothand.setMat(assgrotmat)
# detect the collisions when hand is open!
robothand.setJawwidth(robothand.jawwidthopen)
hndbullnode = cd.genCollisionMeshMultiNp(robothand.handnp)
result0 = bulletworld.contactTest(hndbullnode)
robothand.setJawwidth(objfag.freegripjawwidth[i])
hndbullnode = cd.genCollisionMeshMultiNp(robothand.handnp)
result1 = bulletworld.contactTest(hndbullnode)
if (not result0.getNumContacts()) and (not result1.getNumContacts()):
cct0 = objMat4.xformPoint(objfag.freegripcontacts[i][0])
cct1 = objMat4.xformPoint(objfag.freegripcontacts[i][1])
cctn0 = objMat4.xformPoint(objfag.freegripnormals[i][0])
cctn1 = objMat4.xformPoint(objfag.freegripnormals[i][1])
assgripcontacts.append([cct0, cct1])
assgripnormals.append([cctn0, cctn1])
assgriprotmat4s.append(assgrotmat)
assgripjawwidth.append(objfag.freegripjawwidth[i])
assgripidfreeair.append(objfag.freegripids[i])
return [assgripcontacts, assgripnormals, assgriprotmat4s, assgripjawwidth, assgripidfreeair]
示例6: __init__
def __init__(self):
self.register_signals()
self.world = BulletWorld()
self.world.setGravity((0, 0, -9.81))
# # Seems that this does not function
# on_contact_added = PythonCallbackObject(self._on_contact_added)
# self.world.set_contact_added_callback(on_contact_added)
# on_filter = PythonCallbackObject(self._filter_collision)
# self.world.set_filter_callback(on_filter)
self.listener = DirectObject()
self.listener.accept('bullet-contact-added', self._on_contact_added)
self.listener.accept('bullet-contact-destroyed', self._on_contact_removed)
debug_node = BulletDebugNode('Debug')
debug_node.showWireframe(True)
debug_node.showConstraints(True)
debug_node.showBoundingBoxes(False)
debug_node.showNormals(False)
self.debug_nodepath = render.attachNewNode(debug_node)
self.world.set_debug_node(debug_node)
self.debug_nodepath.show()
示例7: __init__
def __init__(self):
## Setup a bullet world.
# World Node (MAIN)
self.worldNP = render.attachNewNode("World")
# World
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, worldGravity))
PHYSICS["WORLD"] = self.world
# Add the simulation method to the taskmgr
taskMgr.add(self.update, "update bullet world")
# Setup test World
self.box = ""
self.hinge = ""
self.pickTest = False
self.sensor = ""
# test the class test
self.test = MakeObject(self, "Box1", "b", 20.0)
self.test.bodyNP.setPos(0, 1, 1)
pos = 1
# for x in range(5):
# x = MakeObject(self, 'box', 'b', 5.0)
# pos += 1
# x.bodyNP.setPos(0, 0, pos)
self.accept("e", self.playerPickup)
self.accept("f1", self.showDebug)
self.setup_world()
示例8: setup
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)
示例9: setup
def setup(self):
# World
self.debugNP = self.render.attachNewNode(BulletDebugNode('Debug'))
self.debugNP.hide()
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNP.node())
# Create starting platforms
Platform(self.render, self.world, self.loader, 0, 1, 2, 0, 0, -3)
Platform(self.render, self.world, self.loader, 0, 2, 2, 100, 100, -3)
# Generate platforms
PlatformFactory(self.render, self.world, self.loader)
# Create player character
self.player = Player(self.render, self.world, 0, 0, 0)
# Music and sound
self.level1Music = base.loader.loadSfx("sounds/level1.mp3")
self.level1Music.setLoop()
self.level1Music.setVolume(0.4)
self.level1Music.play()
self.level2Music = base.loader.loadSfx("sounds/level2.mp3")
self.level2Music.setLoop()
self.level2Music.setVolume(0.4)
self.winMusic = base.loader.loadSfx("sounds/win.ogg")
self.winMusic.setLoop()
self.winMusic.setVolume(0.4)
self.laughSound = base.loader.loadSfx("sounds/laugh.ogg")
self.collectSound = base.loader.loadSfx("sounds/collect.mp3")
self.createMainMenu()
示例10: setup
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)
mesh.addTriangle(p1, p2, p3)
shape = BulletTriangleMeshShape(mesh, dynamic=False)
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Mesh'))
np.node().addShape(shape)
np.setPos(0, 0, -2)
np.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(np.node())
# Soft body world information
info = self.world.getWorldInfo()
info.setAirDensity(1.2)
info.setWaterDensity(0)
info.setWaterOffset(0)
info.setWaterNormal(Vec3(0, 0, 0))
# Softbody
for i in range(50):
p00 = Point3(-2, -2, 0)
p10 = Point3( 2, -2, 0)
p01 = Point3(-2, 2, 0)
p11 = Point3( 2, 2, 0)
node = BulletSoftBodyNode.makePatch(info, p00, p10, p01, p11, 6, 6, 0, True)
node.generateBendingConstraints(2)
node.getCfg().setLiftCoefficient(0.004)
node.getCfg().setDynamicFrictionCoefficient(0.0003)
node.getCfg().setAeroModel(BulletSoftBodyConfig.AMVertexTwoSided)
node.setTotalMass(0.1)
node.addForce(Vec3(0, 2, 0), 0)
np = self.worldNP.attachNewNode(node)
np.setPos(self.Vec3Rand() * 10 + Vec3(0, 0, 20))
np.setHpr(self.Vec3Rand() * 16)
self.world.attachSoftBody(node)
fmt = GeomVertexFormat.getV3n3t2()
geom = BulletHelper.makeGeomFromFaces(node, fmt, True)
node.linkGeom(geom)
nodeV = GeomNode('')
nodeV.addGeom(geom)
npV = np.attachNewNode(nodeV)
示例11: setup
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())
self.model = TinyDancer(self.world,self.worldNP)
#floor
shape = BulletBoxShape(Vec3(100, 100, 1))
floor = BulletRigidBodyNode('Floor')
bodyNP = self.worldNP.attachNewNode(floor)
bodyNP.node().addShape(shape)
bodyNP.setCollideMask(BitMask32.allOn())
bodyNP.setPos(0, 0, -12)
visNP = loader.loadModel('models/black.egg')
visNP.setScale(Vec3(200, 200, 2))
visNP.clearModelNodes()
visNP.reparentTo(bodyNP)
self.world.attachRigidBody(floor)
示例12: __init__
def __init__(self, camera, debug=False, audio3d=None, client=None, server=None):
self.objects = {}
self.incarnators = []
self.collidables = set()
self.updatables = set()
self.updatables_to_add = set()
self.garbage = set()
self.scene = NodePath('world')
# Set up the physics world. TODO: let maps set gravity.
self.gravity = DEFAULT_GRAVITY
self.physics = BulletWorld()
self.physics.set_gravity(self.gravity)
self.debug = debug
if debug:
debug_node = BulletDebugNode('Debug')
debug_node.show_wireframe(True)
debug_node.show_constraints(True)
debug_node.show_bounding_boxes(False)
debug_node.show_normals(False)
np = self.scene.attach_new_node(debug_node)
np.show()
self.physics.set_debug_node(debug_node)
示例13: __init__
def __init__(self, camera, debug=False, audio3d=None, client=None, server=None):
self.objects = {}
self.incarnators = []
self.collidables = set()
self.updatables = set()
self.updatables_to_add = set()
self.garbage = set()
self.render = NodePath('world')
self.camera = camera
self.audio3d = audio3d
self.ambient = self._make_ambient()
self.celestials = CompositeObject()
self.sky = self.attach(Sky())
# Set up the physics world. TODO: let maps set gravity.
self.gravity = DEFAULT_GRAVITY
self.physics = BulletWorld()
self.physics.set_gravity(self.gravity)
self.debug = debug
self.client = client
self.server = server
if debug:
debug_node = BulletDebugNode('Debug')
debug_node.show_wireframe(True)
debug_node.show_constraints(True)
debug_node.show_bounding_boxes(False)
debug_node.show_normals(False)
np = self.render.attach_new_node(debug_node)
np.show()
self.physics.set_debug_node(debug_node)
示例14: __init__
def __init__(self, root_nodepath, world):
self.world = BulletWorld()
self.world.setGravity((0, 0, -9.81))
self._timestep = 1 / world.tick_rate
# # Seems that this does not function
# on_contact_added = PythonCallbackObject(self._on_contact_added)
# self.world.set_contact_added_callback(on_contact_added)
# on_filter = PythonCallbackObject(self._filter_collision)
# self.world.set_filter_callback(on_filter)
self.listener = DirectObject()
self.listener.accept('bullet-contact-added', self._on_contact_added)
self.listener.accept('bullet-contact-destroyed', self._on_contact_removed)
self.tracked_contacts = defaultdict(int)
self.existing_collisions = set()
# Debugging info
debug_node = BulletDebugNode('Debug')
debug_node.showWireframe(True)
debug_node.showConstraints(True)
debug_node.showBoundingBoxes(False)
debug_node.showNormals(False)
# Add to world
self.debug_nodepath = root_nodepath.attachNewNode(debug_node)
self.world.set_debug_node(debug_node)
self.debug_nodepath.show()
示例15: setupPhysics
def setupPhysics(self, use_default_objs = True):
# 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.cam.setPos(self.world_node_,0, -self.cam_zoom_*6, self.cam_step_*25)
self.physics_world_.setGravity(Vec3(0, 0, -9.81))
self.debug_node_ = self.world_node_.attachNewNode(BulletDebugNode('Debug'))
self.debug_node_.show()
self.debug_node_.node().showWireframe(True)
self.debug_node_.node().showConstraints(True)
self.debug_node_.node().showBoundingBoxes(False)
self.debug_node_.node().showNormals(True)
self.physics_world_.setDebugNode(self.debug_node_.node())
self.debug_node_.hide()
self.object_nodes_ = []
self.controlled_objects_ = []
self.ground_ = None
if use_default_objs:
# 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(BitMask32.allOn())
self.physics_world_.attachRigidBody(self.ground_.node())
self.setupLevel()