public GFModel(H3DModel mdl, H3DDict <H3DLUT> H3DLUTs) : this() { Name = mdl.Name; foreach (H3DBone Bone in mdl.Skeleton) { Skeleton.Add(new GFBone(Bone, mdl.Skeleton)); } foreach (H3DMaterial Material in mdl.Materials) { H3DMesh Mesh = null; foreach (H3DMesh M in mdl.Meshes) { if (mdl.Materials[M.MaterialIndex] == Material) { Mesh = M; break; } } Materials.Add(new GFMaterial(Material, Mesh)); } Transform = mdl.WorldTransform; PokemonBBoxGen.CreateModelBBox(mdl); H3DMetaDataValue BBox = mdl.MetaData[mdl.MetaData.Find(PokemonBBoxGen.BBOX_MIN_MAX)]; List <float> BBoxMinMax = (List <float>)BBox.Values; BBoxMinVector = new Vector4(BBoxMinMax[0], BBoxMinMax[1], BBoxMinMax[2], 1); BBoxMaxVector = new Vector4(BBoxMinMax[3], BBoxMinMax[4], BBoxMinMax[5], 1); foreach (H3DLUT LUT in H3DLUTs) { if (LUT.Name.Equals(DefaultLUTName)) { foreach (H3DLUTSampler Sampler in LUT.Samplers) { LUTs.Add(new GFLUT() { Type = GetLUTType(Sampler.Name, mdl.Materials), Name = Sampler.Name, Table = Sampler.Table }); } } } foreach (H3DMesh Mesh in mdl.Meshes) { Meshes.Add(new GFMesh(Mesh, mdl)); } }
public GFMesh(H3DMesh Mesh, H3DModel Parent) : this() { if (Mesh.NodeIndex >= 0 && Mesh.NodeIndex < Parent.MeshNodesTree.Count) { Name = Parent.MeshNodesTree.Find(Mesh.NodeIndex); } else { Name = "Mesh_" + Parent.Meshes.IndexOf(Mesh); } if (Mesh.MetaData.Find(PokemonBBoxGen.BBOX_MIN_MAX) == -1) { PokemonBBoxGen.CreateModelBBox(Parent); } H3DMetaDataValue BBox = Mesh.MetaData[Mesh.MetaData.Find(PokemonBBoxGen.BBOX_MIN_MAX)]; List <float> BBoxMinMax = (List <float>)BBox.Values; BBoxMinVector = new Vector4(BBoxMinMax[0], BBoxMinMax[1], BBoxMinMax[2], 1); BBoxMaxVector = new Vector4(BBoxMinMax[3], BBoxMinMax[4], BBoxMinMax[5], 1); BoneIndicesPerVertex = 4; int SubMeshIdx = 0; List <PICAVertex> Vertices = Mesh.GetVertices().ToList(); foreach (H3DSubMesh SubMesh in Mesh.SubMeshes) { string MaterialName; if (Mesh.MaterialIndex >= 0 && Mesh.MaterialIndex < Parent.Materials.Count) { MaterialName = Parent.Materials[Mesh.MaterialIndex].Name; } else { MaterialName = null; } SubMeshes.Add(new GFSubMesh(SubMesh, Mesh, Vertices, MaterialName)); SubMeshIdx++; } }
public static void Save(string FileName, H3D Scene) { foreach (H3DModel Model in Scene.Models) { PokemonBBoxGen.CreateModelBBox(Model); } using (FileStream FS = new FileStream(FileName, FileMode.Create)) { H3DHeader Header = new H3DHeader(); H3DRelocator Relocator = new H3DRelocator(FS, Header); BinarySerializer Serializer = new BinarySerializer(FS, GetSerializationOptions()); Section Contents = Serializer.Sections[(uint)H3DSectionId.Contents]; Contents.Header = Header; /* * Those comparisons are used to sort Strings and data buffers. * Strings are sorted in alphabetical order (like on the original file), * while buffers places textures first, and then vertex/index data after. * It's unknown why textures needs to come first, but placing the textures * at the end or at random order causes issues on the game. * It's most likely an alignment issue. */ Comparison <RefValue> CompStr = H3DComparers.GetComparisonStr(); Comparison <RefValue> CompRaw = H3DComparers.GetComparisonRaw(); Section Strings = new Section(0x10, CompStr); Section Commands = new Section(0x80); Section RawData = new Section(0x80, CompRaw); Section RawExt = new Section(0x80, CompRaw); Section Relocation = new Section(); Serializer.AddSection((uint)H3DSectionId.Strings, Strings, typeof(string)); Serializer.AddSection((uint)H3DSectionId.Strings, Strings, typeof(H3DStringUtf16)); Serializer.AddSection((uint)H3DSectionId.Commands, Commands, typeof(uint[])); Serializer.AddSection((uint)H3DSectionId.RawData, RawData); Serializer.AddSection((uint)H3DSectionId.RawExt, RawExt); Serializer.AddSection((uint)H3DSectionId.Relocation, Relocation); Header.BackwardCompatibility = Scene.BackwardCompatibility; Header.ForwardCompatibility = Scene.ForwardCompatibility; Header.ConverterVersion = Scene.ConverterVersion; Header.Flags = Scene.Flags; Serializer.Serialize(Scene); Header.AddressCount = (ushort)RawData.Values.Count; Header.AddressCount += (ushort)RawExt.Values.Count; Header.UnInitDataLength = Header.AddressCount * 4; Header.ContentsAddress = Contents.Position; Header.StringsAddress = Strings.Position; Header.CommandsAddress = Commands.Position; Header.RawDataAddress = RawData.Position; Header.RawExtAddress = RawExt.Position; Header.RelocationAddress = Relocation.Position; Header.ContentsLength = Contents.Length; Header.StringsLength = Strings.Length; Header.CommandsLength = Commands.Length; Header.RawDataLength = RawData.Length; Header.RawExtLength = RawExt.Length; Relocator.ToRelative(Serializer); FS.Seek(0, SeekOrigin.Begin); Serializer.WriteValue(Header); } }