Exemplo n.º 1
0
        void ReplaceConstruct(ConstructNode c, AbstractConstruct newc)
        {
            var cmp = (CmpFile)drawable;

            foreach (var part in cmp.Parts)
            {
                if (part.Construct == c.Con)
                {
                    part.UpdateConstruct(newc);
                }
            }
            for (int i = 0; i < cmp.Constructs.Count; i++)
            {
                if (cmp.Constructs[i] == c.Con)
                {
                    cmp.Constructs[i] = newc;
                    break;
                }
            }
            foreach (var gz in gizmos)
            {
                if (gz.Parent == c.Con)
                {
                    gz.Parent = newc;
                }
            }
            if (addConstruct == c.Con)
            {
                addConstruct = newc;
            }
            c.Con = newc;
            cmp.Constructs.ClearParents();
        }
Exemplo n.º 2
0
        string ConType(AbstractConstruct construct)
        {
            var type = "???";

            if (construct is FixConstruct)
            {
                type = "Fix";
            }
            if (construct is RevConstruct)
            {
                type = "Rev";
            }
            if (construct is LooseConstruct)
            {
                type = "Loose";
            }
            if (construct is PrisConstruct)
            {
                type = "Pris";
            }
            if (construct is SphereConstruct)
            {
                type = "Sphere";
            }
            return(type);
        }
Exemplo n.º 3
0
 public Hardpoint(HardpointDefinition def, AbstractConstruct parent)
 {
     this.parent = parent;
     if (def != null)
     {
         this.transform = def.Transform;
     }
     else
     {
         this.transform = Matrix4.Identity;
     }
     Name     = def == null ? "Dummy Hardpoint" : def.Name;
     IsStatic = parent is FixConstruct && def is FixedHardpointDefinition;
 }
Exemplo n.º 4
0
 bool PlaceNode(List <ConstructNode> n, AbstractConstruct con)
 {
     foreach (var node in n)
     {
         if (node.Con.ChildName == con.ParentName)
         {
             node.Nodes.Add(GetNodeCmp((CmpFile)drawable, con));
             return(true);
         }
         if (PlaceNode(node.Nodes, con))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 5
0
        ConstructNode GetNodeCmp(CmpFile c, AbstractConstruct con)
        {
            var node = new ConstructNode()
            {
                Con = con
            };

            foreach (var p in c.Parts)
            {
                if (p.Value.Construct == con)
                {
                    node.Model = p.Value.Model;
                }
            }
            return(node);
        }
Exemplo n.º 6
0
		void PopulateHardpoints(IDrawable drawable, AbstractConstruct transform = null)
		{
			if (drawable is CmpFile)
			{
				foreach (var part in CmpParts)
				{
					PopulateHardpoints(part.Model, part.Construct);
				}
			}
			else if (drawable is ModelFile)
			{
				var model = (ModelFile)drawable;
				foreach (var hpdef in model.Hardpoints)
				{
					//Workaround broken models
					if(!hardpoints.ContainsKey(hpdef.Name))
						hardpoints.Add(hpdef.Name, new Hardpoint(hpdef, transform));
				}
			}
		}
Exemplo n.º 7
0
        ConstructNode GetNodeCmp(CmpFile c, AbstractConstruct con)
        {
            var node = new ConstructNode()
            {
                Con = con
            };

            foreach (var p in c.Parts)
            {
                if (p.Construct == con)
                {
                    node.Camera = p.Camera;
                    if (node.Camera == null)
                    {
                        node.Model = p.Model;
                    }
                    else if (p.ObjectName.Equals("cockpit cam", StringComparison.OrdinalIgnoreCase))
                    {
                        cameraPart = p;
                    }
                }
            }
            return(node);
        }
 void AddPartEditor(AbstractConstruct p)
 {
     partEditors.Add(new HardpointEditor(p,this));
 }
 public unsafe void PartEditor()
 {
     if (editingPart == null) return;
     if(editingPart != null && !partEditorOpen) {
         partEditorOpen = true;
         partFirst = true;
         SetPartValues();
     }
     if(ImGui.Begin("Part Editor##" + editingPart.ChildName,ref partEditorOpen,partFirst ? ImGuiWindowFlags.AlwaysAutoResize : ImGuiWindowFlags.None)) {
         partFirst = false;
         ImGui.Text(editingPart.ChildName);
         ImGui.Text("Type: " + ModelViewer.ConType(editingPart));
         if (ImGui.Button("Reset")) SetPartValues();
         ImGui.Separator();
         ImGui.Text("Position");
             ImGui.InputFloat("X##posX", ref partX, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
             ImGui.InputFloat("Y##posY", ref partY, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
             ImGui.InputFloat("Z##posZ", ref partZ, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
         ImGui.Separator();
         ImGui.Text("Rotation");
             ImGui.InputFloat("Pitch", ref partPitch, 0.1f, 1f, "%.7f", ImGuiInputTextFlags.CharsDecimal);
             ImGui.InputFloat("Yaw", ref partYaw, 0.1f, 1f, "%.7f", ImGuiInputTextFlags.CharsDecimal);
             ImGui.InputFloat("Roll", ref partRoll, 0.1f, 1f, "%.7f", ImGuiInputTextFlags.CharsDecimal);
         ImGui.Separator();
         if (!(editingPart is FixConstruct))
         {
             ImGui.Text("Offset");
                 ImGui.InputFloat("X##offX", ref partOX, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
                 ImGui.InputFloat("Y##offY", ref partOY, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
                 ImGui.InputFloat("Z##offZ", ref partOZ, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
             ImGui.Separator();
         }
         if((editingPart is RevConstruct) || (editingPart is PrisConstruct)) {
             ImGui.Text("Axis");
                 ImGui.InputFloat("X##axX", ref partAxX, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
                 ImGui.InputFloat("Y##axY", ref partAxY, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
                 ImGui.InputFloat("Z##axZ", ref partAxZ, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
                 ImGui.InputFloat("Min", ref partMin, 0.1f, 1f, "%.4f", ImGuiInputTextFlags.CharsDecimal);
                 ImGui.InputFloat("Max", ref partMax, 0.1f, 1f, "%.4f", ImGuiInputTextFlags.CharsDecimal);
             if (ImGui.Button("0")) partPreview = 0;
             ImGui.SameLine();
             ImGui.PushItemWidth(-1);
             if (partMax > partMin)
                 ImGui.SliderFloat("Preview", ref partPreview, partMin, partMax, "%f", 1);
             else
                 ImGui.SliderFloat("Preview", ref partPreview, partMax, partMin, "%f", 1);
             ImGui.PopItemWidth();
             ImGui.Separator();
         }
         if(editingPart is SphereConstruct) {
                 ImGui.InputFloat("Min1", ref min1, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
                 ImGui.InputFloat("Max1", ref max1, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
                 ImGui.InputFloat("Min2", ref min2, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
                 ImGui.InputFloat("Max2", ref max2, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
                 ImGui.InputFloat("Min3", ref min3, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
                 ImGui.InputFloat("Max3", ref max3, 0.01f, 0.25f, "%.5f", ImGuiInputTextFlags.CharsDecimal);
             ImGui.Separator();
         }
         var jointPreview = Matrix4x4.Identity;
         if(editingPart is RevConstruct) {
             jointPreview = Matrix4x4.CreateFromAxisAngle(
             new Vector3(partAxX, partAxY, partAxZ),
                 MathHelper.DegreesToRadians(partPreview));
         } else if (editingPart is PrisConstruct) {
             var translate = new Vector3(partAxX, partAxY, partAxZ).Normalized() * partPreview;
             jointPreview = Matrix4x4.CreateTranslation(translate);
         }
         editingPart.OverrideTransform = Matrix4x4.CreateFromYawPitchRoll(
         MathHelper.DegreesToRadians(partPitch),
         MathHelper.DegreesToRadians(partYaw),
         MathHelper.DegreesToRadians(partRoll)) * jointPreview *
             Matrix4x4.CreateTranslation(new Vector3(partX, partY, partZ) + new Vector3(partOX, partOY, partOZ));
         if(ImGui.Button("Apply")) {
             editingPart.Origin = new Vector3(partX, partY, partZ);
             editingPart.Rotation = Matrix4x4.CreateFromYawPitchRoll(
                 MathHelper.DegreesToRadians(partYaw),
                 MathHelper.DegreesToRadians(partPitch),
                 MathHelper.DegreesToRadians(partRoll)
             );
             if(editingPart is RevConstruct) {
                 var rev = (RevConstruct)editingPart;
                 rev.Offset = new Vector3(partOX, partOY, partOZ);
                 rev.AxisRotation = new Vector3(partAxX, partAxY, partAxZ);
                 rev.Min = MathHelper.DegreesToRadians(partMin);
                 rev.Max = MathHelper.DegreesToRadians(partMax);
             }
             if(editingPart is PrisConstruct) {
                 var pris = (PrisConstruct)editingPart;
                 pris.Offset = new Vector3(partOX, partOY, partOZ);
                 pris.AxisTranslation = new Vector3(partAxX, partAxY, partAxZ);
                 pris.Min = partMin;
                 pris.Max = partMax;
             }
             if(editingPart is SphereConstruct) {
                 var sphere = (SphereConstruct)editingPart;
                 sphere.Offset = new Vector3(partOX, partOY, partOZ);
                 sphere.Min1 = min1;
                 sphere.Max1 = max1;
                 sphere.Min2 = min2;
                 sphere.Max2 = max2;
                 sphere.Min3 = min3;
                 sphere.Max3 = max3;
             }
             mv.OnDirtyPart();
         }
         ImGui.SameLine();
         if (ImGui.Button("Cancel")) partEditorOpen = false;
         ImGui.End();
     }
     if (!partEditorOpen) {
         editingPart.OverrideTransform = null;
         editingPart = null;
     }
 }
Exemplo n.º 10
0
 public HardpointEditor(AbstractConstruct part, ModelViewer mv)
 {
     editingPart = part;
     this.mv = mv;
 }
Exemplo n.º 11
0
 public HardpointGizmo(HardpointDefinition def, AbstractConstruct parent)
 {
     Definition = def;
     Parent     = parent;
     Enabled    = false;
 }
Exemplo n.º 12
0
 void DoCamera(CmpCameraInfo cam, AbstractConstruct con)
 {
 }
Exemplo n.º 13
0
        void DoModel(ModelFile mdl, AbstractConstruct con)
        {
            //Hardpoints
            bool open = ImGui.TreeNode(ImGuiExt.Pad("Hardpoints"));
            var  act  = NewHpMenu(mdl.Path);

            switch (act)
            {
            case ContextActions.NewFixed:
            case ContextActions.NewRevolute:
                newIsFixed   = act == ContextActions.NewFixed;
                addTo        = mdl.Hardpoints;
                addConstruct = con;
                newHpBuffer.Clear();
                popups.OpenPopup("New Hardpoint");
                break;
            }
            Theme.RenderTreeIcon("Hardpoints", "hardpoint", Color4.CornflowerBlue);
            if (open)
            {
                List <Action> addActions = new List <Action>();
                foreach (var hp in mdl.Hardpoints)
                {
                    if (doFilter)
                    {
                        if (hp.Name.IndexOf(currentFilter, StringComparison.OrdinalIgnoreCase) == -1)
                        {
                            continue;
                        }
                    }
                    HardpointGizmo gz = null;
                    foreach (var gizmo in gizmos)
                    {
                        if (gizmo.Definition == hp)
                        {
                            gz = gizmo;
                            break;
                        }
                    }
                    if (hp is RevoluteHardpointDefinition)
                    {
                        Theme.Icon("rev", Color4.LightSeaGreen);
                    }
                    else
                    {
                        Theme.Icon("fix", Color4.Purple);
                    }
                    ImGui.SameLine();
                    if (Theme.IconButton("visible$" + hp.Name, "eye", gz.Enabled ? Color4.White : Color4.Gray))
                    {
                        gz.Enabled = !gz.Enabled;
                    }
                    ImGui.SameLine();
                    ImGui.Selectable(ImGuiExt.IDSafe(hp.Name));
                    var action = EditDeleteHpMenu(mdl.Path + hp.Name);
                    if (action == ContextActions.Delete)
                    {
                        hpDelete     = hp;
                        hpDeleteFrom = mdl.Hardpoints;
                        popups.OpenPopup("Confirm Delete");
                    }
                    if (action == ContextActions.Edit)
                    {
                        hpEditing = hp;
                    }
                    if (action == ContextActions.MirrorX)
                    {
                        var newHp = MakeDuplicate(GetDupName(hp.Name), hp);
                        //do mirroring
                        newHp.Position.X   = -newHp.Position.X;
                        newHp.Orientation *= new Matrix4(
                            -1, 0, 0, 0,
                            0, 1, 0, 0,
                            0, 0, 1, 0,
                            0, 0, 0, 1
                            );
                        //add
                        addActions.Add(() =>
                        {
                            mdl.Hardpoints.Add(newHp);
                            gizmos.Add(new HardpointGizmo(newHp, gz.Parent));
                            OnDirtyHp();
                        });
                    }
                    if (action == ContextActions.MirrorY)
                    {
                        var newHp = MakeDuplicate(GetDupName(hp.Name), hp);
                        //do mirroring
                        newHp.Position.Y   = -newHp.Position.Y;
                        newHp.Orientation *= new Matrix4(
                            1, 0, 0, 0,
                            0, -1, 0, 0,
                            0, 0, 1, 0,
                            0, 0, 0, 1
                            );
                        //add
                        addActions.Add(() =>
                        {
                            mdl.Hardpoints.Add(newHp);
                            gizmos.Add(new HardpointGizmo(newHp, gz.Parent));
                            OnDirtyHp();
                        });
                    }
                    if (action == ContextActions.MirrorZ)
                    {
                        var newHp = MakeDuplicate(GetDupName(hp.Name), hp);
                        //do mirroring
                        newHp.Position.Z   = -newHp.Position.Z;
                        newHp.Orientation *= new Matrix4(
                            1, 0, 0, 0,
                            0, 1, 0, 0,
                            0, 0, -1, 0,
                            0, 0, 0, 1
                            );
                        //add
                        addActions.Add(() =>
                        {
                            mdl.Hardpoints.Add(newHp);
                            gizmos.Add(new HardpointGizmo(newHp, gz.Parent));
                            OnDirtyHp();
                        });
                    }
                }
                foreach (var action in addActions)
                {
                    action();
                }
                ImGui.TreePop();
            }
        }
Exemplo n.º 14
0
 public HardpointEditor(AbstractConstruct part)
 {
     editingPart = part;
 }
Exemplo n.º 15
0
        void DoModel(ModelFile mdl, AbstractConstruct con)
        {
            //Hardpoints
            bool open = ImGui.TreeNode(ImGuiExt.Pad("Hardpoints"));
            var  act  = NewHpMenu(mdl.Path);

            switch (act)
            {
            case ContextActions.NewFixed:
            case ContextActions.NewRevolute:
                newIsFixed   = act == ContextActions.NewFixed;
                addTo        = mdl.Hardpoints;
                addConstruct = con;
                newHpBuffer.Clear();
                popups.OpenPopup("New Hardpoint");
                break;
            }
            Theme.RenderTreeIcon("Hardpoints", "hardpoint", Color4.CornflowerBlue);
            if (open)
            {
                foreach (var hp in mdl.Hardpoints)
                {
                    if (doFilter)
                    {
                        if (hp.Name.IndexOf(currentFilter, StringComparison.OrdinalIgnoreCase) == -1)
                        {
                            continue;
                        }
                    }
                    HardpointGizmo gz = null;
                    foreach (var gizmo in gizmos)
                    {
                        if (gizmo.Definition == hp)
                        {
                            gz = gizmo;
                            break;
                        }
                    }
                    if (hp is RevoluteHardpointDefinition)
                    {
                        Theme.Icon("rev", Color4.LightSeaGreen);
                    }
                    else
                    {
                        Theme.Icon("fix", Color4.Purple);
                    }
                    ImGui.SameLine();
                    if (Theme.IconButton("visible$" + hp.Name, "eye", gz.Enabled ? Color4.White : Color4.Gray))
                    {
                        gz.Enabled = !gz.Enabled;
                    }
                    ImGui.SameLine();
                    ImGui.Selectable(hp.Name);
                    var action = EditDeleteHpMenu(mdl.Path + hp.Name);
                    if (action == ContextActions.Delete)
                    {
                        hpDelete     = hp;
                        hpDeleteFrom = mdl.Hardpoints;
                        popups.OpenPopup("Confirm Delete");
                    }
                    if (action == ContextActions.Edit)
                    {
                        hpEditing = hp;
                    }
                }
                ImGui.TreePop();
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// EDITOR USE ONLY: Changes the construct object for the part
 /// </summary>
 public void UpdateConstruct(AbstractConstruct con)
 {
     construct = con;
 }