本文整理汇总了Python中panda3d.bullet.BulletWorld.attachSoftBody方法的典型用法代码示例。如果您正苦于以下问题:Python BulletWorld.attachSoftBody方法的具体用法?Python BulletWorld.attachSoftBody怎么用?Python BulletWorld.attachSoftBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.bullet.BulletWorld
的用法示例。
在下文中一共展示了BulletWorld.attachSoftBody方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachSoftBody [as 别名]
#.........这里部分代码省略.........
def doReset(self):
self.cleanup()
self.setup()
def toggleWireframe(self):
base.toggleWireframe()
def toggleTexture(self):
base.toggleTexture()
def toggleDebug(self):
if self.debugNP.isHidden():
self.debugNP.show()
else:
self.debugNP.hide()
def doScreenshot(self):
base.screenshot('Bullet')
# ____TASK___
def update(self, task):
dt = globalClock.getDt()
#dt *= 0.01
self.world.doPhysics(dt, 10, 0.008)
return task.cont
def cleanup(self):
self.world = None
self.worldNP.removeNode()
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
def makeSB(pos, hpr):
import torus
geom = torus.makeGeom()
#geom = loader.loadModel('models/torus.egg') \
# .findAllMatches('**/+GeomNode').getPath(0).node() \
# .modifyGeom(0)
geomNode = GeomNode('')
geomNode.addGeom(geom)
node = BulletSoftBodyNode.makeTriMesh(info, geom)
node.linkGeom(geomNode.modifyGeom(0))
node.generateBendingConstraints(2)
node.getCfg().setPositionsSolverIterations(2)
node.getCfg().setCollisionFlag(BulletSoftBodyConfig.CFVertexFaceSoftSoft, True)
node.randomizeConstraints()
node.setTotalMass(50, True)
softNP = self.worldNP.attachNewNode(node)
softNP.setPos(pos)
softNP.setHpr(hpr)
self.world.attachSoftBody(node)
geomNP = softNP.attachNewNode(geomNode)
makeSB(Point3(-3, 0, 4), (0, 0, 0))
makeSB(Point3(0, 0, 4), (0, 90, 90))
makeSB(Point3(3, 0, 4), (0, 0, 0))
示例2: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachSoftBody [as 别名]
#.........这里部分代码省略.........
else:
self.debugNP.hide()
def doScreenshot(self):
base.screenshot('Bullet')
# ____TASK___
def update(self, task):
dt = globalClock.getDt()
self.world.doPhysics(dt, 10, 0.008)
return task.cont
def cleanup(self):
self.world = None
self.worldNP.removeNode()
def setup(self):
self.worldNP = render.attachNewNode('World')
# World
self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
self.debugNP.show()
#self.debugNP.showTightBounds()
#self.debugNP.showBounds()
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())
# Stair
origin = Point3(0, 0, 0)
size = Vec3(2, 10, 1)
shape = BulletBoxShape(size * 0.5)
for i in range(10):
pos = origin + size * i
pos.setY(0)
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Stair%i' % i))
np.node().addShape(shape)
np.setPos(pos)
np.setCollideMask(BitMask32.allOn())
npV = loader.loadModel('models/box.egg')
npV.reparentTo(np)
npV.setScale(size)
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
center = Point3(0, 0, 0)
radius = Vec3(1, 1, 1) * 1.5
node = BulletSoftBodyNode.makeEllipsoid(info, center, radius, 128)
node.setName('Ellipsoid')
node.getMaterial(0).setLinearStiffness(0.1)
node.getCfg().setDynamicFrictionCoefficient(1)
node.getCfg().setDampingCoefficient(0.001)
node.getCfg().setPressureCoefficient(1500)
node.setTotalMass(30, True)
node.setPose(True, False)
np = self.worldNP.attachNewNode(node)
np.setPos(15, 0, 12)
#np.setH(90.0)
#np.showBounds()
#np.showTightBounds()
self.world.attachSoftBody(np.node())
geom = BulletHelper.makeGeomFromFaces(node)
node.linkGeom(geom)
nodeV = GeomNode('EllipsoidVisual')
nodeV.addGeom(geom)
npV = np.attachNewNode(nodeV)
示例3: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachSoftBody [as 别名]
#.........这里部分代码省略.........
def toggleDebug(self):
if self.debugNP.isHidden():
self.debugNP.show()
else:
self.debugNP.hide()
def doScreenshot(self):
base.screenshot('Bullet')
# ____TASK___
def update(self, task):
dt = globalClock.getDt()
self.world.doPhysics(dt, 10, 0.004)
return task.cont
def cleanup(self):
self.world = None
self.worldNP.removeNode()
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())
# 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
def make(p1):
n = 8
p2 = p1 + Vec3(10, 0, 0)
bodyNode = BulletSoftBodyNode.makeRope(info, p1, p2, n, 1)
bodyNode.setTotalMass(50.0)
bodyNP = self.worldNP.attachNewNode(bodyNode)
self.world.attachSoftBody(bodyNode)
# Render option 1: Line geom
#geom = BulletSoftBodyNode.makeGeomFromLinks(bodyNode)
#bodyNode.linkGeom(geom)
#visNode = GeomNode('')
#visNode.addGeom(geom)
#visNP = bodyNP.attachNewNode(visNode)
# Render option 2: NURBS curve
curve = NurbsCurveEvaluator()
curve.reset(n + 2)
bodyNode.linkCurve(curve)
visNode = RopeNode('')
visNode.setCurve(curve)
visNode.setRenderMode(RopeNode.RMTube)
visNode.setUvMode(RopeNode.UVParametric)
visNode.setNumSubdiv(4)
visNode.setNumSlices(8)
visNode.setThickness(0.4)
visNP = self.worldNP.attachNewNode(visNode)
#visNP = bodyNP.attachNewNode(visNode) # --> renders with offset!!!
visNP.setTexture(loader.loadTexture('models/iron.jpg'))
#bodyNP.showBounds()
#visNP.showBounds()
return bodyNP
np1 = make(Point3(-2, -1, 8))
np2 = make(Point3(-2, 1, 8))
# Box
shape = BulletBoxShape(Vec3(2, 2, 6))
boxNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
boxNP.node().setMass(50.0)
boxNP.node().addShape(shape)
boxNP.setPos(10, 0, 8)
boxNP.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(boxNP.node())
np1.node().appendAnchor(np1.node().getNumNodes() - 1, boxNP.node())
np2.node().appendAnchor(np1.node().getNumNodes() - 1, boxNP.node())
visNP = loader.loadModel('models/box.egg')
visNP.clearModelNodes()
visNP.setScale(4, 4, 12)
visNP.reparentTo(boxNP)
示例4: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachSoftBody [as 别名]
#.........这里部分代码省略.........
def doScreenshot(self):
base.screenshot('Bullet')
# ____TASK___
def update(self, task):
dt = globalClock.getDt()
self.world.doPhysics(dt, 10, 0.008)
return task.cont
def cleanup(self):
self.world = None
self.worldNP.removeNode()
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, -4)
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 - From points/indices
#import cube
#points = [Point3(x,y,z) * 3 for x,y,z in cube.nodes]
#indices = sum([list(x) for x in cube.elements], [])
#node = BulletSoftBodyNode.makeTetMesh(info, points, indices, True)
#node.setVolumeMass(300);
#node.getShape(0).setMargin(0.01)
#node.getMaterial(0).setLinearStiffness(0.8)
#node.getCfg().setPositionsSolverIterations(1)
#node.getCfg().clearAllCollisionFlags()
#node.getCfg().setCollisionFlag(BulletSoftBodyConfig.CFClusterSoftSoft, True)
#node.getCfg().setCollisionFlag(BulletSoftBodyConfig.CFClusterRigidSoft, True)
#node.generateClusters(16)
#softNP = self.worldNP.attachNewNode(node)
#softNP.setPos(0, 0, 8)
#softNP.setHpr(0, 0, 45)
#self.world.attachSoftBody(node)
# Softbody - From tetgen data
ele = file('models/cube/cube.1.ele', 'r').read()
face = file('models/cube/cube.1.face', 'r').read()
node = file('models/cube/cube.1.node', 'r').read()
node = BulletSoftBodyNode.makeTetMesh(info, ele, face, node)
node.setName('Tetra')
node.setVolumeMass(300)
node.getShape(0).setMargin(0.01)
node.getMaterial(0).setLinearStiffness(0.1)
node.getCfg().setPositionsSolverIterations(1)
node.getCfg().clearAllCollisionFlags()
node.getCfg().setCollisionFlag(BulletSoftBodyConfig.CFClusterSoftSoft, True)
node.getCfg().setCollisionFlag(BulletSoftBodyConfig.CFClusterRigidSoft, True)
node.generateClusters(6)
softNP = self.worldNP.attachNewNode(node)
softNP.setPos(0, 0, 8)
softNP.setHpr(45, 0, 0)
self.world.attachSoftBody(node)
# Option 1:
visNP = loader.loadModel('models/cube/cube.egg')
visNP.reparentTo(softNP)
geom = visNP \
.findAllMatches('**/+GeomNode').getPath(0).node() \
.modifyGeom(0)
node.linkGeom(geom)
示例5: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachSoftBody [as 别名]
#.........这里部分代码省略.........
def doReset(self):
self.cleanup()
self.setup()
def toggleWireframe(self):
base.toggleWireframe()
def toggleTexture(self):
base.toggleTexture()
def toggleDebug(self):
if self.debugNP.isHidden():
self.debugNP.show()
else:
self.debugNP.hide()
def doScreenshot(self):
base.screenshot('Bullet')
# ____TASK___
def update(self, task):
dt = globalClock.getDt()
self.world.doPhysics(dt, 10, 0.008)
return task.cont
def cleanup(self):
self.world = None
self.worldNP.removeNode()
@staticmethod
def Vec3Rand():
x = 2 * random.random() - 1
y = 2 * random.random() - 1
z = 2 * random.random() - 1
return Vec3(x, y, z)
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)
示例6: __init__
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachSoftBody [as 别名]
#.........这里部分代码省略.........
# print (vdata,vdata.hasColumn(InternalName.getVertex()))
geomNode = GeomNode('')
geomNode.addGeom(geom)
#step 4) create the bullet softbody and node
bodyNode = BulletSoftBodyNode.makeTriMesh(info, geom)
# bodyNode.linkGeom(geomNode.modifyGeom(0))
bodyNode.setName('Tri')
bodyNode.linkGeom(geom)
bodyNode.generateBendingConstraints(1)#???
#bodyNode.getMaterial(0).setLinearStiffness(0.8)
bodyNode.getCfg().setPositionsSolverIterations(4)
# bodyNode.getCfg().setCollisionFlag(BulletSoftBodyConfig.CFVertexFaceSoftSoft, True)
bodyNode.getCfg().setDynamicFrictionCoefficient(1)
bodyNode.getCfg().setDampingCoefficient(0.001)
bodyNode.getCfg().setPressureCoefficient(15000*10.0)
bodyNode.getCfg().setPoseMatchingCoefficient(0.2)
bodyNode.setPose(True, True)
# bodyNode.randomizeConstraints()
bodyNode.setTotalMass(50000*10, True)
bodyNP = self.worldNP.attachNewNode(bodyNode)
# fmt = GeomVertexFormat.getV3n3t2()
# geom = BulletHelper.makeGeomFromFaces(bodyNode, fmt,True)
# bodyNode.linkGeom(geomNode.modifyGeom(0))
# geomNode = GeomNode('')
# geomNode.addGeom(geom)
# world.attachSoftBody(bodyNode)
# inodenp.setPos(0, 0, 0.1)
# self.setRB(bodyNP,**kw)#set po
# inodenp.setCollideMask(BitMask32.allOn())
self.world.attachSoftBody(bodyNode)
geomNP = bodyNP.attachNewNode(geomNode)
return bodyNP,geomNP
def addTetraMeshSB(self,vertices, faces,normals = None,ghost=False,**kw):
#step 1) create GeomVertexData and add vertex information
# Soft body world information
info = self.world.getWorldInfo()
info.setAirDensity(1.2)
info.setWaterDensity(0)
info.setWaterOffset(0)
info.setWaterNormal(Vec3(0, 0, 0))
points = [Point3(x,y,z) * 3 for x,y,z in vertices]
indices = sum([list(x) for x in faces], [])
#step 4) create the bullet softbody and node
bodyNode = BulletSoftBodyNode.makeTetMesh(info, points, indices, True)
bodyNode.setName('Tetra')
bodyNode.setVolumeMass(150000)
bodyNode.getShape(0).setMargin(0.01)
bodyNode.getMaterial(0).setLinearStiffness(0.9)
bodyNode.getCfg().setPositionsSolverIterations(4)
bodyNode.getCfg().clearAllCollisionFlags()
bodyNode.getCfg().setCollisionFlag(BulletSoftBodyConfig.CFClusterSoftSoft, True)
bodyNode.getCfg().setCollisionFlag(BulletSoftBodyConfig.CFClusterRigidSoft, True)
bodyNode.generateClusters(12)
bodyNode.setPose(True, True)
bodyNP = self.worldNP.attachNewNode(bodyNode)
geom = BulletHelper.makeGeomFromFaces(bodyNode)
geomNode = GeomNode('vtetra')
geomNode.addGeom(geom)
示例7: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachSoftBody [as 别名]
#.........这里部分代码省略.........
def doReset(self):
self.cleanup()
self.setup()
def toggleWireframe(self):
base.toggleWireframe()
def toggleTexture(self):
base.toggleTexture()
def toggleDebug(self):
if self.debugNP.isHidden():
self.debugNP.show()
else:
self.debugNP.hide()
def doScreenshot(self):
base.screenshot('Bullet')
# ____TASK___
def update(self, task):
dt = globalClock.getDt()
self.world.doPhysics(dt, 10, 0.004)
return task.cont
def cleanup(self):
self.world = None
self.worldNP.removeNode()
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())
# Box
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5) * 2.0)
boxNP = self.worldNP.attachNewNode(BulletRigidBodyNode('Box'))
boxNP.node().setMass(150.0)
boxNP.node().addShape(shape)
boxNP.setPos(0, 0, 2)
boxNP.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(boxNP.node())
visualNP = loader.loadModel('models/box.egg')
visualNP.clearModelNodes()
visualNP.setScale(2.0)
visualNP.reparentTo(boxNP)
# 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
nx = 31
ny = 31
p00 = Point3(-8, -8, 0)
p10 = Point3( 8, -8, 0)
p01 = Point3(-8, 8, 0)
p11 = Point3( 8, 8, 0)
bodyNode = BulletSoftBodyNode.makePatch(info, p00, p10, p01, p11, nx, ny, 1+2+4+8, True)
material = bodyNode.appendMaterial()
material.setLinearStiffness(0.4)
bodyNode.generateBendingConstraints(2, material);
bodyNode.setTotalMass(50.0)
bodyNode.getShape(0).setMargin(0.5)
bodyNP = self.worldNP.attachNewNode(bodyNode)
self.world.attachSoftBody(bodyNode)
# Rendering with Geom:
fmt = GeomVertexFormat.getV3n3t2()
geom = BulletHelper.makeGeomFromFaces(bodyNode, fmt, True)
bodyNode.linkGeom(geom)
visNode = GeomNode('')
visNode.addGeom(geom)
visNP = bodyNP.attachNewNode(visNode)
# Now we want to have a texture and texture coordinates.
# The geom's format has already a column for texcoords, so we just need
# to write texcoords using a GeomVertexRewriter.
tex = loader.loadTexture('models/panda.jpg')
visNP.setTexture(tex)
BulletHelper.makeTexcoordsForPatch(geom, nx, ny)