示例#1
0
 private void DebugDrawMountPoints(MySlimBlock block)
 {
     if (block.FatBlock is MyCompoundCubeBlock)
     {
         foreach (MySlimBlock block2 in (block.FatBlock as MyCompoundCubeBlock).GetBlocks())
         {
             this.DebugDrawMountPoints(block2);
         }
     }
     else
     {
         Matrix matrix;
         block.GetLocalMatrix(out matrix);
         MatrixD drawMatrix = matrix * this.m_cubeGrid.WorldMatrix;
         if ((!MyFakes.ENABLE_FRACTURE_COMPONENT || (block.FatBlock == null)) || !block.FatBlock.Components.Has <MyFractureComponentBase>())
         {
             MyCubeBuilder.DrawMountPoints(this.m_cubeGrid.GridSize, block.BlockDefinition, ref drawMatrix);
         }
         else
         {
             MyFractureComponentCubeBlock fractureComponent = block.GetFractureComponent();
             if (fractureComponent != null)
             {
                 MyCubeBuilder.DrawMountPoints(this.m_cubeGrid.GridSize, block.BlockDefinition, drawMatrix, fractureComponent.MountPoints.GetInternalArray <MyCubeBlockDefinition.MountPoint>());
             }
         }
     }
 }
示例#2
0
        public static MyFracturedPiece CreateFracturePiece(MyFractureComponentCubeBlock fractureBlockComponent, bool sync)
        {
            MyPhysicalModelDefinition definition;

            if (!fractureBlockComponent.Block.BlockDefinition.CreateFracturedPieces)
            {
                return(null);
            }
            if (!fractureBlockComponent.Shape.IsValid())
            {
                MyLog.Default.WriteLine("Invalid shape in fracture component, Id: " + fractureBlockComponent.Block.BlockDefinition.Id.ToString() + ", closed: " + fractureBlockComponent.Block.FatBlock.Closed.ToString());
                return(null);
            }
            MatrixD          worldMatrix = fractureBlockComponent.Block.FatBlock.WorldMatrix;
            MyFracturedPiece piece       = CreateFracturePiece(ref fractureBlockComponent.Shape, ref worldMatrix, false);

            piece.OriginalBlocks.Add(fractureBlockComponent.Block.BlockDefinition.Id);
            if (MyFakes.ENABLE_FRACTURE_PIECE_SHAPE_CHECK)
            {
                piece.DebugCheckValidShapes();
            }
            if (MyDefinitionManager.Static.TryGetDefinition <MyPhysicalModelDefinition>(piece.OriginalBlocks[0], out definition))
            {
                piece.Physics.MaterialType = definition.PhysicalMaterial.Id.SubtypeId;
            }
            if (MyExternalReplicable.FindByObject(piece) == null)
            {
                Sandbox.Game.Entities.MyEntities.RaiseEntityCreated(piece);
            }
            Sandbox.Game.Entities.MyEntities.Add(piece, true);
            return(piece);
        }
示例#3
0
        public MyFractureComponentCubeBlock GetFractureComponent()
        {
            MyFractureComponentCubeBlock fractureComponent = null;

            if (MyFakes.ENABLE_FRACTURE_COMPONENT)
            {
                fractureComponent = Components.Get <MyFractureComponentBase>() as MyFractureComponentCubeBlock;
            }
            return(fractureComponent);
        }
        public static MyFracturedPiece CreateFracturePiece(MyFractureComponentCubeBlock fractureBlockComponent, bool sync)
        {
            if (!fractureBlockComponent.Block.BlockDefinition.CreateFracturedPieces)
            {
                return(null);
            }

            if (!fractureBlockComponent.Shape.IsValid())
            {
                Debug.Fail("Invalid shape in fracture component");
                MyLog.Default.WriteLine("Invalid shape in fracture component, Id: " + fractureBlockComponent.Block.BlockDefinition.Id.ToString() + ", closed: " + fractureBlockComponent.Block.FatBlock.Closed);
                return(null);
            }

            System.Diagnostics.Debug.Assert(Sync.IsServer, "Only on server");
            var m  = fractureBlockComponent.Block.FatBlock.WorldMatrix;
            var fp = CreateFracturePiece(ref fractureBlockComponent.Shape, ref m, false);

            fp.OriginalBlocks.Add(fractureBlockComponent.Block.BlockDefinition.Id);

            // Check valid shapes from block definitions.
            if (MyFakes.ENABLE_FRACTURE_PIECE_SHAPE_CHECK)
            {
                fp.DebugCheckValidShapes();
            }

            MyPhysicalModelDefinition def;

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

            ProfilerShort.Begin("MyEntities.Add");
            if (MyExternalReplicable.FindByObject(fp) == null)
            {
                MyEntities.RaiseEntityCreated(fp);
            }
            MyEntities.Add(fp);
            ProfilerShort.End();

            return(fp);
        }
示例#5
0
        public static MyFracturedPiece CreateFracturePiece(MyFractureComponentCubeBlock fractureBlockComponent, bool sync)
        {
            System.Diagnostics.Debug.Assert(Sync.IsServer, "Only on server");
            var m  = fractureBlockComponent.Block.FatBlock.WorldMatrix;
            var fp = CreateFracturePiece(ref fractureBlockComponent.Shape, fractureBlockComponent.Block.CubeGrid.Physics.HavokWorld.DestructionWorld, ref m, false);

            fp.OriginalBlocks.Add(fractureBlockComponent.Block.BlockDefinition.Id);

            MyPhysicalModelDefinition def;

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

            if (sync)
            {
                MySyncDestructions.CreateFracturePiece((Sandbox.Common.ObjectBuilders.MyObjectBuilder_FracturedPiece)fp.GetObjectBuilder());
            }

            return(fp);
        }
示例#6
0
        private void CreateMountPoints()
        {
            ProfilerShort.Begin("FB.CreateMountPoints");
            if (MyFakes.FRACTURED_BLOCK_AABB_MOUNT_POINTS)
            {
                MountPoints = new List <MyCubeBlockDefinition.MountPoint>();
                var blockBB = BoundingBox.CreateInvalid();
                for (int i = 0; i < OriginalBlocks.Count; i++)
                {
                    var    b = OriginalBlocks[i];
                    Matrix m;
                    Orientations[i].GetMatrix(out m);
                    var size = new Vector3(MyDefinitionManager.Static.GetCubeBlockDefinition(b).Size);
                    var bb   = new BoundingBox(-size / 2, size / 2);
                    blockBB = blockBB.Include(bb.Transform(m));
                }
                var he = blockBB.HalfExtents;
                blockBB.Min += he;
                blockBB.Max += he;

                Shape.GetChildren(m_children);
                foreach (var child in m_children)
                {
                    var shape = child.Shape;
                    shape = MyFractureComponentCubeBlock.AddMountForShape(shape, child.GetTransform(), ref blockBB, CubeGrid.GridSize, MountPoints);
                }
                if (m_children.Count == 0)
                {
                    MyFractureComponentCubeBlock.AddMountForShape(Shape, Matrix.Identity, ref blockBB, CubeGrid.GridSize, MountPoints);
                }
                m_children.Clear();
            }
            else
            {
                MountPoints = MyCubeBuilder.AutogenerateMountpoints(new HkShape[] { Shape.GetShape() }, CubeGrid.GridSize);
            }
            ProfilerShort.End();
        }
示例#7
0
 private unsafe void CreateMountPoints()
 {
     if (!MyFakes.FRACTURED_BLOCK_AABB_MOUNT_POINTS)
     {
         HkShape[] shapes = new HkShape[] { this.Shape.GetShape() };
         this.MountPoints = MyCubeBuilder.AutogenerateMountpoints(shapes, base.CubeGrid.GridSize);
     }
     else
     {
         this.MountPoints = new List <MyCubeBlockDefinition.MountPoint>();
         BoundingBox blockBB = BoundingBox.CreateInvalid();
         for (int i = 0; i < this.OriginalBlocks.Count; i++)
         {
             Matrix         matrix;
             MyDefinitionId id = this.OriginalBlocks[i];
             this.Orientations[i].GetMatrix(out matrix);
             Vector3     vector2 = new Vector3(MyDefinitionManager.Static.GetCubeBlockDefinition(id).Size);
             BoundingBox box2    = new BoundingBox(-vector2 / 2f, vector2 / 2f);
             blockBB = blockBB.Include(box2.Transform(matrix));
         }
         Vector3  halfExtents = blockBB.HalfExtents;
         Vector3 *vectorPtr1  = (Vector3 *)ref blockBB.Min;
         vectorPtr1[0] += halfExtents;
         Vector3 *vectorPtr2 = (Vector3 *)ref blockBB.Max;
         vectorPtr2[0] += halfExtents;
         this.Shape.GetChildren(m_children);
         foreach (HkdShapeInstanceInfo info in m_children)
         {
             MyFractureComponentCubeBlock.AddMountForShape(info.Shape, info.GetTransform(), ref blockBB, base.CubeGrid.GridSize, this.MountPoints);
         }
         if (m_children.Count == 0)
         {
             MyFractureComponentCubeBlock.AddMountForShape(this.Shape, Matrix.Identity, ref blockBB, base.CubeGrid.GridSize, this.MountPoints);
         }
         m_children.Clear();
     }
 }
示例#8
0
        /// <summary>
        /// Returns true if this block can connect to another block (of the given type) in the given position.
        /// This is called only if CheckConnectionAllowed == true.
        /// If this method would return true for any position, set CheckConnectionAllowed to false to avoid
        /// unnecessary overhead. It is the block's responsibility to call CubeGrid.UpdateBlockNeighbors every time the
        /// conditions that are checked by this method change.
        /// </summary>
        public virtual bool ConnectionAllowed(ref Vector3I otherBlockPos, ref Vector3I faceNormal, MyCubeBlockDefinition def)
        {
            if (MyFakes.ENABLE_FRACTURE_COMPONENT && Components.Has <MyFractureComponentBase>())
            {
                MyFractureComponentCubeBlock fractureComponent = GetFractureComponent();

                if (fractureComponent == null || fractureComponent.MountPoints == null)
                {
                    return(true);
                }

                var other = CubeGrid.GetCubeBlock(otherBlockPos);
                if (other == null)
                {
                    return(true);
                }

                MyBlockOrientation or = other.Orientation;
                var position          = Position;
                Debug.Assert(m_tmpMountPoints.Count == 0);
                m_tmpMountPoints.Clear();

                if (other.FatBlock != null && other.FatBlock.Components.Has <MyFractureComponentBase>())
                {
                    MyFractureComponentCubeBlock otherFractureComponent = other.GetFractureComponent();
                    if (otherFractureComponent != null)
                    {
                        m_tmpMountPoints.AddRange(otherFractureComponent.MountPoints);
                    }
                }
                else if (other.FatBlock is MyCompoundCubeBlock)
                {
                    var lst = new List <MyCubeBlockDefinition.MountPoint>();
                    foreach (var b in (other.FatBlock as MyCompoundCubeBlock).GetBlocks())
                    {
                        MyFractureComponentCubeBlock blockInCompoundFractureComponent = b.GetFractureComponent();
                        if (blockInCompoundFractureComponent != null)
                        {
                            m_tmpMountPoints.AddRange(blockInCompoundFractureComponent.MountPoints);
                        }
                        else
                        {
                            var mountPoints = b.BlockDefinition.GetBuildProgressModelMountPoints(b.BuildLevelRatio);
                            lst.Clear();
                            MyCubeGrid.TransformMountPoints(lst, b.BlockDefinition, mountPoints, ref b.Orientation);
                            m_tmpMountPoints.AddRange(lst);
                        }
                    }
                }
                else
                {
                    var mountPoints = def.GetBuildProgressModelMountPoints(other.BuildLevelRatio);
                    MyCubeGrid.TransformMountPoints(m_tmpMountPoints, def, mountPoints, ref or);
                }

                bool result = MyCubeGrid.CheckMountPointsForSide(fractureComponent.MountPoints, ref SlimBlock.Orientation, ref position, BlockDefinition.Id, ref faceNormal, m_tmpMountPoints,
                                                                 ref or, ref otherBlockPos, def.Id);

                m_tmpMountPoints.Clear();

                return(result);
            }

            return(true);
        }