Exemple #1
2
        private BlueprintManager LoadBlueprints()
        {
            var           blueprintManager           = new BlueprintManager();
            XmlSerializer blueprintManagerSerializer = null;

            Object[] blueprintAssets = Resources.LoadAll(this.BlueprintAssetsFolder);

            foreach (var blueprintObjectAsset in blueprintAssets)
            {
                var blueprintAsset = blueprintObjectAsset as TextAsset;

                if (blueprintAsset != null)
                {
                    var blueprintStream = new MemoryStream(blueprintAsset.bytes);

                    // Load blueprints.
                    BlueprintManager subBlueprintManager = null;

                    if (Application.isEditor || this.UseXmlInBuild)
                    {
                        if (blueprintManagerSerializer == null)
                        {
                            blueprintManagerSerializer = new XmlSerializer(typeof(BlueprintManager));
                        }
                        try
                        {
                            subBlueprintManager =
                                (BlueprintManager)blueprintManagerSerializer.Deserialize(blueprintStream);
                        }
                        catch (XmlException e)
                        {
                            Debug.LogError(
                                string.Format(
                                    "Exception deserializing blueprint xml '{0}': {1}", blueprintAsset.name, e.Message));
                        }
                    }
                    else
                    {
                        BinaryDeserializer binaryDeserializer = new BinaryDeserializer(blueprintStream);
                        subBlueprintManager = binaryDeserializer.Deserialize <BlueprintManager>();
                    }

                    if (subBlueprintManager != null)
                    {
                        blueprintManager.AddBlueprints(subBlueprintManager);
                    }
                }
                else
                {
                    Debug.LogError(string.Format("Blueprint asset is no text asset: {0}", blueprintObjectAsset.name));
                }
            }

            // Resolve parents.
            BlueprintUtils.ResolveParents(blueprintManager, blueprintManager);

            return(blueprintManager);
        }
        public void SimpleParentUserTestDeserializeBase(byte[] Result, SimpleParentUserInfo Value, BaseOptionInfo SerializerOptions)
        {
            //in this example server side has SimpleUserInfo
            //server side has Id, Name, Family
            //and the client side has SimpleUserOldStructureInfo
            //client side has Id, Age, BirthDate ,Name

            //new structure of models
            var newStructureModels = BinarySerializer.GetStructureModels(SerializerOptions);

            //my old deserializer
            var myDeserializer = new BinaryDeserializer();

            myDeserializer.Options = new BinaryGo.Helpers.BaseOptionInfo();

            #region VersionChangedControl
            //generate type
            myDeserializer.Options.GenerateType <SimpleParentUserOldStructureInfo>();
            //add model renamed
            myDeserializer.AddMovedType(myDeserializer.GetStrcutureModelName(typeof(SimpleParentUserInfo)), typeof(SimpleParentUserOldStructureInfo));
            //build new structure to old structure
            myDeserializer.BuildStructure(newStructureModels);
            #endregion

            var result = myDeserializer.Deserialize <SimpleParentUserOldStructureInfo>(Result);
            Assert.True(result.IsEquals(Value));

            //now serialize from client side and deserialize from server side happen
            result.Passport = "AV12345678";
            BinarySerializer binarySerializer = new BinarySerializer(myDeserializer.Options);
            var resultSerialized   = binarySerializer.Serialize(result);
            var resultDeserialized = myDeserializer.Deserialize <SimpleParentUserOldStructureInfo>(resultSerialized);
            Assert.True(resultDeserialized.IsEquals(Value));
        }
 /// <summary>
 ///   Reads this object from its binary representation.
 /// </summary>
 /// <param name="deserializer">Deserializer to read the object with.</param>
 public void Deserialize(BinaryDeserializer deserializer)
 {
     this.AdditionalComponentTypes =
         deserializer.Deserialize <string[]>().Select <string, Type>(ReflectionUtils.FindType).ToList();
     this.BlueprintId   = deserializer.Deserialize <string>();
     this.Configuration = deserializer.Deserialize <AttributeTable>();
 }
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;

            /*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 #5
0
        public static H3D Open(Stream Input)
        {
            BinaryDeserializer Deserializer = new BinaryDeserializer(Input, GetSerializationOptions());

            GfxHeader Header = Deserializer.Deserialize <GfxHeader>();
            Gfx       Scene  = Deserializer.Deserialize <Gfx>();

            return(Scene.ToH3D());
        }
Exemple #6
0
        public static Gfx Open(string FileName)
        {
            using (FileStream Input = new FileStream(FileName, FileMode.Open))
            {
                BinaryDeserializer Deserializer = new BinaryDeserializer(Input, GetSerializationOptions());

                GfxHeader Header = Deserializer.Deserialize <GfxHeader>();
                Gfx       Scene  = Deserializer.Deserialize <Gfx>();

                return(Scene);
            }
        }
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>();

            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);
        }
        /// <summary>
        ///   Reads this object from its binary representation.
        /// </summary>
        /// <param name="deserializer">Deserializer to read the object with.</param>
        public void Deserialize(BinaryDeserializer deserializer)
        {
            Dictionary <object, object> attributeTable = deserializer.Deserialize <Dictionary <object, object> >();

            foreach (KeyValuePair <object, object> keyValuePair in attributeTable)
            {
                this.attributes[keyValuePair.Key] = keyValuePair.Value;
            }
        }
        private void AssertSerializable <T>(T o)
        {
            BinarySerializer binarySerializer = new BinarySerializer(this.memoryStream);

            binarySerializer.Serialize(o);

            this.memoryStream.Seek(0, SeekOrigin.Begin);

            BinaryDeserializer binaryDeserializer = new BinaryDeserializer(this.memoryStream);

            Assert.AreEqual(o, binaryDeserializer.Deserialize <T>());
        }
Exemple #10
0
        public T Obj_DeserializeData <T> (string _serializationDataBase64, string _serializationID = null, T _targetObject = default(T))
        {
            if (string.IsNullOrEmpty(_serializationDataBase64))
            {
                Debug.LogError("[RS] Deserialization failed. Serialization data cant null/empty.");
                return(default(T));
            }

            // Deserialise serialization data
            byte[] _serializationData  = Convert.FromBase64String(_serializationDataBase64);
            T      _deserializedObject = m_binaryDeserializer.Deserialize <T>(_serializationData, _targetObject);

            // Invoke event
            if (!string.IsNullOrEmpty(_serializationID))
            {
                OnDeserializationFinished(_serializationID, _deserializedObject);
            }

            // Return object
            return(_deserializedObject);
        }
Exemple #11
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);
        }
        public void should_handle_numerics_data_as_binary_with_primitive_handler()
        {
            var expected     = SerializationTestHelper.GenerateNumericsModel();
            var serializer   = new BinarySerializer(_mappingRegistry, new [] { new NumericsBinaryPrimitiveHandler() });
            var deserializer = new BinaryDeserializer(_mappingRegistry, _typeCreator, new [] { new NumericsBinaryPrimitiveHandler() });

            var output = serializer.Serialize(expected);

            _outputHelper.WriteLine(output.AsString);

            var actual = deserializer.Deserialize <NumericsTypesModel>(output);

            Assert.AreEqual(expected, actual);
        }
        public void should_correctly_serialize_nulled_data_with_binary()
        {
            var model = SerializationTestHelper.GenerateNulledModel();

            var serializer = new BinarySerializer(_mappingRegistry);
            var output     = serializer.Serialize(model);

            _outputHelper.WriteLine("FileSize: " + output.AsBytes.Length + " bytes");
            _outputHelper.WriteLine(BitConverter.ToString(output.AsBytes));

            var deserializer = new BinaryDeserializer(_mappingRegistry, _typeCreator);
            var result       = deserializer.Deserialize <ComplexModel>(output);

            SerializationTestHelper.AssertNulledData(model, result);
        }
Exemple #14
0
        public void should_correctly_serialize_dynamic_data_with_binary()
        {
            var model      = SerializationTestHelper.GeneratePopulatedDynamicTypesModel();
            var serializer = new BinarySerializer(_mappingRegistry);

            var output = serializer.Serialize(model);

            testOutputHelper.WriteLine("FileSize: " + output.AsString.Length + " bytes");
            testOutputHelper.WriteLine(BitConverter.ToString(output.AsBytes));

            var deserializer = new BinaryDeserializer(_mappingRegistry, _typeCreator);
            var result       = deserializer.Deserialize <DynamicTypesModel>(output);

            SerializationTestHelper.AssertPopulatedDynamicTypesData(model, result);
        }
Exemple #15
0
        public void Serialize_Deserialize()
        {
            // Arrange
            BinarySerializer.RegisterTypes(typeof(Fixed8));
            var _serializer   = new BinarySerializer();
            var _deserializer = new BinaryDeserializer();
            var result        = new byte[] { 0, 66, 151, 137, 190, 22, 15, 9 };

            // Act
            var ret   = _serializer.Serialize(_value);
            var clone = _deserializer.Deserialize <Fixed8>(ret);

            // Assert
            CollectionAssert.AreEqual(result, ret);
            Assert.AreEqual(_value, clone);
        }
        public void Serialize_Deserialize()
        {
            // Arrange
            BinarySerializer.RegisterTypes(typeof(UInt256));
            var _serializer   = new BinarySerializer();
            var _deserializer = new BinaryDeserializer();
            var result        = new byte[] {
                157, 179, 60, 8, 66, 122, 255, 105, 126, 49, 180, 74, 212, 41, 126, 177,
                14, 255, 59, 82, 218, 113, 248, 145, 98, 5, 128, 140, 42, 70, 32, 69
            };

            // Act
            var ret   = _serializer.Serialize(_value);
            var clone = _deserializer.Deserialize <UInt256>(ret);

            // Assert
            CollectionAssert.AreEqual(result, ret);
            Assert.AreEqual(_value, clone);
        }
Exemple #17
0
        internal static H3DFloatKeyFrameGroup ReadGroup(BinaryDeserializer Deserializer, bool Constant)
        {
            H3DFloatKeyFrameGroup FrameGrp = new H3DFloatKeyFrameGroup();

            if (Constant)
            {
                FrameGrp.KeyFrames.Add(new KeyFrame(0, Deserializer.Reader.ReadSingle()));
            }
            else
            {
                uint Address = Deserializer.Reader.ReadUInt32();

                Deserializer.BaseStream.Seek(Address, SeekOrigin.Begin);

                FrameGrp = Deserializer.Deserialize <H3DFloatKeyFrameGroup>();
            }

            return(FrameGrp);
        }
        public void Serialize_Deserialize()
        {
            // Arrange
            BinarySerializer.RegisterTypes(typeof(EndPoint));
            var _serializer   = new BinarySerializer();
            var _deserializer = new BinaryDeserializer();
            var result        = new byte[] {
                23, 116, 99, 112, 58, 47, 47, 49, 49, 46, 50, 50,
                46, 51, 51, 46, 52, 52, 58, 49, 48, 51, 51, 50
            };

            // Act
            var ret   = _serializer.Serialize(_value);
            var clone = _deserializer.Deserialize <EndPoint>(ret);

            // Assert
            CollectionAssert.AreEqual(result, ret);
            Assert.AreEqual(_value, clone);
        }
Exemple #19
0
        void ICustomSerialization.Deserialize(BinaryDeserializer Deserializer)
        {
            int MaxIndex = 0;
            int Index    = 0;

            Nodes.Clear();

            while (Index++ <= MaxIndex)
            {
                H3DPatriciaTreeNode Node = Deserializer.Deserialize <H3DPatriciaTreeNode>();

                MaxIndex = Math.Max(MaxIndex, Node.LeftNodeIndex);
                MaxIndex = Math.Max(MaxIndex, Node.RightNodeIndex);

                if (Nodes.Count > 0)
                {
                    Names.Add(Node.Name);
                }

                Nodes.Add(Node);
            }
        }
Exemple #20
0
 /// <summary>
 ///   Reads this object from its binary representation.
 /// </summary>
 /// <param name="deserializer">Deserializer to read the object with.</param>
 public void Deserialize(BinaryDeserializer deserializer)
 {
     this.AttributeTableSerialized = deserializer.Deserialize <AttributeTable>();
     this.ComponentTypesSerialized = deserializer.Deserialize <string[]>();
     this.ParentId = deserializer.Deserialize <string>();
 }
        private BlueprintManager LoadBlueprints()
        {
            var blueprintManager = new BlueprintManager();
            XmlSerializer blueprintManagerSerializer = null;

            Object[] blueprintAssets = Resources.LoadAll(this.BlueprintAssetsFolder);

            foreach (var blueprintObjectAsset in blueprintAssets)
            {
                var blueprintAsset = blueprintObjectAsset as TextAsset;

                if (blueprintAsset != null)
                {
                    var blueprintStream = new MemoryStream(blueprintAsset.bytes);

                    // Load blueprints.
                    BlueprintManager subBlueprintManager = null;

                    if (Application.isEditor || this.UseXmlInBuild)
                    {
                        if (blueprintManagerSerializer == null)
                        {
                            blueprintManagerSerializer = new XmlSerializer(typeof(BlueprintManager));
                        }
                        try
                        {
                            subBlueprintManager =
                                (BlueprintManager)blueprintManagerSerializer.Deserialize(blueprintStream);
                        }
                        catch (XmlException e)
                        {
                            Debug.LogError(
                                string.Format(
                                    "Exception deserializing blueprint xml '{0}': {1}", blueprintAsset.name, e.Message));
                        }
                    }
                    else
                    {
                        BinaryDeserializer binaryDeserializer = new BinaryDeserializer(blueprintStream);
                        subBlueprintManager = binaryDeserializer.Deserialize<BlueprintManager>();
                    }

                    if (subBlueprintManager != null)
                    {
                        blueprintManager.AddBlueprints(subBlueprintManager);
                    }
                }
                else
                {
                    Debug.LogError(string.Format("Blueprint asset is no text asset: {0}", blueprintObjectAsset.name));
                }
            }

            // Resolve parents.
            BlueprintUtils.ResolveParents(blueprintManager, blueprintManager);

            return blueprintManager;
        }
        public void Load(string path)
        {
            FileInfo file = new FileInfo(path);

            if (!file.Exists)
            {
                this.editorSettings.RecentProjects.Remove(path);
                this.SaveEditorSettings();

                throw new FileNotFoundException(string.Format("Project file not found: {0}", path), path);
            }

            // Load project.
            FileStream fileStream = new FileStream(path, FileMode.Open);
            ProjectSettings newProjectSettings = (ProjectSettings)this.projectSettingsSerializer.Deserialize(fileStream);
            if (newProjectSettings == null)
            {
                throw new SerializationException(
                    string.Format("Couldn't deserialize project settings from '{0}'.", path));
            }

            fileStream.Close();

            // Convert file paths.
            newProjectSettings.ProjectAssemblies =
                newProjectSettings.ProjectAssembliesSerialized.Select(
                    assemblyPath =>
                    ReflectionUtils.FindAssembly(string.Format("{0}\\{1}", Path.GetDirectoryName(path), assemblyPath)))
                                  .ToList();

            newProjectSettings.LanguageFiles =
                newProjectSettings.LanguageFilesSerialized.Select(
                    languageFilePath =>
                    new LanguageFile
                        {
                            Path =
                                new FileInfo(string.Format("{0}\\{1}", Path.GetDirectoryName(path), languageFilePath))
                        .FullName
                        }).ToList();

            for (int i = 0; i < newProjectSettings.LanguageFiles.Count; i++)
            {
                newProjectSettings.LanguageFiles[i].LanguageTag = newProjectSettings.LanguageNamesSerialized[i];
            }

            // Load blueprint files.
            foreach (var blueprintFile in newProjectSettings.BlueprintFiles)
            {
                var blueprintFileName = this.ReadBlueprintsAsBinary
                                            ? Path.ChangeExtension(blueprintFile.Path, "bytes")
                                            : blueprintFile.Path;

                var absoluteBlueprintFilePath = string.Format(
                    "{0}\\{1}", Path.GetDirectoryName(path), blueprintFileName);

                var fileInfo = new FileInfo(absoluteBlueprintFilePath);

                if (!fileInfo.Exists)
                {
                    throw new FileNotFoundException(string.Format("Blueprint file not found: {0}.", blueprintFileName));
                }

                using (var blueprintFileStream = fileInfo.OpenRead())
                {
                    try
                    {
                        BlueprintManager newBlueprintManager;

                        if (this.ReadBlueprintsAsBinary)
                        {
                            var binaryDeserializer = new BinaryDeserializer(blueprintFileStream);
                            newBlueprintManager = binaryDeserializer.Deserialize<BlueprintManager>();
                        }
                        else
                        {
                            newBlueprintManager =
                                (BlueprintManager)this.blueprintManagerSerializer.Deserialize(blueprintFileStream);
                        }

                        if (newBlueprintManager == null)
                        {
                            throw new SerializationException(
                                string.Format("Couldn't deserialize blueprint manager from '{0}'.", path));
                        }

                        blueprintFile.BlueprintManager = newBlueprintManager;
                    }
                    catch (Exception e)
                    {
                        throw new SerializationException(
                            string.Format(
                                "Couldn't deserialize blueprint manager from '{0}': {1}.",
                                path,
                                e.GetBaseException().Message),
                            e);
                    }
                }
            }

            // Set new project.
            this.SetProject(newProjectSettings, path);

            // Save to recent projects.
            this.editorSettings.AddRecentProject(path);
            this.SaveEditorSettings();
        }
 /// <summary>
 ///   Reads this object from its binary representation.
 /// </summary>
 /// <param name="deserializer">Deserializer to read the object with.</param>
 public void Deserialize(BinaryDeserializer deserializer)
 {
     this.AdditionalComponentTypes =
         deserializer.Deserialize<string[]>().Select<string, Type>(ReflectionUtils.FindType).ToList();
     this.BlueprintId = deserializer.Deserialize<string>();
     this.Configuration = deserializer.Deserialize<AttributeTable>();
 }
Exemple #24
0
        //[Benchmark]
        public void RunSimple_Binary_Deserialize_BinaryGo()
        {
            BinaryDeserializer deserializer = new BinaryDeserializer();

            deserializer.Deserialize <SimpleUserInfo>(BinaryGoBinaryBytes);
        }
Exemple #25
0
        void ICustomSerialization.Deserialize(BinaryDeserializer Deserializer)
        {
            Attributes = new H3DVertexDataAttribute[(byte)Deserializer.Reader.ReadUInt16()];
            Indices    = new H3DVertexDataIndices[Deserializer.Reader.ReadUInt16()];

            uint AttributesAddress = Deserializer.Reader.ReadUInt32();
            uint IndicesAddress    = Deserializer.Reader.ReadUInt32();

            Deserializer.BaseStream.Seek(AttributesAddress, SeekOrigin.Begin);

            int BaseAddress = int.MaxValue;

            for (int Index = 0; Index < Attributes.Length; Index++)
            {
                Attributes[Index] = Deserializer.Deserialize <H3DVertexDataAttribute>();

                if (!Attributes[Index].IsFixed &&
                    Attributes[Index].Offset < BaseAddress)
                {
                    BaseAddress = Attributes[Index].Offset;
                }
            }

            VertexStride = 0;

            for (int Index = 0; Index < Attributes.Length; Index++)
            {
                if (!Attributes[Index].IsFixed)
                {
                    Attributes[Index].Offset -= BaseAddress;

                    int Size = Attributes[Index].Elements;

                    switch (Attributes[Index].Format)
                    {
                    case PICAAttributeFormat.Short: Size <<= 1; break;

                    case PICAAttributeFormat.Float: Size <<= 2; break;
                    }

                    VertexStride += Size;
                }
            }

            Deserializer.BaseStream.Seek(IndicesAddress, SeekOrigin.Begin);

            for (int Index = 0; Index < Indices.Length; Index++)
            {
                Indices[Index] = Deserializer.Deserialize <H3DVertexDataIndices>();
            }

            int BufferCount = 0;

            //The PICA doesn't need the total number of Attributes on the Buffer, so it is not present on the Commands
            //So we need to get the Max Index used on the Index Buffer to figure out the total number of Attributes
            foreach (H3DVertexDataIndices SM in Indices)
            {
                if (BufferCount < SM.MaxIndex)
                {
                    BufferCount = SM.MaxIndex;
                }
            }

            BufferCount++;

            Deserializer.BaseStream.Seek(BaseAddress, SeekOrigin.Begin);

            RawBuffer = Deserializer.Reader.ReadBytes(BufferCount * VertexStride);
        }
Exemple #26
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);
        }
 /// <summary>
 ///   Reads this object from its binary representation.
 /// </summary>
 /// <param name="deserializer">Deserializer to read the object with.</param>
 public void Deserialize(BinaryDeserializer deserializer)
 {
     this.AttributeTableSerialized = deserializer.Deserialize<AttributeTable>();
     this.ComponentTypesSerialized = deserializer.Deserialize<string[]>();
     this.ParentId = deserializer.Deserialize<string>();
 }
Exemple #28
0
        public void Load(string path)
        {
            FileInfo file = new FileInfo(path);

            if (!file.Exists)
            {
                this.editorSettings.RecentProjects.Remove(path);
                this.SaveEditorSettings();

                throw new FileNotFoundException(string.Format("Project file not found: {0}", path), path);
            }

            // Load project.
            FileStream      fileStream         = new FileStream(path, FileMode.Open);
            ProjectSettings newProjectSettings = (ProjectSettings)this.projectSettingsSerializer.Deserialize(fileStream);

            if (newProjectSettings == null)
            {
                throw new SerializationException(
                          string.Format("Couldn't deserialize project settings from '{0}'.", path));
            }

            fileStream.Close();

            // Convert file paths.
            newProjectSettings.ProjectAssemblies =
                newProjectSettings.ProjectAssembliesSerialized.Select(
                    assemblyPath =>
                    ReflectionUtils.FindAssembly(string.Format("{0}\\{1}", Path.GetDirectoryName(path), assemblyPath)))
                .ToList();

            newProjectSettings.LanguageFiles =
                newProjectSettings.LanguageFilesSerialized.Select(
                    languageFilePath =>
                    new LanguageFile
            {
                Path =
                    new FileInfo(string.Format("{0}\\{1}", Path.GetDirectoryName(path), languageFilePath))
                    .FullName
            }).ToList();

            for (int i = 0; i < newProjectSettings.LanguageFiles.Count; i++)
            {
                newProjectSettings.LanguageFiles[i].LanguageTag = newProjectSettings.LanguageNamesSerialized[i];
            }

            // Load blueprint files.
            foreach (var blueprintFile in newProjectSettings.BlueprintFiles)
            {
                var blueprintFileName = this.ReadBlueprintsAsBinary
                                            ? Path.ChangeExtension(blueprintFile.Path, "bytes")
                                            : blueprintFile.Path;

                var absoluteBlueprintFilePath = string.Format(
                    "{0}\\{1}", Path.GetDirectoryName(path), blueprintFileName);

                var fileInfo = new FileInfo(absoluteBlueprintFilePath);

                if (!fileInfo.Exists)
                {
                    throw new FileNotFoundException(string.Format("Blueprint file not found: {0}.", blueprintFileName));
                }

                using (var blueprintFileStream = fileInfo.OpenRead())
                {
                    try
                    {
                        BlueprintManager newBlueprintManager;

                        if (this.ReadBlueprintsAsBinary)
                        {
                            var binaryDeserializer = new BinaryDeserializer(blueprintFileStream);
                            newBlueprintManager = binaryDeserializer.Deserialize <BlueprintManager>();
                        }
                        else
                        {
                            newBlueprintManager =
                                (BlueprintManager)this.blueprintManagerSerializer.Deserialize(blueprintFileStream);
                        }

                        if (newBlueprintManager == null)
                        {
                            throw new SerializationException(
                                      string.Format("Couldn't deserialize blueprint manager from '{0}'.", path));
                        }

                        blueprintFile.BlueprintManager = newBlueprintManager;
                    }
                    catch (Exception e)
                    {
                        throw new SerializationException(
                                  string.Format(
                                      "Couldn't deserialize blueprint manager from '{0}': {1}.",
                                      path,
                                      e.GetBaseException().Message),
                                  e);
                    }
                }
            }

            // Set new project.
            this.SetProject(newProjectSettings, path);

            // Save to recent projects.
            this.editorSettings.AddRecentProject(path);
            this.SaveEditorSettings();
        }