Exemple #1
0
        public static H3D Open(MemoryStream MS)
        {
            //Please note that data should be on Memory when opening because addresses are relocated.
            //Otherwise the original file would be corrupted!
            BinaryDeserializer Deserializer = new BinaryDeserializer(MS, GetSerializationOptions());

            H3DHeader Header = Deserializer.Deserialize <H3DHeader>();

            new H3DRelocator(MS, Header).ToAbsolute();

            H3D Scene = Deserializer.Deserialize <H3D>();

            Scene.BackwardCompatibility = Header.BackwardCompatibility;
            Scene.ForwardCompatibility  = Header.ForwardCompatibility;

            Scene.ConverterVersion = Header.ConverterVersion;

            Scene.Flags = Header.Flags;

            /*Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(Scene, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings()
             * {
             *  ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
             * }));*/

            Scene.SourceData.Add(Scene);
            return(Scene);
        }
Exemple #2
0
        public static H3D Open(MemoryStream MS)
        {
            //Please note that data should be on Memory when opening because addresses are relocated.
            //Otherwise the original file would be corrupted!
            BinaryDeserializer Deserializer = new BinaryDeserializer(MS, GetSerializationOptions());

            H3DHeader Header = Deserializer.Deserialize <H3DHeader>();

            Console.Write("H3DHeader printout:\n{0}\n", Header);
            PrintProperties(Header);
            Console.Write("H3DHeader printout end\n\n\n\n\n");

            new H3DRelocator(MS, Header).ToAbsolute();

            H3D Scene = Deserializer.Deserialize <H3D>();

            Console.Write("H3DScene printout:\n{0}\n", Scene);
            foreach (var field in Scene.GetType().GetFields())
            {
                PrintProperties(field);
            }
            //PrintProperties(Scene);

            Scene.BackwardCompatibility = Header.BackwardCompatibility;
            Scene.ForwardCompatibility  = Header.ForwardCompatibility;

            Scene.ConverterVersion = Header.ConverterVersion;

            Scene.Flags = Header.Flags;

            foreach (var thingy in Scene.Textures)
            {
                bool thing = false;
                //thing = true;
                if (thing)
                {
                    string test = (new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location)).Directory + "\\" + thingy.Name + ".bin";
                    var    bw   = new BinaryWriter(File.OpenWrite(test));
                    bw.Write(thingy.RawBuffer);
                    bw.Close();
                }
            }

            return(Scene);
        }
Exemple #3
0
 public void Merge(H3D SceneData)
 {
     AddUnique(SceneData.Models, Models);
     AddUnique(SceneData.Materials, Materials);
     AddUnique(SceneData.Shaders, Shaders);
     AddUnique(SceneData.Textures, Textures);
     AddUnique(SceneData.LUTs, LUTs);
     AddUnique(SceneData.Lights, Lights);
     AddUnique(SceneData.Cameras, Cameras);
     AddUnique(SceneData.Fogs, Fogs);
     AddUnique(SceneData.SkeletalAnimations, SkeletalAnimations);
     AddUnique(SceneData.MaterialAnimations, MaterialAnimations);
     AddUnique(SceneData.VisibilityAnimations, VisibilityAnimations);
     AddUnique(SceneData.LightAnimations, LightAnimations);
     AddUnique(SceneData.CameraAnimations, CameraAnimations);
     AddUnique(SceneData.FogAnimations, FogAnimations);
     AddUnique(SceneData.Scenes, Scenes);
 }
Exemple #4
0
        public static H3D Open(MemoryStream MS)
        {
            //Please note that data should be on Memory when opening because addresses are relocated.
            //Otherwise the original file would be corrupted!
            BinaryDeserializer Deserializer = new BinaryDeserializer(MS, GetSerializationOptions());

            H3DHeader Header = Deserializer.Deserialize <H3DHeader>();

            new H3DRelocator(MS, Header).ToAbsolute();

            H3D Scene = Deserializer.Deserialize <H3D>();

            Scene.BackwardCompatibility = Header.BackwardCompatibility;
            Scene.ForwardCompatibility  = Header.ForwardCompatibility;

            Scene.ConverterVersion = Header.ConverterVersion;

            Scene.Flags = Header.Flags;

            return(Scene);
        }
Exemple #5
0
        public void Merge(H3D SceneData, bool RenameDupes)
        {
            if (SceneData != null)
            {
                AddUnique(SceneData.Models, Models, RenameDupes);
                AddUnique(SceneData.Materials, Materials, RenameDupes);
                AddUnique(SceneData.Shaders, Shaders, RenameDupes);
                AddUnique(SceneData.Textures, Textures, RenameDupes);
                AddUnique(SceneData.LUTs, LUTs, RenameDupes);
                AddUnique(SceneData.Lights, Lights, RenameDupes);
                AddUnique(SceneData.Cameras, Cameras, RenameDupes);
                AddUnique(SceneData.Fogs, Fogs, RenameDupes);
                AddUnique(SceneData.SkeletalAnimations, SkeletalAnimations, RenameDupes);
                AddUnique(SceneData.MaterialAnimations, MaterialAnimations, RenameDupes);
                AddUnique(SceneData.VisibilityAnimations, VisibilityAnimations, RenameDupes);
                AddUnique(SceneData.LightAnimations, LightAnimations, RenameDupes);
                AddUnique(SceneData.CameraAnimations, CameraAnimations, RenameDupes);
                AddUnique(SceneData.FogAnimations, FogAnimations, RenameDupes);
                AddUnique(SceneData.Scenes, Scenes, RenameDupes);

                SourceData.AddRange(SceneData.SourceData);
            }
        }
Exemple #6
0
        public static void Save(string FileName, H3D Scene)
        {
            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);
            }
        }
Exemple #7
0
        public static H3D Open(MemoryStream MS)
        {
            //Please note that data should be on Memory when opening because addresses are relocated.
            //Otherwise the original file would be corrupted!
            BinaryDeserializer Deserializer = new BinaryDeserializer(MS, GetSerializationOptions());

            H3DHeader Header = Deserializer.Deserialize <H3DHeader>();

            new H3DRelocator(MS, Header).ToAbsolute();

            H3D Scene = Deserializer.Deserialize <H3D>();

            Scene.BackwardCompatibility = Header.BackwardCompatibility;
            Scene.ForwardCompatibility  = Header.ForwardCompatibility;

            Scene.ConverterVersion = Header.ConverterVersion;

            Scene.Flags = Header.Flags;

            /*Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(Scene, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings()
             * {
             *  ReferenceLoopHandling = ReferenceLoopHandling.Ignore
             * }));*/

            if (Scene.Models.Count > 0)
            {
                foreach (H3DMaterial mat in Scene.Models[0].Materials)
                {
                    /*  mat.MaterialParams.StencilTest.Reference = 255;
                     * mat.MaterialParams.MetaData[mat.MaterialParams.MetaData.Find("$EdgeID")].Values[0] = 255;
                     * //mat.MaterialParams.MetaData[mat.MaterialParams.MetaData.Find("$EdgeType")].Values[0] = 0;
                     * //mat.MaterialParams.MetaData.Clear();
                     * //mat.MaterialParams.VtxShaderUniforms.Clear();
                     * mat.MaterialParams.FragmentFlags = H3DFragmentFlags.IsLUTReflectionEnabled;
                     * mat.MaterialParams.LUTInputSelection.ReflecR = PICALUTInput.CosNormalView;
                     * mat.MaterialParams.LUTInputSelection.ReflecG = PICALUTInput.CosNormalView;
                     * mat.MaterialParams.LUTInputSelection.ReflecB = PICALUTInput.CosNormalView;
                     * mat.MaterialParams.LUTReflecRSamplerName = null;
                     * mat.MaterialParams.LUTReflecRTableName = null;
                     * mat.MaterialParams.LUTReflecGSamplerName = null;
                     * mat.MaterialParams.LUTReflecGTableName = null;
                     * mat.MaterialParams.LUTReflecBSamplerName = null;
                     * mat.MaterialParams.LUTReflecBTableName = null;*/
                    /*mat.MaterialParams.TextureCoords[0].Flags = H3DTextureCoordFlags.IsDirty;
                     * mat.MaterialParams.TextureCoords[1].Flags = H3DTextureCoordFlags.IsDirty;
                     * mat.MaterialParams.TextureCoords[2].Flags = H3DTextureCoordFlags.IsDirty;
                     * mat.MaterialParams.TextureCoords[0].ReferenceCameraIndex = 0;
                     * mat.MaterialParams.TextureCoords[1].ReferenceCameraIndex = 0;
                     * mat.MaterialParams.TextureCoords[2].ReferenceCameraIndex = 0;*/
                }

                /*Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(Scene.Models[0], Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings()
                 * {
                 *  ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                 * }));*/
            }

            /*RGBA DesiredOuterFireColor = new RGBA(0, 255, 0, 255); //Change this to whatever color you want the fire to be
             * RGBA DesiredInnerFireColor = new RGBA(0, 128, 0, 255); //Change these to whatever color you want the fire to be
             *
             * foreach (H3DModel Model in Scene.Models)
             * {
             *  foreach (H3DMaterial Material in Model.Materials)
             *  {
             *      if (Material.Name.Equals("FireStenA"))
             *      {
             *          SetConstantColor(Material.MaterialParams.GetConstantIndex(0), Material.MaterialParams, DesiredOuterFireColor);
             *          SetConstantColor(Material.MaterialParams.GetConstantIndex(1), Material.MaterialParams, DesiredInnerFireColor);
             *      }
             *  }
             * }*/

            return(Scene);
        }
Exemple #8
0
 private List <MaterialAnimationContent> ImportMaterialAnimations(SPICA.Formats.CtrH3D.H3D scene) =>
 scene.MaterialAnimations.Where(ma => ma.Elements.Any()).Select(ma => ImportMaterialAnimation(scene.Models[0], scene.Materials, ma)).ToList();
Exemple #9
0
 private List <AnimationContent> ImportSkeletalAnimations(SPICA.Formats.CtrH3D.H3D scene) =>
 scene.SkeletalAnimations.Select(sa => ImportSkeletalAnimation(scene.Models[0], sa)).ToList();
Exemple #10
0
 public void Merge(H3D SceneData)
 {
     Merge(SceneData, false);
 }