Esempio n. 1
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;
                    }
                }
            }
        }
Esempio n. 2
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);
                }
            }

        }
Esempio n. 3
0
        public MyObjectBuilder_CubeBlock ConvertToOriginalBlocksWithFractureComponent()
        {
            List <MyObjectBuilder_CubeBlock> cubeBlockBuilders = new List <MyObjectBuilder_CubeBlock>();

            for (int i = 0; i < this.OriginalBlocks.Count; i++)
            {
                MyCubeBlockDefinition definition;
                MyDefinitionId        defId = this.OriginalBlocks[i];
                MyDefinitionManager.Static.TryGetCubeBlockDefinition(defId, out definition);
                if (definition != null)
                {
                    Quaternion         quaternion;
                    float              num2;
                    MultiBlockPartInfo local1;
                    MyBlockOrientation blockOrientation = this.Orientations[i];
                    if ((this.MultiBlocks == null) || (this.MultiBlocks.Count <= i))
                    {
                        local1 = null;
                    }
                    else
                    {
                        local1 = this.MultiBlocks[i];
                    }
                    MultiBlockPartInfo        info = local1;
                    MyObjectBuilder_CubeBlock item = MyObjectBuilderSerializer.CreateNewObject((SerializableDefinitionId)defId) as MyObjectBuilder_CubeBlock;
                    blockOrientation.GetQuaternion(out quaternion);
                    item.Orientation          = quaternion;
                    item.Min                  = base.Position;
                    item.MultiBlockId         = (info != null) ? info.MultiBlockId : 0;
                    item.MultiBlockDefinition = null;
                    if (info != null)
                    {
                        item.MultiBlockDefinition = new SerializableDefinitionId?((SerializableDefinitionId)info.MultiBlockDefinition);
                    }
                    item.ComponentContainer = new MyObjectBuilder_ComponentContainer();
                    MyObjectBuilder_FractureComponentCubeBlock fractureComponentBuilder = new MyObjectBuilder_FractureComponentCubeBlock();
                    m_tmpNamesAndBuildProgress.Clear();
                    GetAllBlockBreakableShapeNames(definition, m_tmpNamesAndBuildProgress);
                    ConvertAllShapesToFractureComponentShapeBuilder(this.Shape, ref Matrix.Identity, blockOrientation, m_tmpNamesAndBuildProgress, fractureComponentBuilder, out num2);
                    m_tmpNamesAndBuildProgress.Clear();
                    if (fractureComponentBuilder.Shapes.Count != 0)
                    {
                        if (definition.BuildProgressModels != null)
                        {
                            foreach (MyCubeBlockDefinition.BuildProgressModel model in definition.BuildProgressModels)
                            {
                                if (model.BuildRatioUpperBound >= num2)
                                {
                                    break;
                                }
                                float buildRatioUpperBound = model.BuildRatioUpperBound;
                            }
                        }
                        MyObjectBuilder_ComponentContainer.ComponentData data = new MyObjectBuilder_ComponentContainer.ComponentData {
                            TypeId    = typeof(MyFractureComponentBase).Name,
                            Component = fractureComponentBuilder
                        };
                        item.ComponentContainer.Components.Add(data);
                        item.BuildPercent     = num2;
                        item.IntegrityPercent = MyDefinitionManager.Static.DestructionDefinition.ConvertedFractureIntegrityRatio * num2;
                        if ((i == 0) && (base.CubeGrid.GridSizeEnum == MyCubeSize.Small))
                        {
                            return(item);
                        }
                        cubeBlockBuilders.Add(item);
                    }
                }
            }
            return((cubeBlockBuilders.Count <= 0) ? null : MyCompoundCubeBlock.CreateBuilder(cubeBlockBuilders));
        }
        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;
                }
            }

        }
Esempio n. 5
0
        public MyObjectBuilder_CubeBlock ConvertToOriginalBlocksWithFractureComponent()
        {
            List<MyObjectBuilder_CubeBlock> blockBuilders = new List<MyObjectBuilder_CubeBlock>();
            Quaternion q;
            for (int i = 0; i < OriginalBlocks.Count; ++i)
            {
                var defId = OriginalBlocks[i];
                MyCubeBlockDefinition def;
                MyDefinitionManager.Static.TryGetCubeBlockDefinition(defId, out def);
                if (def == null)
                {
                    Debug.Fail("Cube block definition not found");
                    continue;
                }
                var orientation = Orientations[i];
                MultiBlockPartInfo multiBlockInfo = MultiBlocks != null && MultiBlocks.Count > i ? MultiBlocks[i] : null;

                MyObjectBuilder_CubeBlock blockBuilder = MyObjectBuilderSerializer.CreateNewObject(defId) as MyObjectBuilder_CubeBlock;
                orientation.GetQuaternion(out q);
                blockBuilder.Orientation = q;
                blockBuilder.Min = Position;
                blockBuilder.MultiBlockId = multiBlockInfo != null ? multiBlockInfo.MultiBlockId : 0;
                blockBuilder.MultiBlockDefinition = null;
                if (multiBlockInfo != null)
                    blockBuilder.MultiBlockDefinition = multiBlockInfo.MultiBlockDefinition;
                blockBuilder.ComponentContainer = new MyObjectBuilder_ComponentContainer();

                var fractureBuilder = new MyObjectBuilder_FractureComponentCubeBlock();
                HashSet<string> shapeNames = new HashSet<string>();
                GetAllBlockBreakableShapeNames(def, shapeNames);
                ConvertAllShapesToFractureComponentShapeBuilder(Shape, ref Matrix.Identity, orientation, shapeNames, fractureBuilder);
                // Count of shapes can be 0!
                if (fractureBuilder.Shapes.Count == 0)
                    continue;

                var componentData = new MyObjectBuilder_ComponentContainer.ComponentData();
                componentData.TypeId = typeof(MyFractureComponentBase).Name;
                componentData.Component = fractureBuilder;
                blockBuilder.ComponentContainer.Components.Add(componentData);

                if (i == 0 && CubeGrid.GridSizeEnum == MyCubeSize.Small)
                    return blockBuilder;

                blockBuilders.Add(blockBuilder);
            }

            if (blockBuilders.Count > 0)
            {
                MyObjectBuilder_CompoundCubeBlock compoundBuilder = MyCompoundCubeBlock.CreateBuilder(blockBuilders);
                return compoundBuilder;
            }

            return null;
        }
        public MyObjectBuilder_CubeBlock ConvertToOriginalBlocksWithFractureComponent()
        {
            List<MyObjectBuilder_CubeBlock> blockBuilders = new List<MyObjectBuilder_CubeBlock>();
            Quaternion q;
            for (int i = 0; i < OriginalBlocks.Count; ++i)
            {
                var defId = OriginalBlocks[i];
                MyCubeBlockDefinition def;
                MyDefinitionManager.Static.TryGetCubeBlockDefinition(defId, out def);
                if (def == null)
                {
                    Debug.Fail("Cube block definition not found");
                    continue;
                }
                var orientation = Orientations[i];
                MultiBlockPartInfo multiBlockInfo = MultiBlocks != null && MultiBlocks.Count > i ? MultiBlocks[i] : null;

                MyObjectBuilder_CubeBlock blockBuilder = MyObjectBuilderSerializer.CreateNewObject(defId) as MyObjectBuilder_CubeBlock;
                orientation.GetQuaternion(out q);
                blockBuilder.Orientation = q;
                blockBuilder.Min = Position;
                blockBuilder.MultiBlockId = multiBlockInfo != null ? multiBlockInfo.MultiBlockId : 0;
                blockBuilder.MultiBlockDefinition = null;
                if (multiBlockInfo != null)
                    blockBuilder.MultiBlockDefinition = multiBlockInfo.MultiBlockDefinition;
                blockBuilder.ComponentContainer = new MyObjectBuilder_ComponentContainer();

                var fractureBuilder = new MyObjectBuilder_FractureComponentCubeBlock();
                m_tmpNamesAndBuildProgress.Clear();
                GetAllBlockBreakableShapeNames(def, m_tmpNamesAndBuildProgress);
                float buildProgress;
                ConvertAllShapesToFractureComponentShapeBuilder(Shape, ref Matrix.Identity, orientation, m_tmpNamesAndBuildProgress, fractureBuilder, out buildProgress);
                m_tmpNamesAndBuildProgress.Clear();
                // Count of shapes can be 0!
                if (fractureBuilder.Shapes.Count == 0)
                    continue;

                float previousBuildRatioUpperBound = 0f;
                if (def.BuildProgressModels != null)
                {
                    foreach (var progress in def.BuildProgressModels)
                    {
                        if (progress.BuildRatioUpperBound >= buildProgress)
                            break;

                        previousBuildRatioUpperBound = progress.BuildRatioUpperBound;
                    }
                }

                var componentData = new MyObjectBuilder_ComponentContainer.ComponentData();
                componentData.TypeId = typeof(MyFractureComponentBase).Name;
                componentData.Component = fractureBuilder;
                blockBuilder.ComponentContainer.Components.Add(componentData);
                blockBuilder.BuildPercent = buildProgress;
                Debug.Assert(buildProgress > previousBuildRatioUpperBound);
                blockBuilder.IntegrityPercent = MyDefinitionManager.Static.DestructionDefinition.ConvertedFractureIntegrityRatio * buildProgress;

                if (i == 0 && CubeGrid.GridSizeEnum == MyCubeSize.Small)
                    return blockBuilder;

                blockBuilders.Add(blockBuilder);
            }

            if (blockBuilders.Count > 0)
            {
                MyObjectBuilder_CompoundCubeBlock compoundBuilder = MyCompoundCubeBlock.CreateBuilder(blockBuilders);
                return compoundBuilder;
            }

            return null;
        }
Esempio n. 7
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);
                }
            }
        }
Esempio n. 8
0
        public MyObjectBuilder_CubeBlock ConvertToOriginalBlocksWithFractureComponent()
        {
            List <MyObjectBuilder_CubeBlock> blockBuilders = new List <MyObjectBuilder_CubeBlock>();
            Quaternion q;

            for (int i = 0; i < OriginalBlocks.Count; ++i)
            {
                var defId = OriginalBlocks[i];
                MyCubeBlockDefinition def;
                MyDefinitionManager.Static.TryGetCubeBlockDefinition(defId, out def);
                if (def == null)
                {
                    Debug.Fail("Cube block definition not found");
                    continue;
                }
                var orientation = Orientations[i];
                MultiBlockPartInfo multiBlockInfo = MultiBlocks != null && MultiBlocks.Count > i ? MultiBlocks[i] : null;

                MyObjectBuilder_CubeBlock blockBuilder = MyObjectBuilderSerializer.CreateNewObject(defId) as MyObjectBuilder_CubeBlock;
                orientation.GetQuaternion(out q);
                blockBuilder.Orientation          = q;
                blockBuilder.Min                  = Position;
                blockBuilder.MultiBlockId         = multiBlockInfo != null ? multiBlockInfo.MultiBlockId : 0;
                blockBuilder.MultiBlockDefinition = null;
                if (multiBlockInfo != null)
                {
                    blockBuilder.MultiBlockDefinition = multiBlockInfo.MultiBlockDefinition;
                }
                blockBuilder.ComponentContainer = new MyObjectBuilder_ComponentContainer();

                var fractureBuilder         = new MyObjectBuilder_FractureComponentCubeBlock();
                HashSet <string> shapeNames = new HashSet <string>();
                GetAllBlockBreakableShapeNames(def, shapeNames);
                ConvertAllShapesToFractureComponentShapeBuilder(Shape, ref Matrix.Identity, orientation, shapeNames, fractureBuilder);
                // Count of shapes can be 0!
                if (fractureBuilder.Shapes.Count == 0)
                {
                    continue;
                }

                var componentData = new MyObjectBuilder_ComponentContainer.ComponentData();
                componentData.TypeId    = typeof(MyFractureComponentBase).Name;
                componentData.Component = fractureBuilder;
                blockBuilder.ComponentContainer.Components.Add(componentData);

                if (i == 0 && CubeGrid.GridSizeEnum == MyCubeSize.Small)
                {
                    return(blockBuilder);
                }

                blockBuilders.Add(blockBuilder);
            }

            if (blockBuilders.Count > 0)
            {
                MyObjectBuilder_CompoundCubeBlock compoundBuilder = MyCompoundCubeBlock.CreateBuilder(blockBuilders);
                return(compoundBuilder);
            }

            return(null);
        }
        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;
                    }
                }
            }
        }
Esempio n. 10
0
        public MyObjectBuilder_CubeBlock ConvertToOriginalBlocksWithFractureComponent()
        {
            List <MyObjectBuilder_CubeBlock> blockBuilders = new List <MyObjectBuilder_CubeBlock>();
            Quaternion q;

            for (int i = 0; i < OriginalBlocks.Count; ++i)
            {
                var defId = OriginalBlocks[i];
                MyCubeBlockDefinition def;
                MyDefinitionManager.Static.TryGetCubeBlockDefinition(defId, out def);
                if (def == null)
                {
                    Debug.Fail("Cube block definition not found");
                    continue;
                }
                var orientation = Orientations[i];
                MultiBlockPartInfo multiBlockInfo = MultiBlocks != null && MultiBlocks.Count > i ? MultiBlocks[i] : null;

                MyObjectBuilder_CubeBlock blockBuilder = MyObjectBuilderSerializer.CreateNewObject(defId) as MyObjectBuilder_CubeBlock;
                orientation.GetQuaternion(out q);
                blockBuilder.Orientation          = q;
                blockBuilder.Min                  = Position;
                blockBuilder.MultiBlockId         = multiBlockInfo != null ? multiBlockInfo.MultiBlockId : 0;
                blockBuilder.MultiBlockDefinition = null;
                if (multiBlockInfo != null)
                {
                    blockBuilder.MultiBlockDefinition = multiBlockInfo.MultiBlockDefinition;
                }
                blockBuilder.ComponentContainer = new MyObjectBuilder_ComponentContainer();

                var fractureBuilder = new MyObjectBuilder_FractureComponentCubeBlock();
                m_tmpNamesAndBuildProgress.Clear();
                GetAllBlockBreakableShapeNames(def, m_tmpNamesAndBuildProgress);
                float buildProgress;
                ConvertAllShapesToFractureComponentShapeBuilder(Shape, ref Matrix.Identity, orientation, m_tmpNamesAndBuildProgress, fractureBuilder, out buildProgress);
                m_tmpNamesAndBuildProgress.Clear();
                // Count of shapes can be 0!
                if (fractureBuilder.Shapes.Count == 0)
                {
                    continue;
                }

                float previousBuildRatioUpperBound = 0f;
                if (def.BuildProgressModels != null)
                {
                    foreach (var progress in def.BuildProgressModels)
                    {
                        if (progress.BuildRatioUpperBound >= buildProgress)
                        {
                            break;
                        }

                        previousBuildRatioUpperBound = progress.BuildRatioUpperBound;
                    }
                }

                var componentData = new MyObjectBuilder_ComponentContainer.ComponentData();
                componentData.TypeId    = typeof(MyFractureComponentBase).Name;
                componentData.Component = fractureBuilder;
                blockBuilder.ComponentContainer.Components.Add(componentData);
                blockBuilder.BuildPercent = buildProgress;
                Debug.Assert(buildProgress > previousBuildRatioUpperBound);
                blockBuilder.IntegrityPercent = MyDefinitionManager.Static.DestructionDefinition.ConvertedFractureIntegrityRatio * buildProgress;

                if (i == 0 && CubeGrid.GridSizeEnum == MyCubeSize.Small)
                {
                    return(blockBuilder);
                }

                blockBuilders.Add(blockBuilder);
            }

            if (blockBuilders.Count > 0)
            {
                MyObjectBuilder_CompoundCubeBlock compoundBuilder = MyCompoundCubeBlock.CreateBuilder(blockBuilders);
                return(compoundBuilder);
            }

            return(null);
        }