ImmutableArray<Mesh> LoadMeshes(Ibasa.IO.BinaryReader reader, int count) { long offset = reader.BaseStream.Position; Mesh[] meshes = new Mesh[count]; for (int i = 0; i < count; ++i) { reader.BaseStream.Position = offset; int material = reader.ReadInt32(); int modelIndex = reader.ReadInt32(); int vertexCount = reader.ReadInt32(); int vertexOffset = reader.ReadInt32(); int flexCount = reader.ReadInt32(); long flexOffset = offset + reader.ReadInt32(); int materialType = reader.ReadInt32(); int materialParam = reader.ReadInt32(); int meshId = reader.ReadInt32(); Vector3f center = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); int modelvertexdata = reader.ReadInt32(); int[] numLODVertexes = new int[8]; for (int l = 0; l < 8; ++l) { numLODVertexes[l] = reader.ReadInt32(); } ImmutableArray<int> lods = new ImmutableArray<int>(numLODVertexes); reader.Seek(8 * 4, SeekOrigin.Current); //skip 8 ints offset = reader.BaseStream.Position; reader.BaseStream.Position = flexOffset; ImmutableArray<Flex> flexes = LoadFlexes(reader, flexCount); meshes[i] = new Mesh(material, vertexCount, vertexOffset, flexes, materialType, materialParam, meshId, center, lods); } return new ImmutableArray<Mesh>(meshes); }
private void ReadData(Ibasa.IO.BinaryReader reader) { LowResImage = new SharpIL.Resource( new Size3i(LowResImageWidth, LowResImageHeight, 1), 1, 1, EncodingFromFormat(LowResImageFormat)); HighResImage = new SharpIL.Resource( new Size3i(Width, Height, Depth), MipmapCount, Frames * Faces, EncodingFromFormat(ImageFormat)); if (VersionMinor < 3) { reader.Read(LowResImage[0, 0], 0, LowResImage[0, 0].Length); for (int mip = MipmapCount-1; mip >=0 ; --mip) { Size3f size = HighResImage.ComputeMipSliceSize(mip); for (int frame = 0; frame < Frames; ++frame) { for (int face = 0; face < Faces; ++face) { int array = face + (Faces * frame); reader.Read( HighResImage[mip, array], 0, HighResImage[mip, array].Length); } } } } else { //low res int lowResOffset = Resources.Find((resource) => resource.Type == ResourceType.LowResImage).Data; reader.Seek((uint)lowResOffset, SeekOrigin.Begin); reader.Read(LowResImage[0, 0], 0, LowResImage[0, 0].Length); //high res int highResOffset = Resources.Find((resource) => resource.Type == ResourceType.Image).Data; reader.Seek((uint)highResOffset, SeekOrigin.Begin); for (int mip = MipmapCount - 1; mip >= 0; --mip) { Size3f size = HighResImage.ComputeMipSliceSize(mip); for (int frame = 0; frame < Frames; ++frame) { for (int face = 0; face < Faces; ++face) { byte[] data = HighResImage[mip, face + (Faces * frame)]; reader.Read(data, 0, data.Length); } } } } }
ImmutableArray<Model> LoadModels(Ibasa.IO.BinaryReader reader, int count) { long offset = reader.BaseStream.Position; Model[] models = new Model[count]; for (int i = 0; i < count; ++i) { reader.BaseStream.Position = offset; string name = Encoding.ASCII.GetString(reader.ReadBytes(64)).Trim('\0'); int type = reader.ReadInt32(); float boundingRadius = reader.ReadSingle(); int meshCount = reader.ReadInt32(); long meshOffset = offset + reader.ReadInt32(); int vertexCount = reader.ReadInt32(); int vertexIndex = reader.ReadInt32(); int tangentIndex = reader.ReadInt32(); int numattachments = reader.ReadInt32(); int attachmentindex = reader.ReadInt32(); int eyeballCount = reader.ReadInt32(); long eyeballOffset = offset + reader.ReadInt32(); int vertexData = reader.ReadInt32(); int indexData = reader.ReadInt32(); reader.Seek(8 * 4, SeekOrigin.Current); //skip 8 ints offset = reader.BaseStream.Position; reader.BaseStream.Position = meshOffset; ImmutableArray<Mesh> meshes = LoadMeshes(reader, meshCount); reader.BaseStream.Position = meshOffset; ImmutableArray<Eyeball> eyeballs = LoadEyeballs(reader, meshCount); models[i] = new Model(name, type, boundingRadius, meshes, vertexCount, vertexIndex, tangentIndex, eyeballs); } return new ImmutableArray<Model>(models); }
ImmutableArray<Texture> LoadTextures(Ibasa.IO.BinaryReader reader, int count) { long offset = reader.BaseStream.Position; Texture[] textures = new Texture[count]; for (int i = 0; i < count; ++i) { reader.BaseStream.Position = offset; long nameOffset = offset + reader.ReadInt32(); int flags = reader.ReadInt32(); int used = reader.ReadInt32(); int unused = reader.ReadInt32(); reader.Seek(12 * 4, SeekOrigin.Current); //skip 12 ints offset = reader.BaseStream.Position; reader.BaseStream.Position = nameOffset; string name = LoadString(reader); textures[i] = new Texture(name, flags); } return new ImmutableArray<Texture>(textures); }
ImmutableArray<HitBox> LoadHitBoxes(Ibasa.IO.BinaryReader reader, int count) { long offset = reader.BaseStream.Position; HitBox[] hitBoxes = new HitBox[count]; for (int i = 0; i < count; ++i) { reader.BaseStream.Position = offset; int bone = reader.ReadInt32(); int group = reader.ReadInt32(); Boxf box = new Boxf( new Point3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()), new Size3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle())); long nameOffset = offset + reader.ReadInt32(); reader.Seek(8*4, SeekOrigin.Current); //skip 8 ints offset = reader.BaseStream.Position; reader.BaseStream.Position = nameOffset; string name = LoadString(reader); hitBoxes[i] = new HitBox(bone, group, box, name); } return new ImmutableArray<HitBox>(hitBoxes); }
ImmutableArray<BoneController> LoadBoneControllers(Ibasa.IO.BinaryReader reader, int count) { BoneController[] boneControllers = new BoneController[count]; for (int i = 0; i < count; ++i) { boneControllers[i] = new BoneController( reader.ReadInt32(), (BoneControllerType)reader.ReadInt32(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadInt32(), reader.ReadInt32()); reader.Seek(8 * 4, SeekOrigin.Current); //skip 8 ints } return new ImmutableArray<BoneController>(boneControllers); }
ImmutableArray<Bone> LoadBones(Ibasa.IO.BinaryReader reader, int count) { long offset = reader.BaseStream.Position; Bone[] bones = new Bone[count]; for (int i = 0; i < count; ++i) { reader.BaseStream.Position = offset; long nameOffset = offset + reader.ReadInt32(); int parent = reader.ReadInt32(); ImmutableArray<int> boneControllers = new ImmutableArray<int>(new int[] { reader.ReadInt32(),reader.ReadInt32(),reader.ReadInt32(), reader.ReadInt32(),reader.ReadInt32(),reader.ReadInt32()}); Vector3f position = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Quaternionf quaternion = new Quaternionf(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Vector3f rotation = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Vector3f positionScale = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Vector3f rotationScale = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Matrix4x4f poseToBone = new Matrix4x4f( reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), 0, 0, 0, 1); Quaternionf alignment = new Quaternionf(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); int flags = reader.ReadInt32(); int procType = reader.ReadInt32(); int procIndex = reader.ReadInt32(); int physicsBone = reader.ReadInt32(); int surfacePropIdx = reader.ReadInt32(); int contents = reader.ReadInt32(); reader.Seek(8 * 4, SeekOrigin.Current); //skip 8 ints offset = reader.BaseStream.Position; reader.BaseStream.Position = nameOffset; string name = LoadString(reader); bones[i] = new Bone(name, parent, boneControllers, position, quaternion, rotation, positionScale, rotationScale, poseToBone, alignment, flags, procType, procIndex, physicsBone, surfacePropIdx, contents); } return new ImmutableArray<Bone>(bones); }