Example #1
0
        public static void ToFile(AFrameMaterial mtl, string name, string filename)
        {
            var exporter = new MtlExporter();

            using (StreamWriter sw = new StreamWriter(filename)) {
                var txt = exporter.MaterialToString(mtl, name);
                sw.Write(txt);
            }
        }
        public AFrameNode Create(MeshElem el)
        {
            var node = new AFrameNode("a-entity");

            WriteCommonAFrameNode(el, node);

            AFrameNode geometryNode = null;
            var        mtl          = MaterialFacade.Instance.CreateMaterial(el.Material);

            // TODO 타입 하드코딩해서 분기하는거 제거하기
            if (el.Geometry.Type != "BufferGeometry")
            {
                var v = new AFrameExportVisitor(sharedNodeTable);
                el.Geometry.Accept(v);
                geometryNode = v.Node;

                // v0.3.2
                var standard = mtl.Shader as StandardAFrameShader;
                var flat     = mtl.Shader as FlatAFrameShader;

                var props = new Dictionary <string, IProperty>();
                if (standard != null)
                {
                    var shader = standard;
                    props["shader"]    = new SimpleProperty <string>(shader.ShaderName);
                    props["color"]     = new ColorProperty(shader.Color, StandardAFrameShader.DefaultColor);
                    props["roughness"] = new SimpleProperty <float>(shader.Roughness, StandardAFrameShader.DefaultRoughness);
                    props["metalness"] = new SimpleProperty <float>(shader.Metalness, StandardAFrameShader.DefaultMetalness);
                    props["repeat"]    = new Vector2Property(shader.Repeat, StandardAFrameShader.DefaultRepeat);
                    props["src"]       = new SimpleProperty <string>(shader.Src, "");
                }

                if (flat != null)
                {
                    var shader = flat;
                    props["shader"] = new SimpleProperty <string>(shader.ShaderName);
                    props["color"]  = new ColorProperty(shader.Color, StandardAFrameShader.DefaultColor);
                    props["repeat"] = new Vector2Property(shader.Repeat, StandardAFrameShader.DefaultRepeat);
                    props["src"]    = new SimpleProperty <string>(shader.Src, "");
                }

                foreach (var kv in props)
                {
                    geometryNode.AddAttribute(kv.Key, kv.Value);
                }

                node.AddChild(geometryNode);
            }
            else
            {
                var geom = el.Geometry as BufferGeometryElem;
                var sb   = new StringBuilder();
                sb.Append("obj: ");

                sb.Append("#" + geom.CreateSafeMeshName("-obj"));
                sb.Append("; ");

                var exporter = new MtlExporter();
                if (!exporter.IsBlank(mtl))
                {
                    sb.Append("mtl: ");
                    sb.Append("#" + geom.CreateSafeMeshName("-mtl"));
                }

                node.AddAttribute("obj-model", sb.ToString());
            }

            return(node);
        }