Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import direct.directbase.DirectStart
- from panda3d.core import Vec3, NodePath
- from panda3d.bullet import BulletWorld, BulletDebugNode
- from panda3d.bullet import BulletPlaneShape
- from panda3d.bullet import BulletRigidBodyNode
- from panda3d.bullet import BulletBoxShape
- base.cam.setPos(10, -30, 20)
- base.cam.lookAt(0, 0, 5)
- # World
- world = BulletWorld()
- world.setGravity(Vec3(0, 0, -9.81))
- # Root node A, its content node and neighbour node
- node_A = NodePath("region_node_A")
- content_A = NodePath("region_content_node_A")
- neighbour_A_to_B = NodePath("region_A_to_B")
- neighbour_A_to_B.reparentTo(node_A)
- # Root node B and its content
- node_B = NodePath("region_node_B")
- content_B = NodePath("region_content_node_B")
- neighbour_B_to_A = NodePath("region_B_to_A")
- neighbour_B_to_A.reparentTo(node_B)
- # Reparent content_A to node_A and content_B to node_B
- node_A.attachNewNode(content_A.node())
- node_B.attachNewNode(content_B.node())
- neighbour_A_to_B.attachNewNode(content_B.node())
- neighbour_B_to_A.attachNewNode(content_A.node())
- ## A to render!
- node_B.reparentTo(render)
- neighbour_A_to_B.setPos(-2.5, 0, 0)
- neighbour_B_to_A.setPos(-5.0, 0, 0)
- # Plane
- shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
- node = BulletRigidBodyNode('Ground')
- node.addShape(shape)
- np = render.attachNewNode(node)
- np.setPos(0, 0, -2)
- world.attachRigidBody(node)
- ## Debug on
- debugNode = BulletDebugNode('Debug')
- debugNode.showWireframe(True)
- debugNode.showConstraints(True)
- debugNode.showBoundingBoxes(False)
- debugNode.showNormals(False)
- debugNP = render.attachNewNode(debugNode)
- debugNP.show()
- world.setDebugNode(debugNP.node())
- # Boxes
- model = loader.loadModel('models/box.egg')
- model.setPos(-0.5, -0.5, -0.5)
- model.flattenLight()
- shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
- for i in range(10):
- node = BulletRigidBodyNode('Box')
- node.setMass(1.0)
- node.addShape(shape)
- np = None
- if i < 5:
- np = content_A.attachNewNode(node)
- else:
- np = content_B.attachNewNode(node)
- np.setPos(0, 0, 2+i*2)
- world.attachRigidBody(node)
- model.copyTo(np)
- # Update
- def update(task):
- dt = globalClock.getDt()
- world.doPhysics(dt)
- return task.cont
- taskMgr.add(update, 'update')
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement