Пример #1
0
        public override void Draw()
        {
            if (MyAPIGateway.Input.IsNewKeyPressed(MyKeys.OemQuotes))
            {
                base.DumpData();
            }
            for (var i = 0; i < Segments.Count; i++)
            {
                Segment segment = Segments.GetInternalArray()[i];
                if (segment == null)
                {
                    continue;
                }
                var state = segment.CurrentEma;
                if (state.Output <= 0)
                {
                    continue;
                }
                var c     = BeamColor(state.OutputColor, state.Output);
                var width = BeamWidth(state.Output);

                // TODO stronger caching
                if (segment.Path.Count > 0)
                {
                    Vector3D prev     = segment.Path[0].Dummy.WorldPosition;
                    bool     prevView = MyAPIGateway.Session.Camera.IsInFrustum(ref prev);
                    for (var j = 1; j < segment.Path.Count; j++)
                    {
                        var curr     = segment.Path[j].Dummy.WorldPosition;
                        var currView = MyAPIGateway.Session.Camera.IsInFrustum(ref curr);
                        // todo custom quad billboard with control over thickness at both ends
                        if (prevView || currView)
                        {
                            MySimpleObjectDraw.DrawLine(prev, curr, LaserMaterial, ref c, width);
                        }
                        prev     = curr;
                        prevView = currView;
                    }
                }

                foreach (var conn in segment.Connections)
                {
                    var tsi = conn.To.Segment?.Path.Count ?? 0;
                    var fsi = conn.From.Segment?.Path.Count ?? 0;
                    var tci = conn.To.Segment?.Connections.Count ?? 0;
                    var fci = conn.From.Segment?.Connections.Count ?? 0;
                    // choose source segment by first which has more elements, then by which has fewer connections, then just choose from;
                    Segment preferredSegment = conn.From.Segment;
                    if (tsi != fsi)
                    {
                        preferredSegment = tsi > fsi ? conn.To.Segment : conn.From.Segment;
                    }
                    else if (tci != fci)
                    {
                        preferredSegment = tci < fci ? conn.To.Segment : conn.From.Segment;
                    }
                    if (segment == preferredSegment)
                    {
                        var a = conn.From.Dummy.WorldPosition;
                        var b = conn.To.Dummy.WorldPosition;
                        if (MyAPIGateway.Session.Camera.IsInFrustum(ref a) ||
                            MyAPIGateway.Session.Camera.IsInFrustum(ref b))
                        {
                            MySimpleObjectDraw.DrawLine(a, b, LaserMaterial, ref c, width);
                        }
                    }
                }
            }
        }