]> git.mxchange.org Git - flightgear.git/blobdiff - Tools/process-dem.pl
tweaks.
[flightgear.git] / Tools / process-dem.pl
index 1fa022559176a0d8ba72baea4824ba0c5f33e978..adca9c3d36e8b08b86b8ad6fce18124e0b907d48 100755 (executable)
 #---------------------------------------------------------------------------
 
 
+$max_area = 10000;            # maximum triangle area
+
 $| = 1;                         # flush buffers after every write
 
-$do_dem2node =     1;
+$do_dem2node =   1;
 $do_triangle_1 = 1;
 $do_fixnode =    1;
 $do_splittris =  1;
@@ -38,21 +40,18 @@ $do_triangle_2 = 1;
 $do_tri2obj =    1;
 $do_strips =     1;
 $do_fixobj =     1;
+$do_install =    1;
 
 
-# set the FG_ROOT environment variable if it hasn't already been set.
-if ( $ENV{FG_ROOT} eq "" ) {
-    # look for a file called fgtop as a place marker
-    die "You must remember to set the FG_ROOT environment variable!\n";
-}
-
-
-if ( $#ARGV < 1 ) {
-    die "Usage: $0 <error^2> dem-file1 [ dem-file2 dem-file3 ... ]\n";
+if ( $#ARGV < 3 ) {
+    die "Usage: $0 <fg-root-dir> <work-dir> <error^2> dem-file(s)\n";
 }
 
 # Start with file.dem
 
+$fg_root = shift(@ARGV);
+$work_dir = shift(@ARGV);
 $error = shift(@ARGV);
 $error += 0.0;
 
@@ -68,7 +67,7 @@ while ( $dem_file = shift(@ARGV) ) {
     if ( $do_dem2node ) {
        dem2node() ;
     } else {
-       $subdir = "../Scenery/w100n040/w093n045";
+       $subdir = "./work/Scenery/w100n040/w093n045/";
        print "WARNING:  Hardcoding subdir = $subdir\n";
     }
 
@@ -80,6 +79,7 @@ while ( $dem_file = shift(@ARGV) ) {
     tri2obj() if ( $do_tri2obj );
     strips() if ( $do_strips );
     fixobj() if ( $do_fixobj );
+    install() if ( $do_install );
 }
 
 
@@ -112,7 +112,7 @@ sub file_root {
 }
 
 
-# 1.  dem2node $FG_ROOT dem_file tolerance^2 (meters)
+# 1.  dem2node work_dir dem_file tolerance^2 (meters)
 # 
 #     - dem2node .. dem_file 160000
 #
@@ -120,7 +120,7 @@ sub file_root {
 #     irregularly fitted vertices
 
 sub dem2node {
-    $command = "Dem2node/dem2node $ENV{FG_ROOT} $dem_file $error";
+    $command = "Dem2node/dem2node $work_dir $dem_file $error";
     $command = fix_command($command);
     print "Running '$command'\n";
 
@@ -148,7 +148,7 @@ sub triangle_1 {
        print $file;
        chop($file);
        if ( ($file =~ m/\.node$/) && ($file !~ m/\.\d\.node$/) ) {
-           $command = "Triangle/triangle -q $subdir/$file";
+           $command = "Triangle/triangle -a$max_area -q $subdir/$file";
            $command = fix_command($command);
            print "Running '$command'\n";
            open(OUT, "$command |");
@@ -332,9 +332,10 @@ sub strips {
     foreach $file ( @FILES ) {
        chop($file);
        if ( $file =~ m/\.1\.obj$/ ) {
-           $command = "Stripe_u/strips $subdir/$file";
+           $command = "Stripe_w/strips $subdir/$file";
            $command = fix_command($command);
            print "Running '$command'\n";
+           # $input = <STDIN>;
            open(OUT, "$command |");
            while ( <OUT> ) {
                print $_;
@@ -345,7 +346,8 @@ sub strips {
            $newfile = $file;
            $newfile =~ s/\.1\.obj$//;
            print "Copying to $subdir/$newfile.2.obj\n";
-           open(IN, "<bands.d");
+           # open(IN, "<bands.d");
+           open(IN, "<stripe.objf");
            open(OUT, ">$subdir/$newfile.2.obj");
            while ( <IN> ) {
                print OUT $_;
@@ -386,8 +388,60 @@ sub fixobj {
 }
 
 
+# 9.  install
+#
+#     rename, compress, and install scenery files
+
+sub install {
+    $tmp = $subdir;
+    $tmp =~ s/$work_dir//;
+    # print "Temp dir = $tmp\n";
+    $install_dir = "$fg_root/$tmp";
+    print "Install dir = $install_dir\n";
+    system("mkdir -p $install_dir");
+
+    @FILES = `ls $subdir`;
+    foreach $file ( @FILES ) {
+       chop($file);
+       if ( $file =~ m/\d\d.obj$/ ) {
+           $new_file = file_root($file);
+           
+           $command = "gzip -v --best < $subdir/$file > $install_dir/$new_file.gz";
+           # $command = fix_command($command);
+           print "Running '$command'\n";
+           open(OUT, "$command |");
+           while ( <OUT> ) {
+               print $_;
+           }
+           close(OUT);
+
+           unlink("$subdir/$file");
+       }
+    }
+}
+
+
 #---------------------------------------------------------------------------
 # $Log$
+# Revision 1.22  1998/07/08 14:49:13  curt
+# tweaks.
+#
+# Revision 1.21  1998/06/08 17:18:37  curt
+# Mods to test new Stripe fixes from Wilbur Streett.
+#
+# Revision 1.20  1998/06/05 18:20:24  curt
+# Added DemInfo to dump out "A" record DEM info.
+# Modified process-dem.pl to work in a temp directory and compress/copy the
+# result to the final destination.
+#
+# Revision 1.19  1998/05/27 02:25:26  curt
+# Added a flag to the first run of "triangle" to impose a maximum triangle
+# size.  This forces really flat areas to be subdivided a certain amount
+# anyways.  This makes for slightly more interesting scenery.
+#
+# Revision 1.18  1998/05/20 20:55:40  curt
+# Makefile tweaks
+#
 # Revision 1.17  1998/04/28 01:23:25  curt
 # Added a work around so that we can get past the "triangle" program
 # hanging, by aborting and rerunning with that tile marked to use the "-i"