private void ReadHeader70(Ibasa.IO.BinaryReader reader) { Width = reader.ReadUInt16(); Height = reader.ReadUInt16(); Flags = (TextureFlags)reader.ReadInt32(); Frames = reader.ReadUInt16(); StartFrame = reader.ReadUInt16(); reader.ReadBytes(4); //skip padding Reflectivity = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); reader.ReadBytes(4); //skip padding BumpmapScale = reader.ReadSingle(); ImageFormat = (ImageFormat)reader.ReadInt32(); MipmapCount = reader.ReadByte(); LowResImageFormat = (ImageFormat)reader.ReadInt32(); LowResImageWidth = reader.ReadByte(); LowResImageHeight = reader.ReadByte(); }
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); }
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<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); }