예제 #1
0
        private static void WriteMatParams(XmlDocument doc, Nud.Material mat, XmlNode matnode)
        {
            foreach (string materialProperty in mat.PropertyNames)
            {
                XmlNode      paramnode = doc.CreateElement("param");
                XmlAttribute a         = doc.CreateAttribute("name"); a.Value = materialProperty; paramnode.Attributes.Append(a);
                matnode.AppendChild(paramnode);

                if (materialProperty == "NU_materialHash")
                {
                    // Material hash should be in hex for easier reading.
                    foreach (float f in mat.GetPropertyValues(materialProperty))
                    {
                        paramnode.InnerText += BitConverter.ToUInt32(BitConverter.GetBytes(f), 0).ToString("x") + " ";
                    }
                }
                else
                {
                    int count = 0;
                    foreach (float f in mat.GetPropertyValues(materialProperty))
                    {
                        // Only print 4 values and avoids tons of trailing 0's.
                        if (count <= 4)
                        {
                            paramnode.InnerText += f.ToString() + " ";
                        }
                        count += 1;
                    }
                }
            }
        }
예제 #2
0
        private static void ReadMatParams(XmlNode polyNode, Nud.Material material, XmlNode materialNode)
        {
            if (!materialNode.Name.Equals("param"))
            {
                return;
            }

            string       name      = GetNodeName(materialNode);
            List <float> valueList = ParamValuesFromMaterialPropertyText(materialNode, name);

            // Parameters should always have 4 values.
            if (valueList.Count != 4)
            {
                throw new ParamArrayLengthException(polyNode.ChildNodes.Count, name);
            }

            // Prevents duplicate material parameters.
            if (!material.HasProperty(name))
            {
                material.UpdateProperty(name, valueList.ToArray());
            }
            else
            {
                MessageBox.Show(String.Format("Polygon{0} contains more than 1 instance of {1}. \n"
                                              + "Only the first instance of {1} will be added.", polyNode.ChildNodes.Count.ToString(), name));
            }
        }
예제 #3
0
        private static void ReadMaterials(List <Nud.Material> materialList, XmlNode polyNode)
        {
            foreach (XmlNode matnode in polyNode.ChildNodes)
            {
                if (matnode.Name.Equals("material"))
                {
                    Nud.Material mat = new Nud.Material();
                    materialList.Add(mat);

                    ReadAttributes(matnode, mat);

                    foreach (XmlNode mnode in matnode.ChildNodes)
                    {
                        if (mnode.Name.Equals("texture"))
                        {
                            ReadTextures(mat, mnode);
                        }
                        else if (mnode.Name.Equals("param"))
                        {
                            ReadMatParams(polyNode, mat, mnode);
                        }
                    }
                }
            }
        }
예제 #4
0
        private void SetFaceCulling(Nud.Material material)
        {
            bool         enabled      = true;
            CullFaceMode cullFaceMode = CullFaceMode.Back;

            switch (material.CullMode)
            {
            case 0x0000:
                enabled = false;
                break;

            case 0x0404:
                cullFaceMode = CullFaceMode.Front;
                break;

            case 0x0405:
                cullFaceMode = CullFaceMode.Back;
                break;

            default:
                enabled = false;
                break;
            }

            renderSettings.faceCullingSettings = new FaceCullingSettings(enabled, cullFaceMode);
        }
예제 #5
0
 private void InitializeTextBoxes(Nud.Material mat)
 {
     flagsTB.Text    = mat.Flags.ToString("X");
     srcTB.Text      = mat.SrcFactor + "";
     dstTB.Text      = mat.DstFactor + "";
     refAlphaTB.Text = mat.RefAlpha + "";
     zBufferTB.Text  = mat.ZBufferOffset + "";
 }
예제 #6
0
 private void cullModeComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     Nud.Material mat = currentMaterialList[currentMatIndex];
     if (matValueByCullModeName.ContainsKey(cullModeComboBox.SelectedItem.ToString()))
     {
         mat.CullMode = matValueByCullModeName[cullModeComboBox.SelectedItem.ToString()];
     }
 }
예제 #7
0
        public void SetRenderSettings(Nud.Material material)
        {
            SetAlphaBlending(material);
            SetAlphaTesting(material);
            SetDepthTesting(material);
            SetFaceCulling(material);

            GLRenderSettings.SetRenderSettings(renderSettings);
        }
예제 #8
0
 private void AddTextureThumbnails(ImageList imageList)
 {
     // Reuse the same context to avoid CPU bottlenecks.
     using (OpenTK.GameWindow gameWindow = OpenTkSharedResources.CreateGameWindowContext(64, 64))
     {
         Nud.Material mat = currentMaterialList[currentMatIndex];
         RenderMaterialTexturesAddToImageList(imageList, mat);
     }
 }
예제 #9
0
        private void InitializeCheckBoxes(Nud.Material mat)
        {
            shadowCB.Checked = mat.HasShadow;
            GlowCB.Checked   = mat.Glow;

            alphaTestCB.Checked = mat.AlphaTest == (int)NudEnums.AlphaTest.Enabled;
            // Enable/disable extra controls.
            alphaTestCB_CheckedChanged(null, null);
        }
예제 #10
0
        public void FillForm()
        {
            Nud.Material mat = currentMaterialList[currentMatIndex];

            InitializeComboBoxes(mat);
            InitializeTextBoxes(mat);
            InitializeCheckBoxes(mat);
            InitializeTextureListView(mat);
            InitializePropertiesListView(mat);
        }
예제 #11
0
 private static void WriteMatAttributes(XmlDocument doc, Nud.Material mat, XmlNode matNode)
 {
     AddUintAttribute(doc, "flags", mat.Flags, matNode, true);
     AddIntAttribute(doc, "srcFactor", mat.SrcFactor, matNode, false);
     AddIntAttribute(doc, "dstFactor", mat.DstFactor, matNode, false);
     AddIntAttribute(doc, "AlphaFunc", mat.AlphaFunction, matNode, false);
     AddIntAttribute(doc, "AlphaTest", mat.AlphaTest, matNode, false);
     AddIntAttribute(doc, "RefAlpha", mat.RefAlpha, matNode, false);
     AddIntAttribute(doc, "cullmode", mat.CullMode, matNode, true);
     AddIntAttribute(doc, "zbuffoff", mat.ZBufferOffset, matNode, false);
 }
예제 #12
0
        private static void ReadAttributes(XmlNode materialNode, Nud.Material material)
        {
            int value = 0;

            foreach (XmlAttribute attribute in materialNode.Attributes)
            {
                switch (attribute.Name)
                {
                case "flags":
                    uint newFlags = 0;
                    if (uint.TryParse(attribute.Value, NumberStyles.HexNumber, null, out newFlags))
                    {
                        material.Flags = newFlags;
                    }
                    break;

                case "srcFactor":
                    int.TryParse(attribute.Value, out value);
                    material.SrcFactor = value;
                    break;

                case "dstFactor":
                    int.TryParse(attribute.Value, out value);
                    material.DstFactor = value;
                    break;

                case "AlphaFunc":
                    int.TryParse(attribute.Value, out value);
                    material.AlphaFunction = value;
                    break;

                case "AlphaTest":
                    int.TryParse(attribute.Value, out value);
                    material.AlphaTest = value;
                    break;

                case "RefAlpha":
                    int.TryParse(attribute.Value, out value);
                    material.RefAlpha = value;
                    break;

                case "cullmode":
                    int.TryParse(attribute.Value, NumberStyles.HexNumber, null, out value);
                    material.CullMode = value;
                    break;

                case "zbuffoff":
                    int.TryParse(attribute.Value, out value);
                    material.ZBufferOffset = value;
                    break;
                }
            }
        }
예제 #13
0
 private void propertiesListView_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Delete || e.KeyCode == Keys.D)
     {
         Nud.Material mat = currentMaterialList[currentMatIndex];
         foreach (ListViewItem property in propertiesListView.SelectedItems)
         {
             mat.RemoveProperty(property.Text);
         }
         FillForm();
         e.Handled = true;
     }
 }
예제 #14
0
        private void SetAlphaTesting(Nud.Material material)
        {
            bool enabled = (material.AlphaTest == (int)NudEnums.AlphaTest.Enabled);

            AlphaFunction alphaFunc = AlphaFunction.Always;

            if (NudEnums.alphaFunctionByMatValue.ContainsKey(material.AlphaFunction))
            {
                alphaFunc = NudEnums.alphaFunctionByMatValue[material.AlphaFunction];
            }

            float refAlpha = material.RefAlpha / 255.0f;

            renderSettings.alphaTestSettings = new AlphaTestSettings(enabled, alphaFunc, refAlpha);
        }
예제 #15
0
        private void InitializePropertiesListView(Nud.Material mat)
        {
            propertiesListView.Items.Clear();
            propertiesListView.View = View.List;
            foreach (string propertyName in mat.PropertyNames)
            {
                propertiesListView.Items.Add(propertyName);
            }

            // Select the first property.
            if (propertiesListView.Items.Count > 0)
            {
                propertiesListView.SelectedIndices.Add(0);
            }
        }
예제 #16
0
        private static void WriteTextureAttributes(XmlDocument doc, Nud.Material mat, XmlNode matnode)
        {
            foreach (Nud.MatTexture tex in mat.textures)
            {
                XmlNode texnode = doc.CreateElement("texture");

                AddIntAttribute(doc, "hash", tex.hash, texnode, true);
                AddIntAttribute(doc, "wrapmodeS", tex.wrapModeS, texnode, true);
                AddIntAttribute(doc, "wrapmodeT", tex.wrapModeT, texnode, true);
                AddIntAttribute(doc, "minfilter", tex.minFilter, texnode, true);
                AddIntAttribute(doc, "magfilter", tex.magFilter, texnode, true);
                AddIntAttribute(doc, "mipdetail", tex.mipDetail, texnode, true);

                matnode.AppendChild(texnode);
            }
        }
예제 #17
0
        private void SetAlphaBlending(Nud.Material material)
        {
            renderSettings.alphaBlendSettings.enabled = material.SrcFactor != 0 || material.DstFactor != 0;
            if (NudEnums.srcFactorByMatValue.ContainsKey(material.SrcFactor))
            {
                renderSettings.alphaBlendSettings.sourceFactor = NudEnums.srcFactorByMatValue[material.SrcFactor];
            }

            if (NudEnums.dstFactorByMatValue.ContainsKey(material.DstFactor))
            {
                renderSettings.alphaBlendSettings.destinationFactor = NudEnums.dstFactorByMatValue[material.DstFactor];
            }

            renderSettings.alphaBlendSettings.blendingEquationRgb = BlendEquationMode.FuncAdd;
            if (material.DstFactor == 3 || material.DstFactor == 5)
            {
                renderSettings.alphaBlendSettings.blendingEquationRgb = BlendEquationMode.FuncReverseSubtract;
            }

            renderSettings.alphaBlendSettings.blendingEquationAlpha = BlendEquationMode.FuncAdd;
        }
예제 #18
0
        private static void ReadTextures(Nud.Material material, XmlNode textureNode)
        {
            if (!(textureNode.Name.Equals("texture")))
            {
                return;
            }

            Nud.MatTexture matTexture = new Nud.MatTexture();
            material.textures.Add(matTexture);

            foreach (XmlAttribute attribute in textureNode.Attributes)
            {
                switch (attribute.Name)
                {
                case "hash":
                    int.TryParse(attribute.Value, NumberStyles.HexNumber, null, out matTexture.hash);
                    break;

                case "wrapmodeS":
                    int.TryParse(attribute.Value, out matTexture.wrapModeS);
                    break;

                case "wrapmodeT":
                    int.TryParse(attribute.Value, out matTexture.wrapModeT);
                    break;

                case "minfilter":
                    int.TryParse(attribute.Value, out matTexture.minFilter);
                    break;

                case "magfilter":
                    int.TryParse(attribute.Value, out matTexture.magFilter);
                    break;

                case "mipdetail":
                    int.TryParse(attribute.Value, out matTexture.mipDetail);
                    break;
                }
            }
        }
예제 #19
0
        private void loadPresetButton_Click(object sender, EventArgs e)
        {
            MaterialSelector matSelector = new MaterialSelector();

            matSelector.ShowDialog();
            if (matSelector.exitStatus == MaterialSelector.ExitStatus.Opened)
            {
                List <Nud.Material> presetMaterials = ReadMaterialListFromPreset(matSelector.path);

                // Store the original material to preserve Tex IDs.
                Nud.Material original = currentPolygon.materials[0].Clone();
                currentPolygon.materials = presetMaterials;

                // Copy the old Tex IDs.
                currentPolygon.materials[0].CopyTextureIds(original);

                currentMaterialList = currentPolygon.materials;
                currentMatIndex     = 0;
                Init();
                FillForm();
            }
        }
예제 #20
0
        private static void RenderMaterialTexturesAddToImageList(ImageList imageList, Nud.Material mat)
        {
            // Shaders weren't initialized.
            if (OpenTkSharedResources.SetupStatus != OpenTkSharedResources.SharedResourceStatus.Initialized)
            {
                return;
            }

            // Generate thumbnails for all textures in case the material's texture IDs are changed.
            foreach (NUT nut in Runtime.textureContainers)
            {
                foreach (var texture in nut.glTexByHashId)
                {
                    if (!(nut.glTexByHashId[texture.Key] is Texture2D))
                    {
                        continue;
                    }

                    Bitmap bitmap = TextureToBitmap.RenderBitmapUseExistingContext((Texture2D)nut.glTexByHashId[texture.Key], 64, 64);
                    imageList.Images.Add(texture.Key.ToString("X"), bitmap);

                    // StackOverflow makes the bad exceptions go away.
                    var dummy = imageList.Handle;
                    bitmap.Dispose();
                }
            }
        }
예제 #21
0
 private void InitializeComboBoxes(Nud.Material mat)
 {
     alphaFuncComboBox.SelectedItem = alphaFuncByMatValue[mat.AlphaFunction];
     cullModeComboBox.SelectedItem  = cullModeByMatValue[mat.CullMode];
 }
예제 #22
0
        private void InitializeTextureListView(Nud.Material mat)
        {
            texturesListView.Items.Clear();

            // Jigglypuff has weird eyes.
            if ((mat.Flags & 0xFFFFFFFF) == 0x9AE11163)
            {
                texturesListView.Items.Add("Diffuse", mat.Diffuse1Id.ToString("X"));
                texturesListView.Items.Add("Diffuse2", mat.Diffuse2Id.ToString("X"));
                texturesListView.Items.Add("NormalMap", mat.NormalId.ToString("X"));
            }
            else if ((mat.Flags & 0xFFFFFFFF) == 0x92F01101)
            {
                // These flags are even weirder.
                texturesListView.Items.Add("Diffuse", mat.Diffuse1Id.ToString("X"));
                texturesListView.Items.Add("Diffuse2", mat.Diffuse2Id.ToString("X"));
                if (currentMatIndex == 0)
                {
                    // The second material doesn't have these textures.
                    // The texture are probably shared with the first material.
                    texturesListView.Items.Add("Ramp", mat.RampId.ToString("X"));
                    texturesListView.Items.Add("DummyRamp", mat.DummyRampId.ToString("X"));
                }
            }
            else
            {
                // The order of the textures is critical.
                if (mat.HasDiffuse)
                {
                    texturesListView.Items.Add("Diffuse", mat.Diffuse1Id.ToString("X"));
                }
                if (mat.HasSphereMap)
                {
                    texturesListView.Items.Add("SphereMap", mat.SphereMapId.ToString("X"));
                }
                if (mat.HasDiffuse2)
                {
                    texturesListView.Items.Add("Diffuse2", mat.Diffuse2Id.ToString("X"));
                }
                if (mat.HasDiffuse3)
                {
                    texturesListView.Items.Add("Diffuse3", mat.Diffuse3Id.ToString("X"));
                }
                if (mat.HasStageMap)
                {
                    texturesListView.Items.Add("StageMap", mat.StageMapId.ToString("X"));
                }
                if (mat.HasCubeMap)
                {
                    texturesListView.Items.Add("Cubemap", mat.CubeMapId.ToString("X"));
                }
                if (mat.HasAoMap)
                {
                    texturesListView.Items.Add("AOMap", mat.AoMapId.ToString("X"));
                }
                if (mat.HasNormalMap)
                {
                    texturesListView.Items.Add("NormalMap", mat.NormalId.ToString("X"));
                }
                if (mat.HasRamp)
                {
                    texturesListView.Items.Add("Ramp", mat.RampId.ToString("X"));
                }
                if (mat.HasDummyRamp)
                {
                    texturesListView.Items.Add("DummyRamp", mat.DummyRampId.ToString("X"));
                }
            }
        }
예제 #23
0
        private void SetDepthTesting(Nud.Material material)
        {
            bool depthMask = (material.SrcFactor != 4) && (material.SrcFactor != 51) && (material.SrcFactor != 50);

            renderSettings.depthTestSettings = new DepthTestSettings(true, depthMask, DepthFunction.Lequal);
        }
예제 #24
0
 public void SetMaterialValues(Shader shader, Nud.Material material)
 {
     NudUniforms.SetMaterialPropertyUniforms(uniformBlock, shader, material);
 }