public override List <string> GetDifferences(Chunk xiChunk) { TMDChunk lOther = xiChunk as TMDChunk; if (Flags != lOther.Flags || ObjectCount != lOther.ObjectCount || !Utils.ArrayCompare(Faces, lOther.Faces) || !Utils.ArrayCompare(Vertices, lOther.Vertices) || !Utils.ArrayCompare(Normals, lOther.Normals) || ObjScale != lOther.ObjScale) { List <string> lRet = base.GetDifferences(xiChunk); lRet.Add("Changed TMD #" + mIdx.ToString()); return(lRet); } return(base.GetDifferences(xiChunk)); }
public IEnumerable <GLTK.Entity> GetEntities(Chunk xiRootChunk, eTextureMode xiTextureMode, eTexMetaDataEntries xiSelectedMetadata) { //a bit hacky: if (this.TreeNode.Checked) { return(new Entity[0]); } List <GLTK.Entity> lRet = new List <Entity>(); TMDChunk lObjt = ((Level)xiRootChunk).GetObjtById(this.ObjtType); if (lObjt != null) { Entity lE = lObjt.GetEntity(xiRootChunk, xiTextureMode, xiSelectedMetadata, this); //nasty, but required because the PS 3D world coords are left-handed, //and the OpenGl 3D coords are right handed lE.Scale(1, 1, -1); if (this.RotationVector.Norm() != 0) { //the rotation is z-y-x lE.RotateAboutWorldOrigin(-this.RotationVector.Z / 1024.0 * Math.PI / 2.0, Vector.ZAxis); lE.RotateAboutWorldOrigin(-this.RotationVector.Y / 1024.0 * Math.PI / 2.0, Vector.YAxis); lE.RotateAboutWorldOrigin(-this.RotationVector.X / 1024.0 * Math.PI / 2.0, Vector.XAxis); } lE.Position = ThreeDeeViewer.Short3CoordToPoint(this.OriginPosition); //return to right handed coords lE.Scale(1, 1, -1); lRet.Add(lE); } return(lRet); }
public override void Deserialise(Stream inStr) { if (inStr is FileStream) { mName = ((FileStream)inStr).Name; } List <Chunk> lChildren = new List <Chunk>(); MemoryStream lUnparseableBuff = new MemoryStream(); long lUnparseableBuffStart = 0; int lNextRead = inStr.ReadByte(); //what are bytes 1-8 of the two structs? byte[] lTIMStart4bpp = new byte[] { 0, 0, 0, 8, 0, 0, 0 }; byte[] lTIMStart8bpp = new byte[] { 0, 0, 0, 9, 0, 0, 0 }; byte[] lTMDStart = new byte[] { 0, 0, 0, 0, 0, 0, 0 }; byte[] lSevenBuff = new byte[7]; while (lNextRead != -1) { byte lNextByte = (byte)lNextRead; bool lByteParsed = false; // might it be a TIM? if (lNextByte == (byte)TIMChunk.TIM_MAGIC_NUMBER) { long lPos = inStr.Position; try { inStr.Read(lSevenBuff, 0, 7); if (SixOfSevenAreZero(lSevenBuff)) { inStr.Seek(-8, SeekOrigin.Current); TIMChunk lTIM = new TIMChunk(inStr, string.Format("TIM at {0}", inStr.Position)); if (lUnparseableBuff.Length != 0) { lChildren.Add(new RawDataChunk( string.Format("data at {0}", lUnparseableBuffStart), lUnparseableBuff.ToArray())); lUnparseableBuff.SetLength(0); lUnparseableBuffStart = inStr.Position; } lChildren.Add(lTIM); lByteParsed = true; } else { inStr.Seek(-7, SeekOrigin.Current); } } catch { inStr.Seek(lPos, SeekOrigin.Begin); } } else if (lNextByte == (byte)TMDChunk.TMD_MAGIC_NUMBER) // maybe a TMD? { long lPos = inStr.Position; try { inStr.Read(lSevenBuff, 0, 7); if (CompareSevenBytes(lSevenBuff, lTMDStart)) { inStr.Seek(-8, SeekOrigin.Current); TMDChunk lTMD = new TMDChunk(inStr, string.Format("TMD at {0}", inStr.Position)); if (lUnparseableBuff.Length != 0) { lChildren.Add(new RawDataChunk( string.Format("data at {0}", lUnparseableBuffStart), lUnparseableBuff.ToArray())); lUnparseableBuff.SetLength(0); lUnparseableBuffStart = inStr.Position; } lChildren.Add(lTMD); lByteParsed = true; } else { inStr.Seek(-7, SeekOrigin.Current); } } catch (Exception) { inStr.Seek(lPos, SeekOrigin.Begin); } } if (!lByteParsed) // dunno what this is { lUnparseableBuff.WriteByte(lNextByte); } lNextRead = inStr.ReadByte(); } // add any left over bytes as a child if (lUnparseableBuff.Length != 0) { lChildren.Add(new RawDataChunk("data", lUnparseableBuff.ToArray())); } // finish mChildren = lChildren.ToArray(); }
public override void Deserialise(Stream inStr) { if (inStr is FileStream) { mName = ((FileStream)inStr).Name; } List<Chunk> lChildren = new List<Chunk>(); MemoryStream lUnparseableBuff = new MemoryStream(); long lUnparseableBuffStart = 0; int lNextRead = inStr.ReadByte(); //what are bytes 1-8 of the two structs? byte[] lTIMStart4bpp = new byte[] { 0, 0, 0, 8, 0, 0, 0 }; byte[] lTIMStart8bpp = new byte[] { 0, 0, 0, 9, 0, 0, 0 }; byte[] lTMDStart = new byte[] { 0, 0, 0, 0, 0, 0, 0 }; byte[] lSevenBuff = new byte[7]; while (lNextRead != -1) { byte lNextByte = (byte)lNextRead; bool lByteParsed = false; // might it be a TIM? if (lNextByte == (byte)TIMChunk.TIM_MAGIC_NUMBER) { long lPos = inStr.Position; try { inStr.Read(lSevenBuff, 0, 7); if (SixOfSevenAreZero(lSevenBuff)) { inStr.Seek(-8, SeekOrigin.Current); TIMChunk lTIM = new TIMChunk(inStr, string.Format("TIM at {0}", inStr.Position)); if (lUnparseableBuff.Length != 0) { lChildren.Add(new RawDataChunk( string.Format("data at {0}", lUnparseableBuffStart), lUnparseableBuff.ToArray())); lUnparseableBuff.SetLength(0); lUnparseableBuffStart = inStr.Position; } lChildren.Add(lTIM); lByteParsed = true; } else { inStr.Seek(-7, SeekOrigin.Current); } } catch { inStr.Seek(lPos, SeekOrigin.Begin); } } else if (lNextByte == (byte)TMDChunk.TMD_MAGIC_NUMBER) // maybe a TMD? { long lPos = inStr.Position; try { inStr.Read(lSevenBuff, 0, 7); if (CompareSevenBytes(lSevenBuff, lTMDStart)) { inStr.Seek(-8, SeekOrigin.Current); TMDChunk lTMD = new TMDChunk(inStr, string.Format("TMD at {0}", inStr.Position)); if (lUnparseableBuff.Length != 0) { lChildren.Add(new RawDataChunk( string.Format("data at {0}", lUnparseableBuffStart), lUnparseableBuff.ToArray())); lUnparseableBuff.SetLength(0); lUnparseableBuffStart = inStr.Position; } lChildren.Add(lTMD); lByteParsed = true; } else { inStr.Seek(-7, SeekOrigin.Current); } } catch (Exception) { inStr.Seek(lPos, SeekOrigin.Begin); } } if (!lByteParsed) // dunno what this is { lUnparseableBuff.WriteByte(lNextByte); } lNextRead = inStr.ReadByte(); } // add any left over bytes as a child if (lUnparseableBuff.Length != 0) { lChildren.Add(new RawDataChunk("data", lUnparseableBuff.ToArray())); } // finish mChildren = lChildren.ToArray(); }