Beispiel #1
0
        void DrawGL(int renderWidth, int renderHeight)
        {
            //Set state
            renderTarget.BindFramebuffer();
            rstate.Cull = true;
            var cc = rstate.ClearColor;

            rstate.DepthEnabled = true;
            rstate.ClearColor   = Color4.CornflowerBlue;
            rstate.ClearAll();
            vps.Push(0, 0, renderWidth, renderHeight);
            //Draw Model
            var cam = new ChaseCamera(new Viewport(0, 0, renderWidth, renderHeight));

            cam.ChasePosition         = Vector3.Zero;
            cam.ChaseOrientation      = Matrix4.CreateRotationX(MathHelper.Pi);
            cam.DesiredPositionOffset = new Vector3(drawable.GetRadius() * 2, 0, 0);
            cam.OffsetDirection       = Vector3.UnitX;
            cam.Reset();
            cam.Update(TimeSpan.FromSeconds(500));
            buffer.StartFrame();
            drawable.Update(cam, TimeSpan.Zero, TimeSpan.Zero);
            drawable.Update(cam, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0));
            drawable.DrawBuffer(buffer, Matrix4.Identity, Lighting.Empty);
            buffer.DrawOpaque(rstate);
            rstate.DepthWrite = false;
            buffer.DrawTransparent(rstate);
            rstate.DepthWrite = true;
            //Restore state
            rstate.Cull         = false;
            rstate.BlendMode    = BlendMode.Normal;
            rstate.DepthEnabled = false;
            rstate.ClearColor   = cc;
            RenderTarget2D.ClearBinding();
            vps.Pop();
        }
Beispiel #2
0
        void DrawGL(int renderWidth, int renderHeight)
        {
            //Set state
            renderTarget.BindFramebuffer();
            rstate.Cull = true;
            var cc = rstate.ClearColor;

            rstate.DepthEnabled = true;
            rstate.ClearColor   = Color4.CornflowerBlue * new Color4(0.3f, 0.3f, 0.3f, 1f);
            rstate.ClearAll();
            vps.Push(0, 0, renderWidth, renderHeight);
            //Draw Model
            var cam = new ChaseCamera(new Viewport(0, 0, renderWidth, renderHeight));

            cam.ChasePosition         = Vector3.Zero;
            cam.ChaseOrientation      = Matrix4.CreateRotationX(MathHelper.Pi);
            cam.DesiredPositionOffset = new Vector3(drawable.GetRadius() * 2, 0, 0);
            //cam.OffsetDirection = Vector3.UnitX;
            cam.Reset();
            cam.Update(TimeSpan.FromSeconds(500));
            cam.UpdateFrameNumber(rand.Next()); //Stop bad matrix caching
            drawable.Update(cam, TimeSpan.Zero, TimeSpan.Zero);
            if (viewMode != M_NONE)
            {
                buffer.StartFrame(rstate);
                if (drawable is CmpFile)
                {
                    DrawCmp(cam, false);
                }
                else
                {
                    DrawSimple(cam, false);
                }
                buffer.DrawOpaque(rstate);
                rstate.DepthWrite = false;
                buffer.DrawTransparent(rstate);
                rstate.DepthWrite = true;
            }
            if (doWireframe)
            {
                buffer.StartFrame(rstate);
                GL.PolygonOffset(1, 1);
                rstate.Wireframe = true;
                if (drawable is CmpFile)
                {
                    DrawCmp(cam, true);
                }
                else
                {
                    DrawSimple(cam, false);
                }
                GL.PolygonOffset(0, 0);
                buffer.DrawOpaque(rstate);
                rstate.Wireframe = false;
            }
            //Draw hardpoints
            DrawHardpoints(cam);
            //Restore state
            rstate.Cull         = false;
            rstate.BlendMode    = BlendMode.Normal;
            rstate.DepthEnabled = false;
            rstate.ClearColor   = cc;
            RenderTarget2D.ClearBinding();
            vps.Pop();
        }
Beispiel #3
0
        public ModelViewer(string title, string name, IDrawable drawable, MainWindow win, UtfTab parent)
        {
            Title         = title;
            Name          = name;
            this.drawable = drawable;
            this.parent   = parent;
            rstate        = win.RenderState;
            vps           = win.Viewport;
            res           = win.Resources;
            buffer        = win.Commands;
            SetupViewport();
            zoom = drawable.GetRadius() * 2;
            if (drawable is CmpFile)
            {
                //Setup Editor UI for constructs + hardpoints
                var cmp = (CmpFile)drawable;
                foreach (var p in cmp.Parts)
                {
                    var parentHp = p.Value.Construct != null ? p.Value.Construct.Transform : Matrix4.Identity;
                    foreach (var hp in p.Value.Model.Hardpoints)
                    {
                        gizmos.Add(new HardpointGizmo(hp, p.Value.Construct));
                    }
                }
                if (cmp.Animation != null)
                {
                    animator = new AnimationComponent(cmp.Constructs, cmp.Animation);
                }
                foreach (var p in cmp.Parts)
                {
                    if (p.Value.Construct == null)
                    {
                        rootModel = p.Value.Model;
                    }
                }
                var q = new Queue <AbstractConstruct>();
                foreach (var c in cmp.Constructs)
                {
                    if (c.ParentName == "Root" || string.IsNullOrEmpty(c.ParentName))
                    {
                        cons.Add(GetNodeCmp(cmp, c));
                    }
                    else
                    {
                        if (cmp.Constructs.Find(c.ParentName) != null)
                        {
                            q.Enqueue(c);
                        }
                        else
                        {
                            conOrphan.Add(c);
                        }
                    }
                }
                while (q.Count > 0)
                {
                    var c = q.Dequeue();
                    if (!PlaceNode(cons, c))
                    {
                        q.Enqueue(c);
                    }
                }
                int maxLevels = 0;
                foreach (var p in cmp.Parts)
                {
                    maxLevels = Math.Max(maxLevels, p.Value.Model.Levels.Length - 1);
                    if (p.Value.Model.Switch2 != null)
                    {
                        for (int i = 0; i < p.Value.Model.Switch2.Length - 1; i++)
                        {
                            maxDistance = Math.Max(maxDistance, p.Value.Model.Switch2[i]);
                        }
                    }
                }
                levels = new string[maxLevels + 1];
                for (int i = 0; i <= maxLevels; i++)
                {
                    levels[i] = i.ToString();
                }
            }
            else if (drawable is ModelFile)
            {
                var mdl = (ModelFile)drawable;
                rootModel = mdl;
                foreach (var hp in mdl.Hardpoints)
                {
                    gizmos.Add(new HardpointGizmo(hp, null));
                }

                levels = new string[mdl.Levels.Length];
                for (int i = 0; i < mdl.Levels.Length; i++)
                {
                    levels[i] = i.ToString();
                }
                if (mdl.Switch2 != null)
                {
                    for (int i = 0; i < mdl.Switch2.Length - 1; i++)
                    {
                        maxDistance = Math.Max(maxDistance, mdl.Switch2[i]);
                    }
                }
            }
            maxDistance += 50;
        }