コード例 #1
0
        private static void ConvertAllShapesToFractureComponentShapeBuilder(HkdBreakableShape shape, ref Matrix shapeRotation, MyBlockOrientation blockOrientation, HashSet <string> names, MyObjectBuilder_FractureComponentCubeBlock fractureComponentBuilder)
        {
            var name = shape.Name;

            if (names.Contains(name))
            {
                MyBlockOrientation shapeOrientation = new MyBlockOrientation(ref shapeRotation);
                if (shapeOrientation == blockOrientation)
                {
                    MyObjectBuilder_FractureComponentCubeBlock.FracturedShape builderShape = new MyObjectBuilder_FractureComponentBase.FracturedShape();
                    builderShape.Name  = name;
                    builderShape.Fixed = MyDestructionHelper.IsFixed(shape);

                    fractureComponentBuilder.Shapes.Add(builderShape);
                }
            }

            if (shape.GetChildrenCount() > 0)
            {
                List <HkdShapeInstanceInfo> children = new List <HkdShapeInstanceInfo>();
                shape.GetChildren(children);
                foreach (var child in children)
                {
                    var childShapeRotation = child.GetTransform();
                    ConvertAllShapesToFractureComponentShapeBuilder(child.Shape, ref childShapeRotation, blockOrientation, names, fractureComponentBuilder);
                }
            }
        }
コード例 #2
0
        private bool CheckVolumeMassRec(HkdBreakableShape bShape, float minVolume, float minMass)
        {
            if (bShape.Name.Contains("Fake"))
            {
                return(true);
            }
            if (bShape.Volume <= minVolume)
            {
                return(false);
            }
            HkMassProperties mp = new HkMassProperties();

            bShape.BuildMassProperties(ref mp);
            if (mp.Mass <= minMass)
            {
                return(false);
            }
            if (mp.InertiaTensor.M11 == 0 || mp.InertiaTensor.M22 == 0 || mp.InertiaTensor.M33 == 0)
            {
                return(false);
            }
            for (int i = 0; i < bShape.GetChildrenCount(); i++)
            {
                if (!CheckVolumeMassRec(bShape.GetChildShape(i), minVolume, minMass))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #3
0
        protected void SerializeInternal(MyObjectBuilder_FractureComponentBase ob)
        {
            Debug.Assert(m_tmpChildren.Count == 0);

            if (string.IsNullOrEmpty(Shape.Name) || Shape.IsCompound() || Shape.GetChildrenCount() > 0)
            {
                Shape.GetChildren(m_tmpChildren);
                foreach (var child in m_tmpChildren)
                {
                    var shape = new MyObjectBuilder_FractureComponentCubeBlock.FracturedShape()
                    {
                        Name  = child.ShapeName,
                        Fixed = MyDestructionHelper.IsFixed(child.Shape)
                    };
                    ob.Shapes.Add(shape);
                }
                m_tmpChildren.Clear();
            }
            else
            {
                ob.Shapes.Add(new MyObjectBuilder_FractureComponentCubeBlock.FracturedShape()
                {
                    Name = Shape.Name
                });
            }
        }
コード例 #4
0
        private bool GetCurrentFracturedShapeList(HkdBreakableShape breakableShape, List <MyObjectBuilder_FractureComponentBase.FracturedShape> shapeList, string[] excludeShapeNames = null)
        {
            var  shapeName      = breakableShape.Name;
            bool shapeNameEmpty = string.IsNullOrEmpty(shapeName);

            if (excludeShapeNames != null && !shapeNameEmpty)
            {
                foreach (var shapeNameToRemove in excludeShapeNames)
                {
                    if (shapeName == shapeNameToRemove)
                    {
                        return(false);
                    }
                }
            }

            if (breakableShape.GetChildrenCount() > 0)
            {
                List <HkdShapeInstanceInfo> shapeInst = new List <HkdShapeInstanceInfo>();
                breakableShape.GetChildren(shapeInst);

                bool allChildrenAdded = true;
                foreach (var inst in shapeInst)
                {
                    allChildrenAdded &= GetCurrentFracturedShapeList(inst.Shape, shapeList, excludeShapeNames: excludeShapeNames);
                }

                if (!shapeNameEmpty && allChildrenAdded)
                {
                    foreach (var inst in shapeInst)
                    {
                        shapeList.RemoveAll(s => s.Name == inst.ShapeName);
                    }

                    shapeList.Add(new MyObjectBuilder_FractureComponentBase.FracturedShape()
                    {
                        Name = shapeName, Fixed = breakableShape.IsFixed()
                    });
                }

                return(allChildrenAdded);
            }
            else
            {
                if (!shapeNameEmpty)
                {
                    shapeList.Add(new MyObjectBuilder_FractureComponentBase.FracturedShape()
                    {
                        Name = shapeName, Fixed = breakableShape.IsFixed()
                    });
                    return(true);
                }
            }

            return(false);
        }
コード例 #5
0
        private static void ConvertAllShapesToFractureComponentShapeBuilder(HkdBreakableShape shape, ref Matrix shapeRotation, MyBlockOrientation blockOrientation,
                                                                            HashSet <Tuple <string, float> > namesAndBuildProgress, MyObjectBuilder_FractureComponentCubeBlock fractureComponentBuilder, out float buildProgress)
        {
            buildProgress = 1f;

            var name = shape.Name;
            Tuple <string, float> foundTuple = null;

            foreach (var tuple in namesAndBuildProgress)
            {
                if (tuple.Item1 == name)
                {
                    foundTuple = tuple;
                    break;
                }
            }

            if (foundTuple != null)
            {
                MyBlockOrientation shapeOrientation = new MyBlockOrientation(ref shapeRotation);
                if (shapeOrientation == blockOrientation)
                {
                    MyObjectBuilder_FractureComponentCubeBlock.FracturedShape builderShape = new MyObjectBuilder_FractureComponentBase.FracturedShape();
                    builderShape.Name  = name;
                    builderShape.Fixed = MyDestructionHelper.IsFixed(shape);

                    fractureComponentBuilder.Shapes.Add(builderShape);
                    buildProgress = foundTuple.Item2;
                }
            }

            if (shape.GetChildrenCount() > 0)
            {
                List <HkdShapeInstanceInfo> children = new List <HkdShapeInstanceInfo>();
                shape.GetChildren(children);
                foreach (var child in children)
                {
                    var   childShapeRotation = child.GetTransform();
                    float localBuildProgress;
                    ConvertAllShapesToFractureComponentShapeBuilder(child.Shape, ref childShapeRotation, blockOrientation, namesAndBuildProgress,
                                                                    fractureComponentBuilder, out localBuildProgress);

                    if (foundTuple == null)
                    {
                        buildProgress = localBuildProgress;
                    }
                }
            }
        }
コード例 #6
0
        public static void GetAllBlockBreakableShapeNames(HkdBreakableShape shape, HashSet <Tuple <string, float> > outNamesAndBuildProgress, float buildProgress)
        {
            string name = shape.Name;

            if (!string.IsNullOrEmpty(name))
            {
                outNamesAndBuildProgress.Add(new Tuple <string, float>(name, buildProgress));
            }
            if (shape.GetChildrenCount() > 0)
            {
                List <HkdShapeInstanceInfo> list = new List <HkdShapeInstanceInfo>();
                shape.GetChildren(list);
                foreach (HkdShapeInstanceInfo info in list)
                {
                    GetAllBlockBreakableShapeNames(info.Shape, outNamesAndBuildProgress, buildProgress);
                }
            }
        }
コード例 #7
0
        private static void GetAllBlockBreakableShapeNames(HkdBreakableShape shape, HashSet <string> outNames)
        {
            var name = shape.Name;

            if (!string.IsNullOrEmpty(name))
            {
                outNames.Add(name);
            }

            if (shape.GetChildrenCount() > 0)
            {
                List <HkdShapeInstanceInfo> children = new List <HkdShapeInstanceInfo>();
                shape.GetChildren(children);
                foreach (var child in children)
                {
                    GetAllBlockBreakableShapeNames(child.Shape, outNames);
                }
            }
        }
コード例 #8
0
        private static void ConvertAllShapesToFractureComponentShapeBuilder(HkdBreakableShape shape, ref Matrix shapeRotation, MyBlockOrientation blockOrientation, HashSet <Tuple <string, float> > namesAndBuildProgress, MyObjectBuilder_FractureComponentCubeBlock fractureComponentBuilder, out float buildProgress)
        {
            buildProgress = 1f;
            string name = shape.Name;
            Tuple <string, float> tuple = null;

            foreach (Tuple <string, float> tuple2 in namesAndBuildProgress)
            {
                if (tuple2.Item1 == name)
                {
                    tuple = tuple2;
                    break;
                }
            }
            if ((tuple != null) && (new MyBlockOrientation(ref shapeRotation) == blockOrientation))
            {
                MyObjectBuilder_FractureComponentBase.FracturedShape item = new MyObjectBuilder_FractureComponentBase.FracturedShape {
                    Name  = name,
                    Fixed = MyDestructionHelper.IsFixed(shape)
                };
                fractureComponentBuilder.Shapes.Add(item);
                buildProgress = tuple.Item2;
            }
            if (shape.GetChildrenCount() > 0)
            {
                List <HkdShapeInstanceInfo> list = new List <HkdShapeInstanceInfo>();
                shape.GetChildren(list);
                foreach (HkdShapeInstanceInfo info in list)
                {
                    float  num;
                    Matrix transform = info.GetTransform();
                    ConvertAllShapesToFractureComponentShapeBuilder(info.Shape, ref transform, blockOrientation, namesAndBuildProgress, fractureComponentBuilder, out num);
                    if (tuple == null)
                    {
                        buildProgress = num;
                    }
                }
            }
        }
コード例 #9
0
 private bool CheckVolumeMassRec(HkdBreakableShape bShape, float minVolume, float minMass)
 {
     if (bShape.Name.Contains("Fake"))
         return true;
     if (bShape.Volume <= minVolume)
         return false;
     HkMassProperties mp = new HkMassProperties();
     bShape.BuildMassProperties(ref mp);
     if (mp.Mass <= minMass)
         return false;
     if (mp.InertiaTensor.M11 == 0 || mp.InertiaTensor.M22 == 0 || mp.InertiaTensor.M33 == 0)
         return false;
     for (int i = 0; i < bShape.GetChildrenCount(); i++)
     {
         if (!CheckVolumeMassRec(bShape.GetChildShape(i), minVolume, minMass))
             return false;
     }
     return true;
 }
コード例 #10
0
 private static bool IsBreakableShapeCompound(HkdBreakableShape shape)
 {
     return (string.IsNullOrEmpty(shape.Name) || shape.IsCompound() || shape.GetChildrenCount() > 0);
 }
コード例 #11
0
        private static void ConvertAllShapesToFractureComponentShapeBuilder(HkdBreakableShape shape, ref Matrix shapeRotation, MyBlockOrientation blockOrientation, HashSet<string> names, MyObjectBuilder_FractureComponentCubeBlock fractureComponentBuilder)
        {
            var name = shape.Name;
            if (names.Contains(name))
            {
                MyBlockOrientation shapeOrientation = new MyBlockOrientation(ref shapeRotation);
                if (shapeOrientation == blockOrientation)
                {
                    MyObjectBuilder_FractureComponentCubeBlock.FracturedShape builderShape = new MyObjectBuilder_FractureComponentBase.FracturedShape();
                    builderShape.Name = name;
                    builderShape.Fixed = MyDestructionHelper.IsFixed(shape);

                    fractureComponentBuilder.Shapes.Add(builderShape);
                }
            }

            if (shape.GetChildrenCount() > 0)
            {
                List<HkdShapeInstanceInfo> children = new List<HkdShapeInstanceInfo>();
                shape.GetChildren(children);
                foreach (var child in children) 
                {
                    var childShapeRotation = child.GetTransform();
                    ConvertAllShapesToFractureComponentShapeBuilder(child.Shape, ref childShapeRotation, blockOrientation, names, fractureComponentBuilder);
                }
            }

        }
コード例 #12
0
        private static void GetAllBlockBreakableShapeNames(HkdBreakableShape shape, HashSet<string> outNames)
        {
            var name = shape.Name;
            if (!string.IsNullOrEmpty(name))
                outNames.Add(name);

            if (shape.GetChildrenCount() > 0)
            {
                List<HkdShapeInstanceInfo> children = new List<HkdShapeInstanceInfo>();
                shape.GetChildren(children);
                foreach (var child in children)
                    GetAllBlockBreakableShapeNames(child.Shape, outNames);
            }
        }
コード例 #13
0
        private static bool GetCurrentFracturedShapeList(HkdBreakableShape breakableShape, List<MyObjectBuilder_FractureComponentBase.FracturedShape> shapeList, string[] excludeShapeNames = null)
        {
            Debug.Assert(breakableShape.IsValid());
            if (!breakableShape.IsValid())
                return false;

            var shapeName = breakableShape.Name;
            bool shapeNameEmpty = string.IsNullOrEmpty(shapeName);

            if (excludeShapeNames != null && !shapeNameEmpty)
            {
                foreach (var shapeNameToRemove in excludeShapeNames)
                {
                    if (shapeName == shapeNameToRemove)
                        return false;
                }
            }

            if (breakableShape.GetChildrenCount() > 0)
            {
                List<HkdShapeInstanceInfo> shapeInst = new List<HkdShapeInstanceInfo>();
                breakableShape.GetChildren(shapeInst);

                bool allChildrenAdded = true;
                foreach (var inst in shapeInst)
                {
                    allChildrenAdded &= GetCurrentFracturedShapeList(inst.Shape, shapeList, excludeShapeNames: excludeShapeNames);
                }

                if (!shapeNameEmpty && allChildrenAdded)
                {
                    foreach (var inst in shapeInst)
                    {
                        if (inst.Shape.IsValid())
                            shapeList.RemoveAll(s => s.Name == inst.ShapeName);
                    }

                    shapeList.Add(new MyObjectBuilder_FractureComponentBase.FracturedShape() { Name = shapeName, Fixed = breakableShape.IsFixed() });
                }

                return allChildrenAdded;
            }
            else
            {
                if (!shapeNameEmpty)
                {
                    shapeList.Add(new MyObjectBuilder_FractureComponentBase.FracturedShape() { Name = shapeName, Fixed = breakableShape.IsFixed() });
                    return true;
                }
            }

            return false;
        }
コード例 #14
0
        private static void ConvertAllShapesToFractureComponentShapeBuilder(HkdBreakableShape shape, ref Matrix shapeRotation, MyBlockOrientation blockOrientation,
            HashSet<Tuple<string, float>> namesAndBuildProgress, MyObjectBuilder_FractureComponentCubeBlock fractureComponentBuilder, out float buildProgress)
        {
            buildProgress = 1f;

            var name = shape.Name;
            Tuple<string, float> foundTuple = null;
            foreach (var tuple in namesAndBuildProgress)
            {
                if (tuple.Item1 == name)
                {
                    foundTuple = tuple;
                    break;
                }
            }

            if (foundTuple != null)
            {
                MyBlockOrientation shapeOrientation = new MyBlockOrientation(ref shapeRotation);
                if (shapeOrientation == blockOrientation)
                {
                    MyObjectBuilder_FractureComponentCubeBlock.FracturedShape builderShape = new MyObjectBuilder_FractureComponentBase.FracturedShape();
                    builderShape.Name = name;
                    builderShape.Fixed = MyDestructionHelper.IsFixed(shape);

                    fractureComponentBuilder.Shapes.Add(builderShape);
                    buildProgress = foundTuple.Item2;
                }
            }

            if (shape.GetChildrenCount() > 0)
            {
                List<HkdShapeInstanceInfo> children = new List<HkdShapeInstanceInfo>();
                shape.GetChildren(children);
                foreach (var child in children) 
                {
                    var childShapeRotation = child.GetTransform();
                    float localBuildProgress;
                    ConvertAllShapesToFractureComponentShapeBuilder(child.Shape, ref childShapeRotation, blockOrientation, namesAndBuildProgress, 
                        fractureComponentBuilder, out localBuildProgress);

                    if (foundTuple == null)
                        buildProgress = localBuildProgress;
                }
            }

        }
コード例 #15
0
        public static void GetAllBlockBreakableShapeNames(HkdBreakableShape shape, HashSet<Tuple<string, float>> outNamesAndBuildProgress, float buildProgress)
        {
            var name = shape.Name;
            if (!string.IsNullOrEmpty(name))
                outNamesAndBuildProgress.Add(new Tuple<string, float>(name, buildProgress));

            if (shape.GetChildrenCount() > 0)
            {
                List<HkdShapeInstanceInfo> children = new List<HkdShapeInstanceInfo>();
                shape.GetChildren(children);
                foreach (var child in children)
                    GetAllBlockBreakableShapeNames(child.Shape, outNamesAndBuildProgress, buildProgress);
            }
        }
コード例 #16
0
        public static unsafe void FixPosition(MyFracturedPiece fp)
        {
            HkdBreakableShape breakableShape = fp.Physics.BreakableBody.BreakableShape;

            if (breakableShape.GetChildrenCount() != 0)
            {
                breakableShape.GetChildren(m_tmpInfos);
                Vector3 translation = m_tmpInfos[0].GetTransform().Translation;
                if (translation.LengthSquared() < 1f)
                {
                    m_tmpInfos.Clear();
                }
                else
                {
                    List <HkdConnection>        resultList = new List <HkdConnection>();
                    HashSet <HkdBreakableShape> set        = new HashSet <HkdBreakableShape>();
                    HashSet <HkdBreakableShape> set2       = new HashSet <HkdBreakableShape>();
                    set.Add(breakableShape);
                    breakableShape.GetConnectionList(resultList);
                    fp.PositionComp.SetPosition(Vector3D.Transform(translation, fp.PositionComp.WorldMatrix), null, false, true);
                    foreach (HkdShapeInstanceInfo info2 in m_tmpInfos)
                    {
                        Matrix  transform  = info2.GetTransform();
                        Matrix *matrixPtr1 = (Matrix *)ref transform;
                        matrixPtr1.Translation -= translation;
                        info2.SetTransform(ref transform);
                        m_tmpInfos2.Add(info2);
                        HkdBreakableShape shape = info2.Shape;
                        shape.GetConnectionList(resultList);
                        while (true)
                        {
                            if (!shape.HasParent)
                            {
                                set2.Add(info2.Shape);
                                break;
                            }
                            shape = shape.GetParent();
                            if (set.Add(shape))
                            {
                                shape.GetConnectionList(resultList);
                            }
                        }
                    }
                    m_tmpInfos.Clear();
                    HkdBreakableShape parent = (HkdBreakableShape) new HkdCompoundBreakableShape(new HkdBreakableShape?(breakableShape), m_tmpInfos2);
                    parent.RecalcMassPropsFromChildren();
                    ((HkdBreakableShape *)ref parent).SetChildrenParent(parent);
                    foreach (HkdConnection connection in resultList)
                    {
                        HkBaseSystem.EnableAssert(0x1745920b, true);
                        if (set2.Contains(connection.ShapeA) && set2.Contains(connection.ShapeB))
                        {
                            HkdConnection connection2 = connection;
                            parent.AddConnection(ref connection2);
                        }
                    }
                    fp.Physics.BreakableBody.BreakableShape = parent;
                    m_tmpInfos2.Clear();
                    parent.RecalcMassPropsFromChildren();
                }
            }
        }