Example #1
0
        protected override void Load()
        {
            Title     = "LancerEdit";
            guiHelper = new ImGuiHelper(this);
            Audio     = new AudioManager(this);
            FileDialog.RegisterParent(this);
            Viewport = new ViewportManager(RenderState);
            var texturefilters = new List <string>(defaultFilters);

            if (RenderState.MaxAnisotropy > 0)
            {
                anisotropyLevels = RenderState.GetAnisotropyLevels();
                foreach (var lvl in anisotropyLevels)
                {
                    texturefilters.Add(string.Format("Anisotropic {0}x", lvl));
                }
            }
            filters     = texturefilters.ToArray();
            Resources   = new ResourceManager(this);
            Commands    = new CommandBuffer();
            Billboards  = new Billboards();
            Polyline    = new PolylineRender(Commands);
            DebugRender = new PhysicsDebugRenderer();
            Viewport.Push(0, 0, 800, 600);
        }
 public void DrawBeams(PolylineRender polyline, PhysicsDebugRenderer debug, Matrix4 transform, float sparam)
 {
     if (Beams != null)
     {
         foreach (var kv in Beams)
         {
             if (NodeEnabled(kv.Node))
             {
                 kv.BeamApp.DrawBeamApp(polyline, (float)globaltime, kv.Node, this, ref transform, sparam);
             }
         }
     }
 }
Example #3
0
 protected override void Load()
 {
     Title     = "LancerEdit";
     guiHelper = new ImGuiHelper(this);
     Audio     = new AudioManager(this);
     FileDialog.RegisterParent(this);
     Viewport    = new ViewportManager(RenderState);
     Resources   = new ResourceManager(this);
     Commands    = new CommandBuffer();
     Billboards  = new Billboards();
     Polyline    = new PolylineRender(Commands);
     DebugRender = new PhysicsDebugRenderer();
     Viewport.Push(0, 0, 800, 600);
 }
Example #4
0
        protected override void Load()
        {
            Title     = "LancerEdit";
            guiHelper = new ImGuiHelper(this);
            Audio     = new AudioManager(this);
            FileDialog.RegisterParent(this);
            Viewport = new ViewportManager(RenderState);
            var texturefilters = new List <string>(defaultFilters);

            if (RenderState.MaxAnisotropy > 0)
            {
                anisotropyLevels = RenderState.GetAnisotropyLevels();
                foreach (var lvl in anisotropyLevels)
                {
                    texturefilters.Add(string.Format("Anisotropic {0}x", lvl));
                }
            }
            filters     = texturefilters.ToArray();
            Resources   = new ResourceManager(this);
            Commands    = new CommandBuffer();
            Billboards  = new Billboards();
            Polyline    = new PolylineRender(Commands);
            DebugRender = new PhysicsDebugRenderer();
            Viewport.Push(0, 0, 800, 600);
            Keyboard.KeyDown += Keyboard_KeyDown;

            //TODO: Icon-setting code very messy
            int w, h, c;
            var stream = typeof(MainWindow).Assembly.GetManifestResourceStream("LancerEdit.reactor_64.png");
            var bytes  = new byte[stream.Length];

            stream.Read(bytes, 0, (int)stream.Length);
            StbSharp.Stb.stbi_set_flip_vertically_on_load(0);
            var img = StbSharp.Stb.stbi_load_from_memory(bytes, out w, out h, out c, StbSharp.Stb.STBI_rgb_alpha);

            StbSharp.Stb.stbi_set_flip_vertically_on_load(1);
            SetWindowIcon(w, h, img);

            //Open passed in files!
            if (InitOpenFile != null)
            {
                foreach (var f in InitOpenFile)
                {
                    OpenFile(f);
                }
            }
        }
 public void Draw(PolylineRender polyline, Billboards billboards, PhysicsDebugRenderer debug)
 {
     for (int i = 0; i < Particles.Length; i++)
     {
         if (!Particles[i].Active)
         {
             continue;
         }
         var inst = Particles[i].Instance;
         if (inst.NodeEnabled(Particles[i].Appearance))
         {
             var app = (FxAppearance)Particles[i].Appearance.Node;
             app.Debug = debug;
             app.Draw(ref Particles[i], (float)inst.LastTime, (float)inst.GlobalTime, Particles[i].Appearance, inst.Resources, billboards, ref inst.DrawTransform, inst.DrawSParam);
         }
     }
 }
Example #6
0
        protected override void Load()
        {
            Title     = "LancerEdit";
            guiHelper = new ImGuiHelper(this);
            guiHelper.PauseWhenUnfocused = Config.PauseWhenUnfocused;
            Audio = new AudioManager(this);
            FileDialog.RegisterParent(this);
            Viewport = new ViewportManager(RenderState);
            InitOptions();
            Resources   = new GameResourceManager(this);
            Commands    = new CommandBuffer();
            Billboards  = new Billboards();
            Polyline    = new PolylineRender(Commands);
            DebugRender = new PhysicsDebugRenderer();
            Viewport.Push(0, 0, 800, 600);
            Keyboard.KeyDown += Keyboard_KeyDown;

            //TODO: Icon-setting code very messy
            int w, h, c;
            var stream = typeof(MainWindow).Assembly.GetManifestResourceStream("LancerEdit.reactor_64.png");
            var bytes  = new byte[stream.Length];

            stream.Read(bytes, 0, (int)stream.Length);
            StbSharp.Stb.stbi_set_flip_vertically_on_load(0);
            var img = StbSharp.Stb.stbi_load_from_memory(bytes, out w, out h, out c, StbSharp.Stb.STBI_rgb_alpha);

            StbSharp.Stb.stbi_set_flip_vertically_on_load(1);
            SetWindowIcon(w, h, img);

            //Open passed in files!
            if (InitOpenFile != null)
            {
                foreach (var f in InitOpenFile)
                {
                    OpenFile(f);
                }
            }

            Renderer2D = new Renderer2D(RenderState);
            RichText   = Renderer2D.CreateRichTextEngine();
            Services.Add(Renderer2D);
            Fonts = new FontManager(this);
            Fonts.ConstructDefaultFonts();
            Services.Add(Fonts);
        }
Example #7
0
 public AleViewer(string title, string name, AleFile ale, MainWindow main)
 {
     plib        = new ParticleLibrary(main.Resources, ale);
     effectNames = new string[plib.Effects.Count];
     for (int i = 0; i < effectNames.Length; i++)
     {
         effectNames[i] = string.Format("{0} (0x{1:X})", plib.Effects[i].Name, plib.Effects[i].CRC);
     }
     Title       = title;
     this.name   = name;
     this.rstate = main.RenderState;
     vps         = main.Viewport;
     buffer      = main.Commands;
     billboards  = main.Billboards;
     polyline    = main.Polyline;
     debug       = main.DebugRender;
     SetupRender(0);
 }
 public void Draw(PolylineRender polyline, Billboards billboards, PhysicsDebugRenderer debug, Matrix4 transform, float sparam)
 {
     DrawTransform = transform;
     DrawSParam    = sparam;
     if (Pool == null)
     {
         return;
     }
     DrawTransform = transform;
     DrawSParam    = sparam;
     foreach (var kv in BeamAppearances)
     {
         if (NodeEnabled(kv.Key))
         {
             var app = (FLBeamAppearance)kv.Key.Node;
             app.DrawBeamApp(polyline, kv.Value, (float)globaltime, kv.Key, this, Effect.ResourceManager, billboards, ref transform, sparam);
         }
     }
 }
Example #9
0
 protected override void Load()
 {
     DefaultMaterialMap.Init();
     Title     = "LancerEdit";
     guiHelper = new ImGuiHelper(this, DpiScale * Config.UiScale);
     guiHelper.PauseWhenUnfocused = Config.PauseWhenUnfocused;
     Audio = new AudioManager(this);
     FileDialog.RegisterParent(this);
     options     = new OptionsWindow(this);
     Resources   = new GameResourceManager(this);
     Commands    = new CommandBuffer();
     Polyline    = new PolylineRender(Commands);
     DebugRender = new PhysicsDebugRenderer();
     RenderContext.PushViewport(0, 0, 800, 600);
     Keyboard.KeyDown += Keyboard_KeyDown;
     //TODO: Icon-setting code very messy
     using (var stream = typeof(MainWindow).Assembly.GetManifestResourceStream("LancerEdit.reactor_64.png"))
     {
         var icon = LibreLancer.ImageLib.Generic.BytesFromStream(stream);
         SetWindowIcon(icon.Width, icon.Height, icon.Data);
     }
     using (var stream = typeof(MainWindow).Assembly.GetManifestResourceStream("LancerEdit.reactor_128.png"))
     {
         var icon = (Texture2D)LibreLancer.ImageLib.Generic.FromStream(stream);
         logoTexture = ImGuiHelper.RegisterTexture(icon);
     }
     //Open passed in files!
     if (InitOpenFile != null)
     {
         foreach (var f in InitOpenFile)
         {
             OpenFile(f);
         }
     }
     RichText = RenderContext.Renderer2D.CreateRichTextEngine();
     Fonts    = new FontManager();
     Fonts.ConstructDefaultFonts();
     Services.Add(Fonts);
     Make3dbDlg = new CommodityIconDialog(this);
     LoadScripts();
 }
Example #10
0
 public AleViewer(string title, string name, AleFile ale, MainWindow main)
 {
     plib        = new ParticleLibrary(main.Resources, ale);
     pool        = new ParticleEffectPool();
     effectNames = new string[plib.Effects.Count];
     for (int i = 0; i < effectNames.Length; i++)
     {
         effectNames[i] = string.Format("{0} (0x{1:X})", plib.Effects[i].Name, plib.Effects[i].CRC);
     }
     Title       = title;
     this.name   = name;
     this.rstate = main.RenderState;
     aleViewport = new Viewport3D(main);
     aleViewport.DefaultOffset    =
         aleViewport.CameraOffset = new Vector3(0, 0, 200);
     aleViewport.ModelScale       = 25;
     buffer     = main.Commands;
     billboards = main.Billboards;
     polyline   = main.Polyline;
     debug      = main.DebugRender;
     SetupRender(0);
 }
Example #11
0
 public void Draw(PolylineRender polyline, Billboards billboards, PhysicsDebugRenderer debug, Matrix4 transform, float sparam)
 {
     for (int i = 0; i < Particles.Length; i++)
     {
         if (!Particles[i].Active)
         {
             continue;
         }
         if (DrawEnabled(Particles[i].Appearance))
         {
             Particles[i].Appearance.Debug = debug;
             Particles[i].Appearance.Draw(ref Particles[i], (float)globaltime, Effect, Effect.ResourceManager, billboards, ref transform, sparam);
         }
     }
     foreach (var kv in BeamAppearances)
     {
         if (DrawEnabled(kv.Key))
         {
             kv.Key.DrawBeamApp(polyline, kv.Value, (float)globaltime, Effect, this, Effect.ResourceManager, billboards, ref transform, sparam);
         }
     }
 }
Example #12
0
        public void DrawBeamApp(PolylineRender poly, float globalTime, NodeReference reference, ParticleEffectInstance instance, ref Matrix4x4 transform, float sparam)
        {
            //get particles!
            var beam = instance.Beams[reference.BeamIndex];
            if (beam.ParticleCount < 2) { beam.ParticleCount = 0;  return; }
            AgeComparer.Instance.Particles = instance.Pool.Particles;
            Array.Sort(beam.ParticleIndices, 0, beam.ParticleCount, AgeComparer.Instance);
            //draw
            var node_tr = GetAttachment(reference, transform);
            Texture2D tex;
            Vector2 tl, tr, bl, br;
            var res = instance.Resources;
            TextureHandler.Update(Texture, res);
            var frame = GetFrame(globalTime, sparam, ref instance.Pool.Particles[beam.ParticleIndices[0]]);
            int index = (int) Math.Floor((TextureHandler.FrameCount - 1) * frame) * 4;
            tl = TextureHandler.Coordinates[index];
            tr = TextureHandler.Coordinates[index + 1];
            bl = TextureHandler.Coordinates[index + 2];
            br = TextureHandler.Coordinates[index + 3];
            //Sorting hack kinda
            var z = RenderHelpers.GetZ(instance.Pool.Camera.Position, Vector3.Transform(Vector3.Zero, node_tr));
            for (int j = 0; j < 2; j++) //two planes
            {
                poly.StartLine(TextureHandler.Texture ?? res.WhiteTexture, BlendInfo);
                bool odd = true;
                Vector3 dir = Vector3.Zero;

                for (int i = 0; i < beam.ParticleCount; i++)
                {
                    var pos = Vector3.Transform(instance.Pool.Particles[beam.ParticleIndices[i]].Position, node_tr);
                    if (i + 1 < beam.ParticleCount) {
                        var pos2 = Vector3.Transform(instance.Pool.Particles[beam.ParticleIndices[i + 1]].Position, node_tr);
                        var forward = (pos2 - pos).Normalized();
                        var toCamera = (instance.Pool.Camera.Position - pos).Normalized();
                        var up = Vector3.Cross(toCamera, forward);
                        up.Normalize();
                        dir = up;
                        if (j == 1)
                        {
                            //Broken? Doesn't show up
                            var right = Vector3.Cross(up, forward).Normalized();
                            dir = right;
                        }
                    }
                    var time = instance.Pool.Particles[beam.ParticleIndices[i]].TimeAlive / instance.Pool.Particles[beam.ParticleIndices[i]].LifeSpan;
                    var w = Width.GetValue(sparam, time);
                    poly.AddPoint(
                        pos + (dir * w / 2),
                        pos - (dir * w / 2),
                        odd ? tl : bl,
                        odd ? tr : br,
                        new Color4(
                            Color.GetValue(sparam, time),
                            Alpha.GetValue(sparam, time)
                        )
                    );
                    odd = !odd;
                }
                poly.FinishLine(z);
            }
            beam.ParticleCount = 0;
        }
Example #13
0
        public unsafe void DrawBeamApp(PolylineRender poly, LineBuffer points, float globalTime, NodeReference reference, ParticleEffectInstance instance, ResourceManager res, Billboards billboards, ref Matrix4 transform, float sparam)
        {
            //TODO: Cross-plane not showing
            //TODO: In some cases particles are going backwards? (Broken emitter or LineBuffer)
            //TODO: See if z sorting can be better for Polyline
            //TODO: Implement FLBeamAppearance properties
            if (points.Count() < 2)
            {
                return;
            }
            //Get only active indices, alloc on stack for 0 GC pressure
            //int* indices = stackalloc int[512];
            var indices   = new int[512];
            var particles = new Particle[512];

            for (int i = 0; i < 512; i++)
            {
                indices[i] = -1;
            }
            int ptCount = 0;

            for (int i = 0; i < points.Count(); i++)
            {
                if (points[i].Active)
                {
                    indices[ptCount++] = points[i].ParticleIndex;
                }
            }
            if (ptCount < 2)
            {
                return;
            }
            for (int i = 0; i < ptCount; i++)
            {
                particles[i] = instance.Particles[indices[i]];
            }
            for (int i = 1; i < ptCount; i++)
            {
                if (particles[i - 1].TimeAlive > particles[i].TimeAlive)
                {
                    Console.WriteLine("bad order");
                }
            }
            var       node_tr = GetAttachment(reference, transform);
            Texture2D tex;
            Vector2   tl, tr, bl, br;

            HandleTexture(res, globalTime, sparam, ref instance.Particles[indices[0]], out tex, out tl, out tr, out bl, out br);
            //Sorting hack kinda
            var z = RenderHelpers.GetZ(billboards.Camera.Position, node_tr.Transform(Vector3.Zero));

            for (int j = 0; j < 2; j++)             //two planes
            {
                poly.StartLine(tex, BlendInfo);
                bool    odd = true;
                Vector3 dir = Vector3.Zero;

                for (int i = 0; i < ptCount; i++)
                {
                    var pos = node_tr.Transform(instance.Particles[indices[i]].Position);
                    if (i + 1 < ptCount)
                    {
                        var pos2     = node_tr.Transform(instance.Particles[indices[i + 1]].Position);
                        var forward  = (pos2 - pos).Normalized();
                        var toCamera = (billboards.Camera.Position - pos).Normalized();
                        var up       = Vector3.Cross(toCamera, forward);
                        up.Normalize();
                        dir = up;
                        if (j == 1)
                        {
                            //Broken? Doesn't show up
                            var right = Vector3.Cross(up, forward).Normalized();
                            dir = right;
                        }
                    }
                    var time = instance.Particles[indices[i]].TimeAlive / instance.Particles[indices[i]].LifeSpan;
                    var w    = Width.GetValue(sparam, time);
                    poly.AddPoint(
                        pos + (dir * w / 2),
                        pos - (dir * w / 2),
                        odd ? tl : bl,
                        odd ? tr : br,
                        new Color4(
                            Color.GetValue(sparam, time),
                            Alpha.GetValue(sparam, time)
                            )
                        );
                    odd = !odd;
                }
                poly.FinishLine(z);
            }
        }