我正在使用Bullet开源物理库1.5.8使用Panda3D 1.10编写游戏。如何从鸡蛋文件生成碰撞形状?
这是我到目前为止的代码:
tree = BulletRigidBodyNode('Tree')
tree.setMass(10.0)
shape = getCollisionFromEgg('tree.egg') # This is the 'magic function' I'm after
tree.addShape(shape)
np = render.attachNewNode(tree)
np.setPos(10, 0, 2)
self.world.attachRigidBody(tree)
model = loader.loadModel('tree.egg')
model.reparentTo(np)
我认为我有一个灵魂,但是,我也有问题。
def toShape(model):
shape=BulletTriangleMesh()
geomNodeCollection = model.findAllMatches('**/+GeomNode')
for nodePath in geomNodeCollection:
geomNode = nodePath.node()
for i in range(geomNode.getNumGeoms()):
geom = geomNode.getGeom(i)
state = geomNode.getGeomState(i)
shape.addGeom(geom)
shape=BulletTriangleMeshShape(shape, True)
return shape
它看起来像工作,但我有问题...试一试。