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)
Exemple #2
0
    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)
        
#        self.setRB(bodyNP,**kw)#set po
#        inodenp.setCollideMask(BitMask32.allOn())
        self.world.attachSoftBody(bodyNode)
        geomNP = bodyNP.attachNewNode(geomNode)
        bodyNode.linkGeom(geom)
        return bodyNP,geomNP
Exemple #3
0
    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.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)
  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)
Exemple #6
0
    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)
    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)