Пример #1
0
        static void ConvMtlLib()
        {
            string filename = @"C:\temp\3d\cartoonforest\Enviroment_GroupTrees.mtl";
            var    dstbase  = @"c:\prog\overloadleveleditor\decaltextures\";
            var    srcbase  = Directory.GetParent(filename) + @"\";
            string cur      = null;

            foreach (var line in File.ReadAllLines(filename))
            {
                var ic = line.IndexOf("#");
                if (ic == 0 || line.Length == 0)
                {
                    continue;
                }
                var parts = ic >= 0 ? line.Substring(0, ic).TrimEnd().Split(new char[0], StringSplitOptions.RemoveEmptyEntries) :
                            line.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
                switch (parts[0])
                {
                case "newmtl":
                    cur = parts[1];
                    break;

                case "map_Kd":
                    var src = srcbase + parts[1];
                    var dst = dstbase + NameConv.Conv(cur) + ".png";
                    File.Copy(src, dst);
                    break;
                }
            }
        }
Пример #2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var model = (Model)value;

            var uvEmpty = new Vector2(0, 0);

            writer.WriteStartObject();
            writer.WritePropertyName("verts");
            writer.WriteStartArray();
            foreach (var vert in model.verts)
            {
                WriteXYZ(writer, vert, vertScale);
            }
            writer.WriteEndArray();

            writer.WritePropertyName("polys");
            writer.WriteStartObject();
            writer.WriteEndObject();

            writer.WritePropertyName("triangles");
            writer.WriteStartObject();
            int i = 0;

            foreach (var face in model.faces)
            {
                var idxs = face.Item1;
                writer.WritePropertyName(i.ToString());
                i++;
                writer.WriteStartObject();
                writer.WriteProp("tex_index", face.Item2);
                writer.WriteProp("flags", 0);
                writer.WritePropertyName("verts");
                writer.WriteStartArray();
                for (var j = 2; j >= 0; j--)
                {
                    writer.WriteValue(idxs[j][0]);
                }
                writer.WriteEndArray();

                writer.WritePropertyName("normals");
                writer.WriteStartArray();
                for (var j = 2; j >= 0; j--)
                {
                    WriteXYZ(writer, model.norms[idxs[j][2]]);
                }
                writer.WriteEndArray();

                writer.WritePropertyName("uvs");
                writer.WriteStartArray();
                for (var j = 2; j >= 0; j--)
                {
                    WriteUV(writer, idxs[j][1] >= 0 ? model.uvs[idxs[j][1]] : uvEmpty);
                }
                writer.WriteEndArray();

                writer.WriteEndObject();
            }
            writer.WriteEndObject();

            writer.WritePropertyName("tex_names");
            writer.WriteStartArray();
            foreach (var x in model.mtls)
            {
                writer.WriteValue(NameConv.Conv(x));
            }
            writer.WriteEndArray();

            writer.WritePropertyName("lights");
            writer.WriteStartObject();
            for (int j = 0; j < 4; j++)
            {
                writer.WritePropertyName(j.ToString());
                writer.WriteStartObject();
                writer.WriteProp("enabled", false);
                writer.WriteProp("style", "POINT");
                writer.WriteProp("flare", "NONE");
                writer.WritePropertyName("position");
                writer.WriteStartArray();
                for (int k = 0; k < 3; k++)
                {
                    writer.WriteValue(0.0);
                }
                writer.WriteEndArray();
                writer.WriteProp("rot_yaw", 0.0);
                writer.WriteProp("rot_pitch", 0.0);
                writer.WriteProp("color_index", 0);
                writer.WriteProp("intensity", 1.0);
                writer.WriteProp("range", 10.0);
                writer.WriteProp("angle", 45.0);
                writer.WriteEndObject();
            }
            writer.WriteEndObject();

            writer.WritePropertyName("colors");
            writer.WriteStartArray();
            for (int j = 0; j < 4; j++)
            {
                writer.WriteStartObject();
                writer.WriteProp("r", 255);
                writer.WriteProp("g", 255);
                writer.WriteProp("b", 255);
                writer.WriteEndObject();
            }
            writer.WriteEndArray();

            writer.WriteProp("smooth_diff", 0);
            writer.WriteProp("smooth_same", 0);

            writer.WriteEndObject();
        }