예제 #1
0
        public static List <ModifiedMaterial> Setup(RigidModel model, ResourceManager res)
        {
            var mats = new List <ModifiedMaterial>();

            foreach (var p in model.AllParts)
            {
                if (p.Mesh == null)
                {
                    continue;
                }
                foreach (var l in p.Mesh.Levels)
                {
                    if (l == null)
                    {
                        continue;
                    }
                    foreach (var dc in l)
                    {
                        var mat = dc.GetMaterial(res)?.Render;
                        if (mat is BasicMaterial bm)
                        {
                            if (mats.Any(x => x.Mat == bm))
                            {
                                continue;
                            }
                            mats.Add(new ModifiedMaterial()
                            {
                                Mat = bm, Dc = bm.Dc, Dt = bm.DtSampler
                            });
                        }
                    }
                }
            }
            return(mats);
        }
예제 #2
0
        public void ModelTab()
        {
            ImGui.BeginChild("##tabinner");
            if (ImGui.Button("Add"))
            {
                modelSelector        = new FileSelector(context.FlDirectory);
                modelSelector.Filter = FileSelector.MakeFilter(".3db", ".cmp");
                modelSelector.Open();
            }
            string newfile;

            if ((newfile = modelSelector.Draw()) != null)
            {
                var name = Path.GetFileName(newfile);
                resources.Models.Add(new InterfaceModel()
                {
                    Name = name, Path = newfile
                });
            }
            ImGui.Columns(2);
            ImGui.BeginChild("##items");
            for (int i = 0; i < resources.Models.Count; i++)
            {
                if (ImGui.Selectable(ImGuiExt.IDWithExtra(resources.Models[i].Name, i.ToString()), _selModelIndex == i))
                {
                    _selModelIndex = i;
                    drawable       = context.GetModel(resources.Models[i].Path);
                    modelName.SetText(resources.Models[i].Name);
                }
            }
            ImGui.EndChild();
            ImGui.NextColumn();
            ImGui.BeginChild("##pane");
            if (_selModelIndex >= 0 && _selModelIndex < resources.Models.Count)
            {
                var mdl = resources.Models[_selModelIndex];
                ImGui.SameLine(ImGui.GetColumnWidth() - 65);
                if (ImGui.Button("Delete"))
                {
                    resources.Models.RemoveAt(_selModelIndex);
                    _selModelIndex = -1;
                }
                ImGui.AlignTextToFramePadding();
                ImGui.Text("Name: ");
                ImGui.SameLine();
                modelName.InputText("##Name", ImGuiInputTextFlags.None);
                mdl.Name = modelName.GetText();
                ImGui.Text($"Path: {mdl.Path}");
                ImGui.InputFloat("Offset X", ref mdl.X);
                ImGui.InputFloat("Offset Y", ref mdl.Y);
                ImGui.InputFloat("Scale X", ref mdl.XScale);
                ImGui.InputFloat("Scale Y", ref mdl.YScale);
                DoViewport(mdl);
            }

            ImGui.EndChild();
            ImGui.EndChild();
        }
예제 #3
0
        public RigidModel CreateRigidModel(bool drawable)
        {
            var model = new RigidModel();
            var part  = new RigidModelPart();
            var dcs   = new List <MeshDrawcall>();
            var scale = Matrix4x4.CreateScale(Radius);

            if (drawable && SideMaterials.Length >= 6)
            {
                for (int i = 0; i < 6; i++)
                {
                    int     start, count;
                    Vector3 pos;
                    sphere.GetDrawParameters(faces[i], out start, out count, out pos);
                    var dc = new MeshDrawcall();
                    dc.Buffer         = sphere.VertexBuffer;
                    dc.MaterialCrc    = CrcTool.FLModelCrc(sideMaterialNames[i]);
                    dc.BaseVertex     = 0;
                    dc.StartIndex     = start;
                    dc.PrimitiveCount = count;
                    dc.HasScale       = true;
                    dc.Scale          = scale;
                    dcs.Add(dc);
                }

                if (SideMaterials.Length > 6)
                {
                    var crc = CrcTool.FLModelCrc(sideMaterialNames[6]);
                    for (int i = 0; i < 6; i++)
                    {
                        int     start, count;
                        Vector3 pos;
                        sphere.GetDrawParameters(faces[i], out start, out count, out pos);
                        var dc = new MeshDrawcall();
                        dc.Buffer         = sphere.VertexBuffer;
                        dc.MaterialCrc    = crc;
                        dc.BaseVertex     = 0;
                        dc.StartIndex     = start;
                        dc.PrimitiveCount = count;
                        dc.HasScale       = true;
                        dc.Scale          = scale;
                        dcs.Add(dc);
                    }
                }
            }
            var vmesh = new VisualMesh();

            vmesh.Radius      = Radius;
            vmesh.BoundingBox = BoundingBox.CreateFromSphere(new BoundingSphere(Vector3.Zero, Radius));
            vmesh.Levels      = new[] { dcs.ToArray() };
            part.Hardpoints   = new List <Hardpoint>();
            part.Mesh         = vmesh;
            model.Root        = part;
            model.AllParts    = new[] { part };
            return(model);
        }
예제 #4
0
        public RigidModel CreateRigidModel(bool drawable)
        {
            var model = new RigidModel();

            model.Root          = CreatePart(drawable);
            model.Root.Name     = "Root";
            model.From3db       = true;
            model.AllParts      = new[] { model.Root };
            model.Path          = Path;
            model.MaterialAnims = MaterialAnim;
            return(model);
        }
예제 #5
0
 void LoadModel(UiContext context)
 {
     if (string.IsNullOrWhiteSpace(ModelPath))
     {
         model       = null;
         _loadedPath = null;
         return;
     }
     if (model == null || (_loadedPath != ModelPath))
     {
         _loadedPath = ModelPath;
         model       = context.Data.GetModel(ModelPath);
     }
 }
예제 #6
0
        public RigidModel CreateRigidModel(bool drawable)
        {
            var mdl = new RigidModel()
            {
                Path = Path
            };

            mdl.Parts = new Dictionary <string, RigidModelPart>(StringComparer.OrdinalIgnoreCase);
            var rp = GetRootPart();
            List <RigidModelPart> allParts = new List <RigidModelPart>();

            foreach (var p in Parts)
            {
                if (p.Camera != null)
                {
                    continue;
                }
                var mdlPart = p.Model.CreatePart(drawable);
                mdlPart.Name = p.ObjectName;
                mdlPart.Path = p.FileName;
                if (p.Construct != null)
                {
                    mdlPart.Construct = p.Construct.Clone();
                }
                mdlPart.Children = new List <RigidModelPart>();
                allParts.Add(mdlPart);
            }
            foreach (var p in allParts)
            {
                mdl.Parts.Add(p.Name, p);
                if (p.Construct != null)
                {
                    var parent = allParts.First(x =>
                                                x.Name.Equals(p.Construct.ParentName, StringComparison.OrdinalIgnoreCase));
                    parent.Children.Add(p);
                }
                else
                {
                    mdl.Root = p;
                }
            }
            mdl.AllParts      = allParts.ToArray();
            mdl.MaterialAnims = MaterialAnim;
            mdl.Animation     = Animation;
            mdl.UpdateTransform();
            return(mdl);
        }
예제 #7
0
 bool CanRender(UiContext context)
 {
     if (!loadable)
     {
         return(false);
     }
     if (model == null)
     {
         model = context.GetModel(Model.Path);
         if (model == null)
         {
             loadable = false;
             return(false);
         }
         if (Tint != null)
         {
             mats = MaterialModification.Setup(model, context.ResourceManager);
         }
     }
     return(true);
 }
예제 #8
0
        public ModelViewer(string name, IDrawable drawable, MainWindow win, UtfTab parent, ModelNodes hprefs)
        {
            Title         = string.Format("Model Viewer ({0})", name);
            Name          = name;
            this.drawable = drawable;
            this.parent   = parent;
            this.hprefs   = hprefs;
            rstate        = win.RenderState;
            vps           = win.Viewport;
            res           = win.Resources;
            buffer        = win.Commands;
            _window       = win;
            if (drawable is CmpFile)
            {
                //Setup Editor UI for constructs + hardpoints
                vmsModel = (drawable as CmpFile).CreateRigidModel(true);
                animator = new AnimationComponent(vmsModel, (drawable as CmpFile).Animation);
                int maxLevels = 0;
                foreach (var p in vmsModel.AllParts)
                {
                    if (p.Mesh != null && p.Mesh.Levels != null)
                    {
                        maxLevels = Math.Max(maxLevels, p.Mesh.Levels.Length);
                        if (p.Mesh.Switch2 != null)
                        {
                            foreach (var d in p.Mesh.Switch2)
                            {
                                maxDistance = Math.Max(d, maxDistance);
                            }
                        }
                    }
                }
                foreach (var cmpPart in (drawable as CmpFile).Parts)
                {
                    if (cmpPart.Camera != null)
                    {
                        cameraPart = cmpPart;
                        break;
                    }
                }
                levels = new string[maxLevels];
                for (int i = 0; i < maxLevels; i++)
                {
                    levels[i] = i.ToString();
                }
            }
            else if (drawable is ModelFile)
            {
                vmsModel = (drawable as ModelFile).CreateRigidModel(true);
                levels   = new string[vmsModel.AllParts[0].Mesh.Levels.Length];
                for (int i = 0; i < levels.Length; i++)
                {
                    levels[i] = i.ToString();
                }
                if (vmsModel.Root.Mesh.Switch2 != null)
                {
                    foreach (var d in vmsModel.Root.Mesh.Switch2)
                    {
                        maxDistance = Math.Max(d, maxDistance);
                    }
                }
            }
            else if (drawable is SphFile)
            {
                levels   = new string[] { "0" };
                vmsModel = (drawable as SphFile).CreateRigidModel(true);
            }
            if (vmsModel != null)
            {
                foreach (var p in vmsModel.AllParts)
                {
                    foreach (var hp in p.Hardpoints)
                    {
                        gizmos.Add(new HardpointGizmo(hp, p));
                    }
                    if (p.Wireframe != null)
                    {
                        hasVWire = true;
                    }
                }
            }
            SetupViewport();
            maxDistance += 50;

            popups = new PopupManager();
            popups.AddPopup("Confirm Delete", ConfirmDelete, ImGuiWindowFlags.AlwaysAutoResize);
            popups.AddPopup("Warning", MinMaxWarning, ImGuiWindowFlags.AlwaysAutoResize);
            popups.AddPopup("Apply Complete", (x) =>
            {
                ImGui.Text("Hardpoints successfully written");
                if (ImGui.Button("Ok"))
                {
                    ImGui.CloseCurrentPopup();
                }
            }, ImGuiWindowFlags.AlwaysAutoResize);
            popups.AddPopup("Apply Complete##Parts", (x) =>
            {
                ImGui.Text("Parts successfully written");
                if (ImGui.Button("Ok"))
                {
                    ImGui.CloseCurrentPopup();
                }
            }, ImGuiWindowFlags.AlwaysAutoResize);
            popups.AddPopup("New Hardpoint", NewHardpoint, ImGuiWindowFlags.AlwaysAutoResize);
        }
 public RigidModelController(MainForm topform, RigidModel item) : base(topform, item)
 {
     Data = item;
     AddMenu("Export mesh to PLY", Menu_ExportPLY);
     AddMenu("Open model viewer", Menu_OpenViewer);
 }