]> git.mxchange.org Git - flightgear.git/blobdiff - Tools/process-dem.pl
Cumulative tweaks.
[flightgear.git] / Tools / process-dem.pl
index 62915bb712c144e4ba21e0e2e4f883f67291d4d5..22d8ee9a7162130e338dc660c6cbab311b14f444 100755 (executable)
 
 $| = 1;                         # flush buffers after every write
 
-$do_demfit =     0;
-$do_triangle_1 = 0;
-$do_fixnode =    0;
-$do_splittris =  0;
+$do_demfit =     1;
+$do_triangle_1 = 1;
+$do_fixnode =    1;
+$do_splittris =  1;
 $do_assemtris =  1;
+$do_triangle_2 = 1;
 
-$do_tri2obj =    0;
-$do_strips =     0;
-$do_fixobj =     0;
-
-
-# return the file name root (ending at last ".")
-sub file_root {
-    my($file) = @_;
-    my($pos);
-
-    $pos = rindex($file, ".");
-    return substr($file, 0, $pos);
-}
+$do_tri2obj =    1;
+$do_strips =     1;
+$do_fixobj =     1;
 
 
 # set the FG_ROOT environment variable if it hasn't already been set.
@@ -60,27 +51,69 @@ if ( $ENV{FG_ROOT} eq "" ) {
 }
 
 
-# 1.  Start with file.dem
+if ( $#ARGV < 1 ) {
+    die "Usage: $0 <error^2> dem-file1 [ dem-file2 dem-file3 ... ]\n";
+}
+
+# Start with file.dem
 
-$dem_file = shift(@ARGV);
 $error = shift(@ARGV);
 $error += 0.0;
 
-print "Source file = $dem_file  Error tolerance = $error\n";
+while ( $dem_file = shift(@ARGV) ) {
+    print "Source file = $dem_file  Error tolerance = $error\n";
+
+    if ( $error < 0.5 ) {
+       die "I doubt you'll be happy with an error tolerance as " . 
+           "low as $error.\n";
+    }
+
 
-if ( $error < 0.5 ) {
-    die "I doubt you'll be happy with an error tolerance as low as $error.\n";
+    if ( $do_demfit ) {
+       demfit() ;
+    } else {
+       $subdir = "../Scenery/w100n040/w093n045";
+       print "WARNING:  Hardcoding subdir = $subdir\n";
+    }
+    
+    triangle_1() if ( $do_triangle_1 );
+    fixnode() if ( $do_fixnode );
+    splittris() if ( $do_splittris );
+    assemtris() if ( $do_assemtris );
+    triangle_2() if ( $do_triangle_2);
+    tri2obj() if ( $do_tri2obj );
+    strips() if ( $do_strips );
+    fixobj() if ( $do_fixobj );
 }
 
-# 2.  dem2node $FG_ROOT dem_file tolerance^2 (meters)
+
+# exit normally
+exit(0);
+
+
+# return the file name root (ending at last ".")
+sub file_root {
+    my($file) = @_;
+    my($pos);
+
+    $pos = rindex($file, ".");
+    return substr($file, 0, $pos);
+}
+
+
+# 1.  dem2node $FG_ROOT dem_file tolerance^2 (meters)
 # 
 #     - dem2node .. dem_file 160000
 #
 #     splits dem file into 64 file.node's which contain the
 #     irregularly fitted vertices
 
-if ( $do_demfit ) {
-    $command = "./Dem2node/demfit $ENV{FG_ROOT} $dem_file $error";
+sub demfit {
+    if ( $dem_file =~ m/.gz$/ ) {
+       $command = "gzip -dc $dem_file | ./Dem2node/demfit $ENV{FG_ROOT} - $error";
+    } else {
+       $command = "./Dem2node/demfit $ENV{FG_ROOT} $dem_file $error";
+    }
 
     print "Running '$command'\n";
 
@@ -94,17 +127,15 @@ if ( $do_demfit ) {
        }
     }
     close(OUT);
-} else {
-    $subdir = "../Scenery/w120n030/w111n033";
-    print "WARNING:  Hardcoding subdir = $subdir\n";
-}
+} 
+
 
-# 3.  triangle -q file (Takes file.node and produces file.1.node and
+# 2.  triangle -q file (Takes file.node and produces file.1.node and
 #                      file.1.ele)
 
 print "Subdirectory for this dem file is $subdir\n";
 
-if ( $do_triangle_1 ) {
+sub triangle_1 {
     @FILES = `ls $subdir`;
     foreach $file ( @FILES ) {
        print $file;
@@ -124,14 +155,19 @@ if ( $do_triangle_1 ) {
     }
 }
 
-# 4.  fixnode file.dem subdir
+
+# 3.  fixnode file.dem subdir
 #
 #     Take the original .dem file (for interpolating Z values) and the
 #     subdirecotry containing all the file.1.node's and replace with
 #     fixed file.1.node
 
-if ( $do_fixnode ) {
-    $command = "./FixNode/fixnode $dem_file $subdir";
+sub fixnode {
+    if ( $dem_file =~ m/.gz$/ ) {
+       $command = "gzip -dc $dem_file | ./FixNode/fixnode - $subdir";
+    } else {
+       $command = "./FixNode/fixnode $dem_file $subdir";
+    }
     print "Running '$command'\n";
     open(OUT, "$command |");
     while ( <OUT> ) {
@@ -156,7 +192,7 @@ if ( $do_fixnode ) {
 #     gets to define the edge verticies and normals.  All the other
 #     adjacent tiles must use these.
 
-if ( $do_splittris ) {
+sub splittris {
     @FILES = `ls $subdir`;
     foreach $file ( @FILES ) {
        chop($file);
@@ -183,12 +219,12 @@ if ( $do_splittris ) {
 #     using the proper shared corners and edges.  Save as a node file
 #     so we can retriangulate.
 
-if ( $do_assemtris ) {
+sub assemtris {
     @FILES = `ls $subdir`;
     foreach $file ( @FILES ) {
        chop($file);
        if ( $file =~ m/\.1\.body$/ ) {
-           $file =~ s/\.body$//;  # strip off the ".node"
+           $file =~ s/\.body$//;  # strip off the ".body"
        
            $command = "./AssemTris/assemtris $subdir/$file";
            print "Running '$command'\n";
@@ -198,18 +234,46 @@ if ( $do_assemtris ) {
            }
            close(OUT);
        }
+       unlink("$subdir/$file.body");
     }
 }
 
 
-# 4.3 Retriangulate fixed up files (without -q option)
+# 4.3 Retriangulate reassembled files (without -q option) so no new
+#     nodes are generated.
+
+sub triangle_2 {
+    @FILES = `ls $subdir`;
+    foreach $file ( @FILES ) {
+       print $file;
+       chop($file);
+       if ( ($file =~ m/\.node$/) && ($file !~ m/\.\d\.node$/) ) {
+           $command = "./Triangle/triangle $subdir/$file";
+           print "Running '$command'\n";
+           open(OUT, "$command |");
+           while ( <OUT> ) {
+               print $_;
+           }
+           close(OUT);
+
+           # remove input file.node
+           unlink("$subdir/$file");
+       }
+    }
+}
 
 
 # 5.  tri2obj file (.1.node) (.1.ele)
 #
 #     Take the file.1.node and file.1.ele and produce file.1.obj
+#
+#     Extracts normals out of the shared edge/vertex files, and uses
+#     the precalcuated normals for these nodes instead of calculating
+#     new ones.  By sharing normals as well as vertices, not only are
+#     the gaps between tiles eliminated, but the colors and lighting
+#     transition smoothly across tile boundaries.
 
-if ( $do_tri2obj ) {
+sub tri2obj {
     @FILES = `ls $subdir`;
     foreach $file ( @FILES ) {
        chop($file);
@@ -234,13 +298,14 @@ if ( $do_tri2obj ) {
 
 # 6.  strip file.1.obj
 # 
-#     Strip the file.1.obj's
+#     Strip the file.1.obj's.  Note, strips doesn't handle the minimal
+#     case of striping a square correctly.
 #
 # 7.  cp bands.d file.2.obj
 #
 #     strips produces a file called "bands.d" ... copy this to file.2.obj
 
-if ( $do_strips ) {
+sub strips {
     @FILES = `ls $subdir`;
     foreach $file ( @FILES ) {
        chop($file);
@@ -275,7 +340,7 @@ if ( $do_strips ) {
 #
 #     Sort file.2.obj by strip winding
 
-if ( $do_fixobj ) {
+sub fixobj {
     @FILES = `ls $subdir`;
     foreach $file ( @FILES ) {
        chop($file);
@@ -299,6 +364,26 @@ if ( $do_fixobj ) {
 
 #---------------------------------------------------------------------------
 # $Log$
+# Revision 1.11  1998/03/03 03:36:57  curt
+# Cumulative tweaks.
+#
+# Revision 1.10  1998/02/01 03:42:26  curt
+# Modifications to handle compressed dem files.
+#
+# Revision 1.9  1998/01/27 18:36:54  curt
+# Lots of updates to get back in sync with changes made over in .../Src/
+#
+# Revision 1.8  1998/01/21 17:59:05  curt
+# Uncomment lines to remove several intermediate files.
+#
+# Revision 1.7  1998/01/19 19:51:06  curt
+# A couple final pre-release tweaks.
+#
+# Revision 1.6  1998/01/15 21:33:33  curt
+# Assembling triangles and building a new .node file with the proper shared
+# vertices now works.  Now we just have to use the shared normals and we'll
+# be all set.
+#
 # Revision 1.5  1998/01/15 02:50:08  curt
 # Tweaked to add next stage.
 #