Exemple #1
0
        /// <summary>
        /// GLBバイト列
        /// </summary>
        /// <returns></returns>
        public byte[] ToGlbBytes()
        {
            var f = new JsonFormatter();

            GltfSerializer.Serialize(f, Gltf);

            var json = f.ToString().ParseAsJson().ToString("  ");

            json = GltfJsonUtil.FindUsedExtensionsAndUpdateJson(json);

            return(Glb.Create(json, BinBytes).ToBytes());
        }
Exemple #2
0
        public void Replace_extensionUsed()
        {
            var dst = GltfJsonUtil.FindUsedExtensionsAndUpdateJson(@"{
    ""asset"": {
        ""generator"": ""COLLADA2GLTF"",
        ""version"": ""2.0""
    },
    ""scene"": 0,
    ""scenes"": [
        {
            ""nodes"": [
                0
            ]
    }
    ],
    ""extensionUsed"": [""dummy""],
    ""materials"": [
        {
            ""pbrMetallicRoughness"": {
                ""baseColorFactor"": [
                    0.800000011920929,
                    0.0,
                    0.0,
                    1.0
                ],
                ""metallicFactor"": 0.0
            },
            ""name"": ""Red"",
            ""extensions"": {
                ""KHR_materials_unlit"": {}
            }
        }
    ]
}");

            var parsed = dst.ParseAsJson();

            Assert.AreEqual(new string[] { "KHR_materials_unlit" },
                            parsed["extensionUsed"].ArrayItems().Select(x => x.GetString()).ToArray());
        }
Exemple #3
0
        /// <summary>
        /// glTF 形式で出力する?
        /// </summary>
        /// <param name="gltfPath"></param>
        /// <returns></returns>
        public (string, glTFBuffer) ToGltf(string gltfPath)
        {
            // fix buffer path
            if (Gltf.buffers.Count == 1)
            {
                var withoutExt = Path.GetFileNameWithoutExtension(gltfPath);
                Gltf.buffers[0].uri = $"{withoutExt}.bin";
            }
            else
            {
                throw new NotImplementedException();
            }

            var f = new JsonFormatter();

            GltfSerializer.Serialize(f, Gltf);
            var json = f.ToString().ParseAsJson().ToString("  ");

            json = GltfJsonUtil.FindUsedExtensionsAndUpdateJson(json);

            return(json, Gltf.buffers[0]);
        }
Exemple #4
0
        public void Empty_extensionUsed()
        {
            var dst = GltfJsonUtil.FindUsedExtensionsAndUpdateJson(@"{
    ""asset"": {
        ""generator"": ""COLLADA2GLTF"",
        ""version"": ""2.0""
    },
    ""scene"": 0,
    ""scenes"": [
        {
            ""nodes"": [
                0
            ]
    }
    ],
    ""extensionUsed"": [""dummy""]  ,  
    ""materials"": [
        {
            ""pbrMetallicRoughness"": {
                ""baseColorFactor"": [
                    0.800000011920929,
                    0.0,
                    0.0,
                    1.0
                ],
                ""metallicFactor"": 0.0
            },
            ""name"": ""Red""
        }
    ]
}");

            var parsed = dst.ParseAsJson();

            Assert.False(parsed.ContainsKey("extensionUsed"));
        }