Exemplo n.º 1
0
        public ParticleEffect GetEffect(string effectName)
        {
            var effect = fldata.Effects.FindEffect(effectName);

            Legacy.Effects.VisEffect visfx;
            if (effect == null)
            {
                visfx = fldata.Effects.FindVisEffect(effectName);
            }
            else
            {
                visfx = fldata.Effects.FindVisEffect(effect.VisEffect);
            }
            foreach (var texfile in visfx.Textures)
            {
                var path = Compatibility.VFS.GetPath(fldata.Freelancer.DataPath + texfile);
                if (path.EndsWith(".txm"))
                {
                    resource.LoadTxm(path);
                }
                else if (path.EndsWith(".mat"))
                {
                    resource.LoadMat(path);
                }
            }
            var alepath = Compatibility.VFS.GetPath(fldata.Freelancer.DataPath + visfx.AlchemyPath);
            var ale     = new AleFile(alepath);
            var lib     = new ParticleLibrary(resource, ale);

            return(lib.FindEffect((uint)visfx.EffectCrc));
        }
Exemplo n.º 2
0
 public ParticleLibrary(ResourceManager res, AleFile ale)
 {
     Resources = res;
     foreach (var effect in ale.FxLib.Effects)
     {
         var fx = new ParticleEffect(this);
         fx.CRC  = effect.CRC;
         fx.Name = effect.Name;
         Dictionary <uint, NodeReference> nodesByIndex = new Dictionary <uint, NodeReference>();
         foreach (var noderef in effect.Fx)
         {
             FxNode node = null;
             if (!noderef.IsAttachmentNode)
             {
                 var nd = ale.NodeLib.Nodes.FirstOrDefault((arg) => arg.CRC == noderef.CRC);
                 if (nd == null)
                 {
                     node = new FxNode("error node", "error node");
                     FLLog.Error("Fx", fx.Name + " bad node CRC 0x" + noderef.CRC.ToString("x"));
                 }
                 else
                 {
                     node = NodeFromAle(ale.NodeLib.Nodes.Where((arg) => arg.CRC == noderef.CRC).First());
                 }
             }
             var reference = new NodeReference();
             reference.Node             = node;
             reference.IsAttachmentNode = noderef.IsAttachmentNode;
             nodesByIndex.Add(noderef.Index, reference);
         }
         foreach (var noderef in effect.Fx)
         {
             var nd = nodesByIndex[noderef.Index];
             if (noderef.Parent != 32768)
             {
                 var parent = nodesByIndex[noderef.Parent];
                 parent.Children.Add(nd);
                 nd.Parent = parent;
             }
         }
         foreach (var pair in effect.Pairs)
         {
             var n1 = nodesByIndex[pair.Item1];
             var n2 = nodesByIndex[pair.Item2];
             n1.Paired.Add(n2);
         }
         fx.References = new List <NodeReference>(nodesByIndex.Values);
         Effects.Add(fx);
     }
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
0
        public override void Draw()
        {
            //Child Window
            var size = ImGui.GetWindowSize();

            ImGui.BeginChild("##utfchild", new Vector2(size.X - 15, size.Y - 50), false, 0);
            //Layout
            if (selectedNode != null)
            {
                ImGui.Columns(2, "NodeColumns", true);
            }
            //Headers
            ImGui.Separator();
            ImGui.Text("Nodes");
            if (selectedNode != null)
            {
                ImGui.NextColumn();
                ImGui.Text("Node Information");
                ImGui.NextColumn();
            }
            ImGui.Separator();
            //Tree
            ImGui.BeginChild("##scroll");
            var flags  = selectedNode == Utf.Root ? ImGuiTreeNodeFlags.Selected | tflags : tflags;
            var isOpen = ImGui.TreeNodeEx("/", flags);

            if (ImGui.IsItemClicked(0))
            {
                selectedNode = Utf.Root;
            }
            ImGui.PushID("/##ROOT");
            DoNodeMenu("/##ROOT", Utf.Root, null);
            ImGui.PopID();
            if (isOpen)
            {
                for (int i = 0; i < Utf.Root.Children.Count; i++)
                {
                    DoNode(Utf.Root.Children[i], Utf.Root, i);
                }
                ImGui.TreePop();
            }
            ImGui.EndChild();
            //End Tree
            if (selectedNode != null)
            {
                //Node preview
                ImGui.NextColumn();
                NodeInformation();
            }
            //Action Bar
            ImGui.EndChild();
            ImGui.Separator();
            if (ImGui.Button("Actions"))
            {
                ImGui.OpenPopup("actions");
            }
            if (ImGui.BeginPopup("actions"))
            {
                if (ImGui.MenuItem("View Model"))
                {
                    IDrawable  drawable = null;
                    ModelNodes hpn      = new ModelNodes();
                    try
                    {
                        drawable = LibreLancer.Utf.UtfLoader.GetDrawable(Utf.Export(), main.Resources);
                        drawable.Initialize(main.Resources);
                        if (Utf.Root.Children.Any((x) => x.Name.Equals("cmpnd", StringComparison.OrdinalIgnoreCase)))
                        {
                            foreach (var child in Utf.Root.Children.Where((x) => x.Name.EndsWith(".3db", StringComparison.OrdinalIgnoreCase)))
                            {
                                var n = new ModelHpNode();
                                n.Name           = child.Name;
                                n.Node           = child;
                                n.HardpointsNode = child.Children.FirstOrDefault((x) => x.Name.Equals("hardpoints", StringComparison.OrdinalIgnoreCase));
                                hpn.Nodes.Add(n);
                            }
                            var cmpnd = Utf.Root.Children.First((x) => x.Name.Equals("cmpnd", StringComparison.OrdinalIgnoreCase));
                            hpn.Cons = cmpnd.Children.FirstOrDefault((x) => x.Name.Equals("cons", StringComparison.OrdinalIgnoreCase));
                        }
                        else
                        {
                            var n = new ModelHpNode();
                            n.Name           = "ROOT";
                            n.Node           = Utf.Root;
                            n.HardpointsNode = Utf.Root.Children.FirstOrDefault((x) => x.Name.Equals("hardpoints", StringComparison.OrdinalIgnoreCase));
                            hpn.Nodes.Add(n);
                        }
                    }
                    catch (Exception ex) { ErrorPopup("Could not open as model\n" + ex.Message + "\n" + ex.StackTrace); drawable = null; }
                    if (drawable != null)
                    {
                        main.AddTab(new ModelViewer(DocumentName, drawable, main, this, hpn));
                    }
                }
                if (ImGui.MenuItem("Export Collada"))
                {
                    LibreLancer.Utf.Cmp.ModelFile model = null;
                    LibreLancer.Utf.Cmp.CmpFile   cmp   = null;
                    try
                    {
                        var drawable = LibreLancer.Utf.UtfLoader.GetDrawable(Utf.Export(), main.Resources);
                        model = (drawable as LibreLancer.Utf.Cmp.ModelFile);
                        cmp   = (drawable as LibreLancer.Utf.Cmp.CmpFile);
                    }
                    catch (Exception) { ErrorPopup("Could not open as model"); model = null; }
                    if (model != null)
                    {
                        var output = FileDialog.Save();
                        if (output != null)
                        {
                            model.Path = DocumentName;
                            try
                            {
                                ColladaExport.ExportCollada(model, main.Resources, output);
                            }
                            catch (Exception ex)
                            {
                                ErrorPopup("Error\n" + ex.Message + "\n" + ex.StackTrace);
                            }
                        }
                    }
                    if (cmp != null)
                    {
                        var output = FileDialog.Save();
                        if (output != null)
                        {
                            cmp.Path = DocumentName;
                            try
                            {
                                ColladaExport.ExportCollada(cmp, main.Resources, output);
                            }
                            catch (Exception ex)
                            {
                                ErrorPopup("Error\n" + ex.Message + "\n" + ex.StackTrace);
                            }
                        }
                    }
                }
                if (ImGui.MenuItem("View Ale"))
                {
                    AleFile ale = null;
                    try
                    {
                        ale = new AleFile(Utf.Export());
                    }
                    catch (Exception)
                    {
                        ErrorPopup("Could not open as ale");
                        ale = null;
                    }
                    if (ale != null)
                    {
                        main.AddTab(new AleViewer(Title, ale, main));
                    }
                }

                if (ImGui.MenuItem("Resolve Audio Hashes"))
                {
                    var folder = FileDialog.ChooseFolder();
                    if (folder != null)
                    {
                        var idtable = new IDTable(folder);
                        foreach (var n in Utf.Root.IterateAll())
                        {
                            if (n.Name.StartsWith("0x"))
                            {
                                uint v;
                                if (uint.TryParse(n.Name.Substring(2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out v))
                                {
                                    idtable.UtfNicknameTable.TryGetValue(v, out n.ResolvedName);
                                }
                            }
                            else
                            {
                                n.ResolvedName = null;
                            }
                        }
                    }
                }
                ImGui.EndPopup();
            }
            ImGui.SameLine();
            if (ImGui.Button("Reload Resources"))
            {
                main.Resources.RemoveResourcesForId(Unique.ToString());
                main.Resources.AddResources(Utf.Export(), Unique.ToString());
            }
            Popups();
        }
Exemplo n.º 6
0
        public override bool Draw()
        {
            //Child Window
            var size = ImGui.GetWindowSize();

            ImGui.BeginChild("##utfchild", new Vector2(size.X - 15, size.Y - 50), false, 0);
            //Layout
            if (selectedNode != null)
            {
                ImGui.Columns(2, "NodeColumns", true);
            }
            //Headers
            ImGui.Separator();
            ImGui.Text("Nodes");
            if (selectedNode != null)
            {
                ImGui.NextColumn();
                ImGui.Text("Node Information");
                ImGui.NextColumn();
            }
            ImGui.Separator();
            //Tree
            ImGui.BeginChild("##scroll", false, 0);
            var flags  = selectedNode == Utf.Root ? TreeNodeFlags.Selected | tflags : tflags;
            var isOpen = ImGui.TreeNodeEx("/", flags);

            if (ImGuiNative.igIsItemClicked(0))
            {
                selectedNode = Utf.Root;
            }
            ImGui.PushID("/##ROOT");
            DoNodeMenu("/##ROOT", Utf.Root, null);
            ImGui.PopID();
            if (isOpen)
            {
                for (int i = 0; i < Utf.Root.Children.Count; i++)
                {
                    DoNode(Utf.Root.Children[i], Utf.Root, i);
                }
                ImGui.TreePop();
            }
            ImGui.EndChild();
            //End Tree
            if (selectedNode != null)
            {
                //Node preview
                ImGui.NextColumn();
                NodeInformation();
            }
            //Action Bar
            ImGui.EndChild();
            ImGui.Separator();
            if (ImGui.Button("Actions"))
            {
                ImGui.OpenPopup("actions");
            }
            if (ImGui.BeginPopup("actions"))
            {
                if (ImGui.MenuItem("View Model"))
                {
                    IDrawable drawable = null;
                    try
                    {
                        drawable = LibreLancer.Utf.UtfLoader.GetDrawable(Utf.Export(), main.Resources);
                        drawable.Initialize(main.Resources);
                    }
                    catch (Exception) { ErrorPopup("Could not open as model"); drawable = null; }
                    if (drawable != null)
                    {
                        main.AddTab(new ModelViewer("Model Viewer (" + Title + ")", Title, drawable, main, this));
                    }
                }
                if (ImGui.MenuItem("View Ale"))
                {
                    AleFile ale = null;
                    try
                    {
                        ale = new AleFile(Utf.Export());
                    }
                    catch (Exception)
                    {
                        ErrorPopup("Could not open as ale");
                        ale = null;
                    }
                    if (ale != null)
                    {
                        main.AddTab(new AleViewer("Ale Viewer (" + Title + ")", Title, ale, main));
                    }
                }
                if (ImGui.MenuItem("Refresh Resources"))
                {
                    main.Resources.RemoveResourcesForId(Unique.ToString());
                    main.Resources.AddResources(Utf.Export(), Unique.ToString());
                }
                ImGui.EndPopup();
            }
            Popups();
            return(open);
        }
Exemplo n.º 7
0
 public ParticleLibrary(ResourceManager res, AleFile ale)
 {
     Resources = res;
     foreach (var effect in ale.FxLib.Effects)
     {
         var fx   = new ParticleEffect(this);
         var root = new FxRootNode();
         fx.CRC  = effect.CRC;
         fx.Name = effect.Name;
         List <FxNode>             nodes        = new List <FxNode>();
         Dictionary <uint, FxNode> nodesByIndex = new Dictionary <uint, FxNode>();
         foreach (var noderef in effect.Fx)
         {
             FxNode node;
             if (noderef.IsAttachmentNode)
             {
                 node = new FxNode("Attachment_0x" + noderef.CRC.ToString("X"), "Empty")
                 {
                     CRC = noderef.CRC
                 };
             }
             else
             {
                 node = NodeFromAle(ale.NodeLib.Nodes.Where((arg) => arg.CRC == noderef.CRC).First());
             }
             nodes.Add(node);
             nodesByIndex.Add(noderef.Index, node);
         }
         foreach (var noderef in effect.Fx)
         {
             var nd = nodesByIndex[noderef.Index];
             //var nd = FindNode(noderef.CRC);
             if (noderef.Parent != 32768)
             {
                 fx.Parents.Add(nd, nodesByIndex[noderef.Parent]);
             }
             else
             {
                 fx.Parents.Add(nd, root);
             }
             if (noderef.IsAttachmentNode)
             {
                 fx.AttachmentNodes.Add(nd);
             }
         }
         foreach (var pair in effect.Pairs)
         {
             var n1 = nodesByIndex[pair.Item1];
             var n2 = nodesByIndex[pair.Item2];
             List <Fx.FxNode> pairedTo;
             if (!fx.Pairs.TryGetValue(n1, out pairedTo))
             {
                 pairedTo = new List <FxNode>();
                 fx.Pairs.Add(n1, pairedTo);
             }
             pairedTo.Add(n2);
         }
         fx.SetNodes(nodes);
         Effects.Add(fx);
     }
 }