Esempio n. 1
0
 public void Activate()
 {
     if (TxNative.WorldObjectExists(worldID, objectID))
     {
         TxNative.WorldObjectSetActive(worldID, objectID, true);
     }
 }
Esempio n. 2
0
 public void Disable()
 {
     if (TxNative.WorldObjectExists(worldID, objectID))
     {
         TxNative.WorldObjectSetEnabled(worldID, objectID, false);
     }
 }
Esempio n. 3
0
 protected override void OnValidate()
 {
     base.OnValidate();
     m_margin         = Mathf.Max(m_margin, 0.001f);
     m_adiabaticIndex = Mathf.Clamp(m_adiabaticIndex, 1.1f, 11.1f);
     m_massScale      = Mathf.Max(m_massScale, 0.01f);
     if (Application.isPlaying && TxNative.WorldExists(worldID))
     {
         TxNative.TrussInstanceSetMassScale(worldID, m_trussInstanceID, m_massScale);
         if (m_filling)
         {
             TxNative.TrussInstanceSetInternalPressure(worldID, m_trussInstanceID, m_internalPressure);
             TxNative.TrussInstanceSetAdiabaticIndex(worldID, m_trussInstanceID, m_adiabaticIndex);
         }
         else
         {
             TxNative.TrussInstanceSetInternalPressure(worldID, m_trussInstanceID, 0);
             TxNative.TrussInstanceSetAdiabaticIndex(worldID, m_trussInstanceID, 0);
         }
         if (m_deactivation)
         {
             TxNative.TrussInstanceSetDeactivationSpeed(worldID, m_trussInstanceID, m_deactivationSpeed);
             TxNative.TrussInstanceSetDeactivationTime(worldID, m_trussInstanceID, m_deactivationTime);
         }
         else
         {
             TxNative.TrussInstanceSetDeactivationSpeed(worldID, m_trussInstanceID, 0);
             TxNative.TrussInstanceSetDeactivationTime(worldID, m_trussInstanceID, float.MaxValue);
         }
         TxNative.TrussInstanceSetFastRotation(worldID, m_trussInstanceID, m_fastRotation);
     }
     m_spawnActive = m_spawnEnabled ? m_spawnActive : false;
 }
Esempio n. 4
0
 protected override void OnBeforeStep()
 {
     if (m_rigidBody)
     {
         Rigidbody rb = m_rigidBody;
         TxNative.RigidInstanceSetLocation(worldID, m_rigidInstanceID, m_prevPosition, m_prevRotation);
         Vector3 linearVelocity = (rb.worldCenterOfMass - m_prevCenterOfMass) / Time.fixedDeltaTime;
         float   angle; Vector3 axis; (rb.rotation * Quaternion.Inverse(m_prevRotation)).ToAngleAxis(out angle, out axis);
         Vector3 angularVelocity = axis * angle * Mathf.Deg2Rad / Time.fixedDeltaTime;
         TxNative.RigidInstanceSetVelocity(worldID, m_rigidInstanceID, linearVelocity, angularVelocity);
         if (TxNative.WorldObjectGetEnabled(worldID, objectID))
         {
             if (rb.IsSleeping() == TxNative.WorldObjectGetActive(worldID, objectID))
             {
                 TxNative.WorldObjectSetActive(worldID, objectID, !rb.IsSleeping());
             }
         }
     }
     else
     {
         TxNative.WorldObjectSetTransform(worldID, objectID, transform);
         TxNative.RigidInstanceSetVelocity(worldID, m_rigidInstanceID, Vector3.zero, Vector3.zero);
     }
     base.OnBeforeStep();
 }
Esempio n. 5
0
 void DestroyWorld()
 {
     if (TxNative.WorldExists(m_worldID))
     {
         TxNative.DestroyWorld(m_worldID);
         TxNative.ThreadsStopWorkers();
     }
 }
Esempio n. 6
0
 public bool RayCast(Vector3 _origin, Vector3 _direction, float _distance, TxBody _skip, out TxBody _body, out Vector3 _point, out Vector3 _normal, out int _face)
 {
     _body = null; int hitObjectID = -1; _point = Vector3.zero; _normal = Vector3.zero; _face = -1;
     if (TxNative.WorldRayCast(m_worldID, _origin, _direction, _distance, _skip ?_skip.objectID : -1, ref hitObjectID, ref _point, ref _normal, ref _face))
     {
         _body = TxBody.Find(hitObjectID);
         return(true);
     }
     return(false);
 }
Esempio n. 7
0
 public void RemoveComponent()
 {
     m_enabledComponents--;
     if (m_enabledComponents <= 0)
     {
         TxNative.ThreadsStopWorkers();
         TxNative.DestroyWorld(m_worldID);
         DestroyImmediate(gameObject);
     }
 }
Esempio n. 8
0
 void SetupCollisionMatrix()
 {
     for (int i = 0; i < 32; ++i)
     {
         for (int j = i; j < 32; ++j)
         {
             bool colliding = !Physics.GetIgnoreLayerCollision(i, j);
             TxNative.WorldSetColliding(m_worldID, i, j, colliding);
         }
     }
 }
Esempio n. 9
0
 void OnEnable()
 {
     if (Application.isPlaying)
     {
         int workerThreads = settings.workerThreads < 0 ? SystemInfo.processorCount + settings.workerThreads : Mathf.Min(SystemInfo.processorCount, settings.workerThreads);
         if (workerThreads > 0)
         {
             TxNative.ThreadsStartWorkers(workerThreads);
         }
     }
 }
Esempio n. 10
0
 protected void DestroyBody()
 {
     if (m_groupRoot && TxNative.WorldExists(m_worldID) && TxNative.WorldGroupExists(m_worldID, m_groupID))
     {
         TxNative.WorldDestroyGroup(m_worldID, m_groupID);
     }
     if (TxNative.WorldExists(m_worldID) && TxNative.WorldObjectExists(m_worldID, m_objectID))
     {
         TxNative.WorldDestroyObject(m_worldID, m_objectID);
         sm_bodies.Remove(m_objectID);
     }
 }
Esempio n. 11
0
 protected override void OnAfterUpdate()
 {
     TxNative.WorldObjectGetInterpolatedTransform(worldID, objectID, transform);
     if (m_meshFilter && TxNative.SkinExists(m_skinID) && isActive)
     {
         TxNative.WorldObjectComputeSkinning(worldID, objectID, m_positions, m_normals, m_tangents, 0, m_positions.Length);
         m_meshFilter.mesh.vertices = m_positions;
         m_meshFilter.mesh.normals  = m_normals;
         m_meshFilter.mesh.tangents = m_tangents;
         m_meshFilter.mesh.RecalculateBounds();
     }
     base.OnAfterUpdate();
 }
Esempio n. 12
0
 void OnValidate()
 {
     foreach (var s in m_snaps)
     {
         s.minLimit = Mathf.Max(0.0f, Mathf.Min(s.minLimit, s.minLimit));
         s.maxLimit = Mathf.Max(0.0f, Mathf.Max(s.minLimit, s.maxLimit));
     }
     if (Application.isPlaying && TxNative.MotorExists(m_motorID))
     {
         int worldID = TxWorld.instance.worldID;
         TxNative.MotorInstanceSetRate(worldID, m_motorInstanceID, m_targetRate);
         TxNative.MotorInstanceSetTorque(worldID, m_motorInstanceID, m_maxTorque);
     }
 }
Esempio n. 13
0
    protected void CreateBody()
    {
        m_worldID = TxWorld.instance.worldID;
        if (!TxNative.WorldObjectExists(m_worldID, m_objectID))
        {
            m_objectID = TxNative.WorldCreateObject(m_worldID, transform.localToWorldMatrix);

            sm_bodies.Add(m_objectID, this);

            TxNative.WorldObjectSetEnabled(m_worldID, m_objectID, m_spawnEnabled);

            if (m_groupRoot)
            {
                m_groupID = TxNative.WorldCreateGroup(m_worldID);
                TxNative.WorldObjectSetGroup(m_worldID, m_objectID, m_groupID);
                for (int i = 0; i < 8; ++i)
                {
                    for (int j = i; j < 8; ++j)
                    {
                        int  index = i * 8 - i * (i + 1) / 2 + j;
                        bool yes   = m_groupCollision[index];
                        TxNative.WorldGroupSetColliding(m_worldID, m_groupID, i, j, yes);
                    }
                }
            }
            else
            {
                m_groupID = -1;
                Transform parent = transform;
                while (parent != null)
                {
                    TxBody parentBody = parent.GetComponent <TxBody>();
                    if (parentBody != null && parentBody.groupRoot)
                    {
                        if (!parentBody.isValid)
                        {
                            parentBody.Create();
                        }
                        m_groupID = parentBody.groupID;
                        break;
                    }
                    parent = parent.parent;
                }
                TxNative.WorldObjectSetGroup(m_worldID, m_objectID, m_groupID);
            }

            TxNative.WorldObjectSetWorldLayer(m_worldID, m_objectID, gameObject.layer);
            TxNative.WorldObjectSetGroupLayer(m_worldID, m_objectID, m_groupLayer);
        }
    }
Esempio n. 14
0
    void DestroyStaticBody()
    {
        if (TxNative.ShapeExists(m_shapeID))
        {
            TxNative.DestroyShape(m_shapeID);
        }
        Mesh shapeMesh; TerrainData shapeTerrain; Vector3 shapeCenter, shapeSize; int capsuleDirection;

        switch (DetectCollisionType(out shapeMesh, out shapeTerrain, out shapeCenter, out shapeSize, out capsuleDirection))
        {
        case CollisionType.Mesh:
            if (TxNative.MeshExists(m_colliderID))
            {
                TxNative.ReleaseMesh(m_colliderID);
            }
            break;

        case CollisionType.Terrain:
            if (TxNative.TerrainExists(m_colliderID))
            {
                TxNative.ReleaseTerrain(m_colliderID);
            }
            break;

        case CollisionType.Convex:
            if (TxNative.ConvexExists(m_colliderID))
            {
                TxNative.ReleaseConvex(m_colliderID);
            }
            break;

        case CollisionType.Box:
        case CollisionType.Capsule:
        case CollisionType.Sphere:
            if (TxNative.ConvexExists(m_colliderID))
            {
                TxNative.DestroyConvex(m_colliderID);
            }
            break;
        }
        for (int i = 0; i < m_matterIDs.Length; ++i)
        {
            TxNative.ReleaseMatter(m_matterIDs[i]);
        }
        DestroyBody();
    }
Esempio n. 15
0
 void OnTriggerStay(Collider _collider)
 {
     if (!Application.isPlaying)
     {
         m_advanceSimulation = false;
     }
     if (m_advanceSimulation)
     {
         m_advanceSimulation = false;
         TxNative.DebugClear();
         OnBeforeStep();
         m_simulationTime = Time.realtimeSinceStartup;
         TxNative.WorldAdvance(m_worldID);
         m_simulationTime = Time.realtimeSinceStartup - m_simulationTime;
         OnAfterStep();
     }
 }
Esempio n. 16
0
 void Update()
 {
     if (Application.isPlaying)
     {
         m_interpolationTime = Time.realtimeSinceStartup;
         TxNative.WorldInterpolate(m_worldID, (Time.time - Time.fixedTime) / Time.fixedDeltaTime);
         m_interpolationTime = Time.realtimeSinceStartup - m_interpolationTime;
         OnAfterUpdate();
         TxNative.DebugDraw();
     }
     else
     {
         if (TxNative.WorldExists(m_worldID))
         {
             TxNative.WorldInterpolate(m_worldID, 0);
         }
     }
 }
Esempio n. 17
0
    void DestroyConstraint()
    {
        TxSoftBody softBody = m_attachedBody;

        if (softBody.exists)
        {
            TxNative.WorldObjectDetachJoint(softBody.worldID, softBody.objectID, m_jointInstanceID);
            if (TxNative.JointExists(m_jointID))
            {
                TxNative.DestroyJoint(m_jointID);
            }
            TxNative.WorldObjectDetachMotor(softBody.worldID, softBody.objectID, m_motorInstanceID);
            if (TxNative.MotorExists(m_motorID))
            {
                TxNative.DestroyMotor(m_motorID);
            }
        }
    }
Esempio n. 18
0
    void DestroyRigidBody()
    {
        TxPhysics.onBeforePhysX -= OnBeforePhysX;
        if (TxNative.ShapeExists(m_shapeID))
        {
            TxNative.DestroyShape(m_shapeID);
        }
        for (int i = 0; i < m_matterIDs.Length; ++i)
        {
            TxNative.ReleaseMatter(m_matterIDs[i]);
        }
        Mesh shapeMesh; Vector3 shapeCenter, shapeSize; int capsuleDirection;

        switch (DetectCollisionType(out shapeMesh, out shapeCenter, out shapeSize, out capsuleDirection))
        {
        case CollisionType.Mesh:
            if (TxNative.MeshExists(m_colliderID))
            {
                TxNative.ReleaseMesh(m_colliderID);
            }
            break;

        case CollisionType.Convex:
            if (TxNative.ConvexExists(m_colliderID))
            {
                TxNative.ReleaseConvex(m_colliderID);
            }
            break;

        case CollisionType.Box:
        case CollisionType.Capsule:
        case CollisionType.Sphere:
            if (TxNative.ConvexExists(m_colliderID))
            {
                TxNative.DestroyConvex(m_colliderID);
            }
            break;
        }
        DestroyBody();
        if (TxNative.RigidExists(m_rigidID))
        {
            TxNative.DestroyRigid(m_rigidID);
        }
    }
Esempio n. 19
0
    protected override void OnAfterStep()
    {
        if (m_rigidBody)
        {
            Rigidbody rb = m_rigidBody;
            if (TxNative.WorldObjectGetActive(worldID, objectID))
            {
                switch (m_interaction)
                {
                case InteractionType.Heavy:
                {
                    Vector3 force = Vector3.zero, torque = Vector3.zero;
                    TxNative.RigidInstanceExtractForces(worldID, m_rigidInstanceID, ref force, ref torque);
                    if (force != Vector3.zero)
                    {
                        rb.AddForce(force / m_massScale);
                    }
                    if (torque != Vector3.zero)
                    {
                        rb.AddTorque(torque / m_massScale);
                    }
                }
                break;

                case InteractionType.Light:
                {
                    Vector3 position = Vector3.zero; Quaternion rotation = Quaternion.identity;
                    TxNative.RigidInstanceGetLocation(worldID, m_rigidInstanceID, ref position, ref rotation);
                    rb.MovePosition(position);
                    rb.velocity = (position - m_prevPosition) / Time.fixedDeltaTime;
                    rb.MoveRotation(rotation);
                    float angle; Vector3 axis; (rotation * Quaternion.Inverse(m_prevRotation)).ToAngleAxis(out angle, out axis);
                    rb.angularVelocity = axis * angle * Mathf.Deg2Rad / Time.fixedDeltaTime;
                }
                break;
                }
            }
            else
            {
                rb.Sleep();
            }
        }
        base.OnAfterStep();
    }
Esempio n. 20
0
 protected override void OnAfterStep()
 {
     if (onCollision != null)
     {
         int contactID = TxNative.WorldObjectFirstContact(m_worldID, m_objectID);
         while (TxNative.WorldContactExists(m_worldID, contactID))
         {
             Contact c = new Contact();
             int     objectA = -1, objectB = -1;
             if (TxNative.WorldContactGetInfo(m_worldID, contactID, ref objectA, ref objectB, ref c.averagePosition, ref c.averageNormal, ref c.minimumDistance, ref c.totalImpulse, ref c.relativeVelocity))
             {
                 c.bodyA = TxBody.Find(objectA);
                 c.bodyB = TxBody.Find(objectB);
                 onCollision(c);
             }
             contactID = TxNative.WorldObjectNextContact(m_worldID, m_objectID, contactID);
         }
     }
     base.OnAfterStep();
 }
 void OnValidate()
 {
     m_simulationStep   = Time.fixedDeltaTime;// Mathf.Max(m_simulationStep, 0.0f);
     m_substepPower     = Mathf.Max(m_substepPower, 0);
     m_solverIterations = Mathf.Max(m_solverIterations, 1);
     m_globalPressure   = Mathf.Max(m_globalPressure, 0.0f);
     if (Application.isPlaying)
     {
         int worldID = TxPhysics.world.worldID;
         TxNative.WorldSetSimulationStep(worldID, m_simulationStep);
         TxNative.WorldSetSimulationSubstepPower(worldID, m_substepPower);
         TxNative.WorldSetSolverIterations(worldID, m_solverIterations);
         TxNative.WorldSetGlobalGravity(worldID, m_globalGravity);
         TxNative.WorldSetGlobalPressure(worldID, m_globalPressure);
         TxNative.ThreadsStopWorkers();
         int workerThreads = m_workerThreads < 0 ? SystemInfo.processorCount + m_workerThreads : Mathf.Min(SystemInfo.processorCount, m_workerThreads);
         if (workerThreads > 0)
         {
             TxNative.ThreadsStartWorkers(workerThreads);
         }
     }
 }
Esempio n. 22
0
 void DestroySoftBody()
 {
     TxNative.ReleaseTruss(m_trussID);
     if (TxNative.ShapeExists(m_shapeID))
     {
         TxNative.DestroyShape(m_shapeID);
     }
     for (int i = 0; i < m_matterIDs.Length; ++i)
     {
         TxNative.ReleaseMatter(m_matterIDs[i]);
     }
     TxNative.ReleaseMesh(m_meshID);
     if (TxNative.SkinExists(m_skinID))
     {
         TxNative.DestroySkin(m_skinID);
     }
     if (m_sharedMesh)
     {
         m_meshFilter.sharedMesh = m_sharedMesh;
     }
     DestroyBody();
 }
Esempio n. 23
0
    void CreateWorld()
    {
        if (!TxNative.WorldExists(m_worldID))
        {
            if (Application.isPlaying)
            {
                int workerThreads = settings.workerThreads < 0 ? SystemInfo.processorCount + settings.workerThreads : Mathf.Min(SystemInfo.processorCount, settings.workerThreads);
                if (workerThreads > 0)
                {
                    TxNative.ThreadsStartWorkers(workerThreads);
                }
            }

            m_worldID = TxNative.CreateWorld();
            TxNative.WorldSetSimulationStep(m_worldID, settings.simulationStep);
            TxNative.WorldSetSimulationSubstepPower(m_worldID, settings.substepPower);
            TxNative.WorldSetSolverIterations(m_worldID, settings.solverIterations);
            TxNative.WorldSetGlobalGravity(m_worldID, settings.globalGravity);
            TxNative.WorldSetGlobalPressure(m_worldID, settings.globalPressure);

            CreateAfterPhysXTrigger();
            SetupCollisionMatrix();
        }
    }
Esempio n. 24
0
 protected override void OnBeforeStep()
 {
     TxNative.WorldObjectSetTransform(worldID, objectID, transform);
     base.OnBeforeStep();
 }
Esempio n. 25
0
 public void ResetGroup()
 {
     TxNative.WorldObjectSetGroup(worldID, objectID, -1);
 }
Esempio n. 26
0
    void CreateStaticBody()
    {
        CreateBody();
        if (m_collision != CollisionType.None)
        {
            m_matterIDs = new int[m_matters.Length];
            for (int i = 0; i < m_matterIDs.Length; ++i)
            {
                m_matterIDs[i] = TxNative.CreateMatter(m_matters[i]);
            }
            m_shapeID = TxNative.CreateShape();
            Mesh shapeMesh; TerrainData shapeTerrain; Vector3 shapeCenter, shapeSize; int capsuleDirection;
            switch (DetectCollisionType(out shapeMesh, out shapeTerrain, out shapeCenter, out shapeSize, out capsuleDirection))
            {
            case CollisionType.Mesh:
            {
                if (shapeMesh != null)
                {
                    m_colliderID = TxNative.CreateMesh(shapeMesh);
                    TxNative.ShapeSetMesh(m_shapeID, m_colliderID);
                }
                break;
            }

            case CollisionType.Terrain:
            {
                if (shapeTerrain != null)
                {
                    m_colliderID = TxNative.CreateTerrain(shapeTerrain);
                    TxNative.ShapeSetTerrain(m_shapeID, m_colliderID);
                }
                break;
            }

            case CollisionType.Convex:
            {
                if (shapeMesh != null)
                {
                    m_colliderID = TxNative.CreateConvex(shapeMesh);
                    TxNative.ShapeSetConvex(m_shapeID, m_colliderID);
                }
                break;
            }

            case CollisionType.Box:
            {
                m_colliderID = TxNative.CreateConvex(shapeCenter, shapeSize);
                TxNative.ShapeSetConvex(m_shapeID, m_colliderID);
                break;
            }

            case CollisionType.Capsule:
            {
                m_colliderID = TxNative.CreateConvex(shapeCenter, shapeSize.x, shapeSize.y, capsuleDirection);
                TxNative.ShapeSetConvex(m_shapeID, m_colliderID);
                break;
            }

            case CollisionType.Sphere:
            {
                m_colliderID = TxNative.CreateConvex(shapeCenter, shapeSize.x);
                TxNative.ShapeSetConvex(m_shapeID, m_colliderID);
                break;
            }
            }
            TxNative.ShapeSetMatterCount(m_shapeID, m_matterIDs.Length);
            TxNative.ShapeSetMatters(m_shapeID, m_matterIDs, 0, m_matterIDs.Length);
            TxNative.ShapeSetMargin(m_shapeID, m_margin);
            TxNative.WorldObjectAttachShape(worldID, objectID, m_shapeID);
        }
    }
Esempio n. 27
0
 public void ApplyImpulse(Vector3 _impulse, int _node)
 {
     TxNative.TrussInstanceApplyImpulse(worldID, m_trussInstanceID, _impulse, _node);
 }
Esempio n. 28
0
 public void ApplyImpulse(Vector3 _impulse, Vector3 _point, int _face)
 {
     TxNative.TrussInstanceApplyImpulse(worldID, m_trussInstanceID, _impulse, _point, _face);
 }
Esempio n. 29
0
 void CreateSoftBody()
 {
     CreateBody();
     m_trussID         = TxNative.CreateTruss(m_truss);
     m_trussInstanceID = TxNative.WorldObjectAttachTruss(worldID, objectID, m_trussID);
     TxNative.TrussInstanceSetMassScale(worldID, m_trussInstanceID, m_massScale);
     if (m_collision)
     {
         m_matterIDs = new int[m_matters.Length];
         for (int i = 0; i < m_matterIDs.Length; ++i)
         {
             m_matterIDs[i] = TxNative.CreateMatter(m_matters[i]);
         }
         m_shapeID = TxNative.CreateShape();
         TxNative.ShapeSetTruss(m_shapeID, m_trussID);
         if (m_matterIDs.Length > 0)
         {
             TxNative.ShapeSetMatterCount(m_shapeID, m_matterIDs.Length);
             TxNative.ShapeSetMatters(m_shapeID, m_matterIDs, 0, m_matterIDs.Length);
         }
         TxNative.ShapeSetMargin(m_shapeID, m_margin);
         TxNative.WorldObjectAttachShape(worldID, objectID, m_shapeID);
     }
     if (m_skinning)
     {
         m_meshFilter = GetComponent <MeshFilter>();
         if (m_meshFilter)
         {
             m_sharedMesh = m_meshFilter.sharedMesh;
             m_meshID     = TxNative.CreateMesh(m_meshFilter.sharedMesh);
             m_skinID     = TxNative.CreateSkin();
             TxNative.SkinSetup(m_skinID, m_trussID, m_meshID, true);
             TxNative.WorldObjectAttachSkin(worldID, objectID, m_skinID);
             m_positions = m_sharedMesh.vertices; //new Vector3[m_meshFilter.sharedMesh.vertexCount];
             m_normals   = m_sharedMesh.normals;  //new Vector3[m_meshFilter.sharedMesh.vertexCount];
             m_tangents  = m_sharedMesh.tangents;
         }
     }
     if (m_filling)
     {
         TxNative.TrussInstanceSetInternalPressure(worldID, m_trussInstanceID, m_internalPressure);
         TxNative.TrussInstanceSetAdiabaticIndex(worldID, m_trussInstanceID, m_adiabaticIndex);
     }
     else
     {
         TxNative.TrussInstanceSetInternalPressure(worldID, m_trussInstanceID, 0);
         TxNative.TrussInstanceSetAdiabaticIndex(worldID, m_trussInstanceID, 0);
     }
     if (m_spawnActive)
     {
         TxNative.WorldObjectSetActive(worldID, objectID, true);
     }
     if (m_deactivation)
     {
         TxNative.TrussInstanceSetDeactivationSpeed(worldID, m_trussInstanceID, m_deactivationSpeed);
         TxNative.TrussInstanceSetDeactivationTime(worldID, m_trussInstanceID, m_deactivationTime);
     }
     else
     {
         TxNative.TrussInstanceSetDeactivationSpeed(worldID, m_trussInstanceID, 0);
         TxNative.TrussInstanceSetDeactivationTime(worldID, m_trussInstanceID, float.MaxValue);
     }
     if (m_fastRotation)
     {
         TxNative.TrussInstanceSetFastRotation(worldID, m_trussInstanceID, true);
     }
 }
Esempio n. 30
0
    void CreateRigidBody()
    {
        m_rigidBody = GetComponent <Rigidbody>();
        Rigidbody rb = m_rigidBody;

        m_rigidID = TxNative.CreateRigid();
        TxNative.RigidSetType(m_rigidID, (int)m_interaction);
        TxNative.RigidSetMass(m_rigidID, rb.mass * m_massScale, rb.centerOfMass, rb.inertiaTensor * m_massScale, rb.inertiaTensorRotation); // Unity 4 crash on object duplicate
        CreateBody();
        m_rigidInstanceID = TxNative.WorldObjectAttachRigid(worldID, objectID, m_rigidID);
        if (m_collision != CollisionType.None)
        {
            m_matterIDs = new int[m_matters.Length];
            for (int i = 0; i < m_matterIDs.Length; ++i)
            {
                m_matterIDs[i] = TxNative.CreateMatter(m_matters[i]);
            }
            m_shapeID = TxNative.CreateShape();
            Mesh shapeMesh; Vector3 shapeCenter, shapeSize; int capsuleDirection;
            switch (DetectCollisionType(out shapeMesh, out shapeCenter, out shapeSize, out capsuleDirection))
            {
            case CollisionType.Mesh:
            {
                if (shapeMesh != null)
                {
                    m_colliderID = TxNative.CreateMesh(shapeMesh);
                    TxNative.ShapeSetMesh(m_shapeID, m_colliderID);
                }
                break;
            }

            case CollisionType.Convex:
            {
                if (shapeMesh != null)
                {
                    m_colliderID = TxNative.CreateConvex(shapeMesh);
                    TxNative.ShapeSetConvex(m_shapeID, m_colliderID);
                }
                break;
            }

            case CollisionType.Box:
            {
                m_colliderID = TxNative.CreateConvex(shapeCenter, shapeSize);
                TxNative.ShapeSetConvex(m_shapeID, m_colliderID);
                break;
            }

            case CollisionType.Capsule:
            {
                m_colliderID = TxNative.CreateConvex(shapeCenter, shapeSize.x, shapeSize.y, capsuleDirection);
                TxNative.ShapeSetConvex(m_shapeID, m_colliderID);
                break;
            }

            case CollisionType.Sphere:
            {
                m_colliderID = TxNative.CreateConvex(shapeCenter, shapeSize.x);
                TxNative.ShapeSetConvex(m_shapeID, m_colliderID);
                break;
            }
            }
            TxNative.ShapeSetMatterCount(m_shapeID, m_matterIDs.Length);
            TxNative.ShapeSetMatters(m_shapeID, m_matterIDs, 0, m_matterIDs.Length);
            TxNative.ShapeSetMargin(m_shapeID, m_margin);
            TxNative.WorldObjectAttachShape(worldID, objectID, m_shapeID);
        }
        TxPhysics.onBeforePhysX += OnBeforePhysX;
    }