/// <summary> /// Parse binary block. /// </summary> public Managed Parse(BinaryParser parser) { var skel = this.context.Resolve<AnimSkel>(); skel.NameHash = parser.ConsumeUInt32(); var numBones = parser.ConsumeUInt32(); while (numBones > 0) { parser.Expect(Hash.Get("CIwAnimBone")); var nameHash = parser.ConsumeUInt32(); var parent = parser.ConsumeUInt32(); var parentIndex = skel.EnsureBone(parent); var boneIndex = skel.EnsureBone(nameHash); var bone = skel.Bones[boneIndex]; bone.Parent = parentIndex; bone.BindingRot = parser.ConsumeQuaternion(); bone.BindingPos = parser.ConsumeVector3(); bone.SkelId = parser.ConsumeUInt16(); bone.Flags = parser.ConsumeUInt16(); --numBones; } return skel; }
/// <summary> /// Parse binary block. /// </summary> public Managed Parse(BinaryParser parser) { var model = this.context.Resolve<Model>(); model.NameHash = parser.ConsumeUInt32(); model.Flags = parser.ConsumeUInt32(); var numVerts = parser.ConsumeUInt32(); var numVertsUnique = parser.ConsumeUInt32(); model.Center = parser.ConsumeVector3(); model.Radius = parser.ConsumeFloat(); var streamMesh = this.context.Resolve<Mesh>(); model.Meshes.Add(streamMesh); streamMesh.NameHash = parser.ConsumeUInt32(); //parser.Expect((uint)0x466dbf2a); var num = parser.ConsumeUInt32(); for (; num > 0; --num) { var type = parser.ConsumeUInt32(); var name = parser.ConsumeUInt32(); var size = parser.ConsumeUInt32(); var numItems = parser.ConsumeUInt32(); var flags = parser.ConsumeUInt16(); if (type == Hash.Get("CIwModelBlockGLUVs")) { this.ParseModelBlockGLUVs(parser, model, name, size, numItems, flags); continue; } if (type == Hash.Get("CIwModelBlockCols")) { this.ParseModelBlockCols(parser, model, name, size, numItems, flags); continue; } if (type == Hash.Get("CIwModelBlockGLTriList")) { this.ParseModelBlockGLTriList(parser, model, name, size, numItems, flags); continue; } if (type == Hash.Get("CIwModelBlockNorms")) { this.ParseModelBlockNorms(parser, model, name, size, numItems, flags); continue; } if (type == Hash.Get("CIwModelBlockVerts")) { this.ParseModelBlockVerts(parser, model, name, size, numItems, flags); continue; } if (type == Hash.Get("CIwModelBlockVerts2D")) { this.ParseModelBlockVerts2D(parser, model, name, size, numItems, flags); continue; } if (type == Hash.Get("CIwModelBlockBiTangents")) { this.ParseModelBlockBiTangents(parser, model, name, size, numItems, flags); continue; } if (type == Hash.Get("CIwModelBlockTangents")) { this.ParseModelBlockTangents(parser, model, name, size, numItems, flags); continue; } if (type == Hash.Get("CIwModelBlockChunk")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockChunkTree")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockChunkVerts")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockCols16")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockFaceFlags")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockGLPrimBase")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockGLRenderEdges")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockGLRenderVerts")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockGLTriStrip")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockGLUVs2")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockIndGroups")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockPrimBase")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockPrimF3")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockPrimF4")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockPrimFT3")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockPrimFT4")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockPrimG3")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockPrimG4")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockPrimGen3")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockPrimGen4")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockPrimGT3")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockPrimGT4")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockRenderEdges")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockRenderVerts")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelBlockSWOptim1")) { throw new NotImplementedException(); } throw new FormatException("Unknown element"); } num = parser.ConsumeUInt32(); for (; num > 0; --num) { var type = parser.ConsumeUInt32(); var name = parser.ConsumeUInt32(); var flags = parser.ConsumeUInt32(); if (type == Hash.Get("CIwModelExtPos")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelExtSelSet")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelExtSelSetEdge")) { throw new NotImplementedException(); } if (type == Hash.Get("CIwModelExtSelSetFace")) { this.ParseModelExtSelSetFace(parser, model, name, flags); continue; } if (type == Hash.Get("CIwModelExtSelSetVert")) { this.ParseModelExtSelSetVert(parser, model, name, flags); continue; } if (type == Hash.Get("CIwModelExtSphere")) { throw new NotImplementedException(); } throw new FormatException("Unknown element"); } num = parser.ConsumeUInt32(); uint[] materials = new uint[num]; for (uint matIndex = 0; matIndex < num; ++matIndex) { materials[matIndex] = parser.ConsumeUInt32(); } foreach (var mesh in model.Meshes) { foreach (Surface submesh in mesh.Surfaces) { submesh.Material.HashReference = materials[submesh.Material.HashReference]; } } return model; }
private void ParseModelBlockVerts(BinaryParser parser, Model model, uint name, uint size, uint numItems, ushort flags) { var uniqueValues = parser.ConsumeUInt16(); var streamMesh = (model.Meshes[0]); streamMesh.Vertices.Clear(); var itemsToRead = (int)uniqueValues; streamMesh.Vertices.EnsureAt((int)numItems - 1); for (int i = 0; i < itemsToRead; ++i) { float x = parser.ConsumeFloat(); parser.Skip(1); streamMesh.Vertices[i] = new Vector3(x, 0, 0); } for (int i = 0; i < itemsToRead; ++i) { float x = parser.ConsumeFloat(); parser.Skip(1); streamMesh.Vertices[i] = new Vector3(streamMesh.Vertices[i].X, x, 0); } for (int i = 0; i < itemsToRead; ++i) { float x = parser.ConsumeFloat(); parser.Skip(1); streamMesh.Vertices[i] = new Vector3(streamMesh.Vertices[i].X, streamMesh.Vertices[i].Y, x); } while (itemsToRead < numItems) { streamMesh.Vertices[itemsToRead] = streamMesh.Vertices[parser.ConsumeUInt16()]; ++itemsToRead; } //var len = this.uniqueValues; // this.numItems; // //this.Resize(this.numItems); //if (serialise.IsWriting()) //{ // throw new NotImplementedException(); //} //for (int i = 0; i < len; ++i) //{ // short x = (short)(this.verts[i].X - mediane); // serialise.Int16(ref x); // this.verts[i].X = x + mediane; //} //for (int i = 0; i < len; ++i) //{ // short y = (short)(this.verts[i].Y - mediane); // serialise.Int16(ref y); // this.verts[i].Y = y + mediane; //} //for (int i = 0; i < len; ++i) //{ // short z = (short)(this.verts[i].Z - mediane); // serialise.Int16(ref z); // this.verts[i].Z = z + mediane; //} //ushort[] links = new ushort[this.numItems - this.uniqueValues]; //serialise.Serialise(ref links); //for (int i = this.uniqueValues; i < this.numItems; ++i) //{ // this.verts[i] = this.verts[links[i - this.uniqueValues]]; //} }
private Image ParseImage(BinaryParser parser) { var image = new Image(); image.Format = (ImageFormat)parser.ConsumeUInt8(); image.Flags = parser.ConsumeUInt16(); image.width = parser.ConsumeUInt16(); image.height = parser.ConsumeUInt16(); image.pitch = parser.ConsumeUInt16(); image.palette = parser.ConsumeUInt32(); byte[] d = new byte[image.height * image.pitch]; parser.ConsumeArray(d); image.data = d; switch (image.Format) { case ImageFormat.ABGR_8888: case ImageFormat.BGR_888: case ImageFormat.RGB_888: return image; //case Image.PALETTE4_ABGR_1555: // format = (new Palette4Abgr1555(image.width, image.height, image.pitch)); // Debug.WriteLine(string.Format("Image PALETTE4_ABGR_1555 {0}x{1}", image.width, image.height)); // break; //case Image.PALETTE4_RGB_888: // format = (new Palette4Rgb888(image.width, image.height, image.pitch)); // Debug.WriteLine(string.Format("Image PALETTE4_RGB_888 {0}x{1}", image.width, image.height)); // break; //case Image.PALETTE8_ABGR_1555: // format = (new Palette8Abgr1555(image.width, image.height, image.pitch)); // Debug.WriteLine(string.Format("Image PALETTE8_ABGR_1555 {0}x{1}", image.width, image.height)); // break; //case Image.ABGR_1555: // Debug.WriteLine(string.Format("Image ABGR_1555 {0}x{1}", image.width, image.height)); // LoadABGR1555(serialise); // return; //case Image.RGBA_6666: // Debug.WriteLine(string.Format("Image RGBA_6666 {0}x{1}", image.width, image.height)); // LoadRgba6666(serialise); // return; case ImageFormat.PALETTE8_RGB_888: image.PaletteData = parser.ConsumeByteArray(256 * 3); return image; case ImageFormat.PALETTE8_ABGR_8888: case ImageFormat.PALETTE8_ARGB_8888: case ImageFormat.PALETTE8_RGBA_8888: image.PaletteData = parser.ConsumeByteArray(256 * 4); return image; case ImageFormat.PALETTE4_RGB_888: image.PaletteData = parser.ConsumeByteArray(16 * 3); return image; case ImageFormat.PALETTE4_ABGR_8888: case ImageFormat.PALETTE4_ARGB_8888: case ImageFormat.PALETTE4_RGBA_8888: image.PaletteData = parser.ConsumeByteArray(16 * 4); return image; default: throw new FormatException(string.Format(CultureInfo.CurrentCulture, "Unknown image format 0x{0:x}", image.Format)); } }