コード例 #1
0
ファイル: Program.cs プロジェクト: lewa-j/osm2vmf
        static void Main(string[] args)
        {
            String filename = "ny_manhattan1.osm";

            if (args.Length > 0)
            {
                filename = args[0];
            }

            OsmChunk map = new OsmChunk();

            if (map.Load(filename))
            {
                return;
            }

            if (Settings.cull)
            {
                map.Cull(Settings.cullBounding);
            }

            ExportOBJ(filename.Replace(".osm", ""), map);
            ExportVMF(filename.Replace(".osm", ".vmf"), map);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: lewa-j/osm2vmf
        public static void ExportOBJ(string filename, OsmChunk map)
        {
            filename = filename.Replace(".\\", "");

            StreamWriter msw = new StreamWriter(filename + ".mtl");

            msw.Write("newmtl roof_mat\n\n");
            msw.Write("newmtl wall_mat\n\n");

            msw.Close();

            StreamWriter sw = new StreamWriter(filename + ".obj");

            sw.Write("mtllib " + filename + ".mtl\n");
            sw.Write("o " + filename + "\n\n");

            /*
             * for (int i = 0; i < map.nodes.Count; i++)
             * {
             *      OsmNode n = map.nodes.ElementAt(i).Value;
             *      vec3 v = map.GetNodeCoords(n);
             *      v *= 0.05f;
             *      sw.Write("v " + v.ToString() + "\n");
             * }
             * for (int i = 0; i < map.buildings.Count; i++)
             * {
             *      OsmBuilding bd = map.buildings[i];
             *
             *      sw.Write("f");
             *      for (int j = 0; j < bd.nodeIds.Length - 1; j++)
             *      {
             *              long id = map.nodes.Keys.ToList().IndexOf(bd.nodeIds[j]);
             *              sw.Write(" " + (id + 1));
             *      }
             *      sw.Write("\n");
             * }
             */
            int v = 0;

            for (int i = 0; i < map.buildings.Count; i++)
            {
                OsmBuilding bd = map.buildings[i];
                //if (bd.outline)
                //	continue;
                Polygon[] polys = map.GetBuildingPolys(bd);

                //flat roof
                sw.Write("usemtl roof_mat\n");
                sw.Write("s off\n");
                for (int j = 0; j < polys.Length; j++)
                {
                    for (int k = 0; k < polys[j].verts.Length; k++)
                    {
                        vec3 v1 = polys[j].verts[k];
                        v1.y = bd.height;

                        v1 *= Settings.scale;
                        sw.Write("v " + v1.ToString() + "\n");
                    }

                    sw.Write("f");
                    for (int k = 0; k < polys[j].verts.Length; k++)
                    {
                        //long id = map.nodes.Keys.ToList().IndexOf(bd.nodeIds[j]);
                        //sw.Write(" " + (id + 1));
                        v++;
                        sw.Write(" " + v);
                    }
                    sw.Write("\n\n");
                }

                if (bd.min_height > 0.001)
                {
                    for (int j = 0; j < polys.Length; j++)
                    {
                        for (int k = polys[j].verts.Length - 1; k >= 0; k--)
                        {
                            vec3 v1 = polys[j].verts[k];
                            v1.y = bd.min_height;
                            v1  *= Settings.scale;
                            sw.Write("v " + v1.ToString() + "\n");
                        }

                        sw.Write("f");
                        for (int k = 0; k < polys[j].verts.Length; k++)
                        {
                            //long id = map.nodes.Keys.ToList().IndexOf(bd.nodeIds[j]);
                            //sw.Write(" " + (id + 1));
                            v++;
                            sw.Write(" " + v);
                        }
                        sw.Write("\n\n");
                    }
                }

                //walls
                sw.Write("usemtl wall_mat\n");
                sw.Write("s off\n");
                for (int j = 0; j < bd.nodeIds.Length - 1; j++)
                {
                    vec3 v1 = map.GetNodeCoords(map.nodes[bd.nodeIds[j]]);
                    vec3 v2 = map.GetNodeCoords(map.nodes[bd.nodeIds[j + 1]]);
                    vec3 v3 = v2;
                    vec3 v4 = v1;

                    v1.y = bd.height;
                    v2.y = bd.height;
                    v3.y = bd.min_height;
                    v4.y = bd.min_height;
                    v1  *= Settings.scale;
                    v2  *= Settings.scale;
                    v3  *= Settings.scale;
                    v4  *= Settings.scale;
                    sw.Write("v " + v1.ToString() + "\n");
                    sw.Write("v " + v2.ToString() + "\n");
                    sw.Write("v " + v3.ToString() + "\n");
                    sw.Write("v " + v4.ToString() + "\n");

                    sw.Write("f {0} {1} {2} {3}\n", v + 1, v + 2, v + 3, v + 4);
                    v += 4;
                }
                sw.Write("\n");
            }

            Console.WriteLine("obj: verts count {0}", v);

            sw.Close();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: lewa-j/osm2vmf
        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);
        }