/// <summary> /// /// </summary> public void PreLoadTexture(HSD_TOBJ tobj) { if (!imageBufferTextureIndex.ContainsKey(tobj.ImageData.ImageData)) { var rawImageData = tobj.ImageData.ImageData; var width = tobj.ImageData.Width; var height = tobj.ImageData.Height; List <byte[]> mips = new List <byte[]>(); if (tobj.LOD != null && tobj.ImageData.MaxLOD != 0) { for (int i = 0; i < tobj.ImageData.MaxLOD - 1; i++) { mips.Add(tobj.GetDecodedImageData(i)); } } else { mips.Add(tobj.GetDecodedImageData()); } var index = TextureManager.Add(mips, width, height); imageBufferTextureIndex.Add(rawImageData, index); } }
/// <summary> /// /// </summary> /// <param name="tobj"></param> /// <returns></returns> public static bool IsTransparent(HSD_TOBJ tobj) { if (tobj.ImageData.Format == GXTexFmt.RGB565) { return(false); } if ((tobj.ImageData.Format == GXTexFmt.CI8 && tobj.TlutData.Format == GXTlutFmt.RGB565) || (tobj.ImageData.Format == GXTexFmt.CI4 && tobj.TlutData.Format == GXTlutFmt.RGB565)) { return(false); } var d = tobj.GetDecodedImageData(); for (int i = 0; i < d.Length; i += 4) { if (d[i + 3] != 255) { return(true); } } return(false); }
private void exportFramesToolStripMenuItem_Click(object sender, EventArgs e) { if (TexAnim == null) { return; } var f = Tools.FileIO.SaveFile(ApplicationSettings.ImageFileFilter); if (f != null) { for (int i = 0; i < TexAnim.ImageCount; i++) { var v = TexAnim.ImageBuffers.Array[i]; HSD_TlutBuffer pal = null; if (TexAnim.TlutBuffers != null) { pal = TexAnim.TlutBuffers.Array[i]; } HSD_TOBJ tobj = new HSD_TOBJ(); tobj.ImageData = v.Data; if (pal != null) { tobj.TlutData = pal.Data; } var frame = Tools.BitmapTools.BGRAToBitmap(tobj.GetDecodedImageData(), v.Data.Width, v.Data.Height); frame.Save(Path.GetDirectoryName(f) + "\\" + Path.GetFileNameWithoutExtension(f) + "_" + i.ToString() + Path.GetExtension(f)); frame.Dispose(); } } }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public static Bitmap TOBJToBitmap(HSD_TOBJ tobj) { if (tobj == null || tobj.ImageData == null) { return(null); } var data = tobj.GetDecodedImageData(); var width = tobj.ImageData.Width; var height = tobj.ImageData.Height; if (width == 0) { width = 1; } if (height == 0) { height = 1; } Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); try { BitmapData bmpData = bmp.LockBits( new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat); Marshal.Copy(data, 0, bmpData.Scan0, data.Length); bmp.UnlockBits(bmpData); } catch { bmp.Dispose(); throw; } return(bmp); }
/// <summary> /// Converts <see cref="HSD_TOBJ"/> into <see cref="Bitmap"/> /// </summary> /// <param name="tobj"></param> /// <returns></returns> public static Bitmap ToBitmap(HSD_TOBJ tobj) { if (tobj.ImageData == null) { return(null); } var rgba = tobj.GetDecodedImageData(); return(BitmapTools.BGRAToBitmap(rgba, tobj.ImageData.Width, tobj.ImageData.Height)); }
/// <summary> /// Converts <see cref="HSD_TOBJ"/> into <see cref="Bitmap"/> /// </summary> /// <param name="tobj"></param> /// <returns></returns> public static Bitmap ToBitmap(HSD_TOBJ tobj) { var rgba = tobj.GetDecodedImageData(); return(RgbaToImage(rgba, tobj.ImageData.Width, tobj.ImageData.Height)); }
public SBAnimation ImportSBAnimation(string FileName, SBSkeleton skeleton) { SBAnimation anim = new SBAnimation(); HSDRawFile f = new HSDRawFile(FileName); foreach (var root in f.Roots) { if (root == null || root.Data == null) { continue; } anim.Name = root.Name; if (root.Data is HSD_AnimJoint joint) { var joints = joint.BreathFirstList; int nodeIndex = -1; foreach (var j in joints) { nodeIndex++; if (j.AOBJ == null || j.AOBJ.FObjDesc == null) { continue; } SBConsole.WriteLine(nodeIndex + " " + j.Flags.ToString("X8") + " " + j.AOBJ.Flags.ToString()); SBTransformAnimation a = new SBTransformAnimation(); if (nodeIndex < skeleton.Bones.Length) { a.Name = skeleton.Bones[nodeIndex].Name; } else { a.Name = "JOBJ_" + nodeIndex; } anim.TransformNodes.Add(a); anim.FrameCount = Math.Max(anim.FrameCount, j.AOBJ.EndFrame); foreach (var fobj in j.AOBJ.FObjDesc.List) { a.Tracks.Add(DecodeFOBJ(fobj.ToFOBJ())); } } } if (root.Data is HSD_FigaTree tree) { anim.FrameCount = tree.FrameCount; int nodeIndex = 0; foreach (var node in tree.Nodes) { SBTransformAnimation a = new SBTransformAnimation(); a.Name = skeleton.Bones[nodeIndex++].Name; anim.TransformNodes.Add(a); foreach (var att in node.Tracks) { if (att.FOBJ == null) { continue; } a.Tracks.Add(DecodeFOBJ(att.FOBJ)); } } } if (root.Data is HSD_MatAnimJoint matjoint) { var joints = matjoint.BreathFirstList; anim.FrameCount = 0; int nodeIndex = -1; foreach (var j in joints) { if (j.MaterialAnimation == null) { continue; } var matAnims = j.MaterialAnimation.List; foreach (var manim in matAnims) { nodeIndex++; var aobj = manim.AnimationObject; if (aobj != null) { anim.FrameCount = Math.Max(anim.FrameCount, aobj.EndFrame); } var texanim = manim.TextureAnimation; if (texanim == null) { continue; } var texAOBJ = texanim.AnimationObject; if (texAOBJ == null || texAOBJ.FObjDesc == null) { continue; } anim.FrameCount = Math.Max(anim.FrameCount, texAOBJ.EndFrame); //TODO: tex anim is a list if (texanim != null) { SBTextureAnimation textureAnim = new SBTextureAnimation(); anim.TextureNodes.Add(textureAnim); textureAnim.MeshName = "DOBJ_" + nodeIndex; textureAnim.TextureAttibute = texanim.GXTexMapID.ToString(); textureAnim.Keys = DecodeFOBJ(texAOBJ.FObjDesc.ToFOBJ()).Keys; for (int i = 0; i < texanim.ImageCount; i++) { HSD_TOBJ tobj = new HSD_TOBJ(); tobj.ImageData = texanim.ImageBuffers.Array[i].Data; if (texanim.TlutCount > i) { tobj.TlutData = texanim.TlutBuffers.Array[i].Data; } var surface = new SBSurface(); surface.Arrays.Add(new MipArray() { Mipmaps = new List <byte[]>() { tobj.GetDecodedImageData() } }); surface.Width = tobj.ImageData.Width; surface.Height = tobj.ImageData.Height; surface.PixelFormat = PixelFormat.Bgra; surface.PixelType = PixelType.UnsignedByte; surface.InternalFormat = InternalFormat.Rgba; textureAnim.Surfaces.Add(surface); } } } } SBConsole.WriteLine(nodeIndex); } } return(anim); }