Example #1
0
        public static XmlDocument CreateMaterialXml(MeleeRootNode rootNode)
        {
            XmlDocument doc      = new XmlDocument();
            XmlNode     mainNode = doc.CreateElement("DAT");

            doc.AppendChild(mainNode);

            DatDOBJ[] dOBJs = rootNode.Root.GetDataObjects();
            for (int i = 0; i < dOBJs.Length; i++)
            {
                DatDOBJ d = dOBJs[i];

                string  name     = $"DataObject{ i }";
                XmlNode dobjNode = doc.CreateElement(name);
                AppendAttributes(doc, dobjNode, d);

                XmlNode texturesListNode = doc.CreateElement("Textures");
                foreach (var tex in d.Material.Textures)
                {
                    XmlNode texNode = doc.CreateElement("Texture");
                    AppendTexAttributes(doc, tex, texNode);
                    texturesListNode.AppendChild(texNode);
                }
                dobjNode.AppendChild(texturesListNode);

                mainNode.AppendChild(dobjNode);
            }

            return(doc);
        }
 private void SetAlphaBlending(DatDOBJ datDOBJ, RenderSettings renderSettings)
 {
     if (datDOBJ?.Material.PixelProcessing != null)
     {
         renderSettings.alphaBlendSettings.enabled = datDOBJ?.Material?.PixelProcessing.BlendMode == MeleeLib.GCX.GXBlendMode.Blend;
     }
 }
Example #3
0
        private static void AppendAttributes(XmlDocument doc, XmlNode dobjNode, DatDOBJ d)
        {
            XmlAttribute flagsAttribute = doc.CreateAttribute("Flags");

            flagsAttribute.Value = d.Material.Flags.ToString("X");
            dobjNode.Attributes.Append(flagsAttribute);
        }
Example #4
0
        public void SetRenderSettings(DatDOBJ datDOBJ)
        {
            if (datDOBJ.Material == null)
            {
                return;
            }

            SetAlphaTesting(datDOBJ);
            SetAlphaBlending(datDOBJ);
        }
        private void SetAlphaTesting(DatDOBJ datDOBJ, RenderSettings renderSettings)
        {
            bool          enabled       = (datDOBJ.Material.Flags & (uint)MeleeDatEnums.MiscFlags.AlphaTest) > 0;
            float         refAlpha      = AlphaTestSettings.Default.referenceAlpha;
            AlphaFunction alphaFunction = AlphaTestSettings.Default.alphaFunction;

            if (datDOBJ?.Material.PixelProcessing != null)
            {
                refAlpha      = datDOBJ.Material.PixelProcessing.AlphaRef0 / 255.0f;
                alphaFunction = MeleeDatToOpenGL.GetAlphaFunction(datDOBJ.Material.PixelProcessing.AlphaComp0);
            }

            renderSettings.alphaTestSettings = new AlphaTestSettings(enabled, alphaFunction, refAlpha);
        }
Example #6
0
        public void RemoveAllTextures(object sender, EventArgs args)
        {
            // grab textures used by material animations
            List <byte[]> MaterialAnims = new List <byte[]>();

            foreach (DATRoot r in Root.ParentDAT.Roots)
            {
                foreach (DatMatAnim anim in r.MatAnims)
                {
                    foreach (DatMatAnimGroup g in anim.Groups)
                    {
                        foreach (DatMatAnimData d in g.TextureData)
                        {
                            foreach (DatMatAnimTextureData t in d.Textures)
                            {
                                MaterialAnims.Add(t.Data);
                            }
                        }
                    }
                }
            }
            if (MaterialAnims.Count > 0)
            {
                MessageBox.Show("Warning: Models with Material Animations may freeze in-game");
            }

            // clear textures that aren't part of material animation and don't have polygons
            foreach (MeleeDataObjectNode n in DataObjects.Nodes)
            {
                DatDOBJ o = n.DOBJ;
                if (n.DOBJ.Polygons.Count == 0)
                {
                    foreach (DatTexture t in o.Material.Textures)
                    {
                        if (t.ImageData == null || !MaterialAnims.Contains(t.ImageData.Data))
                        {
                            o.Material.RemoveTexture(t);
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (o.Material.Textures.Length == 0)
                    {
                        o.Material.Flags = (int)(o.Material.Flags & 0xFFFFF00F);
                    }
                }
            }
        }
        public MeleeDataObjectNode(DatDOBJ DOBJ)
        {
            ImageKey         = "mesh";
            SelectedImageKey = "mesh";
            this.DOBJ        = DOBJ;
            Checked          = true;

            ContextMenu = new ContextMenu();

            MenuItem Edit = new MenuItem("Edit");

            Edit.Click += OpenEditor;
            ContextMenu.MenuItems.Add(Edit);

            MenuItem Clear = new MenuItem("Clear Polygons");

            Clear.Click += ClearPolygons;
            ContextMenu.MenuItems.Add(Clear);

            MenuItem smd = new MenuItem("Import from File");

            smd.Click += ImportModel;
            ContextMenu.MenuItems.Add(smd);
        }
Example #8
0
        public void RefreshDisplay()
        {
            Nodes.Clear();
            Skeleton.Nodes.Clear();
            DataObjects.Nodes.Clear();
            MatAnims.Nodes.Clear();
            JointAnims.Nodes.Clear();

            // Stage Stuff
            if (Root.Map_Head != null)
            {
                foreach (Map_Model_Group g in Root.Map_Head.ModelObjects)
                {
                    Nodes.Add(new MeleeMapModelNode(g));
                }
            }

            // Bones--------------------------------------
            if (Root.GetJOBJinOrder().Length > 0)
            {
                Nodes.Add(Skeleton);
            }

            int boneIndex = 0;

            RenderBones = new VBN();
            List <DatJOBJ> JOBJS = new List <DatJOBJ>();

            foreach (DatJOBJ j in Root.GetJOBJinOrder())
            {
                Bone b = new Bone(RenderBones);
                b.Text     = "Bone_" + (boneIndex);
                b.position = new float[] { j.TX, j.TY, j.TZ };
                b.rotation = new float[] { j.RX, j.RY, j.RZ };
                b.scale    = new float[] { j.SX, j.SY, j.SZ };
                if (j.Parent != null)
                {
                    b.parentIndex = JOBJS.IndexOf(j.Parent);
                }
                JOBJS.Add(j);
                RenderBones.bones.Add(b);
                Skeleton.Nodes.Add(new MeleeJointNode(j)
                {
                    Text = "Bone_" + boneIndex++, RenderBone = b
                });
            }
            RenderBones.reset();

            if (Root.GetDataObjects().Length > 0)
            {
                Nodes.Add(DataObjects);
                SelectedImageKey = "model";
                ImageKey         = "model";
            }

            // Data Objects--------------------------------------
            DatDOBJ[] dataObjects = Root.GetDataObjects();
            for (int i = 0; i < dataObjects.Length; i++)
            {
                DatDOBJ d = dataObjects[i];

                MeleeDataObjectNode n = new MeleeDataObjectNode(d)
                {
                    Text = $"DataObject {i}"
                };
                DataObjects.Nodes.Add(n);
                n.RefreshRendering();
                n.BoneIndex = JOBJS.IndexOf(n.DOBJ.Parent);

                n.Checked = true;

                if (Parent is MeleeDataNode)
                {
                    MeleeDataNode parentNode = (MeleeDataNode)Parent;
                    if ((parentNode.LodModels.Count > 0) && !parentNode.LodModels.Contains((byte)(i)))
                    {
                        n.Checked = false;
                        n.Text   += "Low";
                    }
                }
            }

            // MaterialAnimation--------------------------------------
            if (Root.MatAnims.Count > 0)
            {
                Nodes.Add(MatAnims);

                foreach (DatMatAnim anim in Root.MatAnims)
                {
                    MatAnims.Nodes.Add(new MeleeMaterialAnimationNode(anim));
                }
            }

            // Animation--------------------------------------
            if (Root.Animations.Count > 0)
            {
                Nodes.Add(JointAnims);

                foreach (DatAnimation anim in Root.Animations)
                {
                    JointAnims.Nodes.Add(new MeleeJointAnimationNode(anim));
                }
            }

            // Scripts--------------------------------------
            foreach (MeleeLib.DAT.Script.DatFighterData r in Root.FighterData)
            {
                Nodes.Add(new MeleeFighterDataNode(r));
            }
        }
Example #9
0
        public DOBJEditor(DatDOBJ DOBJ, MeleeDataObjectNode meleeDataObjectNode)
        {
            InitializeComponent();
            this.DOBJ = DOBJ;
            this.meleeDataObjectNode = meleeDataObjectNode;

            CBWrapS.Items.Add(GXWrapMode.CLAMP);
            CBWrapS.Items.Add(GXWrapMode.MIRROR);
            CBWrapS.Items.Add(GXWrapMode.REPEAT);
            CBWrapT.Items.Add(GXWrapMode.CLAMP);
            CBWrapT.Items.Add(GXWrapMode.MIRROR);
            CBWrapT.Items.Add(GXWrapMode.REPEAT);

            foreach (var suit in Enum.GetValues(typeof(GXAlphaOp)))
            {
                alphaOpComboBox.Items.Add(suit);
            }
            foreach (var suit in Enum.GetValues(typeof(GXCompareType)))
            {
                alphaComp1ComboBox.Items.Add(suit); alphaComp2ComboBox.Items.Add(suit); depthFuncComboBox.Items.Add(suit);
            }
            foreach (var suit in Enum.GetValues(typeof(GXBlendFactor)))
            {
                srcFactorComboBox.Items.Add(suit);
                dstFactorComboBox.Items.Add(suit);
            }
            foreach (var suit in Enum.GetValues(typeof(GXLogicOp)))
            {
                blendOpComboBox.Items.Add(suit);
            }
            foreach (var suit in Enum.GetValues(typeof(GXBlendMode)))
            {
                blendModeComboBox.Items.Add(suit);
            }

            foreach (var cbv in Enum.GetValues(typeof(GXTexMapID)))
            {
                CBTexID.Items.Add(cbv);
            }
            foreach (var cbv in Enum.GetValues(typeof(GXTexGenSrc)))
            {
                CBTexGenSrc.Items.Add(cbv);
            }
            foreach (var cbv in Enum.GetValues(typeof(GXTexFilter)))
            {
                CBTexMag.Items.Add(cbv);
                CBMinFilter.Items.Add(cbv);
            }
            foreach (var cbv in Enum.GetValues(typeof(GXAnisotropy)))
            {
                CBAnisotrophy.Items.Add(cbv);
            }

            Reload();

            if (DOBJ.Material.Textures.Length > 0)
            {
                textureListBox.SelectedIndex = 0;
            }

            pixelProcessingTableLayout.Visible = pixelProcessingCB.Checked;
        }