private void ReturnToPoolInternal(HkdBreakableBody body)
        {
            var rb = body.GetRigidBody();

            if (rb == null)
            {
                return;
            }
            rb.ContactPointCallbackEnabled = false;
            //Debug.Assert(m_givenRBs.Remove(rb), "New body from outside in pool!");
            m_givenRBs.Remove(rb);
            foreach (var b0 in m_bodyPool)
            {
                if (body == b0.Breakable || rb == b0.Rigid)
                {
                    Debug.Fail("Body already in pool!");
                }
            }
            // body.BreakableShape.AddReference();
            var bs = body.BreakableShape;

            bs.ClearConnections();
            body.Clear();
            Bodies b;

            b.Rigid     = rb;
            b.Breakable = body;
            body.InitListener();
            m_bodyPool.Enqueue(b);
        }
Beispiel #2
0
 public static void DebugDrawBreakable(HkdBreakableBody bb, Vector3 offset)
 {
     DebugShapesPositions.Clear();
     if (bb != null)
     {
         int     shapeIndex      = 0;
         Matrix  rigidBodyMatrix = bb.GetRigidBody().GetRigidBodyMatrix();
         MatrixD worldMatrix     = MatrixD.CreateWorld(rigidBodyMatrix.Translation + offset, rigidBodyMatrix.Forward, rigidBodyMatrix.Up);
         DrawBreakableShape(bb.BreakableShape, worldMatrix, 0.3f, ref shapeIndex, null, false);
         DrawConnections(bb.BreakableShape, worldMatrix, 0.3f, ref shapeIndex, null, false);
     }
 }
        public static void DebugDrawBreakable(HkdBreakableBody bb, Vector3 offset)
        {
            const float alpha = 0.3f;

            //var offset = MyPhysics.Clusters.GetObjectOffset(ClusterObjectID);

            DebugShapesPositions.Clear();

            if (bb != null)
            {
                int     index       = 0;
                Matrix  rbMatrix    = bb.GetRigidBody().GetRigidBodyMatrix();
                MatrixD worldMatrix = MatrixD.CreateWorld(rbMatrix.Translation + offset, rbMatrix.Forward, rbMatrix.Up);

                DrawBreakableShape(bb.BreakableShape, worldMatrix, alpha, ref index);
                DrawConnections(bb.BreakableShape, worldMatrix, alpha, ref index);
            }
        }
 private void ReturnToPoolInternal(HkdBreakableBody body)
 {
     var rb = body.GetRigidBody();
     if(rb == null)
     {
         return;
     }
     rb.ContactPointCallbackEnabled = false;
     //Debug.Assert(m_givenRBs.Remove(rb), "New body from outside in pool!");
     m_givenRBs.Remove(rb);
     foreach(var b0 in m_bodyPool)
     {
         if (body == b0.Breakable || rb == b0.Rigid)
             Debug.Fail("Body already in pool!");
     }
     // body.BreakableShape.AddReference();
     var bs = body.BreakableShape;
     bs.ClearConnections();
     body.Clear();
     Bodies b;
     b.Rigid = rb;
     b.Breakable = body;
     body.InitListener();
     m_bodyPool.Enqueue(b);
 }
Beispiel #5
0
        internal void InitFromBreakableBody(HkdBreakableBody b, MatrixD worldMatrix, MyCubeBlock block)
        {
            ProfilerShort.Begin("RemoveGen&SetFixed");

            OriginalBlocks.Clear();
            if (block != null)
            {
                if (block is MyCompoundCubeBlock)
                {
                    foreach (var block2 in (block as MyCompoundCubeBlock).GetBlocks())
                    {
                        OriginalBlocks.Add(block2.BlockDefinition.Id);
                    }
                }
                else if (block is MyFracturedBlock)
                {
                    OriginalBlocks.AddRange((block as MyFracturedBlock).OriginalBlocks);
                }
                else
                {
                    OriginalBlocks.Add(block.BlockDefinition.Id);
                }
            }

            var  rigidBody = b.GetRigidBody();
            bool isFixed   = MyDestructionHelper.IsFixed(b.BreakableShape);

            if (isFixed)
            {
                rigidBody.UpdateMotionType(HkMotionType.Fixed);
                rigidBody.LinearVelocity  = Vector3.Zero;
                rigidBody.AngularVelocity = Vector3.Zero;
            }

            ProfilerShort.Begin("Sync");
            if (SyncFlag)
            {
                CreateSync();
            }
            ProfilerShort.End();

            PositionComp.WorldMatrix = worldMatrix;
            Physics.Flags            = isFixed ? RigidBodyFlag.RBF_STATIC : RigidBodyFlag.RBF_DEBRIS;
            Physics.BreakableBody    = b;
            rigidBody.UserObject     = Physics;
            if (!isFixed)
            {
                rigidBody.Motion.SetDeactivationClass(HkSolverDeactivation.High);
                rigidBody.EnableDeactivation = true;
                if (MyFakes.REDUCE_FRACTURES_COUNT)
                {
                    if (b.BreakableShape.Volume < 1 && MyRandom.Instance.Next(6) > 1)
                    {
                        rigidBody.Layer = MyFracturedPiecesManager.FakePieceLayer;
                    }
                    else
                    {
                        rigidBody.Layer = MyPhysics.CollisionLayers.DefaultCollisionLayer;
                    }
                }
                else
                {
                    rigidBody.Layer = MyPhysics.CollisionLayers.DefaultCollisionLayer;
                }
            }
            else
            {
                rigidBody.Layer = MyPhysics.CollisionLayers.StaticCollisionLayer;
            }
            Physics.BreakableBody.AfterReplaceBody += Physics.FracturedBody_AfterReplaceBody;

            if (OriginalBlocks.Count > 0)
            {
                MyPhysicalModelDefinition def;
                if (MyDefinitionManager.Static.TryGetDefinition <MyPhysicalModelDefinition>(OriginalBlocks[0], out def))
                {
                    Physics.MaterialType = def.PhysicalMaterial.Id.SubtypeId;
                }
            }

            ProfilerShort.BeginNextBlock("Enable");
            Physics.Enabled = true;
            MyDestructionHelper.FixPosition(this);
            SetDataFromHavok(b.BreakableShape);
            var coml = b.GetRigidBody().CenterOfMassLocal;
            var comw = b.GetRigidBody().CenterOfMassWorld;
            var com  = b.BreakableShape.CoM;

            b.GetRigidBody().CenterOfMassLocal = com;
            b.BreakableShape.RemoveReference();
            ProfilerShort.End();
        }
        internal void InitFromBreakableBody(HkdBreakableBody b, MatrixD worldMatrix, MyCubeBlock block)
        {
            ProfilerShort.Begin("RemoveGen&SetFixed");

            OriginalBlocks.Clear();
            if (block != null)
            {
                if (block is MyCompoundCubeBlock)
                {
                    foreach (var block2 in (block as MyCompoundCubeBlock).GetBlocks())
                        OriginalBlocks.Add(block2.BlockDefinition.Id);
                }
                else if (block is MyFracturedBlock)
                {
                    OriginalBlocks.AddRange((block as MyFracturedBlock).OriginalBlocks);
                }
                else
                {
                    OriginalBlocks.Add(block.BlockDefinition.Id);
                }
            }

            var rigidBody = b.GetRigidBody();
            bool isFixed = MyDestructionHelper.IsFixed(b.BreakableShape);
            if (isFixed)
            {
                rigidBody.UpdateMotionType(HkMotionType.Fixed);
                rigidBody.LinearVelocity = Vector3.Zero;
                rigidBody.AngularVelocity = Vector3.Zero;
            }

            ProfilerShort.Begin("Sync");
            if (SyncFlag)
            {
                CreateSync();
            }
            ProfilerShort.End();

            PositionComp.WorldMatrix = worldMatrix;
            Physics.Flags = isFixed ? RigidBodyFlag.RBF_STATIC : RigidBodyFlag.RBF_DEBRIS;
            Physics.BreakableBody = b;
            rigidBody.UserObject = Physics;
            if (!isFixed)
            {
                rigidBody.Motion.SetDeactivationClass(HkSolverDeactivation.High);
                rigidBody.EnableDeactivation = true;
                if (MyFakes.REDUCE_FRACTURES_COUNT)
                {
                    if (b.BreakableShape.Volume < 1 && MyRandom.Instance.Next(6) > 1)
                        rigidBody.Layer = MyFracturedPiecesManager.FakePieceLayer;
                    else
                        rigidBody.Layer = MyPhysics.CollisionLayers.DefaultCollisionLayer;
                }
                else
                    rigidBody.Layer = MyPhysics.CollisionLayers.DefaultCollisionLayer;
            }
            else
                rigidBody.Layer = MyPhysics.CollisionLayers.StaticCollisionLayer;
            Physics.BreakableBody.AfterReplaceBody += Physics.FracturedBody_AfterReplaceBody;

            if(OriginalBlocks.Count > 0)
            {
                MyPhysicalModelDefinition def;
                if(MyDefinitionManager.Static.TryGetDefinition<MyPhysicalModelDefinition>(OriginalBlocks[0],out def))
                    Physics.MaterialType = def.PhysicalMaterial.Id.SubtypeId;
            }

            ProfilerShort.BeginNextBlock("Enable");
            Physics.Enabled = true;
            MyDestructionHelper.FixPosition(this);
            SetDataFromHavok(b.BreakableShape);
            var coml = b.GetRigidBody().CenterOfMassLocal;
            var comw = b.GetRigidBody().CenterOfMassWorld;
            var com = b.BreakableShape.CoM;
            b.GetRigidBody().CenterOfMassLocal = com;
            b.BreakableShape.RemoveReference();
            ProfilerShort.End();

        }
        public static void DebugDrawBreakable(HkdBreakableBody bb, Vector3 offset)
        {
            const float alpha = 0.3f;

            //var offset = MyPhysics.Clusters.GetObjectOffset(ClusterObjectID);

            DebugShapesPositions.Clear();

            if (bb != null)
            {
                int index = 0;
                Matrix rbMatrix = bb.GetRigidBody().GetRigidBodyMatrix();
                MatrixD worldMatrix = MatrixD.CreateWorld(rbMatrix.Translation + offset, rbMatrix.Forward, rbMatrix.Up);

                DrawBreakableShape(bb.BreakableShape, worldMatrix, alpha, ref index);
                DrawConnections(bb.BreakableShape, worldMatrix, alpha, ref index);
            }

        }