private void importBack(string filename) { if (dontModify) { return; } NUT_Texture tex = textureFromFile[filename]; try { DDS dds = new DDS(new FileData(filename)); NUT_Texture ntex = dds.toNUT_Texture(); tex.Height = ntex.Height; tex.Width = ntex.Width; tex.type = ntex.type; tex.mipmaps = ntex.mipmaps; tex.utype = ntex.utype; GL.DeleteTexture(NUT.draw[tex.HASHID]); NUT.draw.Remove(tex.HASHID); NUT.draw.Add(tex.HASHID, NUT.loadImage(tex)); FillForm(); textureList.SelectedItem = tex; glControl1.Invalidate(); //RenderTexture(); } catch { Console.WriteLine("Could not be open for editing"); } }
private NUT ReplaceTexture(NUT_Texture tex, int width, int height, NUT nut) { if (tex.Width == width && tex.Height == height) { tex.HASHID = 0x280052B7; if (nut != null && nut.Nodes.Count > 0) { tex.HASHID = ((NUT_Texture)nut.Nodes[0]).HASHID; nut.Destroy(); } if (nut == null) { nut = new NUT(); } nut.Nodes.Clear(); nut.draw.Clear(); nut.Nodes.Add(tex); nut.draw.Add(tex.HASHID, NUT.loadImage(tex)); } else { MessageBox.Show("Dimensions must be " + width + "x" + height); } return(nut); }
private void RemoveToolStripMenuItem1_Click_1(object sender, EventArgs e) { if (textureList.SelectedIndex >= 0 && NUT != null) { NUT_Texture tex = ((NUT_Texture)textureList.SelectedItem); GL.DeleteTexture(NUT.draw[tex.HASHID]); NUT.draw.Remove(tex.HASHID); NUT.Nodes.Remove(tex); FillForm(); } }
public static int loadImage(NUT_Texture t, bool DDS = false) { int texID = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, texID); if (t.type == PixelInternalFormat.CompressedRgbaS3tcDxt1Ext || t.type == PixelInternalFormat.CompressedRgbaS3tcDxt3Ext || t.type == PixelInternalFormat.CompressedRgbaS3tcDxt5Ext || t.type == PixelInternalFormat.CompressedRedRgtc1 || t.type == PixelInternalFormat.CompressedRgRgtc2) { GL.CompressedTexImage2D <byte>(TextureTarget.Texture2D, 0, t.type, t.Width, t.Height, 0, t.Size, t.mipmaps[0]); if (t.mipmaps.Count > 1 && DDS) { GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, t.mipmaps.Count); GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); for (int i = 0; i < t.mipmaps.Count; i++) { GL.CompressedTexImage2D <byte>(TextureTarget.Texture2D, i, t.type, t.Width / (int)Math.Pow(2, i), t.Height / (int)Math.Pow(2, i), 0, t.mipmaps[i].Length, t.mipmaps[i]); } } else { GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); } Debug.WriteLine(GL.GetError()); } else { GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, t.mipmaps.Count); GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); GL.TexImage2D <byte>(TextureTarget.Texture2D, 0, t.type, t.Width, t.Height, 0, t.utype, t.PixelType, t.mipmaps[0]); /* for (int i = 0; i < t.mipmaps.Count; i++) * GL.TexImage2D<byte>(TextureTarget.Texture2D, i, t.type, t.width, t.height, 0, * t.utype, t.PixelType, t.mipmaps[i]);*/ GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); } //GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); return(texID); }
private void replaceToolStripMenuItem_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialog()) { NUT_Texture tex = (NUT_Texture)(textureList.SelectedItem); if (tex.type == PixelInternalFormat.Rgba) { ofd.Filter = "Portable Networks Graphic (.png)|*.png|" + "All files(*.*)|*.*"; } else { ofd.Filter = "Direct Draw Surface (.dds)|*.dds|" + "All files(*.*)|*.*"; } if (ofd.ShowDialog() == DialogResult.OK) { Edited = true; NUT_Texture ntex = null; if (ofd.FileName.EndsWith(".dds") && NUT != null) { DDS dds = new DDS(new FileData(ofd.FileName)); ntex = dds.toNUT_Texture(); } if (ofd.FileName.EndsWith(".png") && NUT != null) { ntex = fromPNG(ofd.FileName, 1); } tex.Height = ntex.Height; tex.Width = ntex.Width; tex.type = ntex.type; tex.mipmaps = ntex.mipmaps; tex.utype = ntex.utype; if (ntex == null) { return; } GL.DeleteTexture(NUT.draw[tex.HASHID]); NUT.draw.Remove(tex.HASHID); NUT.draw.Add(tex.HASHID, NUT.loadImage(tex)); FillForm(); } } }
public bool getTextureByID(int hash, out NUT_Texture suc) { suc = null; foreach (NUT_Texture t in Nodes) { if (t.HASHID == hash) { suc = t; return(true); } } return(false); }
public static NUT_Texture fromPNG(string fname, int mipcount) { Bitmap bmp = new Bitmap(fname); NUT_Texture tex = new NUT_Texture(); tex.mipmaps.Add(fromPNG(bmp)); for (int i = 1; i < mipcount; i++) { if (bmp.Width / (int)Math.Pow(2, i) < 4 || bmp.Height / (int)Math.Pow(2, i) < 4) { break; } tex.mipmaps.Add(fromPNG(Pixel.ResizeImage(bmp, bmp.Width / (int)Math.Pow(2, i), bmp.Height / (int)Math.Pow(2, i)))); } tex.Width = bmp.Width; tex.Height = bmp.Height; tex.type = PixelInternalFormat.Rgba; tex.utype = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; return(tex); }
private void listBox2_SelectedIndexChanged(object sender, EventArgs e) { if (textureList.SelectedIndex >= 0) { NUT_Texture tex = ((NUT_Texture)textureList.SelectedItem); textBox1.Text = tex.ToString(); label2.Text = "Format: " + (tex.type == PixelInternalFormat.Rgba ? "" + tex.utype : "" + tex.type); label3.Text = "Width: " + tex.Width; label4.Text = "Height:" + tex.Height; label5.Text = "Mipmap:" + tex.mipmaps.Count; //RenderTexture(); } else { textBox1.Text = ""; label2.Text = "Format:"; label3.Text = "Width:"; label4.Text = "Height:"; label5.Text = "Mipmap:"; } glControl1.Invalidate(); }
private void ExportPNG(string fname, NUT_Texture tex) { if (tex.mipmaps.Count > 1) { MessageBox.Show("RGBA texture exported as PNG do not preserve mipmaps"); } switch (tex.utype) { case OpenTK.Graphics.OpenGL.PixelFormat.Rgba: Pixel.fromRGBA(new FileData(tex.mipmaps[0]), tex.Width, tex.Height).Save(fname); break; case OpenTK.Graphics.OpenGL.PixelFormat.AbgrExt: Pixel.fromABGR(new FileData(tex.mipmaps[0]), tex.Width, tex.Height).Save(fname); break; case OpenTK.Graphics.OpenGL.PixelFormat.Bgra: Pixel.fromBGRA(new FileData(tex.mipmaps[0]), tex.Width, tex.Height).Save(fname); break; } }
private void exportAsDDSToolStripMenuItem_Click(object sender, EventArgs e) { if (textureList.SelectedItem == null) { return; } using (var sfd = new SaveFileDialog()) { NUT_Texture tex = (NUT_Texture)(textureList.SelectedItem); if (tex.type == PixelInternalFormat.Rgba) { sfd.Filter = "Portable Networks Graphic (.png)|*.png|" + "All files(*.*)|*.*"; } else { sfd.Filter = "Direct Draw Surface (.dds)|*.dds|" + "All files(*.*)|*.*"; } if (sfd.ShowDialog() == DialogResult.OK) { // use png instead if (sfd.FileName.EndsWith(".png") && NUT != null && tex.type == PixelInternalFormat.Rgba) { ExportPNG(sfd.FileName, tex); } if (sfd.FileName.EndsWith(".dds") && NUT != null) { DDS dds = new DDS(); dds.fromNUT_Texture(tex); dds.Save(sfd.FileName); } } } }
private void importNutFromFolder(object sender, EventArgs e) { using (FolderSelectDialog f = new FolderSelectDialog()) { if (f.ShowDialog() == DialogResult.OK) { Edited = true; if (!Directory.Exists(f.SelectedPath)) { Directory.CreateDirectory(f.SelectedPath); } NUT nut; nut = NUT; foreach (var texPath in Directory.GetFiles(f.SelectedPath)) { if (!(texPath.ToLower().EndsWith(".dds") || texPath.ToLower().EndsWith(".png"))) { return; } int texId; bool isTex = int.TryParse(Path.GetFileNameWithoutExtension(texPath), NumberStyles.HexNumber, new CultureInfo("en-US"), out texId); NUT_Texture texture = null; foreach (NUT_Texture tex in nut.Nodes) { if (tex.HASHID == texId) { texture = tex; } } if (texture == null) { //new texture NUT_Texture tex = null; if (texPath.ToLower().EndsWith(".png")) { tex = fromPNG(texPath, 1); } if (texPath.ToLower().EndsWith(".dds")) { DDS dds = new DDS(new FileData(texPath)); tex = dds.toNUT_Texture(); } if (isTex) { tex.HASHID = texId; } else { tex.HASHID = nut.Nodes.Count; } nut.Nodes.Add(tex); nut.draw.Add(tex.HASHID, NUT.loadImage(tex)); FillForm(); } else { //old texture NUT_Texture tex = texture; NUT_Texture ntex = null; if (texPath.ToLower().EndsWith(".png")) { ntex = fromPNG(texPath, 1); } if (texPath.ToLower().EndsWith(".dds")) { DDS dds = new DDS(new FileData(texPath)); ntex = dds.toNUT_Texture(); } tex.Height = ntex.Height; tex.Width = ntex.Width; tex.type = ntex.type; tex.mipmaps = ntex.mipmaps; tex.utype = ntex.utype; GL.DeleteTexture(NUT.draw[tex.HASHID]); NUT.draw.Remove(tex.HASHID); NUT.draw.Add(tex.HASHID, NUT.loadImage(tex)); FillForm(); } } if (!Runtime.TextureContainers.Contains(nut)) { Runtime.TextureContainers.Add(nut); } } } FillForm(); }
private void Render(object sender, PaintEventArgs e) { if (!ReadyToRender) { return; } glViewport.MakeCurrent(); GL.LoadIdentity(); GL.Viewport(glViewport.ClientRectangle); // Push all attributes so we don't have to clean up later GL.PushAttrib(AttribMask.AllAttribBits); // clear the gf buffer GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); // use fixed function pipeline for drawing background and floor grid GL.UseProgram(0); if (MeshList.treeView1.SelectedNode != null) { if (MeshList.treeView1.SelectedNode is BCH_Texture) { GL.PopAttrib(); BCH_Texture tex = ((BCH_Texture)MeshList.treeView1.SelectedNode); RenderTools.DrawTexturedQuad(tex.display, tex.Width, tex.Height, true, true, true, true, false, true); glViewport.SwapBuffers(); return; } if (MeshList.treeView1.SelectedNode is NUT_Texture) { GL.PopAttrib(); NUT_Texture tex = ((NUT_Texture)MeshList.treeView1.SelectedNode); RenderTools.DrawTexturedQuad(((NUT)tex.Parent).draw[tex.HASHID], tex.Width, tex.Height, true, true, true, true, false, true); glViewport.SwapBuffers(); return; } } if (Runtime.renderBackGround) { // background uses different matrices GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); RenderTools.RenderBackground(); } // Camera Update // ------------------------------------------------------------- GL.MatrixMode(MatrixMode.Projection); if (glViewport.ClientRectangle.Contains(glViewport.PointToClient(Cursor.Position)) && glViewport.Focused && CurrentMode == Mode.Normal && !TransformTool.hit) { Camera.Update(); //if (cameraPosForm != null && !cameraPosForm.IsDisposed) // cameraPosForm.updatePosition(); } try { if (OpenTK.Input.Mouse.GetState() != null) { Camera.mouseSLast = OpenTK.Input.Mouse.GetState().WheelPrecise; } } catch { } Matrix4 matrix = Camera.getMVPMatrix(); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref matrix); // Floor // ------------------------------------------------------------- if (Runtime.renderFloor) { RenderTools.drawFloor(); } // Shadows // ------------------------------------------------------------- if (Runtime.drawModelShadow) { CalculateLightSource(); // update light matrix and setup shadowmap rendering GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref lightMatrix); GL.Enable(EnableCap.DepthTest); GL.Viewport(0, 0, sw, sh); GL.BindFramebuffer(FramebufferTarget.Framebuffer, sfb); foreach (ModelContainer m in draw) { m.RenderShadow(Camera, 0, Matrix4.Zero, Camera.getMVPMatrix()); } // reset matrices and viewport for model rendering again GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); GL.LoadMatrix(ref matrix); GL.Viewport(glViewport.ClientRectangle); } // render models into hdr buffer // ------------------------------------------------------------- if (Runtime.useDepthTest) { GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); } else { GL.Disable(EnableCap.DepthTest); } GL.Enable(EnableCap.DepthTest); // Models // ------------------------------------------------------------- //frameTime.Start(); if (Runtime.renderModel || Runtime.renderModelWireframe) { foreach (TreeNode m in draw) { if (m is ModelContainer) { ((ModelContainer)m).Render(Camera, 0, Matrix4.Zero, Camera.getMVPMatrix()); } } } if (ViewComboBox.SelectedIndex == 1) { foreach (TreeNode m in draw) { if (m is ModelContainer) { ((ModelContainer)m).RenderPoints(Camera); } } } //GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); /*// render gaussian blur stuff * if (Runtime.drawQuadBlur) * DrawQuadBlur(); * * // render full screen quad for post processing * if (Runtime.drawQuadFinalOutput) * DrawQuadFinalOutput();*/ // use fixed function pipeline again for area lights, lvd, bones, hitboxes, etc SetupFixedFunctionRendering(); /*// draw path.bin * if (Runtime.renderPath) * DrawPathDisplay(); * * // area light bounding boxes should intersect stage geometry and not render on top * if (Runtime.drawAreaLightBoundingBoxes) * DrawAreaLightBoundingBoxes();*/ // clear depth buffer so stuff will render on top of the models GL.Clear(ClearBufferMask.DepthBufferBit); if (Runtime.renderLVD) { _lvd.Render(); } if (Runtime.renderBones) { foreach (ModelContainer m in draw) { m.RenderBones(); } } // ACMD if (ParamManager != null && Runtime.renderHurtboxes && draw.Count > 0 && (draw[0] is ModelContainer)) { ParamManager.RenderHurtboxes(Frame, scriptId, ACMDScript, ((ModelContainer)draw[0]).GetVBN()); } if (ACMDScript != null && draw.Count > 0 && (draw[0] is ModelContainer)) { ACMDScript.Render(((ModelContainer)draw[0]).GetVBN()); } //Debug.WriteLine(frameTime.getAverageRenderTime()); // Bone Transform Tool if (ViewComboBox.SelectedIndex == 2) { if (modeBone.Checked) { TransformTool.Render(Camera, new Ray(Camera, glViewport)); if (TransformTool.state == 1) { CurrentMode = Mode.Selection; } else { CurrentMode = Mode.Normal; } } if (TransformTool.HasChanged()) { if (Animation != null && TransformTool.b != null) { // get the node group for the current bone in animation Animation.KeyNode ThisNode = null; foreach (Animation.KeyNode node in Animation.Bones) { if (node.Text.Equals(TransformTool.b.Text)) { // found ThisNode = node; break; } } if (ThisNode == null) { ThisNode = new Animation.KeyNode(TransformTool.b.Text); Animation.Bones.Add(ThisNode); } // update or add the key frame ThisNode.SetKeyFromBone((float)currentFrame.Value, TransformTool.b); } } } // Mouse selection // ------------------------------------------------------------- if (ViewComboBox.SelectedIndex == 1) { try { if (CurrentMode == Mode.Normal && OpenTK.Input.Mouse.GetState().IsButtonDown(OpenTK.Input.MouseButton.Right)) { CurrentMode = Mode.Selection; Vector2 m = GetMouseOnViewport(); sx1 = m.X; sy1 = m.Y; } } catch { } if (CurrentMode == Mode.Selection) { if (!OpenTK.Input.Mouse.GetState().IsButtonDown(OpenTK.Input.MouseButton.Right)) { checkSelect(); CurrentMode = Mode.Normal; } GL.MatrixMode(MatrixMode.Modelview); GL.PushMatrix(); GL.LoadIdentity(); Vector2 m = GetMouseOnViewport(); GL.Color3(Color.Black); GL.LineWidth(2f); GL.Begin(PrimitiveType.LineLoop); GL.Vertex2(sx1, sy1); GL.Vertex2(m.X, sy1); GL.Vertex2(m.X, m.Y); GL.Vertex2(sx1, m.Y); GL.End(); GL.Color3(Color.White); GL.LineWidth(1f); GL.Begin(PrimitiveType.LineLoop); GL.Vertex2(sx1, sy1); GL.Vertex2(m.X, sy1); GL.Vertex2(m.X, m.Y); GL.Vertex2(sx1, m.Y); GL.End(); GL.PopMatrix(); } } /*if (CurrentMode == Mode.Photoshoot) * { * freezeCamera = false; * if (Keyboard.GetState().IsKeyDown(Key.W) && Mouse.GetState().IsButtonDown(MouseButton.Left)) * { * shootX = this.PointToClient(Cursor.Position).X; * shootY = this.PointToClient(Cursor.Position).Y; * freezeCamera = true; * } * // Hold on to your pants, boys * RenderTools.DrawPhotoshoot(glViewport, shootX, shootY, shootWidth, shootHeight); * }*/ GL.PopAttrib(); glViewport.SwapBuffers(); }
public void ReadNTP3(FileData d) { Version = d.readShort(); int count = d.readShort(); d.skip(0x8); if (Version == 0x100) { count -= 1; } int dataPtr = 0; for (int i = 0; i < count; i++) { Debug.WriteLine(d.pos().ToString("x")); NUT_Texture tex = new NUT_Texture(); tex.type = PixelInternalFormat.Rgba32ui; int totalSize = d.readInt(); d.skip(4); // padding int dataSize = d.readInt(); int headerSize = d.readShort(); d.skip(3); int numMips = d.readByte(); Debug.WriteLine(numMips); d.skip(1); tex.setPixelFormatFromNutFormat(d.readByte()); tex.Width = d.readShort(); tex.Height = d.readShort(); d.skip(8); // padding? int dataOffset = d.readInt() + dataPtr + 0x10; d.skip(0x0C); int[] mipSizes = new int[numMips]; if (numMips == 1) { mipSizes[0] = dataSize; } else { for (int j = 0; j < numMips; j++) { mipSizes[j] = d.readInt(); } } d.align(16); d.skip(0x18); tex.HASHID = d.readInt(); d.skip(4); // padding align 8 if (Version == 0x100) { dataOffset = d.pos(); } // add mipmap data for (int miplevel = 0; miplevel < numMips; miplevel++) { byte[] texArray = d.getSection(dataOffset, mipSizes[miplevel]); Debug.WriteLine(texArray.Length.ToString("x")); tex.mipmaps.Add(texArray); dataOffset += mipSizes[miplevel]; } dataPtr += headerSize; if (tex.getNutFormat() == 14 || tex.getNutFormat() == 17) { Console.WriteLine("Endian swap"); // swap foreach (byte[] mip in tex.mipmaps) { for (int t = 0; t < mip.Length; t += 4) { byte t1 = mip[t]; mip[t] = mip[t + 1]; mip[t + 1] = mip[t + 2]; mip[t + 2] = mip[t + 3]; mip[t + 3] = t1; /*byte t1 = mip[t]; * byte t2 = mip[t+1]; * mip[t] = mip[t + 3]; * mip[t + 1] = mip[t + 2]; * mip[t + 2] = t2; * mip[t + 3] = t1;*/ } } } Nodes.Add(tex); /*for (int miplevel = 0; miplevel < numMips; miplevel++) * { * byte[] texArray = d.getSection(dataOffset, mipSizes[miplevel]); * * if (tex.getNutFormat() == 14) * { * byte[] oldArray = texArray; * for (int pos = 0; pos < mipSizes[miplevel]; pos+=4) * { * * for (int p = 0; p < 4; p++) * { * if (p == 0) * texArray[pos + 3] = oldArray[pos]; * else * texArray[pos + p - 1] = oldArray[pos + p]; * } * * } * } * tex.mipmaps.Add(texArray); * dataOffset += mipSizes[miplevel]; * }*/ } foreach (NUT_Texture tex in Nodes) { if (!draw.ContainsKey(tex.HASHID)) { draw.Add(tex.HASHID, loadImage(tex, true)); } } }
public void ReadNTWU(FileData d) { d.skip(0x02); int count = d.readShort(); d.skip(0x10); int headerPtr = d.pos(); int dataPtr = 0; int gtxHeaderOffset = 0; for (int i = 0; i < count; i++) { NUT_Texture tex = new NUT_Texture(); tex.type = PixelInternalFormat.Rgba32ui; d.seek(headerPtr); int totalSize = d.readInt(); int headerSize = d.readShort(); int numMips = d.readInt(); tex.setPixelFormatFromNutFormat(d.readShort()); tex.Width = d.readShort(); tex.Height = d.readShort(); d.skip(8); // mipmaps and padding int dataOffset = d.readInt() + dataPtr + 0x10; headerPtr += headerSize; dataPtr += headerSize; d.skip(0x04); if (i == 0) { gtxHeaderOffset = d.readInt() + 0x10; } else { gtxHeaderOffset += 0x80; d.skip(0x04); } d.skip(0x04); // check for cubemap bool cmap = (d.readInt() == d.readInt()); d.seek(d.pos() - 8); if (cmap) { Console.WriteLine("cubemap detected"); } d.skip(headerSize - 0x50); d.skip(0x18); tex.HASHID = d.readInt(); Console.WriteLine(gtxHeaderOffset.ToString("x")); d.seek(gtxHeaderOffset); d.skip(0x04); // dim d.skip(0x04); // width d.skip(0x04); // height d.skip(0x04); // depth d.skip(0x04); // numMips int format = d.readInt(); d.skip(0x04); // aa d.skip(0x04); // use int imageSize = d.readInt(); d.skip(0x04); // imagePtr int maxSize = d.readInt(); // mipSize d.skip(0x04); // mipPtr int tileMode = d.readInt(); int swizzle = d.readInt(); d.skip(0x04); // alignment int pitch = d.readInt(); int ds = dataOffset; int s1 = 0; int size = 0; Console.WriteLine(totalSize.ToString("x")); for (int mipLevel = 0; mipLevel < numMips; mipLevel++) { // Maybe this is the problem? int mipSize = imageSize >> (mipLevel * 2); int p = pitch >> mipLevel; size = d.readInt(); //Console.WriteLine("\tMIP: " + size.ToString("x") + " " + dataOffset.ToString("x") + " " + mipSize.ToString("x") + " " + p + " " + (size == 0 ? ds + totalSize - dataOffset : size)); //Console.WriteLine(tex.id.ToString("x") + " " + dataOffset.ToString("x") + " " + mipSize.ToString("x") + " " + p + " " + swizzle); //Console.WriteLine((tex.width >> mipLevel) + " " + (tex.height >> mipLevel)); //if (cmap) tex.height *= 2; int w = (tex.Width >> mipLevel); int h = (tex.Height >> mipLevel); { byte[] deswiz = GTX.swizzleBC( d.getSection(dataOffset, d.size() - dataOffset), w, h, format, tileMode, p, swizzle ); tex.mipmaps.Add(new FileData(deswiz).getSection(0, mipSize)); } if (mipLevel == 0) { s1 = size; dataOffset = ds + size; } else { dataOffset = ds + s1 + size; } //dataOffset += mipSize; /*if (cmap) * { * for(int k = 0; k < 5; k++) * { * p = pitch >> (mipLevel + k + 1); * tex.mipmaps.Add(GTX.swizzleBC( * d.getSection(dataOffset, mipSize), * w, * h, * format, * tileMode, * p, * swizzle * )); * * dataOffset += mipSize; * } * }*/ //while (dataOffset % 1024 != 0) dataOffset++; //if (mipSize == 0x4000) dataOffset += 0x400; } Nodes.Add(tex); } foreach (NUT_Texture tex in Nodes) { if (!draw.ContainsKey(tex.HASHID)) { draw.Add(tex.HASHID, loadImage(tex, false)); } // redo mipmaps /*GL.BindTexture(TextureTarget.Texture2D, draw[tex.id]); * for (int k = 1; k < tex.mipmaps.Count; k++) * { * tex.mipmaps[k] = new byte[tex.mipmaps[k].Length]; * GCHandle pinnedArray = GCHandle.Alloc(tex.mipmaps[k], GCHandleType.Pinned); * IntPtr pointer = pinnedArray.AddrOfPinnedObject(); * GL.GetCompressedTexImage(TextureTarget.Texture2D, 0, pointer); * pinnedArray.Free(); * }*/ } //File.WriteAllBytes("C:\\s\\Smash\\extract\\data\\fighter\\duckhunt\\model\\body\\mip1.bin", bytearray); //Console.WriteLine(GL.GetError()); /*int j = 0; * foreach(byte[] b in textures[0].mipmaps) * { * if (j == 3) * { * for(int w = 3; w < 8; w++) * { * for (int p = 3; p < 6; p++) * { * byte[] deswiz = GTX.swizzleBC( * b, * (int)Math.Pow(2, w), * 64, * 51, * 4, * (int)Math.Pow(2, p), * 197632 * ); * File.WriteAllBytes("C:\\s\\Smash\\extract\\data\\fighter\\duckhunt\\model\\body\\chunk_" + (int)Math.Pow(2, p) + "_" + (int)Math.Pow(2, w), deswiz); * } * } * * } * j++; * }*/ }
private void importToolStripMenuItem_Click(object sender, EventArgs e) { if (NUT != null) { using (var ofd = new OpenFileDialog()) { ofd.Filter = "Supported Formats|*.dds;*.png|" + "Direct Draw Surface (.dds)|*.dds|" + "Portable Networks Graphic (.png)|*.png|" + "All files(*.*)|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { Edited = true; int texId; bool isTex = int.TryParse(Path.GetFileNameWithoutExtension(ofd.FileName), NumberStyles.HexNumber, new CultureInfo("en-US"), out texId); if (isTex) { foreach (NUT_Texture te in NUT.Nodes) { if (texId == te.HASHID) { isTex = false; } } } NUT_Texture tex = null; if (ofd.FileName.EndsWith(".dds") && NUT != null) { DDS dds = new DDS(new FileData(ofd.FileName)); tex = dds.toNUT_Texture(); } if (ofd.FileName.EndsWith(".png") && NUT != null) { tex = fromPNG(ofd.FileName, 1); } if (tex != null) { if (isTex) { tex.HASHID = texId; } else { tex.HASHID = 0x40FFFF00 | (NUT.Nodes.Count); } if (NUT.draw.ContainsKey(tex.HASHID)) { NUT.draw.Remove(tex.HASHID); } NUT.Nodes.Add(tex); NUT.draw.Add(tex.HASHID, NUT.loadImage(tex)); FillForm(); } } } } }
public void fromNUT_Texture(NUT_Texture tex) { header = new Header(); header.width = tex.Width; header.height = tex.Height; header.mipmapCount = tex.mipmaps.Count; switch (tex.type) { case PixelInternalFormat.CompressedRedRgtc1: header.dwFourCC = 0x32495441; break; case PixelInternalFormat.CompressedRgRgtc2: header.dwFourCC = 0x31495441; break; case PixelInternalFormat.CompressedRgbaS3tcDxt1Ext: header.dwFourCC = 0x31545844; break; case PixelInternalFormat.CompressedRgbaS3tcDxt3Ext: header.dwFourCC = 0x33545844; break; case PixelInternalFormat.CompressedRgbaS3tcDxt5Ext: header.dwFourCC = 0x35545844; break; case PixelInternalFormat.Rgba: if (tex.utype == OpenTK.Graphics.OpenGL.PixelFormat.Rgba) { header.dwFourCC = 0x0; header.dwBitmask = 0x20; header.dwCaps = 0xFF; header.dwCaps2 = 0xFF00; header.dwCaps3 = 0xFF0000; header.dwCaps4 = 0xFF000000; header.reserve = 0x401008; header.dwFlags = 0x41; } else { header.dwFourCC = 0x0; } break; /*case PixelInternalFormat.CompressedRedRgtc1: * break;*/ /*case PixelInternalFormat.CompressedRgRgtc2: * header.dwFourCC = 0x42433553; * break;*/ default: throw new NotImplementedException($"Unknown pixel format 0x{tex.type:X}"); } List <byte> d = new List <byte>(); foreach (byte[] b in tex.mipmaps) { d.AddRange(b); } data = d.ToArray(); }
private void LetsDance(object sender, EventArgs e) { VBNViewport view = MainForm.Instance.viewports[0]; view.CurrentMode = VBNViewport.Mode.Normal; NUT n = null; if (((MenuItem)sender).GetContextMenu().SourceControl == stock_90_renderer) { n = stock_90; } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_00_renderer) { n = chr_00; } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_11_renderer) { n = chr_11; } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_13_renderer) { n = chr_13; } if (n == null) { return; } byte[] data = RenderTools.DXT5ScreenShot(view.glControl1, view.shootX, view.shootY, view.shootWidth, view.shootHeight); int id = n.Nodes.Count > 0 ? ((NUT_Texture)n.Nodes[0]).HASHID : 0x280052B7; n.Destroy(); n.Nodes.Clear(); n.draw.Clear(); NUT_Texture tex = new NUT_Texture(); tex.Width = view.shootWidth; tex.Height = view.shootHeight; tex.mipmaps.Add(FlipDXT5(data, tex.Width, tex.Height)); tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; tex.HASHID = id; n.Nodes.Add(tex); n.draw.Add(tex.HASHID, NUT.loadImage(tex)); ((MenuItem)sender).GetContextMenu().SourceControl.Invalidate(); if (((MenuItem)sender).GetContextMenu().SourceControl == stock_90_renderer) { if (stock_90_loc != null) { stock_90.Save(stock_90_loc); } } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_00_renderer) { if (chr_00_loc != null) { chr_00.Save(chr_00_loc); } } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_11_renderer) { if (chr_11_loc != null) { chr_11.Save(chr_13_loc); } } if (((MenuItem)sender).GetContextMenu().SourceControl == chr_13_renderer) { if (chr_13_loc != null) { chr_13.Save(chr_13_loc); } } }
public NUT_Texture toNUT_Texture() { NUT_Texture tex = new NUT_Texture(); tex.HASHID = 0x48415348; tex.Height = header.height; tex.Width = header.width; float size = 1; int mips = header.mipmapCount; /*if (mips > header.mipmapCount) * { * mips = header.mipmapCount; * MessageBox.Show("Possible texture error: Only one mipmap"); * }*/ switch (header.dwFourCC) { case 0x0: size = 4f; tex.type = PixelInternalFormat.SrgbAlpha; tex.utype = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; break; case 0x31545844: size = 1 / 2f; tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; break; case 0x35545844: size = 1f; tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; break; case 0x32495441: size = 1 / 2f; tex.type = PixelInternalFormat.CompressedRedRgtc1; break; case 0x31495441: size = 1f; tex.type = PixelInternalFormat.CompressedRgRgtc2; break; default: MessageBox.Show("Unsupported DDS format - 0x" + header.dwFourCC.ToString("x")); break; } // now for mipmap data... FileData d = new FileData(data); int off = 0, w = header.width, h = header.height; if (header.mipmapCount == 0) { header.mipmapCount = 1; } for (int i = 0; i < header.mipmapCount; i++) { int s = (int)((w * h) * size); if (s < 0x8) { s = 0x8; } //Console.WriteLine(off.ToString("x") + " " + s.ToString("x")); w /= 2; h /= 2; tex.mipmaps.Add(d.getSection(off, s)); off += s; } Console.WriteLine(off.ToString("x")); return(tex); }