Exemple #1
0
        public static void CreateFracturePiece(MyEnvironmentItemDefinition itemDefinition, HkdBreakableShape oldBreakableShape, MatrixD worldMatrix, Vector3 hitNormal, List <HkdShapeInstanceInfo> shapeList,
                                               float forceMultiplier, bool canContainFixedChildren, string fallSound = "")
        {
            bool containsFixedChildren = false;

            if (canContainFixedChildren)
            {
                foreach (var shapeInst in shapeList)
                {
                    shapeInst.Shape.SetMotionQualityRecursively(HkdBreakableShape.BodyQualityType.QUALITY_DEBRIS);

                    var t = worldMatrix.Translation + worldMatrix.Up * 1.5f;
                    var o = Quaternion.CreateFromRotationMatrix(worldMatrix.GetOrientation());
                    MyPhysics.GetPenetrationsShape(shapeInst.Shape.GetShape(), ref t, ref o, m_tmpResults, MyPhysics.CollisionLayers.DefaultCollisionLayer);
                    bool flagSet = false;
                    foreach (var res in m_tmpResults)
                    {
                        var entity = res.GetCollisionEntity();

                        if (entity is MyVoxelMap)
                        {
                            shapeInst.Shape.SetFlagRecursively(HkdBreakableShape.Flags.IS_FIXED);
                            containsFixedChildren = true;
                            flagSet = true;
                            break;
                        }

                        if (flagSet)
                        {
                            break;
                        }
                    }
                    m_tmpResults.Clear();
                }
            }

            HkdBreakableShape compound = new HkdCompoundBreakableShape(oldBreakableShape, shapeList);

            ((HkdCompoundBreakableShape)compound).RecalcMassPropsFromChildren();
            //compound.SetMassRecursively(500);
            //compound.SetStrenghtRecursively(5000, 0.7f);

            var fp = MyDestructionHelper.CreateFracturePiece(compound, MyPhysics.SingleWorld.DestructionWorld, ref worldMatrix, containsFixedChildren, itemDefinition.Id, true);

            if (fp != null && !canContainFixedChildren)
            {
                ApplyImpulseToTreeFracture(ref worldMatrix, ref hitNormal, shapeList, ref compound, fp, forceMultiplier);
                fp.Physics.ForceActivate();
                if (fallSound.Length > 0)
                {
                    fp.StartFallSound(fallSound);
                }
            }
        }
Exemple #2
0
        public static void CreateFracturePiece(MyEnvironmentItemDefinition itemDefinition, HkdBreakableShape oldBreakableShape, MatrixD worldMatrix, Vector3 hitNormal, List <HkdShapeInstanceInfo> shapeList, float forceMultiplier, bool canContainFixedChildren, string fallSound = "")
        {
            bool isStatic = false;

            if (canContainFixedChildren)
            {
                foreach (HkdShapeInstanceInfo info in shapeList)
                {
                    info.Shape.SetMotionQualityRecursively(HkdBreakableShape.BodyQualityType.QUALITY_DEBRIS);
                    Vector3D   translation = worldMatrix.Translation + (worldMatrix.Up * 1.5);
                    Quaternion rotation    = Quaternion.CreateFromRotationMatrix(worldMatrix.GetOrientation());
                    MyPhysics.GetPenetrationsShape(info.Shape.GetShape(), ref translation, ref rotation, MyEnvironmentItems.m_tmpResults, 15);
                    bool flag2 = false;
                    using (List <HkBodyCollision> .Enumerator enumerator2 = MyEnvironmentItems.m_tmpResults.GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            if (enumerator2.Current.GetCollisionEntity() is MyVoxelMap)
                            {
                                info.Shape.SetFlagRecursively(HkdBreakableShape.Flags.IS_FIXED);
                                isStatic = true;
                                flag2    = true;
                            }
                            else if (!flag2)
                            {
                                continue;
                            }
                            break;
                        }
                    }
                    MyEnvironmentItems.m_tmpResults.Clear();
                }
            }
            HkdBreakableShape shape = (HkdBreakableShape) new HkdCompoundBreakableShape(new HkdBreakableShape?(oldBreakableShape), shapeList);

            shape.RecalcMassPropsFromChildren();
            MyFracturedPiece fp = MyDestructionHelper.CreateFracturePiece(shape, ref worldMatrix, isStatic, new MyDefinitionId?(itemDefinition.Id), true);

            if ((fp != null) && !canContainFixedChildren)
            {
                ApplyImpulseToTreeFracture(ref worldMatrix, ref hitNormal, shapeList, ref shape, fp, forceMultiplier);
                fp.Physics.ForceActivate();
                if (fallSound.Length > 0)
                {
                    fp.StartFallSound(fallSound);
                }
            }
        }