public void Apply(NUD nud) { Matrix4 rot = Matrix4.CreateRotationX(0.5f * (float)Math.PI); float sc = 1f; bool hasScale = float.TryParse(scaleTB.Text, out sc); bool checkedUVRange = false; bool fixUV = false; bool warning = false; foreach (NUD.Mesh mesh in nud.meshes) { if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"]) { mesh.boneflag = 0; } foreach (NUD.Polygon poly in mesh.Nodes) { if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"]) { poly.polflag = 0; } if (smoothCB.Checked) { poly.SmoothNormals(); } // we only want to calculate new tangents/bitangents for imports // vanilla models have special tangents/bitangents for mirrored normal maps NUD.computeTangentBitangent(poly); poly.vertSize = ((poly.vertSize == 0x6 ? 0 : BoneTypes[(string)comboBox2.SelectedItem])) | (VertTypes[(string)comboBox1.SelectedItem]); if (!warning && poly.vertSize == 0x27) { MessageBox.Show("Using \"" + (string)comboBox2.SelectedItem + "\" and \"" + (string)comboBox1.SelectedItem + "\" can make shadows not appear in-game", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); warning = true; } if (stagematCB.Checked) { // change to stage material NUD.Mat_Texture tex = poly.materials[0].textures[0]; poly.materials[0].textures.Clear(); poly.materials.Clear(); NUD.Material m = new NUD.Material(); poly.materials.Add(m); m.flags = 0xA2011001; m.RefAlpha = 128; m.cullMode = 1029; m.textures.Clear(); m.textures.Add(tex); m.entries.Add("NU_colorSamplerUV", new float[] { 1, 1, 0, 0 }); m.entries.Add("NU_diffuseColor", new float[] { 1, 1, 1, 0.5f }); m.entries.Add("NU_materialHash", new float[] { BitConverter.ToSingle(new byte[] { 0x12, 0xEE, 0x2A, 0x1B }, 0), 0, 0, 0 }); } //if (checkBox1.Checked || checkBox4.Checked || vertcolorCB.Checked || sc != 1f) foreach (NUD.Vertex v in poly.vertices) { if (!checkedUVRange && v.uv.Count > 0 && (Math.Abs(v.uv[0].X) > 4 || Math.Abs(v.uv[0].Y) > 4)) { checkedUVRange = true; DialogResult dialogResult = MessageBox.Show("Some UVs are detected to be out of accurate range.\nFix them now?", "Potential UV Problem", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { fixUV = true; } } if (fixUV) { for (int h = 0; h < v.uv.Count; h++) { v.uv[h] = new Vector2(v.uv[h].X - (int)v.uv[h].X, v.uv[h].Y - (int)v.uv[h].Y); } } if (flipUVCB.Checked) { for (int i = 0; i < v.uv.Count; i++) { v.uv[i] = new Vector2(v.uv[i].X, 1 - v.uv[i].Y); } } if (vertColorDivCB.Checked) //v.col = v.col / 2; { for (int i = 0; i < 3; i++) { v.col[i] = v.col[i] / 2; } } if (vertcolorCB.Checked) { v.col = new Vector4(0x7F, 0x7F, 0x7F, 0x7F); } if (checkBox4.Checked) { v.pos = Vector3.Transform(v.pos, rot); v.nrm = Vector3.Transform(v.nrm, rot); } if (sc != 1f) { v.pos = Vector3.Multiply(v.pos, sc); } } } } //if (VertTypes[(string)comboBox1.SelectedItem] == 3 || VertTypes[(string)comboBox1.SelectedItem] == 7) if (checkBox2.Checked) { foreach (NUD.Mesh mesh in nud.meshes) { if (mesh.Text.Length > 5) { mesh.Text = mesh.Text.Substring(5, mesh.Text.Length - 5); } } } nud.PreRender(); }
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 SFGraphics.GLObjects.Textures.Texture2D)) { continue; } Bitmap bitmap = TextureToBitmap.RenderBitmapUseExistingContext((SFGraphics.GLObjects.Textures.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(); } } }
private void InitializeComboBoxes(NUD.Material mat) { alphaFuncComboBox.SelectedItem = alphaFuncByMatValue[mat.alphaFunction]; cullModeComboBox.SelectedItem = cullModeByMatValue[mat.cullMode]; }
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")); } } }
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); }
public void FillForm() { NUD.Material mat = materials[currentMatIndex]; alphaTestComboBox.SelectedItem = AlphaTest[mat.alphaTest]; AlphaFuncComboBox.SelectedItem = AlphaFunc[mat.alphaFunction]; flagsTB.Text = mat.Flags.ToString("X"); srcTB.Text = mat.srcFactor + ""; dstTB.Text = mat.dstFactor + ""; refAlphaTB.Text = mat.RefAlpha + ""; cullModeTB.Text = mat.cullMode + ""; zBufferTB.Text = mat.zBufferOffset + ""; shadowCB.Checked = mat.hasShadow; GlowCB.Checked = mat.glow; dummy_rampCB.Checked = mat.hasDummyRamp; AOCB.Checked = mat.hasAoMap; diffuseCB.Checked = mat.hasDiffuse; diffuse2CB.Checked = mat.hasDiffuse2; normalCB.Checked = mat.hasNormalMap; sphere_mapCB.Checked = mat.hasSphereMap; cubemapCB.Checked = mat.hasCubeMap; stageMapCB.Checked = mat.hasStageMap; rampCB.Checked = mat.hasRamp; mysteryCB.Checked = mat.unkownWater != 0; texturesListView.Items.Clear(); // Jigglypuff has weird eyes. if ((mat.Flags & 0xFFFFFFFF) == 0x9AE11163) { if (mat.hasDiffuse) { texturesListView.Items.Add("Diffuse"); } if (mat.hasDiffuse2) { texturesListView.Items.Add("Diffuse2"); } if (mat.hasNormalMap) { texturesListView.Items.Add("NormalMap"); } } else { // The order of the textures is critical. if (mat.hasDiffuse) { texturesListView.Items.Add("Diffuse"); } if (mat.hasSphereMap) { texturesListView.Items.Add("SphereMap"); } if (mat.hasDiffuse2) { texturesListView.Items.Add("Diffuse2"); } if (mat.hasDiffuse3) { texturesListView.Items.Add("Diffuse3"); } if (mat.hasStageMap) { texturesListView.Items.Add("StageMap"); } if (mat.hasCubeMap) { texturesListView.Items.Add("Cubemap"); } if (mat.hasAoMap) { texturesListView.Items.Add("AO Map"); } if (mat.hasNormalMap) { texturesListView.Items.Add("NormalMap"); } if (mat.hasRamp) { texturesListView.Items.Add("Ramp"); } if (mat.hasDummyRamp) { texturesListView.Items.Add("Dummy Ramp"); } } propertiesListView.Items.Clear(); propertiesListView.View = View.List; foreach (string propertyName in mat.entries.Keys) { propertiesListView.Items.Add(propertyName); } if (propertiesListView.Items.Count > 0) { propertiesListView.SelectedIndices.Add(0); } }
private void InitializeCheckBoxes(NUD.Material mat) { shadowCB.Checked = mat.hasShadow; GlowCB.Checked = mat.glow; }
public void SetMaterialValues(NUD.Material nudMaterial) { material = new GenericMaterial(); NudUniforms.SetMaterialPropertyUniforms(material, nudMaterial); }
private void InitializeComboBoxes(NUD.Material mat) { alphaTestComboBox.SelectedItem = AlphaTest[mat.alphaTest]; AlphaFuncComboBox.SelectedItem = AlphaFunc[mat.alphaFunction]; }
public void FillForm() { NUD.Material mat = material[current]; textBox1.Text = mat.flags.ToString("X") + ""; textBox3.Text = mat.dstFactor + ""; textBox4.Text = mat.srcFactor + ""; //textBox5.Text = mat.alphaFunc + ""; textBox6.Text = mat.drawPriority + ""; textBox7.Text = mat.cullMode + ""; textBox8.Text = mat.zBufferOffset + ""; checkBox1.Checked = mat.unkownWater != 0; listView1.Items.Clear(); mat.flags = mat.RebuildFlags(); shadowCB.Checked = mat.hasShadow; GlowCB.Checked = mat.glow; specLightCB.Checked = mat.useSpecular; rimLightCB.Checked = mat.useRimLight; if (mat.highlight) { listView1.Items.Add("Specular"); } if (mat.highlight) { listView1.Items.Add("ShineHighlight"); } if (mat.diffuse) { listView1.Items.Add("Diffuse"); } if (mat.diffuse2) { listView1.Items.Add("Diffuse2"); } if (mat.stagemap) { listView1.Items.Add("StageMap"); } if (mat.cubemap) { listView1.Items.Add("Cubemap"); } if (mat.aomap) { listView1.Items.Add("AO Map"); } if (mat.normalmap) { listView1.Items.Add("NormalMap"); } if (mat.ramp) { listView1.Items.Add("Ramp"); } if (mat.useRimLight) { listView1.Items.Add("Dummy Rim"); } /*listView1.View = View.List; * * int[] locs = new int[mat.textures.Count + 4]; * int li = 0; * if ((mat.flags & (uint)NUD.TextureFlags.DiffuseMap) > 0) * locs[li++] = 0; * * if ((mat.flags & (uint)NUD.TextureFlags.RIM) > 0) * { * // as a stage map... * if ((mat.flags & (uint)NUD.TextureFlags.AOMap) > 0) * locs[li++] = 2; * } * else * { * if ((mat.flags & (uint)NUD.TextureFlags.CubeMap) > 0) * locs[li++] = 3; * } * * if ((mat.flags & (uint)NUD.TextureFlags.UnknownTex) > 0) * locs[li++] = 5; * * if ((mat.flags & (uint)NUD.TextureFlags.NormalMap) > 0) * locs[li++] = 1; * else if ((mat.flags & (uint)NUD.TextureFlags.RIM) > 0) * { * locs[li++] = 0; // second diffuse * } * * if ((mat.flags & (uint)NUD.TextureFlags.RIM) > 0) * { * // as a rim lighting * if ((mat.flags & (uint)NUD.TextureFlags.CubeMap) > 0) * locs[li++] = 3; * } * else * { * if ((mat.flags & (uint)NUD.TextureFlags.AOMap) > 0) * locs[li++] = 2; * } * if ((mat.flags & (uint)NUD.TextureFlags.Shadow) > 0) * locs[li++] = 4; * * string[] texnames = new string[] { "Diffuse Map", "Normal Map", * ((mat.flags & (uint)NUD.TextureFlags.RIM) > 0) ? "Stage Map" : "Cube Map", * ((mat.flags & (uint)NUD.TextureFlags.RIM) > 0) ? "Rim Map" : "AO Map", * "Dummy Rim", * "Specular Map"}; * * for (int i = 0; i < mat.textures.Count; i++) * { * listView1.Items.Add(texnames[locs[i]]); * } * listView1.SelectedIndices.Add(0);*/ listView2.Items.Clear(); listView2.View = View.List; foreach (string s in mat.entries.Keys) { listView2.Items.Add(s); } if (listView2.Items.Count > 0) { listView2.SelectedIndices.Add(0); } }
public static void importMaterialAsXML(NUD n, string filename) { int polyCount = 0; foreach (NUD.Mesh m in n.meshes) { foreach (NUD.Polygon p in m.Nodes) { polyCount++; } } XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNode main = doc.ChildNodes[0]; Debug.WriteLine(main.Attributes.GetNamedItem("polycount").Value); List <NUD.Material> materials = new List <NUD.Material>(); List <int> ids = new List <int>(); // validate at every step foreach (XmlNode meshnode in main.ChildNodes) { if (meshnode.Name.Equals("mesh")) { foreach (XmlNode polynode in meshnode.ChildNodes) { if (polynode.Name.Equals("polygon")) { ids.Add(polynode.ChildNodes.Count); if (ids.Count > polyCount) { int countDif = ids.Count - polyCount; MessageBox.Show(String.Format("Expected {0} polygons but found {1} in the XML file. The last {2} polygon(s) will be ignored.", polyCount, ids.Count, countDif)); } foreach (XmlNode matnode in polynode.ChildNodes) { if (matnode.Name.Equals("material")) { // being creating the material NUD.Material mat = new NUD.Material(); materials.Add(mat); foreach (XmlAttribute a in matnode.Attributes) { switch (a.Name) { case "flags": uint f = 0; if (uint.TryParse(a.Value, NumberStyles.HexNumber, null, out f)) { mat.flags = f; } ; break; case "srcFactor": int.TryParse(a.Value, out mat.srcFactor); break; case "dstFactor": int.TryParse(a.Value, out mat.dstFactor); break; case "AlphaFunc": int.TryParse(a.Value, out mat.AlphaFunc); break; case "AlphaTest": int.TryParse(a.Value, out mat.AlphaTest); break; case "RefAlpha": int.TryParse(a.Value, out mat.RefAlpha); break; case "cullmode": int cm = 0; if (int.TryParse(a.Value, NumberStyles.HexNumber, null, out cm)) { mat.cullMode = cm; } ; break; case "zbuffoff": int.TryParse(a.Value, out mat.zBufferOffset); break; } } foreach (XmlNode mnode in matnode.ChildNodes) { //textures if (mnode.Name.Equals("texture")) { NUD.Mat_Texture tex = new NUD.Mat_Texture(); mat.textures.Add(tex); foreach (XmlAttribute a in mnode.Attributes) { switch (a.Name) { case "hash": int f = 0; if (int.TryParse(a.Value, NumberStyles.HexNumber, null, out f)) { tex.hash = f; } ; break; case "wrapmodeS": int.TryParse(a.Value, out tex.WrapMode1); break; case "wrapmodeT": int.TryParse(a.Value, out tex.WrapMode2); break; case "minfilter": int.TryParse(a.Value, out tex.minFilter); break; case "magfilter": int.TryParse(a.Value, out tex.magFilter); break; case "mipdetail": int.TryParse(a.Value, out tex.mipDetail); break; } } } // parameters if (mnode.Name.Equals("param")) { string name = ""; foreach (XmlAttribute a in mnode.Attributes) { switch (a.Name) { case "name": name = a.Value; break; } } string[] values = mnode.InnerText.Split(' '); List <float> v = new List <float>(); float f = 0; foreach (string stringValue in values) { if (v.Count < 4) { if (name == "NU_materialHash") { int hash; if (int.TryParse(stringValue, NumberStyles.HexNumber, null, out hash)) { f = BitConverter.ToSingle(BitConverter.GetBytes(hash), 0); v.Add(f); } } else if (float.TryParse(stringValue, out f)) { v.Add(f); } else { v.Add(0.0f); } } } // array should always have 4 values if (v.Count != 4) { Debug.WriteLine(v.Count); throw new ParamArrayLengthException(polynode.ChildNodes.Count, name); } try { mat.entries.Add(name, v.ToArray()); } catch (System.ArgumentException) { 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)); } } } } } } } } } int pid = 0; int mid = 0; foreach (NUD.Mesh m in n.meshes) { foreach (NUD.Polygon p in m.Nodes) { p.materials.Clear(); for (int i = 0; i < ids[pid]; i++) { p.materials.Add(materials[mid++]); } pid++; } } }
public void FillForm() { NUD.Material mat = material[current]; //mat.flags = mat.RebuildFlags(); textBox1.Text = mat.flags.ToString("X") + ""; textBox3.Text = mat.srcFactor + ""; textBox4.Text = mat.dstFactor + ""; ref1CB.SelectedItem = ref1[mat.ref1]; ref0CB.SelectedItem = ref0[mat.ref0]; textBox6.Text = mat.drawPriority + ""; textBox7.Text = mat.cullMode + ""; textBox8.Text = mat.zBufferOffset + ""; checkBox1.Checked = mat.unkownWater != 0; listView1.Items.Clear(); shadowCB.Checked = mat.hasShadow; GlowCB.Checked = mat.glow; specLightCB.Checked = mat.useSpecular; rimLightCB.Checked = mat.useRimLight; if (mat.highlight) { listView1.Items.Add("Specular"); } if (mat.highlight) { listView1.Items.Add("ShineHighlight"); } if (mat.diffuse) { listView1.Items.Add("Diffuse"); } if (mat.stagemap) { listView1.Items.Add("StageMap"); } if (mat.cubemap) { listView1.Items.Add("Cubemap"); } if (mat.diffuse2) { listView1.Items.Add("Diffuse2"); } if (mat.aomap) { listView1.Items.Add("AO Map"); } if (mat.normalmap) { listView1.Items.Add("NormalMap"); } if (mat.ramp) { listView1.Items.Add("Ramp"); } if (mat.useRimLight) { listView1.Items.Add("Dummy Ramp"); } while (listView1.Items.Count > mat.textures.Count) { listView1.Items.RemoveAt(1); } listView2.Items.Clear(); listView2.View = View.List; foreach (string s in mat.entries.Keys) { listView2.Items.Add(s); } if (listView2.Items.Count > 0) { listView2.SelectedIndices.Add(0); } }
public void Apply(NUD nud) { nud.GenerateBoundingBoxes(); Matrix4 rot = Matrix4.CreateRotationX(0.5f * (float)Math.PI); float sc = 1f; bool hasScale = float.TryParse(scaleTB.Text, out sc); bool checkedMeshName = false; bool fixMeshName = false; bool warning = false; foreach (NUD.Mesh mesh in nud.Nodes) { if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"]) { mesh.boneflag = 0; } if (!checkedMeshName) { checkedMeshName = true; if (mesh.Text.Length > 5) { string sub = mesh.Text.Substring(0, 5); int a = 0; if (sub.StartsWith("_") && sub.EndsWith("_") && int.TryParse(sub.Substring(1, 3), out a)) { fixMeshName = DialogResult.Yes == MessageBox.Show("Detected mesh names that start with \"_###_\". Would you like to fix this?\nIt is recommended that you select \"Yes\".", "Mesh Name Fix", MessageBoxButtons.YesNo); } } } if (fixMeshName) { if (mesh.Text.Length > 5) { mesh.Text = mesh.Text.Substring(5, mesh.Text.Length - 5); } } foreach (NUD.Polygon poly in mesh.Nodes) { if (BoneTypes[(string)comboBox2.SelectedItem] == BoneTypes["No Bones"]) { poly.polflag = 0; } //Smooth normals if (smoothCB.Checked) { poly.SmoothNormals(); } // we only want to calculate new tangents/bitangents for imports // vanilla models have special tangents/bitangents for mirrored normal maps NUD.computeTangentBitangent(poly); poly.vertSize = ((poly.vertSize == 0x6 ? 0 : BoneTypes[(string)comboBox2.SelectedItem])) | (VertTypes[(string)comboBox1.SelectedItem]); if (!warning && poly.vertSize == 0x27) { MessageBox.Show("Using \"" + (string)comboBox2.SelectedItem + "\" and \"" + (string)comboBox1.SelectedItem + "\" can make shadows not appear in-game.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); warning = true; } //Use stage material if (stagematCB.Checked) { NUD.Mat_Texture tex = poly.materials[0].textures[0]; poly.materials[0].textures.Clear(); poly.materials.Clear(); NUD.Material m = new NUD.Material(); poly.materials.Add(m); m.Flags = 0xA2001001; m.RefAlpha = 128; m.cullMode = 1029; m.textures.Clear(); m.textures.Add(tex); m.entries.Add("NU_colorSamplerUV", new float[] { 1, 1, 0, 0 }); m.entries.Add("NU_diffuseColor", new float[] { 1, 1, 1, 0.5f }); m.entries.Add("NU_materialHash", new float[] { BitConverter.ToSingle(new byte[] { 0x12, 0xEE, 0x2A, 0x1B }, 0), 0, 0, 0 }); } foreach (NUD.Vertex v in poly.vertices) { //Scroll UVs V by -1 if (checkBox2.Checked) { for (int i = 0; i < v.uv.Count; i++) { v.uv[i] = new Vector2(v.uv[i].X, v.uv[i].Y + 1); } } //Flip UVs if (flipUVCB.Checked) { for (int i = 0; i < v.uv.Count; i++) { v.uv[i] = new Vector2(v.uv[i].X, 1 - v.uv[i].Y); } } //Halve vertex colors if (vertColorDivCB.Checked) { for (int i = 0; i < 3; i++) { v.col[i] = v.col[i] / 2; } } //Ignore vertex colors if (vertcolorCB.Checked) { v.col = new Vector4(0x7F, 0x7F, 0x7F, 0xFF); } //Rotate 90 degrees if (checkBox4.Checked) { v.pos = Vector3.TransformPosition(v.pos, rot); v.nrm = Vector3.TransformNormal(v.nrm, rot); } //Scale if (sc != 1f) { v.pos = Vector3.Multiply(v.pos, sc); } } } } //if (VertTypes[(string)comboBox1.SelectedItem] == 3 || VertTypes[(string)comboBox1.SelectedItem] == 7) nud.PreRender(); }