예제 #1
0
        public void CatalogSerialization()
        {
            ContentElement boxType = new ContentElement("../../../models/MergeGlTF/Workstation_Pod_SemiPrivate_Harbour - Semi 1600w x 1300d 3.glb",
                                                        new BBox3(new Vector3(-0.5, -0.5, 0), new Vector3(0.5, 0.5, 3)),
                                                        1,
                                                        new Vector3(),
                                                        new Transform(new Vector3(), Vector3.ZAxis),
                                                        BuiltInMaterials.Default,
                                                        null,
                                                        true,
                                                        Guid.NewGuid(),
                                                        "BoxyType");
            ContentElement boxType2 = new ContentElement("../../../models/MergeGlTF/Box.glb",
                                                         new BBox3(new Vector3(-1, -1, 0), new Vector3(1, 1, 2)),
                                                         1,
                                                         new Vector3(),
                                                         new Transform(new Vector3(), Vector3.YAxis),
                                                         BuiltInMaterials.Default,
                                                         null,
                                                         true,
                                                         Guid.NewGuid(),
                                                         "BoxyType");
            var str = boxType2.ToString();

            boxType.AdditionalProperties["ImportantParameter"] = "The Value";


            var testCatalog = new ContentCatalog(new List <ContentElement> {
                boxType, boxType2
            }, Guid.NewGuid(), "test");

            var savePath = "../../../models/ContentCatalog.json";
            var json     = testCatalog.ToJson();

            File.WriteAllText(savePath, json);

            var loadedCatalog = ContentCatalog.FromJson(File.ReadAllText(savePath));

            File.Delete(savePath);
            Assert.Equal(testCatalog.Id, loadedCatalog.Id);
            Assert.Equal(testCatalog.Content.Count, loadedCatalog.Content.Count);
            Assert.Equal("The Value", loadedCatalog.Content[0].AdditionalProperties["ImportantParameter"]);
        }
예제 #2
0
 /// <summary>
 /// Get the ContentCatalog stored in `catalog.json`.
 /// </summary>
 /// <returns></returns>
 public static ContentCatalog GetCatalog()
 {
     if (catalog == null)
     {
         var catalogPath = catalogFilePath ?? Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "catalog.json");
         if (!File.Exists(catalogPath))
         {
             throw new Exception("Catalog not found. To use this class, make sure you have a content catalog stored at catalog.json in the build directory.");
         }
         var json = File.ReadAllText(catalogPath);
         catalog = ContentCatalog.FromJson(json);
         // Mutate IDs, otherwise we run into a bug with the export server, collisions with shared catalogs, big messy mess.
         foreach (var element in catalog.Content)
         {
             element.Id = Guid.NewGuid();
         }
     }
     return(catalog);
 }