コード例 #1
0
        public string ToJson()
        {
            // I did think of using a JSON serialiser,
            // either one of these two provided by the
            // .NET framework or one of the other libraries:
            // System.Runtime.Serialization.Json.DataContractJsonSerializer
            // System.Web.Script.Serialization.JavaScriptSerializer
            // However, reading this comparison and alternative
            // implementation, I decided to just write the couple
            // of lines myself.
            // http://procbits.com/2011/08/11/fridaythe13th-the-best-json-parser-for-silverlight-and-net

            string s = string.Format
                           ("\n \"FacetCount\":{0},"
                           + "\n \"VertexCount\":{1},"
                           + "\n \"VertexCoords\":[{2}],"
                           + "\n \"VertexIndices\":[{3}],"
                           + "\n \"Normals\":[{4}],"
                           + "\n \"NormalIndices\":[{5}],"
                           + "\n \"Center\":[{6}],"
                           + "\n \"Color\":[{7}],"
                           + "\n \"Id\":\"{8}\"",
                           FacetCount,
                           VertexCount,
                           string.Join(",", VertexCoords.Select <int, string>(i => (_export_factor * i).ToString("0.#")).ToArray()),
                           string.Join(",", VertexIndices.Select <int, string>(i => i.ToString()).ToArray()),
                           string.Join(",", Normals.Select <double, string>(a => a.ToString("0.####")).ToArray()),
                           string.Join(",", NormalIndices.Select <int, string>(i => i.ToString())),
                           string.Join(",", Center.Select <int, string>(i => (_export_factor * i).ToString("0.#"))),
                           Color,
                           Id);

            return("\n{" + s + "\n}");
        }
コード例 #2
0
ファイル: ObjModel.cs プロジェクト: xiaomangqiu/ObjConvert
        /// <summary>
        /// write obj file
        /// </summary>
        /// <param name="writer"></param>
        public void Write(StreamWriter writer)
        {
            writer.WriteLine("# File generated by Arctron BIMClient");
            if (!String.IsNullOrEmpty(MatFilename))
            {
                writer.WriteLine($"mtllib {MatFilename}");
            }
            var vs = String.Join(Environment.NewLine, Vertices.Select(v => $"v {v.X} {v.Y} {v.Z}"));

            writer.WriteLine(vs);
            writer.Flush();
            var ts = String.Join(Environment.NewLine, Uvs.Select(t => $"vt {t.U} {t.V}"));

            writer.WriteLine(ts);
            writer.Flush();
            var ns = String.Join(Environment.NewLine, Normals.Select(n => $"vn {n.X} {n.Y} {n.Z}"));

            writer.WriteLine(ns);
            writer.Flush();
            foreach (var g in Geometries)
            {
                g.Write(writer);
            }
        }