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)
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)
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)
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)