Beispiel #1
0
            public override bool DebugDraw()
            {
                if (MyDebugDrawSettings.DEBUG_DRAW_FRACTURED_PIECES)
                {
                    VRageRender.MyRenderProxy.DebugDrawAxis(m_piece.WorldMatrix, 1, false);

                    if (m_piece.Physics != null && m_piece.Physics.RigidBody != null)
                    {
                        MyPhysicsBody pb = m_piece.Physics as MyPhysicsBody;
                        HkRigidBody   rb = pb.RigidBody;

                        Vector3      center = pb.ClusterToWorld(rb.CenterOfMassWorld);// tohle uz je pozice stredu rigid body
                        BoundingBoxD bbox   = new BoundingBoxD(center - Vector3D.One * 0.1f, center + Vector3D.One * 0.1f);

                        if (!Sync.IsServer)
                        {
                            if (m_piece.m_serverPosition != Vector3.Zero)
                            {
                                BoundingBoxD bbox1 = new BoundingBoxD(m_piece.m_serverPosition - Vector3D.One * 0.1f, m_piece.GetBaseEntity().m_serverPosition + Vector3D.One * 0.1f);
                                VRageRender.MyRenderProxy.DebugDrawAABB(bbox1, Color.Yellow, 1.0f, 1.0f, false);

                                BoundingBoxD bbox2 = new BoundingBoxD(m_piece.PositionComp.WorldMatrix.Translation - Vector3D.One * 0.1f, m_piece.PositionComp.WorldMatrix.Translation + Vector3D.One * 0.1f);
                                VRageRender.MyRenderProxy.DebugDrawAABB(bbox2, Color.YellowGreen, 1.0f, 1.0f, false);

                                VRageRender.MyRenderProxy.DebugDrawLine3D(m_piece.GetBaseEntity().m_serverPosition, m_piece.PositionComp.WorldMatrix.Translation, Color.Yellow, Color.YellowGreen, false);
                            }
                        }

                        string str = String.Format("{0}\n, {1}\n{2}", rb.GetMotionType(), pb.Friction, pb.Entity.EntityId.ToString().Substring(0, 5));
                        VRageRender.MyRenderProxy.DebugDrawText3D(center, str, Color.White, 0.6f, false);
                    }
                }
                return(false);
            }
Beispiel #2
0
        public override MyObjectBuilder_EntityBase GetObjectBuilder(bool copy = false)
        {
            var old = base.GetObjectBuilder(copy);
            var ob  = old as MyObjectBuilder_FracturedPiece;

            foreach (var def in OriginalBlocks)
            {
                ob.BlockDefinitions.Add(def);
            }
            if (Physics == null)
            {
                Debug.Assert(m_shapes.Count > 0, "Saving invalid piece!");
                foreach (var shape in m_shapes)
                {
                    ob.Shapes.Add(new MyObjectBuilder_FracturedPiece.Shape()
                    {
                        Name = shape.Name, Orientation = shape.Orientation
                    });
                }
                return(ob);
            }

            if (Physics.BreakableBody.BreakableShape.IsCompound() || string.IsNullOrEmpty(Physics.BreakableBody.BreakableShape.Name))
            {
                Physics.BreakableBody.BreakableShape.GetChildren(m_children);
                if (m_children.Count == 0)
                {
                    Debug.Fail("Saiving invalid piece!");
                    return(ob);
                }

                int childrenCount = m_children.Count;
                for (int i = 0; i < childrenCount; ++i)
                {
                    var child = m_children[i];
                    if (string.IsNullOrEmpty(child.ShapeName))
                    {
                        child.GetChildren(m_children);
                    }
                }

                foreach (var child in m_children)
                {
                    var shapeName = child.ShapeName;
                    if (string.IsNullOrEmpty(shapeName))
                    {
                        continue;
                    }

                    var shape = new MyObjectBuilder_FracturedPiece.Shape()
                    {
                        Name        = shapeName,
                        Orientation = Quaternion.CreateFromRotationMatrix(child.GetTransform().GetOrientation()),
                        Fixed       = MyDestructionHelper.IsFixed(child.Shape)
                    };
                    ob.Shapes.Add(shape);
                }

                if (Physics.IsInWorld)
                {
                    var fixedPosition = Physics.ClusterToWorld(Vector3.Transform(m_children[0].GetTransform().Translation, Physics.RigidBody.GetRigidBodyMatrix()));
                    var posOr         = ob.PositionAndOrientation.Value;
                    posOr.Position            = fixedPosition;
                    ob.PositionAndOrientation = posOr;
                }
                m_children.Clear();
            }
            else
            {
                ob.Shapes.Add(new MyObjectBuilder_FracturedPiece.Shape()
                {
                    Name = Physics.BreakableBody.BreakableShape.Name
                });
            }
            Debug.Assert(ob.Shapes.Count > 0, "Saiving invalid piece!");
            return(ob);
        }