public static void ExportVMF(string filename, OsmChunk map) { long brushId = 1; StreamWriter sw = new StreamWriter(filename); /*versioninfo * { * "formatversion" "100" * "prefab" "1" * }*/ sw.Write("versioninfo\n{\n\"formatversion\" \"100\"\n\"prefab\" \"1\"\n}\n"); /*visgroups * { * } * viewsettings * { * }*/ double s = 30.0 * Settings.scale; sw.Write("world\n{\n"); sw.Write("\"id\" \"1\"\n\"classname\" \"worldspawn\"\n\"skyname\" \"sky_day01_01\"\n"); // for (int i = 0; i < map.buildings.Count; i++) { OsmBuilding bd = map.buildings[i]; //if (bd.outline) // continue; double h1 = bd.min_height * s; double h2 = bd.height * s; if (h2 > 30000) { Console.WriteLine("building {0} is too high {1}", i, h2); } Polygon[] polys = map.GetBuildingPolys(bd); for (int p = 0; p < polys.Length; p++) { sw.Write("solid\n{\n"); sw.Write("\t\"id\" \"{0}\"\n", brushId); brushId++; for (int j = 0; j < polys[p].verts.Length; j++) { vec3 v1 = polys[p].At(j); vec3 v2 = polys[p].At(j + 1); vec3 v3 = new vec3(v2.x, h2, v2.z); v1.y = h1; v2.y = h1; v1 *= s; v2 *= s; v3 *= s; v1.z *= -1; v2.z *= -1; v3.z *= -1; //v1 += (v1 - v3)*4; //v2 += (v2 - v3)*4; v1 = new vec3(v1.x, v1.z, v1.y).Snap(); v2 = new vec3(v2.x, v2.z, v2.y).Snap(); v3 = new vec3(v3.x, v3.z, v3.y).Snap(); vec3 uaxis = new vec3(v2.x - v1.x, v2.y - v1.y, 0); uaxis.Normalize(); sw.Write("\tside\n\t{\n"); sw.Write("\t\t\"plane\" \"(" + v1.ToString() + ") (" + v2.ToString() + ") (" + v3.ToString() + ")\"\n"); sw.Write("\t\t\"material\" \"" + Settings.wallsMaterial + "\"\n"); sw.Write("\t\t\"uaxis\" \"[" + uaxis.ToString() + " 0] 0.25\"\n"); sw.Write("\t\t\"vaxis\" \"[0 0 -1 0] 0.25\"\n"); //"rotation" "0" sw.Write("\t\t\"lightmapscale\" \"" + Settings.lightmapscale + "\"\n"); sw.Write("\t}\n"); } //top sw.Write("\tside\n\t{\n"); sw.Write("\t\t\"plane\" \"(" + new vec3(0, 50, h2).ToString() + ") (" + new vec3(50, 50, h2).ToString() + ") (" + new vec3(50, 0, h2).ToString() + ")\"\n"); sw.Write("\t\t\"material\" \"" + Settings.roofMaterial + "\"\n"); sw.Write("\t\t\"uaxis\" \"[1 0 0 0] 0.25\"\n"); sw.Write("\t\t\"vaxis\" \"[0 -1 0 0] 0.25\"\n"); sw.Write("\t\t\"lightmapscale\" \"" + Settings.lightmapscale + "\"\n"); sw.Write("\t}\n"); //bottom sw.Write("\tside\n\t{\n"); sw.Write("\t\t\"plane\" \"(" + new vec3(0, 0, h1).ToString() + ") (" + new vec3(50, 0, h1).ToString() + ") (" + new vec3(50, 50, h1).ToString() + ")\"\n"); sw.Write("\t\t\"material\" \"" + Settings.ceilingMaterial + "\"\n"); sw.Write("\t\t\"uaxis\" \"[1 0 0 0] 0.25\"\n"); sw.Write("\t\t\"vaxis\" \"[0 -1 0 0] 0.25\"\n"); sw.Write("\t\t\"lightmapscale\" \"" + Settings.lightmapscale + "\"\n"); sw.Write("\t}\n"); sw.Write("}\n"); //end solid } } //sky and ground //(-150, -170, 300, 410) /*VMFWriteSolid(sw, brushId++, new vec3(-5120, -7680, 8128), new vec3(5120, 5312, 8192), "tools/toolsskybox"); * VMFWriteSolid(sw, brushId++, new vec3(-5120, -7680, 0), new vec3(-5056, 5312, 8128), "tools/toolsskybox"); * VMFWriteSolid(sw, brushId++, new vec3(5056, -7680, 0), new vec3(5120, 5312, 8128), "tools/toolsskybox"); * VMFWriteSolid(sw, brushId++, new vec3(-5056, 5248, 0), new vec3(5056, 5312, 8128), "tools/toolsskybox"); * VMFWriteSolid(sw, brushId++, new vec3(-5056, -7680, 0), new vec3(5056, -7616, 8128), "tools/toolsskybox"); * VMFWriteSolid(sw, brushId++, new vec3(-5120, -7680, -64), new vec3(5120, 5312, 0), "concrete/concretefloor005a");*/ VMFWriteSolid(sw, brushId++, new vec3(-12288, -15360, 14000), new vec3(12288, 12288, 14064), "tools/toolsskybox"); VMFWriteSolid(sw, brushId++, new vec3(-12288, -15360, -64), new vec3(12288, 12288, 0), "concrete/concretefloor005a"); VMFWriteSolid(sw, brushId++, new vec3(-12288, -15360, 0), new vec3(-12224, 12288, 14064), "tools/toolsskybox"); VMFWriteSolid(sw, brushId++, new vec3(12224, -15360, 0), new vec3(12288, 12288, 14064), "tools/toolsskybox"); VMFWriteSolid(sw, brushId++, new vec3(-12288, 12224, 0), new vec3(12288, 12288, 14064), "tools/toolsskybox"); VMFWriteSolid(sw, brushId++, new vec3(-12288, -15360, 0), new vec3(12288, -15296, 14064), "tools/toolsskybox"); sw.Write("}\n"); //end world //light sw.Write("entity\n{\n"); //sw.Write("\t\"id\" \"{0}\"\n",id); sw.Write("\t\"classname\" \"light_environment\"\n"); sw.Write("\t\"angles\" \"0 345 0\"\n"); sw.Write("\t\"pitch\" \"-60\"\n"); sw.Write("\t\"SunSpreadAngle\" \"1\"\n"); sw.Write("\t\"_ambient\" \"255 255 255 20\"\n"); sw.Write("\t\"_ambientHDR\" \"-1 -1 -1 1\"\n"); sw.Write("\t\"_AmbientScaleHDR\" \"1\"\n"); sw.Write("\t\"_light\" \"255 255 255 200\"\n"); sw.Write("\t\"_lightHDR\" \"-1 -1 -1 1\"\n"); sw.Write("\t\"_lightscaleHDR\" \"1\"\n"); sw.Write("\t\"origin\" \"-320 -4607 128\"\n"); sw.Write("}\n"); //player sw.Write("entity\n{\n"); //sw.Write("\t\"id\" \"{0}\"\n",id); sw.Write("\t\"classname\" \"info_player_start\"\n"); sw.Write("\t\"angles\" \"0 0 0\"\n"); sw.Write("\t\"origin\" \"-384 -4601 16\"\n"); sw.Write("}\n"); sw.Close(); Console.WriteLine("vmf: brushes count {0}", brushId); }