internal void UnParse(Stream s) { if (ageGender == null) { ageGender = new AgeGenderFlags(0, handler); } ageGender.UnParse(s); new BinaryWriter(s).Write((uint)facialRegion); if (lod1 == null) { lod1 = new LODSection(0, handler); } lod1.UnParse(s); if (lod2 == null) { lod2 = new LODSection(0, handler); } lod2.UnParse(s); if (lod3 == null) { lod3 = new LODSection(0, handler); } lod3.UnParse(s); if (lod4 == null) { lod4 = new LODSection(0, handler); } lod4.UnParse(s); }
private TreeNode LODsToTree() { TreeNode ret = new TreeNode("LODs"); for (int i = 0; i < Mesh.LODs.Count; i++) { LOD currLOD = Mesh.LODs[i]; TreeNode t = new TreeNode("LOD " + i.ToString()); TreeNode t1 = new TreeNode("Points"); for (int k = 0; k < currLOD.points.Count; k++) { TreeNode t2 = new TreeNode(currLOD.points[k].ToString()); t1.Nodes.Add(t2); } t.Nodes.Add(t1); for (int j = 0; j < currLOD.sections.Count; j++) { t1 = new TreeNode("Section " + j.ToString()); LODSection currSec = currLOD.sections[j]; for (int k = 0; k < currSec.count; k++) { TreeNode t2 = new TreeNode("Face " + k.ToString() + " (" + currSec.Faces[k].e0.ToString() + "; " + currSec.Faces[k].e1.ToString() + "; " + currSec.Faces[k].e2.ToString() + ")"); t1.Nodes.Add(t2); } t.Nodes.Add(t1); } ret.Nodes.Add(t); } return(ret); }
public Section1Entry(int APIversion, EventHandler handler, LODSection lod1, LODSection lod2, LODSection lod3, LODSection lod4) : base(APIversion, handler) { lod1 = new LODSection(0, handler, lod1); lod2 = new LODSection(0, handler, lod2); lod3 = new LODSection(0, handler, lod3); lod4 = new LODSection(0, handler, lod4); }
void Parse(Stream s) { ageGender = new AgeGenderFlags(0, handler, s); facialRegion = (FacialRegionFlags) new BinaryReader(s).ReadUInt32(); lod1 = new LODSection(0, handler, s); lod2 = new LODSection(0, handler, s); lod3 = new LODSection(0, handler, s); lod4 = new LODSection(0, handler, s); }
public Section1Entry(int APIversion, EventHandler handler) : base(APIversion, handler) { ageGender = new AgeGenderFlags(requestedApiVersion, handler); lod1 = new LODSection(requestedApiVersion, handler); lod2 = new LODSection(requestedApiVersion, handler); lod3 = new LODSection(requestedApiVersion, handler); lod4 = new LODSection(requestedApiVersion, handler); }
public Section1Entry(EventHandler handler, LODSection lod1, LODSection lod2, LODSection lod3, LODSection lod4) : base(handler) { lod1 = new LODSection(handler, lod1); lod2 = new LODSection(handler, lod2); lod3 = new LODSection(handler, lod3); lod4 = new LODSection(handler, lod4); }
public Section1Entry(EventHandler handler) : base(handler) { ageGender = new AgeGenderFlags(handler); lod1 = new LODSection(handler); lod2 = new LODSection(handler); lod3 = new LODSection(handler); lod4 = new LODSection(handler); }
public PSKFile ExportToPSK(int LOD = 0) { PSKFile PSKf = new PSKFile(); PSK = PSKf.PSK; LOD currLOD = Mesh.LODs[LOD]; PSK.Points = new PSKFile.Vector[currLOD.points.Count]; for (int i = 0; i < currLOD.points.Count; i++) { PSK.Points[i].x = currLOD.points[i].X; PSK.Points[i].y = currLOD.points[i].Y; PSK.Points[i].z = currLOD.points[i].Z; } PSK.Edges = new PSKFile.Edge[currLOD.points.Count]; for (int i = 0; i < currLOD.points.Count; i++) { PSK.Edges[i].U = currLOD.points[i].U; PSK.Edges[i].V = currLOD.points[i].U; PSK.Edges[i].index = i; } PSK.Mats = new PSKFile.Material[1]; PSK.Mats[0].name = ""; PSK.Faces = new PSKFile.Face[currLOD.allFaces]; int n = 0; for (int i = 0; i < currLOD.sections.Count; i++) { LODSection currSel = currLOD.sections[i]; for (int j = 0; j < currSel.count; j++) { PSK.Faces[n].e0 = currSel.Faces[j].e0; PSK.Faces[n].e1 = currSel.Faces[j].e1; PSK.Faces[n].e2 = currSel.Faces[j].e2; n++; } } PSKWriteBones(); PSKWriteWeights(LOD); PSKf.PSK = PSK; return(PSKf); }
private byte[] SerializeLODs() { MemoryStream rbuff = new MemoryStream(); byte[] buff = BitConverter.GetBytes(Mesh.LODs.Count); rbuff.Write(buff, 0, 4); for (int i = 0; i < Mesh.LODs.Count; i++) { LOD curLOD = Mesh.LODs[i]; buff = BitConverter.GetBytes(curLOD.sections.Count); rbuff.Write(buff, 0, 4); for (int j = 0; j < curLOD.sections.Count; j++) { LODSection curSec = curLOD.sections[j]; buff = BitConverter.GetBytes((Int16)curSec.index); rbuff.Write(buff, 0, 2); buff = BitConverter.GetBytes((Int16)curSec.matindex); rbuff.Write(buff, 0, 2); buff = BitConverter.GetBytes((Int32)curSec.offset); rbuff.Write(buff, 0, 4); buff = BitConverter.GetBytes((Int16)curSec.count); rbuff.Write(buff, 0, 2); buff = BitConverter.GetBytes((Int16)curSec.unk1); rbuff.Write(buff, 0, 2); } buff = BitConverter.GetBytes(multi); rbuff.Write(buff, 0, 4); buff = BitConverter.GetBytes((curLOD.allFaces * 6) / multi); rbuff.Write(buff, 0, 4); for (int j = 0; j < curLOD.sections.Count; j++) { LODSection curSec = curLOD.sections[j]; for (int k = 0; k < curSec.count; k++) { buff = BitConverter.GetBytes(curSec.Faces[k].e0); rbuff.Write(buff, 0, 2); buff = BitConverter.GetBytes(curSec.Faces[k].e1); rbuff.Write(buff, 0, 2); buff = BitConverter.GetBytes(curSec.Faces[k].e2); rbuff.Write(buff, 0, 2); } } StreamAppend(rbuff, BitConverter.GetBytes(curLOD.unk0)); StreamAppend(rbuff, curLOD.unk1); StreamAppend(rbuff, BitConverter.GetBytes(curLOD.unk2)); StreamAppend(rbuff, BitConverter.GetBytes(curLOD.unk4.Count)); StreamAppend(rbuff, curLOD.unk3); for (int j = 0; j < curLOD.unk4.Count; j++) { StreamAppend(rbuff, curLOD.unk4[j]); } StreamAppend(rbuff, curLOD.unk5); StreamAppend(rbuff, curLOD.unk6); StreamAppend(rbuff, BitConverter.GetBytes(curLOD.points.Count)); for (int j = 0; j < curLOD.points.Count; j++) { Point p = curLOD.points[j]; StreamAppend(rbuff, BitConverter.GetBytes(p.unknown3)); StreamAppend(rbuff, BitConverter.GetBytes(p.unknown4)); for (int k = 0; k < 4; k++) { rbuff.WriteByte(p.infl.bone[k]); } for (int k = 0; k < 4; k++) { rbuff.WriteByte(p.infl.weight[k]); } StreamAppend(rbuff, BitConverter.GetBytes(p.X)); StreamAppend(rbuff, BitConverter.GetBytes(p.Y)); StreamAppend(rbuff, BitConverter.GetBytes(p.Z)); StreamAppend(rbuff, BitConverter.GetBytes(p.Uraw)); StreamAppend(rbuff, BitConverter.GetBytes(p.Vraw)); } StreamAppend(rbuff, BitConverter.GetBytes(curLOD.unk7)); } return(rbuff.ToArray()); }
private void ReadLODs(int off) { int pos = off; int lodCount = getInt(pos); pos += 4; Mesh.LODs = new List <LOD>(lodCount); for (int l = 0; l < lodCount; l++) { LOD curLOD = new LOD(); #region Section headers int sectionCount = getInt(pos); pos += 4; for (int i = 0; i < sectionCount; i++) { LODSection t = new LODSection { index = (ushort)getInt16(pos), matindex = (ushort)getInt16(pos + 2), offset = getInt(pos + 4), count = (uint)getInt16(pos + 8), unk1 = getInt16(pos + 10) }; pos += 12; t.Faces = new Face[t.count]; curLOD.sections.Add(t); } #endregion #region Faces curLOD.offFace = pos; multi = getInt(pos); if (multi == 0) { multi = 1; } pos += 4; int valuesCount = getInt(pos); valuesCount = (valuesCount * multi) / 6; curLOD.allFaces = valuesCount; pos += 4; for (int i = 0; i < sectionCount; i++) { for (int j = 0; j < curLOD.sections[i].count; j++) { Face t = new Face { off = (uint)pos, e0 = (ushort)getInt16(pos), e1 = (ushort)getInt16(pos + 2), e2 = (ushort)getInt16(pos + 4) }; curLOD.sections[i].Faces[j] = t; pos += 6; } } #endregion #region Unknown data curLOD.unk0 = getInt(pos); pos += 4; int arraySize = getInt(pos); curLOD.unk1 = new byte[arraySize * 2 + 4]; for (int j = 0; j < arraySize * 2 + 4; j++) { curLOD.unk1[j] = memory[pos + j]; } pos += arraySize * 2 + 8; curLOD.unk2 = getInt(pos - 4); int unkHeadCount = getInt(pos); curLOD.unk3 = new byte[12]; for (int j = 0; j < 12; j++) { curLOD.unk3[j] = memory[pos + 4 + j]; } pos += 16; curLOD.unk4 = new List <byte[]>(); for (int j = 0; j < unkHeadCount; j++) { arraySize = getInt(pos); byte[] buff = new byte[arraySize * 2 + 28]; for (int k = 0; k < arraySize * 2 + 28; k++) { buff[k] = memory[pos + k]; } curLOD.unk4.Add(buff); pos += arraySize * 2 + 28; } int actBonesCount = getInt(pos); curLOD.unk5 = new byte[actBonesCount + 4]; for (int j = 0; j < actBonesCount + 4; j++) { curLOD.unk5[j] = memory[pos + j]; } pos += 4 + actBonesCount; curLOD.unk6 = new byte[52]; for (int j = 0; j < 52; j++) { curLOD.unk6[j] = memory[pos + j]; } pos += 52; #endregion #region Points curLOD.offVert = pos; int pointsCount = getInt(pos); pos += 4; for (int j = 0; j < pointsCount; j++) { Influence tmp = new Influence(); tmp.bone = new byte[4]; tmp.weight = new byte[4]; for (int k = 0; k < 4; k++) { tmp.bone[k] = memory[pos + k + 8]; tmp.weight[k] = memory[pos + k + 12]; } Point p = new Point { off = (uint)pos + 16, infl = tmp, unknown3 = getInt(pos), unknown4 = getInt(pos + 4), X = getFloat(pos + 16), Y = getFloat(pos + 20), Z = getFloat(pos + 24), U = getFloat16(pos + 28), V = getFloat16(pos + 30), Uraw = (UInt16)getInt16(pos + 28), Vraw = (UInt16)getInt16(pos + 30) }; curLOD.points.Add(p); pos += 32; } curLOD.unk7 = getInt(pos); pos += 4; Mesh.LODs.Add(curLOD); #endregion } currpos = pos; }