GetSwigPtr() public method

public GetSwigPtr ( ) : SWIGTYPE_p_btVector3
return SWIGTYPE_p_btVector3
Exemplo n.º 1
0
    public bool OnBulletCreate()
    {
        if( rigidBodyObj != null ) // have created!
        {
            return true;
        }

        if( CollisionShapeObject == null )   // if user not give a collision, search it on itself first!
            CollisionShapeObject = GetComponent<BCollisionShape>();

        if( CollisionShapeObject == null )
        {
            Debug.LogError("Bullet RigidBody need a collision shape!");
            return false;
        }

        bool cResult = CollisionShapeObject.OnBulletCreate();

        if( cResult == false )
        {
            Debug.LogError("Collision Shape Create Error!");
            return false;
        }

        btTransform trans = new btTransform();
        trans.setIdentity();
        btVector3 pos = new btVector3(transform.position.x,transform.position.y,transform.position.z);
        trans.setOrigin(pos);
        trans.setRotation(new btQuaternion(transform.rotation.x,transform.rotation.y,transform.rotation.z,transform.rotation.w));

        //rigidbody is dynamic if and only if mass is non zero, otherwise static
        bool isDynamic = (Mass != 0.0f);

        btVector3 localInertia = new btVector3(0,0,0);
        if (isDynamic)
        {
             CollisionShapeObject.CalculateLocalInertia(Mass,localInertia);
        }

        //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
        myMotionState = new btDefaultMotionState(trans);
        rbInfo = new btRigidBodyConstructionInfo(Mass,myMotionState.GetSwigPtr(),CollisionShapeObject.GetCollisionShapePtr(),localInertia.GetSwigPtr());
        rigidBodyObj = new btRigidBody(rbInfo);
        collisionObject = btCollisionObject.GetObjectFromSwigPtr(rigidBodyObj.GetCollisionObject());
        collisionObject.setFriction(Friction);
        return true;
    }
Exemplo n.º 2
0
    public bool OnBulletCreate()
    {
        if( ConstraintType == ConstraintTypes.Point2Point )
        {
            if( RigidBodyA != null && RigidBodyB == null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                point2pointConstraint = new btPoint2PointConstraint(rA,vecA.GetSwigPtr());
                constraintPtr = point2pointConstraint.GetSwigPtr();
                return true;
            }
            else if( RigidBodyA != null && RigidBodyB != null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                btVector3 vecB = new btVector3(PivotInB.x,PivotInB.y,PivotInB.z);
                btRigidBody rB = RigidBodyB.GetRigidBody();
                if( rB == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                point2pointConstraint = new btPoint2PointConstraint(rA,rB,vecA.GetSwigPtr(),vecB.GetSwigPtr());
                constraintPtr = point2pointConstraint.GetSwigPtr();
                return true;
            }

            return false;
        }
        else if( ConstraintType == ConstraintTypes.Hinge )
        {
            if( RigidBodyA != null && RigidBodyB == null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btVector3 axisA = new btVector3(AxisInA.x,AxisInA.y,AxisInA.z);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                hingeConstraint = new btHingeConstraint(rA,vecA.GetSwigPtr(),axisA.GetSwigPtr(),useReferenceFrameAHinge);
                constraintPtr = hingeConstraint.GetSwigPtr();
                return true;
            }
            else if( RigidBodyA != null && RigidBodyB != null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btVector3 axisA = new btVector3(AxisInA.x,AxisInA.y,AxisInA.z);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                btVector3 vecB = new btVector3(PivotInB.x,PivotInB.y,PivotInB.z);
                btVector3 axisB = new btVector3(AxisInB.x,AxisInB.y,AxisInB.z);
                btRigidBody rB = RigidBodyB.GetRigidBody();
                if( rB == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                hingeConstraint = new btHingeConstraint(rA,rB,vecA.GetSwigPtr(),vecB.GetSwigPtr(),axisA.GetSwigPtr(),axisB.GetSwigPtr(),useReferenceFrameAHinge);
                constraintPtr = hingeConstraint.GetSwigPtr();
                return true;
            }

            return false;
        }
        else if( ConstraintType == ConstraintTypes.Slider )
        {
            if( RigidBodyA != null && RigidBodyB == null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btQuaternion rot = new btQuaternion(RotationA.x,RotationA.y,RotationA.z);
                btTransform transA = new btTransform();
                transA.setIdentity();
                transA.setOrigin(vecA);
                transA.setRotation(rot);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                sliderConstraint = new btSliderConstraint(rA,transA.GetSwigPtr(),useLinearReferenceFrameASlider);
                constraintPtr = sliderConstraint.GetSwigPtr();
                return true;
            }
            else if( RigidBodyA != null && RigidBodyB != null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btQuaternion rotA = new btQuaternion(RotationA.x,RotationA.y,RotationA.z);
                btTransform transA = new btTransform();
                transA.setIdentity();
                transA.setOrigin(vecA);
                transA.setRotation(rotA);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                btVector3 vecB = new btVector3(PivotInB.x,PivotInB.y,PivotInB.z);
                btQuaternion rotB = new btQuaternion(RotationB.x,RotationB.y,RotationB.z);
                btTransform transB = new btTransform();
                transB.setIdentity();
                transB.setOrigin(vecB);
                transB.setRotation(rotB);
                btRigidBody rB = RigidBodyB.GetRigidBody();
                if( rB == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                sliderConstraint = new btSliderConstraint(rA,rB,transA.GetSwigPtr(),transB.GetSwigPtr(), useLinearReferenceFrameASlider);
                constraintPtr = sliderConstraint.GetSwigPtr();
                return true;
            }

            return false;
        }
        else if( ConstraintType == ConstraintTypes.ConeTwist )
        {
            if( RigidBodyA != null && RigidBodyB == null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btQuaternion rot = new btQuaternion(RotationA.x,RotationA.y,RotationA.z);
                btTransform transA = new btTransform();
                transA.setIdentity();
                transA.setOrigin(vecA);
                transA.setRotation(rot);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                coneTwistConstraint = new btConeTwistConstraint(rA,transA.GetSwigPtr());
                constraintPtr = coneTwistConstraint.GetSwigPtr();
                return true;
            }
            else if( RigidBodyA != null && RigidBodyB != null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btQuaternion rotA = new btQuaternion(RotationA.x,RotationA.y,RotationA.z);
                btTransform transA = new btTransform();
                transA.setIdentity();
                transA.setOrigin(vecA);
                transA.setRotation(rotA);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                btVector3 vecB = new btVector3(PivotInB.x,PivotInB.y,PivotInB.z);
                btQuaternion rotB = new btQuaternion(RotationB.x,RotationB.y,RotationB.z);
                btTransform transB = new btTransform();
                transB.setIdentity();
                transB.setOrigin(vecB);
                transB.setRotation(rotB);
                btRigidBody rB = RigidBodyB.GetRigidBody();
                if( rB == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                coneTwistConstraint = new btConeTwistConstraint(rA,rB,transA.GetSwigPtr(),transB.GetSwigPtr());
                constraintPtr = coneTwistConstraint.GetSwigPtr();
                return true;
            }

            return false;
        }
        else if( ConstraintType == ConstraintTypes.Gear )
        {
            if( RigidBodyA != null && RigidBodyB != null )
            {
                btVector3 axisA = new btVector3(AxisInA.x,AxisInA.y,AxisInA.z);
                btVector3 axisB = new btVector3(AxisInB.x,AxisInB.y,AxisInB.z);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                btRigidBody rB = RigidBodyB.GetRigidBody();
                if( rB == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                gearConstraint = new btGearConstraint(rA,rB,axisA.GetSwigPtr(),axisB.GetSwigPtr(),GearConstraintRatio);
                constraintPtr = gearConstraint.GetSwigPtr();
                return true;
            }
            return false;
        }
        else if( ConstraintType == ConstraintTypes.Generic6Dof )
        {
            if( RigidBodyA != null && RigidBodyB != null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btQuaternion rotA = new btQuaternion(RotationA.x,RotationA.y,RotationA.z);
                btTransform transA = new btTransform();
                transA.setIdentity();
                transA.setOrigin(vecA);
                transA.setRotation(rotA);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                btVector3 vecB = new btVector3(PivotInB.x,PivotInB.y,PivotInB.z);
                btQuaternion rotB = new btQuaternion(RotationB.x,RotationB.y,RotationB.z);
                btTransform transB = new btTransform();
                transB.setIdentity();
                transB.setOrigin(vecB);
                transB.setRotation(rotB);
                btRigidBody rB = RigidBodyB.GetRigidBody();
                if( rB == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                generic6Dof = new btGeneric6DofConstraint(rA,rB,transA.GetSwigPtr(),transB.GetSwigPtr(),useLinearReferenceFrameASlider);
                if( UseLinearLimit )
                {
                    btVector3 lowerVec = new btVector3(LinearLowerLimit.x,LinearLowerLimit.y,LinearLowerLimit.z);
                    btVector3 uppderVec = new btVector3(LinearUpperLimit.x,LinearUpperLimit.y,LinearUpperLimit.z);
                    generic6Dof.setLinearLowerLimit(lowerVec.GetSwigPtr());
                    generic6Dof.setLinearUpperLimit(uppderVec.GetSwigPtr());
                }
                if( UseAngularLimit )
                {
                    btVector3 lowerVec = new btVector3(AngularLowerLimit.x,AngularLowerLimit.y,AngularLowerLimit.z);
                    btVector3 uppderVec = new btVector3(AngularUpperLimit.x,AngularUpperLimit.y,AngularUpperLimit.z);
                    generic6Dof.setAngularLowerLimit(lowerVec.GetSwigPtr());
                    generic6Dof.setAngularUpperLimit(uppderVec.GetSwigPtr());
                }

                constraintPtr = generic6Dof.GetSwigPtr();
                return true;
            }

            return false;
        }

        return false;
    }
Exemplo n.º 3
0
 public void CalculateLocalInertia(float mass,btVector3 intertiaVec)
 {
     if( ShapeType == CollisionShapeType.BoxShape && boxShape != null)
     {
          boxShape.calculateLocalInertia(mass,intertiaVec.GetSwigPtr());
     }
     else if( ShapeType == CollisionShapeType.SphereShape && sphereShape != null)
     {
         sphereShape.calculateLocalInertia(mass,intertiaVec.GetSwigPtr());
     }
     else if( ShapeType == CollisionShapeType.CapsuleShape && capsuleShape != null)
     {
         capsuleShape.calculateLocalInertia(mass,intertiaVec.GetSwigPtr());
     }
     else if( ShapeType == CollisionShapeType.CylinderShape && cylinderShape != null)
     {
         cylinderShape.calculateLocalInertia(mass,intertiaVec.GetSwigPtr());
     }
     else if( ShapeType == CollisionShapeType.ConeShape && coneShape != null)
     {
         coneShape.calculateLocalInertia(mass,intertiaVec.GetSwigPtr());
     }
     else if( ShapeType == CollisionShapeType.ConvexHull && convexPolyhedral != null )
     {
         convexPolyhedral.calculateLocalInertia(mass,intertiaVec.GetSwigPtr());
     }
     else if( ShapeType == CollisionShapeType.CompoundShape && compoundShape != null )
     {
         compoundShape.calculateLocalInertia(mass,intertiaVec.GetSwigPtr());
     }
     else if( ShapeType == CollisionShapeType.StaticPlaneShape && staticPlaneShape != null)
     {
         staticPlaneShape.calculateLocalInertia(mass,intertiaVec.GetSwigPtr());
     }
 }
Exemplo n.º 4
0
    public bool OnBulletCreate()
    {
        if( collisionShapePtr != null ) // can't be created multi-times
            return true;

        if( ShapeType == CollisionShapeType.BoxShape)
        {
            btVector3 vec = new btVector3(BoxShapeVec.x*transform.localScale.x,BoxShapeVec.y*transform.localScale.y,BoxShapeVec.z*transform.localScale.z);
            boxShape = new btBoxShape(vec.GetSwigPtr());
            collisionShapePtr = boxShape.GetSwigPtr();
        }
        else if( ShapeType == CollisionShapeType.SphereShape)
        {
            float maxFactor = Mathf.Max(transform.localScale.x,transform.localScale.y);
            maxFactor = Mathf.Max(transform.localScale.z,maxFactor);
            sphereShape = new btSphereShape(SphereShapeRadius*maxFactor);
            collisionShapePtr = sphereShape.GetSwigPtr();
        }
        else if( ShapeType == CollisionShapeType.CapsuleShape)
        {
            float maxFactor = Mathf.Max(transform.localScale.x,transform.localScale.z);

            capsuleShape = new btCapsuleShape(CapsuleRadius*maxFactor,CapsuleHeight*transform.localScale.y);
            collisionShapePtr = capsuleShape.GetSwigPtr();
        }
        else if( ShapeType == CollisionShapeType.CylinderShape)
        {
            float maxFactor = Mathf.Max(transform.localScale.x,transform.localScale.z);
            btVector3 vec = new btVector3(CylinderRadius*maxFactor,CylinderHeight*transform.localScale.y,CylinderRadius*maxFactor);
            cylinderShape = new btCylinderShape(vec.GetSwigPtr());
            collisionShapePtr = cylinderShape.GetSwigPtr();
        }
        else if( ShapeType == CollisionShapeType.ConeShape)
        {
            float maxFactor = Mathf.Max(transform.localScale.x,transform.localScale.z);
            coneShape = new btConeShape(ConeRadius*maxFactor,ConeHeight*transform.localScale.y);
            collisionShapePtr = coneShape.GetSwigPtr();
        }
        else if( ShapeType == CollisionShapeType.ConvexHull )
        {
            if(CheckUnityMesh() == false)
                return false;

            List<float> vertexposList = new List<float>();

            for(int index=0;index<meshFilter.mesh.vertexCount;index++)
            {
                Vector3 vec = meshFilter.mesh.vertices[index];
                vertexposList.Add(vec.x);
                vertexposList.Add(vec.y);
                vertexposList.Add(vec.z);
            }

            convexHull = new btConvexHullShape(vertexposList.ToArray(),meshFilter.mesh.vertexCount,3*sizeof(float));
            convexPolyhedral = convexHull.GetPolihedralConvexShape();
            //convexPolyhedral.initializePolyhedralFeatures();
            collisionShapePtr = convexHull.GetSwigPtr();

        }
        else if( ShapeType == CollisionShapeType.CompoundShape )
        {
            // use all its children's collision shapes to create itself...
            if( CollisionShapeArray == null || CollisionShapeArray.Length == 0 )
            {
                Debug.Log("There is no child collision shapes to use CompoundShape!");
                return false;
            }

            compoundShape = new btCompoundShape();

            for( int i=0;i<CollisionShapeArray.Length;i++)
            {
                if( CollisionShapeArray[i] == null )
                    continue;

                if( CollisionShapeArray[i].gameObject == gameObject )
                    continue;

                bool result = CollisionShapeArray[i].OnBulletCreate();
                if( result == false )
                {
                    Debug.Log(" Bullet Collision Create Error!");
                    return false;
                }

                Transform t = CollisionShapeArray[i].transform;
                Matrix4x4 objMatrix = Matrix4x4.TRS(t.localPosition,t.localRotation,t.localScale);

                btVector3 pos = new btVector3(t.localPosition.x,t.localPosition.y,t.localPosition.z);
                btQuaternion rot = new btQuaternion(t.localRotation.x,t.localRotation.y,t.localRotation.z,t.localRotation.w);

                btTransform trans = new btTransform(rot,pos);

                compoundShape.addChildShape(trans.GetSwigPtr(),CollisionShapeArray[i].GetCollisionShapePtr());
            }

            collisionShapePtr = compoundShape.GetSwigPtr();

        }
        else if( ShapeType == CollisionShapeType.BvhTriangleMeshShape )
        {
            if(CheckUnityMesh() == false)
                return false;
            List<float> verList = new List<float>();
            for(int index=0;index<meshFilter.mesh.vertexCount;index++)
            {
                Vector3 vec = meshFilter.mesh.vertices[index];
                //vec = transform.TransformPoint(vec);
                verList.Add(vec.x);
                verList.Add(vec.y);
                verList.Add(vec.z);
            }

            meshVertexArray = verList.ToArray();

            List<int> indexList = new List<int>();
            // Unity3D counter clock-wise to Bullet's clock wise.
            for( int i=0;i< meshFilter.mesh.triangles.Length;i+=3)
            {
                indexList.Add(meshFilter.mesh.triangles[i]);
                indexList.Add(meshFilter.mesh.triangles[i+2]);
                indexList.Add(meshFilter.mesh.triangles[i+1]);
            }

            meshIndexArray = indexList.ToArray();

            triangleArray = new btTriangleIndexVertexArray(indexList.Count/3,meshIndexArray,3*sizeof(int),
                                                                                      meshFilter.mesh.vertexCount,meshVertexArray,3*sizeof(float));
            bvhTriangleMeshShape = new btBvhTriangleMeshShape(triangleArray.GetSwigPtr(),true);
            collisionShapePtr = bvhTriangleMeshShape.GetSwigPtr();
        }
        else if( ShapeType == CollisionShapeType.StaticPlaneShape)
        {
            btVector3 vec = new btVector3(StaticPlaneNormal.x,StaticPlaneNormal.y,StaticPlaneNormal.z);
            staticPlaneShape = new btStaticPlaneShape(vec.GetSwigPtr(),StaticPlaneConstant);
            collisionShapePtr = staticPlaneShape.GetSwigPtr();
        }

        return true;
    }
Exemplo n.º 5
0
    void SetParam()
    {
        if( softBody == null )
            return;

        if( softBodyType == SoftBodyType.Patch )
        {
            softBody.CollisionShapeSetMargin(0.5f);
            BulletCSharp.Material pm=softBody.appendMaterial();
            pm.m_kLST	=	Mathf.Clamp01(MaterialLinearStiffness);
            softBody.generateBendingConstraints(2,pm);
            softBody.setTotalMass(Mass);
        }
        else if( softBodyType == SoftBodyType.Ellipsoid )
        {
            BulletCSharp.Material pm = softBody.m_materials.at(0);
            pm.m_kLST = Mathf.Clamp01(MaterialLinearStiffness);
            softBody.setTotalMass(Mass,true);
            softBody.setPose(true,false);
        }
        else if( softBodyType == SoftBodyType.Rope )
        {
            softBody.m_cfg.piterations = 4; // from softdemo of bullet.
            BulletCSharp.Material pm = softBody.m_materials.at(0);
            pm.m_kLST = Mathf.Clamp01(MaterialLinearStiffness);
            softBody.setTotalMass(Mass);
        }
        else if( softBodyType == SoftBodyType.TriangleMesh )
        {
            softBody.generateBendingConstraints(2);
            softBody.m_cfg.piterations = 2;
            BulletCSharp.Material pm = softBody.m_materials.at(0);
            pm.m_kLST = Mathf.Clamp01(MaterialLinearStiffness);
            softBody.randomizeConstraints();
            softBody.setTotalMass(Mass,true);
        }

        softBody.m_cfg.kDF = Mathf.Clamp01(DynamicFrictionCoefficient);
        softBody.m_cfg.kDP = Mathf.Clamp01(DampingCoefficient);
        softBody.m_cfg.kPR = PressureCoefficient;
        softBody.m_cfg.kVC = Mathf.Max(VolumeConversationCoefficient,0);
        softBody.m_cfg.kCHR = Mathf.Clamp01(RigidContactsHardness);
        softBody.m_cfg.kLF = Mathf.Max(LiftCoefficient);
        softBody.m_cfg.kDG = Mathf.Max(DragCoefficient);

        if( SoftCollisionType == CollisionType.RigidVsSoft )
        {
            softBody.m_cfg.collisions = (int)(fCollision._.SDF_RS);
        }
        else if( SoftCollisionType == CollisionType.SoftVsSoft )
        {
            softBody.m_cfg.collisions = (int)(fCollision._.VF_SS);
        }
        else if( SoftCollisionType == CollisionType.RigidSoftBoth )
        {
            softBody.m_cfg.collisions = (int)(fCollision._.SDF_RS) | (int)(fCollision._.VF_SS);
        }
        else if( SoftCollisionType == CollisionType.RigidVsSoft_Cluster )
        {
            softBody.m_cfg.collisions = (int)(fCollision._.CL_RS);
        }
        else if( SoftCollisionType == CollisionType.SoftVsSoft_Cluster )
        {
            softBody.m_cfg.collisions = (int)(fCollision._.CL_SS);
        }
        else if( SoftCollisionType == CollisionType.RigidSoftBoth_Cluster )
        {
            softBody.m_cfg.collisions = (int)(fCollision._.CL_RS) | (int)(fCollision._.CL_SS);
        }

        if(SoftCollisionType >= CollisionType.RigidVsSoft_Cluster )
        {
            if( SelfCollision )
                softBody.m_cfg.collisions |= (int)(fCollision._.CL_SELF);

            ClusterNum = Mathf.Max(ClusterNum,0);
            softBody.generateClusters(ClusterNum);
        }

        if( bAeroMode )
        {
            softBody.m_cfg.aeromodel = eAeroModel._.V_TwoSided;
        }

        // set anchor
        if( RigidBodyAnchor != null )
        {
            bool result = RigidBodyAnchor.OnBulletCreate();

            if( AnchorNode < 0 )
                AnchorNode = 0;

            if( AnchorNode >= softBody.m_nodes.size() )
                AnchorNode = softBody.m_nodes.size()-1;

            if( result )
            {
                btVector3 pos = new btVector3(0,0,0);
                softBody.appendAnchor(AnchorNode,RigidBodyAnchor.GetRigidBody().GetSwigPtr(),pos.GetSwigPtr());
            }
        }
    }
Exemplo n.º 6
0
    public bool OnBulletCreate(btSoftBodyWorldInfo softBodyWorldInfo)
    {
        if( softBodyType == SoftBodyType.Patch )
        {
            Vector3 c00 = transform.TransformPoint(PatchCorner00);
            Vector3 c01 = transform.TransformPoint(PatchCorner01);
            Vector3 c10 = transform.TransformPoint(PatchCorner10);
            Vector3 c11 = transform.TransformPoint(PatchCorner11);

            btVector3 corner00 = new btVector3(c00.x,c00.y,c00.z);
            btVector3 corner01 = new btVector3(c01.x,c01.y,c01.z);
            btVector3 corner10 = new btVector3(c10.x,c10.y,c10.z);
            btVector3 corner11 = new btVector3(c11.x,c11.y,c11.z);

            int fixFlag = 0;
            if( CornerFix00 )
                fixFlag = 1;
            if ( CornerFix01 )
                fixFlag += 4;
            if( CornerFix10 )
                fixFlag += 2;
            if( CornerFix11 )
                fixFlag += 8;

            softBody = btSoftBodyHelpers.CreatePatch(softBodyWorldInfo,corner00.GetSwigPtr(),corner10.GetSwigPtr(),corner01.GetSwigPtr(),corner11.GetSwigPtr(),
                                                     PatchResolutionX,PatchResolutionY,fixFlag,true);
            collisionObject = btCollisionObject.GetObjectFromSwigPtr(softBody.GetCollisionObject());

            SetParam();
            SpawnMesh();

            return true;
        }
        else if( softBodyType == SoftBodyType.Ellipsoid )
        {
            btVector3 center = new btVector3(transform.position.x,transform.position.y,transform.position.z);
            btVector3 radius = new btVector3(EllipsoidRadius.x*transform.localScale.x,EllipsoidRadius.y*transform.localScale.y,
                                             EllipsoidRadius.z*transform.localScale.z);

            softBody = btSoftBodyHelpers.CreateEllipsoid(softBodyWorldInfo,center.GetSwigPtr(),radius.GetSwigPtr(),MeshResolution);
            SetParam();
            SpawnMesh();
            return true;
        }
        else if( softBodyType == SoftBodyType.Rope )
        {
            int fixFlag = 0;
            if(FixRopeBegin)
                fixFlag += 1;
            if( FixRopeEnd )
                fixFlag += 2;
            Vector3 begin = transform.TransformPoint(RopeFromPos);
            Vector3 end = transform.TransformPoint(RopeToPos);
            btVector3 fromPos = new btVector3(begin.x,begin.y,begin.z);
            btVector3 toPos = new btVector3(end.x,end.y,end.z);
            softBody = btSoftBodyHelpers.CreateRope(softBodyWorldInfo,fromPos.GetSwigPtr(),toPos.GetSwigPtr(),RopeResolution,fixFlag);
            SetParam();
            SpawnLineRender();
            return true;
        }
        else if( softBodyType == SoftBodyType.TriangleMesh )
        {
            if(CheckUnityMesh() == false)
                return false;

            CreateBulletStyleMesh();

            List<float> vertexposList = new List<float>();

            for(int index=0;index<btVectorArray.Length;index++)
            {
                Vector3 vec = btVectorArray[index];
                vec = transform.TransformPoint(vec);
                vertexposList.Add(vec.x);
                vertexposList.Add(vec.y);
                vertexposList.Add(vec.z);
            }

            softBody = btSoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo,vertexposList.ToArray(),btTriangleArray,btTriangleArray.Length/3);
            SetParam();
            return true;
        }
        return false;
    }
Exemplo n.º 7
0
    void CreateSoftDynamicsWorld()
    {
        btVector3 gravityVec = new btVector3(Gravity.x, Gravity.y, Gravity.z);
        btCollisionObject tempObject = new btCollisionObject();
        btConstraintSetting tempObject2 = new btConstraintSetting();

        softBodyWorldInfo = new btSoftBodyWorldInfo();
        ///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
        softCollisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();

        ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
        dispatcher = new btCollisionDispatcher(softCollisionConfiguration.GetSwigPtr());
        softBodyWorldInfo.m_dispatcher = dispatcher.GetSwigPtr();

        btVector3 worldAabbMin = new btVector3(-1000,-1000,-1000);
        btVector3 worldAabbMax = new btVector3(1000,1000,1000);

        axisBroadphase = new btAxisSweep3(worldAabbMin.GetSwigPtr(),worldAabbMax.GetSwigPtr(),32766);
        softBodyWorldInfo.m_broadphase = axisBroadphase.GetSwigPtr();
        ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
        solver = new btSequentialImpulseConstraintSolver();

        softDynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher.GetSwigPtr(), axisBroadphase.GetSwigPtr(), solver.GetSwigPtr(), softCollisionConfiguration.GetSwigPtr());
        dynamicsWorld = btDiscreteDynamicsWorld.GetObjectFromSwigPtr(softDynamicsWorld.getDiscreteDynamicsWorld());
        SWIGTYPE_p_btCollisionWorld collisionWorldPtr = dynamicsWorld.getCollisionWorld();
        collisionWorld = btCollisionWorld.GetObjectFromSwigPtr(collisionWorldPtr);
        dynamicsWorld.setGravity(gravityVec.GetSwigPtr());
        softBodyWorldInfo.m_gravity = gravityVec.GetSwigPtr();
        btVector3 water_nomalVec = new btVector3(0,0,0);
        softBodyWorldInfo.air_density		=	1.2f;
        softBodyWorldInfo.water_density	    =	0;
        softBodyWorldInfo.water_offset		=	0;
        softBodyWorldInfo.water_normal		=	water_nomalVec.GetSwigPtr();
        sparseSdf = softBodyWorldInfo.m_sparsesdf;
        sparseSdf.Initialize();
        AddBulletObjects();
    }
Exemplo n.º 8
0
    void CreateDiscreteDynamicsWorld()
    {
        btVector3 gravityVec = new btVector3(Gravity.x, Gravity.y, Gravity.z);
        ///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
        collisionConfiguration = new btDefaultCollisionConfiguration();

        ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
        dispatcher = new btCollisionDispatcher(collisionConfiguration.GetSwigPtr());

        ///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep.
        overlappingPairCache = new btDbvtBroadphase();

        ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
        solver = new btSequentialImpulseConstraintSolver();

        dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher.GetSwigPtr(), overlappingPairCache.GetSwigPtr(), solver.GetSwigPtr(), collisionConfiguration.GetSwigPtr());

        SWIGTYPE_p_btCollisionWorld collisionWorldPtr = dynamicsWorld.getCollisionWorld();
        collisionWorld = btCollisionWorld.GetObjectFromSwigPtr(collisionWorldPtr);

        dynamicsWorld.setGravity(gravityVec.GetSwigPtr());

        AddBulletObjects();
    }