public RS5DirectoryEntry(RS5Chunk chunk, string name, string type, DateTime modtime) { this.PersistentData = chunk; this.Name = name; this.Type = type; this.ModTime = modtime; }
protected static IEnumerable <XElement> GetExtraData(RS5Chunk chunk) { RS5Chunk HEAD = chunk.Chunks.ContainsKey("HEAD") ? chunk.Chunks["HEAD"] : null; RS5Chunk TAGL = chunk.Chunks.ContainsKey("TAGL") ? chunk.Chunks["TAGL"] : null; RS5Chunk BBH = chunk.Chunks.ContainsKey("BBH ") ? chunk.Chunks["BBH "] : null; RS5Chunk COLR = chunk.Chunks.ContainsKey("COLR") ? chunk.Chunks["COLR"] : null; List <XElement> elements = new List <XElement>(); if (HEAD != null && HEAD.Data != null) { elements.Add(GetHEADData(HEAD.Data, chunk.Name)); } if (TAGL != null && TAGL.Data != null) { elements.Add(GetTAGLData(TAGL.Data, chunk.Name)); } if (BBH != null && BBH.Data != null) { elements.Add(GetBBHData(BBH.Data)); } if (COLR != null && COLR.Data != null) { elements.Add(GetCOLRData(COLR.Data)); } return(elements); }
public RS5DirectoryEntry(RS5Chunk chunk, string name, string type, DateTime modtime) { this.PersistentData = chunk; this.Name = name; this.Type = type; this.ModTime = modtime; }
public static Texture AddTexture(RS5Chunk chunk) { return(GetTexture(chunk.Name, (t) => { t.Chunk = chunk; })); }
public static ModelBase Create(RS5Chunk chunk) { Joint rootjoint = GetRootJoint(chunk); IEnumerable <Triangle> triangles = GetTriangles(chunk, rootjoint); IEnumerable <XElement> extradata = GetExtraData(chunk); return(new ImmobileModel(triangles, rootjoint, extradata)); }
protected static Triangle[] GetTriangles(RS5Chunk chunk, Joint RootJoint) { RS5Chunk BHDR = chunk.Chunks["BHDR"]; RS5Chunk VTXL = chunk.Chunks["VTXL"]; RS5Chunk TRIL = chunk.Chunks["TRIL"]; int numtextures = (BHDR == null || BHDR.Data == null) ? 0 : (int)(BHDR.Data.Length / 144); return(Enumerable.Range(0, numtextures).SelectMany(i => GetTextureTriangles(RootTransform, BHDR, VTXL, TRIL, i)).ToArray()); }
public JointData(RS5Chunk JNTS, RS5Chunk FRMS, int numjoints, int numframes, int index) { int offset = index * 196; Index = index; Name = JNTS.Data.GetString(offset, 128); ReverseBindingMatrix = JNTS.Data.GetMatrix4(offset + 128); Parent = JNTS.Data.GetInt32(offset + 192); AnimationFrames = Enumerable.Range(0, numframes).Select(j => FRMS.Data.GetMatrix4((j * numjoints + index) * 64)).ToArray(); }
protected static Triangle[] GetTriangles(RS5Chunk chunk, Joint rootjoint) { RS5Chunk BLKS = chunk.Chunks["BLKS"]; RS5Chunk VTXS = chunk.Chunks["VTXS"]; RS5Chunk INDS = chunk.Chunks["INDS"]; IndexedJoint[] joints = rootjoint == null ? new IndexedJoint[0] : rootjoint.GetSelfAndDescendents().OfType <IndexedJoint>().OrderBy(j => j.Index).ToArray(); int numtextures = (BLKS == null || BLKS.Data == null) ? 0 : (int)(BLKS.Data.Length / 144); return(Enumerable.Range(0, numtextures).SelectMany(i => GetTextureTriangles(RootTransform, BLKS, VTXS, INDS, i, joints)).ToArray()); }
protected static Vertex GetVertex(Matrix4 transform, RS5Chunk VTXS, int index, Texture texture, Joint[] joints) { int vtxofs = index * 32; return(new Vertex( transform * new Vector4(VTXS.Data.GetSingle(vtxofs + 0), VTXS.Data.GetSingle(vtxofs + 4), VTXS.Data.GetSingle(vtxofs + 8), 1.0), transform * new Vector4((VTXS.Data.GetByte(vtxofs + 22) - 0x80) / 127.0, (VTXS.Data.GetByte(vtxofs + 21) - 0x80) / 127.0, (VTXS.Data.GetByte(vtxofs + 20) - 0x80) / 127.0, 0.0), Vector4.Zero, Vector4.Zero, new TextureCoordinate(texture, VTXS.Data.GetSingle(vtxofs + 12), -VTXS.Data.GetSingle(vtxofs + 16)), Enumerable.Range(0, 4).Select(i => GetJointInfluence(VTXS.Data.GetByte(vtxofs + 24 + i), VTXS.Data.GetByte(vtxofs + 28 + i), joints)).Where(j => j != null), null )); }
protected static Vertex GetVertex(Matrix4 transform, RS5Chunk VTXL, int index, Texture texture) { int vtxofs = index * 36; return(new Vertex( transform * new Vector4(VTXL.Data.GetSingle(vtxofs + 0), VTXL.Data.GetSingle(vtxofs + 4), VTXL.Data.GetSingle(vtxofs + 8), 1.0), transform * new Vector4((VTXL.Data.GetByte(vtxofs + 14) - 0x80) / 127.0, (VTXL.Data.GetByte(vtxofs + 13) - 0x80) / 127.0, (VTXL.Data.GetByte(vtxofs + 12) - 0x80) / 127.0, 0.0), transform * new Vector4((VTXL.Data.GetByte(vtxofs + 18) - 0x80) / 127.0, (VTXL.Data.GetByte(vtxofs + 17) - 0x80) / 127.0, (VTXL.Data.GetByte(vtxofs + 16) - 0x80) / 127.0, 0.0), transform * new Vector4((VTXL.Data.GetByte(vtxofs + 22) - 0x80) / 127.0, (VTXL.Data.GetByte(vtxofs + 21) - 0x80) / 127.0, (VTXL.Data.GetByte(vtxofs + 20) - 0x80) / 127.0, 0.0), new TextureCoordinate(texture, VTXL.Data.GetSingle(vtxofs + 24), -VTXL.Data.GetSingle(vtxofs + 28)), null, VTXL.Data.GetBytes(vtxofs + 32, 4) )); }
protected static Triangle GetTriangle(RS5Chunk TRIL, Vertex[] vertices, int index, int firstvtx, Texture texture) { int triofs = index * 4; int a = TRIL.Data.GetInt32(triofs + 0) - firstvtx; int b = TRIL.Data.GetInt32(triofs + 4) - firstvtx; int c = TRIL.Data.GetInt32(triofs + 8) - firstvtx; return(new Triangle { A = vertices[a], B = vertices[b], C = vertices[c], Texture = texture }); }
public static ModelBase Create(RS5DirectoryEntry dirent) { RS5Chunk chunk = dirent.Data; if (dirent.Type == "IMDL") { return(ImmobileModel.Create(chunk)); } else if (dirent.Type == "AMDL") { return(AnimatedModel.Create(chunk)); } else { throw new ArgumentException("Entry does not represent a model"); } }
protected static Joint GetRootJoint(RS5Chunk chunk) { RS5Chunk JNTS = chunk.Chunks.ContainsKey("JNTS") ? chunk.Chunks["JNTS"] : null; RS5Chunk FRMS = chunk.Chunks.ContainsKey("FRMS") ? chunk.Chunks["FRMS"] : null; if (JNTS != null) { int numjoints = (int)(JNTS.Data.Length / 196); int numframes = (FRMS != null && FRMS.Data != null) ? (int)(FRMS.Data.Length / (numjoints * 64)) : 0; JointData[] jointdata = Enumerable.Range(0, numjoints).Select(i => new JointData(JNTS, FRMS, numjoints, numframes, i)).ToArray(); return(GetJoint(RootTransform, RootTransform, Matrix4.Identity, jointdata, jointdata.Where(j => j.Parent == -1).Single().Index)); } else { return(null); } }
private Dictionary <string, RS5Chunk> GetChunks() { if (!HasData && DataLength != 0) { Dictionary <string, RS5Chunk> ret = new Dictionary <string, RS5Chunk>(); long pos = 0; while (pos < DataLength) { RS5Chunk chunk = new RS5Chunk(ChunkData, DataOffset + pos); ret.Add(chunk.FourCC, chunk); pos += chunk.TotalSize; } return(ret); } else { return(null); } }
protected static Joint GetRootJoint(RS5Chunk chunk) { return(null); }
public void Write(RS5Chunk data, string name, string type, DateTime modtime) { Write(new RS5DirectoryEntry(data, name, type, modtime)); }
protected static IEnumerable <XElement> GetExtraData(RS5Chunk chunk) { return(null); }
protected static IEnumerable <Triangle> GetTextureTriangles(Matrix4 transform, RS5Chunk BLKS, RS5Chunk VTXS, RS5Chunk INDS, int index, Joint[] joints) { int texofs = index * 144; string texname = BLKS.Data.GetString(texofs, 128); int firstvtx = BLKS.Data.GetInt32(texofs + 128); int endvtx = BLKS.Data.GetInt32(texofs + 132); int numvtx = endvtx - firstvtx; int firsttri = BLKS.Data.GetInt32(texofs + 136); int endtri = BLKS.Data.GetInt32(texofs + 140); int numtri = endtri - firsttri; Texture texture = Texture.GetTexture(texname); Vertex[] vertices = Enumerable.Range(0, numvtx).Select(i => GetVertex(transform, VTXS, i + firstvtx, texture, joints)).ToArray(); return(Enumerable.Range(0, numtri / 3).Select(i => GetTriangle(INDS, vertices, i * 3 + firsttri, firstvtx, texture))); }
public static Texture AddTexture(RS5Chunk chunk) { return GetTexture(chunk.Name, (t) => { t.Chunk = chunk; }); }
protected static IEnumerable <Triangle> GetTextureTriangles(Matrix4 transform, RS5Chunk BHDR, RS5Chunk VTXL, RS5Chunk TRIL, int index) { int texofs = index * 144; string texname = BHDR.Data.GetString(texofs, 128); int firstvtx = BHDR.Data.GetInt32(texofs + 128); int numvtx = BHDR.Data.GetInt32(texofs + 136); int firsttri = BHDR.Data.GetInt32(texofs + 132); int numtri = BHDR.Data.GetInt32(texofs + 140); Texture texture = Texture.GetTexture(texname); Vertex[] vertices = Enumerable.Range(0, numvtx).Select(i => GetVertex(transform, VTXL, i + firstvtx, texture)).ToArray(); return(Enumerable.Range(0, numtri / 3).Select(i => GetTriangle(TRIL, vertices, i * 3 + firsttri, texture))); }
private Dictionary<string, RS5Chunk> GetChunks() { if (!HasData && DataLength != 0) { Dictionary<string, RS5Chunk> ret = new Dictionary<string, RS5Chunk>(); long pos = 0; while (pos < DataLength) { RS5Chunk chunk = new RS5Chunk(ChunkData, DataOffset + pos); ret.Add(chunk.FourCC, chunk); pos += chunk.TotalSize; } return ret; } else { return null; } }