Exemple #1
0
        public static void DebugDraw(this IMyConveyorEndpoint endpoint)
        {
            if (!MyDebugDrawSettings.DEBUG_DRAW_CONVEYORS)
            {
                return;
            }

            Vector3 centerPos = new Vector3();

            for (int i = 0; i < endpoint.GetLineCount(); ++i)
            {
                var     position = endpoint.GetPosition(i);
                Vector3 pos      = new Vector3(position.LocalGridPosition) + 0.5f * new Vector3(position.VectorDirection);
                centerPos += pos;
            }
            centerPos = centerPos * endpoint.CubeBlock.CubeGrid.GridSize / (float)endpoint.GetLineCount();
            centerPos = Vector3.Transform(centerPos, endpoint.CubeBlock.CubeGrid.WorldMatrix);

            for (int i = 0; i < endpoint.GetLineCount(); ++i)
            {
                var            position = endpoint.GetPosition(i);
                MyConveyorLine line     = endpoint.GetConveyorLine(i);
                Vector3        pos      = (new Vector3(position.LocalGridPosition) + 0.5f * new Vector3(position.VectorDirection)) * endpoint.CubeBlock.CubeGrid.GridSize;
                Vector3        pos2     = (new Vector3(position.LocalGridPosition) + 0.4f * new Vector3(position.VectorDirection)) * endpoint.CubeBlock.CubeGrid.GridSize;
                pos  = Vector3.Transform(pos, endpoint.CubeBlock.CubeGrid.WorldMatrix);
                pos2 = Vector3.Transform(pos2, endpoint.CubeBlock.CubeGrid.WorldMatrix);
                Vector3 dir = Vector3.TransformNormal(position.VectorDirection * endpoint.CubeBlock.CubeGrid.GridSize * 0.5f, endpoint.CubeBlock.CubeGrid.WorldMatrix);

                Color color = line.IsFunctional ? Color.Orange : Color.DarkRed;
                color = line.IsWorking ? Color.GreenYellow : color;

                EndpointDebugShape shape = EndpointDebugShape.SHAPE_SPHERE;
                float dirMultiplier      = 1.0f;
                float radius             = 0.05f;

                if (line.GetEndpoint(0) == null || line.GetEndpoint(1) == null)
                {
                    if (line.Type == Common.ObjectBuilders.MyObjectBuilder_ConveyorLine.LineType.SMALL_LINE)
                    {
                        dirMultiplier = 0.2f;
                        radius        = 0.015f;
                        shape         = EndpointDebugShape.SHAPE_SPHERE;
                    }
                    else
                    {
                        dirMultiplier = 0.1f;
                        radius        = 0.015f;
                        shape         = EndpointDebugShape.SHAPE_CAPSULE;
                    }
                }
                else
                {
                    if (line.Type == Common.ObjectBuilders.MyObjectBuilder_ConveyorLine.LineType.SMALL_LINE)
                    {
                        dirMultiplier = 1.0f;
                        radius        = 0.05f;
                        shape         = EndpointDebugShape.SHAPE_SPHERE;
                    }
                    else
                    {
                        dirMultiplier = 0.2f;
                        radius        = 0.05f;
                        shape         = EndpointDebugShape.SHAPE_CAPSULE;
                    }
                }

                MyRenderProxy.DebugDrawLine3D(pos, pos + dir * dirMultiplier, color, color, true);
                if (shape == EndpointDebugShape.SHAPE_SPHERE)
                {
                    MyRenderProxy.DebugDrawSphere(pos, radius * endpoint.CubeBlock.CubeGrid.GridSize, color.ToVector3(), 1.0f, false);
                }
                else if (shape == EndpointDebugShape.SHAPE_CAPSULE)
                {
                    MyRenderProxy.DebugDrawCapsule(pos - dir * dirMultiplier, pos + dir * dirMultiplier, radius * endpoint.CubeBlock.CubeGrid.GridSize, color, false);
                }

                if (MyDebugDrawSettings.DEBUG_DRAW_CONVEYORS_LINE_IDS)
                {
                    MyRenderProxy.DebugDrawText3D(pos2, line.GetHashCode().ToString(), color, 0.6f, false);
                }

                MyRenderProxy.DebugDrawLine3D(pos, centerPos, color, color, false);
            }
        }