예제 #1
0
        public void BlendShapeTest()
        {
            var settings = Google.Protobuf.JsonFormatter.Settings.Default.WithPreserveProtoFieldNames(true);
            var q        = "\"";

            {
                var data = new VrmProtobuf.BlendShapeGroup();
                data.IgnoreBlink = true;

                var json = new Google.Protobuf.JsonFormatter(settings).Format(data);
                Assert.AreEqual($"{{ {q}ignoreBlink{q}: true }}", json);
            }

            {
                var blendShape = new VrmLib.BlendShape(VrmLib.BlendShapePreset.Blink, "blink", true)
                {
                    IgnoreBlink  = true,
                    IgnoreLookAt = true,
                    IgnoreMouth  = true,
                };

                // export
                var gltf = Vrm10.BlendShapeAdapter.ToGltf(blendShape, new List <VrmLib.Node>(), new List <VrmLib.Material>());
                Assert.AreEqual(true, gltf.IgnoreBlink);
                Assert.AreEqual(true, gltf.IgnoreLookAt);
                Assert.AreEqual(true, gltf.IgnoreMouth);

                // import
                var imported = Vrm10.BlendShapeAdapter.FromGltf(gltf, new List <VrmLib.Node>(), new List <VrmLib.Material>());
                Assert.AreEqual(true, imported.IgnoreBlink);
                Assert.AreEqual(true, imported.IgnoreLookAt);
                Assert.AreEqual(true, imported.IgnoreMouth);
            }
        }
예제 #2
0
        public byte[] ToBytes()
        {
            Gltf.Buffers[0].ByteLength = Storage.Buffers[0].Bytes.Count;

            var settings = Google.Protobuf.JsonFormatter.Settings.Default.WithPreserveProtoFieldNames(true);
            var json     = new Google.Protobuf.JsonFormatter(settings).Format(Gltf);
            var glb      = new Glb(new GlbChunk(json), new GlbChunk(Storage.Buffers[0].Bytes));

            return(glb.ToBytes());
        }
예제 #3
0
        public void UnityMaterialTest(string materialName, Type vrmLibMaterialType, bool sameShader = true)
        {
            // cerate copy avoid modify asset
            var src = new Material(Resources.Load <Material>(materialName));

            // => vrmlib
            var converter      = new UniVRM10.RuntimeVrmConverter();
            var vrmLibMaterial = converter.Export10(src, (a, b, c, d) => null);

            Assert.AreEqual(vrmLibMaterialType, vrmLibMaterial.GetType());

            // => protobuf
            var textures = new List <VrmLib.Texture>();

            var(protobufMaterial, hasKhrUnlit) = ToProtobufMaterial(vrmLibMaterial, textures);
            Assert.AreEqual(hasKhrUnlit, protobufMaterial.Extensions?.KHRMaterialsUnlit != null);

            // => json
            var settings     = Google.Protobuf.JsonFormatter.Settings.Default.WithPreserveProtoFieldNames(true);
            var jsonMaterial = new Google.Protobuf.JsonFormatter(settings).Format(protobufMaterial);

            // <= json
            var parserSettings = Google.Protobuf.JsonParser.Settings.Default;
            var deserialized   = new Google.Protobuf.JsonParser(parserSettings).Parse <VrmProtobuf.Material>(jsonMaterial);

            // <= protobuf
            var loaded  = deserialized.FromGltf(textures);
            var context = ModelDiffContext.Create();

            ModelDiffExtensions.MaterialEquals(context, vrmLibMaterial, loaded);
            var diff = context.List
                       .Where(x => !s_ignoreKeys.Contains(x.Context))
                       .ToArray();

            if (diff.Length > 0)
            {
                Debug.LogWarning(string.Join("\n", diff.Select(x => $"{x.Context}: {x.Message}")));
            }
            Assert.AreEqual(0, diff.Length);

            // <= vrmlib
            var map = new Dictionary <VrmLib.Texture, Texture2D>();
            var dst = UniVRM10.RuntimeUnityMaterialBuilder.CreateMaterialAsset(loaded, hasVertexColor: false, map);

            dst.name = src.name;

            if (sameShader)
            {
                CompareUnityMaterial(src, dst);
            }
        }
예제 #4
0
        public void MaterialTest()
        {
            var settings = Google.Protobuf.JsonFormatter.Settings.Default.WithPreserveProtoFieldNames(true);
            var q        = "\"";

            {
                var data = new VrmProtobuf.Material
                {
                    Name = "Some",
                };

                var json = new Google.Protobuf.JsonFormatter(settings).Format(data);
                Assert.AreEqual($"{{ {q}name{q}: {q}Some{q} }}", json);
            }

            {
                var data = new VrmProtobuf.glTF();
                data.Textures.Add(new VrmProtobuf.Texture
                {
                });
                var json = new Google.Protobuf.JsonFormatter(settings).Format(data);
                // Assert.Equal($"{{ {q}name{q}: {q}Some{q} }}", json);
            }

            {
                var data = new VrmProtobuf.Material
                {
                    Name = "Alicia_body",
                    PbrMetallicRoughness = new VrmProtobuf.MaterialPbrMetallicRoughness
                    {
                        // BaseColorFactor = new[] { 1, 1, 1, 1 },
                        // BaseColorTexture= { },
                        MetallicFactor  = 0,
                        RoughnessFactor = 0.9f
                    },
                    AlphaMode   = "OPAQUE",
                    AlphaCutoff = 0.5f,
                    Extensions  = new VrmProtobuf.Material.Types.Extensions
                    {
                        KHRMaterialsUnlit = { }
                    }
                };

                var json = new Google.Protobuf.JsonFormatter(settings).Format(data);
                // Assert.Equal($"{{ {q}name{q}: {q}Some{q} }}", json);
            }
        }
예제 #5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            /// input / output parameters
            List <Mesh>    meshes   = new List <Mesh>();
            List <GH_Guid> GH_guids = new List <GH_Guid>();
            List <Guid>    guids    = new List <Guid>();
            string         filepath = "";
            string         output   = "";

            ///import data
            if (!DA.GetDataList("Meshes", meshes))
            {
                return;
            }
            if (!DA.GetData("File path", ref filepath))
            {
                return;
            }
            if (!DA.GetDataList("Guid", GH_guids))
            {
                return;
            }

            /// 0. create proto file
            /// 1.write header
            /// 2. retrieve meshes
            /// 3.

            ///define local parameters


            ///0.
            Element           element            = new Element();
            ElementCollection element_collection = new ElementCollection();

            ///1.
            string[] header =
            {
                "@prefix cc: < http://creativecommons.org/ns#> .",
                "@prefix bot: < https://w3id.org/bot#> .",
                "@prefix dbo: < http://dbpedia.org/ontology/> .",
                "@prefix dce: < http://purl.org/dc/elements/1.1/> .",
                "@prefix dc: < http://purl.org/dc/terms/> .",
                "@prefix owl: < http://www.w3.org/2002/07/owl#> .",
                "@prefix rdf: < http://www.w3.org/1999/02/22-rdf-syntax-ns#> .",
                "@prefix xml: < http://www.w3.org/XML/1998/namespace> .",
                "@prefix xsd: < http://www.w3.org/2001/XMLSchema#> .",
                "@prefix rdfs: < http://www.w3.org/2000/01/rdf-schema#> .",
                "@prefix vann: < http://purl.org/vocab/vann/> .",
                "@prefix pto:  < http://www.productontology.org/id/>.",
                "@prefix Gendarmenmarkt: < http://example.org/Gendarmenmarkt#> .",
                "@prefix foaf : < http://xmlns.com/foaf/0.1/>.",
                "@prefix fog: < https://w3id.org/fog#> .",
                "@prefix inst: < https://example.org/data#> .",
                "@prefix geometry: < http://rdf.bg/geometry.ttl#> .",
                "@prefix omg: < https://w3id.org/omg#> .",
                "@prefix v4d: < https://www.v4d.org/namespace> .",

                "<http://example.org/Gendarmenmarkt> rdf:type owl:Ontology ;",
                "  owl: imports < https://w3id.org/bot> ;",
                " dc: creator < http://www.terkaj.com#V4D> ;",
                "cc: license < http://creativecommons.org/licenses/by/3.0/> ."
            };
            foreach (GH_Guid guid in GH_guids)
            {
                var a = new Guid(guid.ToString());
                guids.Add(a);
            }


            /// retrieve meshes
            List <RhinoObject> Rhino_meshes = new List <RhinoObject>();

            foreach (Guid Guid in guids)
            {
                Rhino_meshes.Add(Rhino.RhinoDoc.ActiveDoc.Objects.FindId(Guid));
            }

            var rhino_ID = new List <string>();

            element_collection.Elements.AddRange(meshes.DuoSelect(Rhino_meshes, (mesh, rhino_mesh) =>
            {
                return(new Element()
                {
                    VertexCount = mesh.Vertices.Count,
                    FaceCount = mesh.Faces.Count,
                    Centroid = mesh.GetBoundingBox(false).Center.ToString(),  /// retrieve centre
                    Min = mesh.GetBoundingBox(false).Min.ToString(),
                    Max = mesh.GetBoundingBox(false).Max.ToString(),

                    ID = rhino_mesh.Attributes.Name,
                    Rdfsquickfixlabel = rhino_mesh.Document.Layers[rhino_mesh.Attributes.LayerIndex].Name,
                    GUID = rhino_mesh.Id.ToString(),
                    BotquickfixElement = rhino_mesh.Attributes.Name,
                    Rdfquickfixtype = "http://www.productontology.org/id/Wall",
                });
            }));

            //foreach (RhinoObject mesh in Rhino_meshes)
            //{
            //    rhino_ID.Add( mesh.Attributes.Name);
            //    var Rdfs333Label = mesh.Document.Layers[mesh.Attributes.LayerIndex].Name;
            //    var GUID = mesh.Id.ToString();
            //    var Bot333Element = mesh.Attributes.Name;
            //    var Rdf333Type = "http://www.productontology.org/id/Wall";
            //}

            //element_collection.Elements.AddRange(meshes.Select(mesh => new Element()
            //{

            //    VertexCount = mesh.Vertices.Count,
            //    FaceCount = mesh.Faces.Count,
            //    Centroid = mesh.GetBoundingBox(false).Center.ToString(), /// retrieve centre
            //    Min = mesh.GetBoundingBox(false).Min.ToString(),
            //    Max = mesh.GetBoundingBox(false).Max.ToString()
            //}));
            //element_collection.Elements.AddRange(Rhino_meshes.Select(mesh => new Element()
            //{
            //    ID = mesh.Attributes.Name,
            //    Rdfs333Label = mesh.Document.Layers[mesh.Attributes.LayerIndex].Name,
            //    GUID = mesh.Id.ToString(),
            //    Bot333Element = mesh.Attributes.Name,
            //    Rdf333Type = "http://www.productontology.org/id/Wall",
            //}));



            var    writer = new Google.Protobuf.JsonFormatter(new Google.Protobuf.JsonFormatter.Settings(true));
            String json   = "";

            using (var file = new StreamWriter(filepath))
                using (StringWriter sw = new StringWriter())
                {
                    foreach (var l in header)
                    {
                        sw.WriteLine(l);
                    }

                    writer.WriteValue(sw, element_collection);
                    json = sw.ToString();
                    json.Replace("333", ":")
                    file.Write(json);
                }

            output = "test";

            ///output = file.ToString();

            DA.SetDataList(0, output);
        }