For completeness, I post the Perl script with which I made the Celestia's Geological features from a set of GMT data, but whatelse text extension is good.
Code:
# Author Fenerit <fenerit@interfree.it>
# Version 1.0, 1.12.2009
# This script convert a rectangular points table coordinates into spherical and
# output an Ascii CMOD format for using in Celestia. The resulting 3d model doesn't need to be oriented
# The resulting file can be loaded in Celestia as it is or previous conversion in binary form.
# Acknowledgements: Dr. Fridger Schrempp <fridger.schrempp@desy.de> for its basic routines.
# USAGE:
# 1) Script and coordinates text files must be in the same folder;
# 2) Run the script. A new file called "rect2spheric.cmod" will be created in the same folder;
# SINTAX: rect2spheric.pl < YOURCOORDS.NAME (in Windows cmd: perl rect2spheric.pl < YOURCOORDS.NAME)
print STDOUT "\n -- Start process... --\n";
open(CMOD, " > rect2spheric.cmod") || die "Can not create rect2spheric.cmod\n";
my $radius = 1;
my $pi = 3.14159265359;
$l = 0;
while (<>) {
# next if ($. == 1); # skip the first text line (uncomment if any);
next if (/^$/); # trim input white spaces at init and at end of file;
# next if ++$seen{$_} > 1; # skip duplicate values (uncomment if any, usually not);
($lat,$long) = split (" ",$_);
$theta = $pi/180.0 * $lat; # Polar angle $theta in radiants
$phi = $pi/180.0 * $long; # Azimuthal angle $phi in radiants
$x[$l] = -($radius * cos($theta) * cos($phi));
$y[$l] = $radius * sin($theta);
$z[$l] = $radius * cos($theta) * sin($phi);
$l++;
}
# invisible container mesh
print CMOD "#celmodel__ascii\n";
print CMOD "\n";
print CMOD "material\n";
print CMOD "diffuse 0 0 0\n";
# print CMOD "emissive 0 0 0\n";
print CMOD "opacity 0\n";
print CMOD "end_material\n";
print CMOD "\n";
# main mesh (edit here)
print CMOD "material\n";
print CMOD "diffuse 1 1 1\n";
print CMOD "#emissive 1 1 1\n";
print CMOD "opacity 1\n";
print CMOD "end_material\n";
print CMOD "\n";
# --------------------------------
print CMOD "mesh\n";
print CMOD "vertexdesc\n";
print CMOD "position f3\n";
print CMOD "end_vertexdesc\n";
print CMOD "\n";
# mesh container boundings
print CMOD "vertices 6\n";
print CMOD "1 0 0\n";
print CMOD "-1 0 0\n";
print CMOD "0 1 0\n";
print CMOD "0 -1 0\n";
print CMOD "0 0 1\n";
print CMOD "0 0 -1\n";
print CMOD "\n";
print CMOD "linestrip 0 6\n";
print CMOD "0 1 2 3 4 5\n";
print CMOD "end_mesh\n";
print CMOD "\n";
print CMOD "mesh\n";
print CMOD "vertexdesc\n";
print CMOD "position f3\n";
print CMOD "end_vertexdesc\n";
$vertexcount = $l;
print CMOD "\nvertices $vertexcount\n";
for ($index=0; $index < $vertexcount; $index++)
{
printf CMOD "%8.6f %8.6f %8.6f\n", $x[$index],$y[$index],$z[$index];
}
printf CMOD "\npoints 1 $vertexcount\n";
# linestrip variation, whether points need to be merged (comment the line above, before)
# printf CMOD "\nlinestrip 1 $vertexcount\n";
for ($index=0; $index < $vertexcount; $index++) # count n° points;
{
printf CMOD "%1d\n", $i++; # write n° points;
;}
print CMOD "\nend_mesh\n\n";
print STDOUT "\n -- Finished! ", $vertexcount, " resulting vertex within rect2spheric.cmod --\n";
close CMOD;
Often, as for the trenches and faults, GMT texts are subdivided in blocks of coordinates specifying just some tracks, so the linestrip method must account for each block. It useful then to append each block into the same output file.
The script could be modifyed as follow:
Code:
open(CMOD, " >> rect2spheric.cmod") || die "Can not create rect2spheric.cmod\n";
Such line must replace the existent whether you want append more blocks. In doing this the script must be devoided of the "container" declarations, since these latters should be added after, when all the linestrips are ready:
Code:
# Author Fenerit <fenerit@interfree.it>
# Version 1.0, 1.12.2009
# This script convert a rectangular points table coordinates into spherical and
# output an Ascii CMOD format for using in Celestia. The resulting 3d model doesn't need to be oriented
# The resulting file can be loaded in Celestia as it is or previous conversion in binary form.
# Acknowledgements: Dr. Fridger Schrempp <fridger.schrempp@desy.de> for its basic routines.
# USAGE:
# 1) Script and coordinates text files must be in the same folder;
# 2) Run the script. A new file called "rect2spheric.cmod" will be created in the same folder;
# SINTAX: rect2spheric.pl < YOURCOORDS.NAME (in Windows cmd: perl rect2spheric.pl < YOURCOORDS.NAME)
print STDOUT "\n -- Start process... --\n";
open(CMOD, " >> rect2spheric.cmod") || die "Can not create rect2spheric.cmod\n";
my $radius = 1;
my $pi = 3.14159265359;
$l = 0;
while (<>) {
# next if ($. == 1); # skip the first text line (uncomment if any);
next if (/^$/); # trim input white spaces at init and at end of file;
# next if ++$seen{$_} > 1; # skip duplicate values (uncomment if any, usually not);
($lat,$long) = split (" ",$_);
$theta = $pi/180.0 * $lat; # Polar angle $theta in radiants
$phi = $pi/180.0 * $long; # Azimuthal angle $phi in radiants
$x[$l] = -($radius * cos($theta) * cos($phi));
$y[$l] = $radius * sin($theta);
$z[$l] = $radius * cos($theta) * sin($phi);
$l++;
}
print CMOD "mesh\n";
print CMOD "vertexdesc\n";
print CMOD "position f3\n";
print CMOD "end_vertexdesc\n";
$vertexcount = $l;
print CMOD "\nvertices $vertexcount\n";
for ($index=0; $index < $vertexcount; $index++)
{
printf CMOD "%8.6f %8.6f %8.6f\n", $x[$index],$y[$index],$z[$index];
}
printf CMOD "\nlinestrip 1 $vertexcount\n";
for ($index=0; $index < $vertexcount; $index++) # count n° points;
{
printf CMOD "%1d\n", $i++; # write n° points;
;}
print CMOD "\nend_mesh\n\n";
print STDOUT "\n -- Finished! ", $vertexcount, " resulting vertex within rect2spheric.cmod --\n";
close CMOD;
The strings above makes the script useful for append, without to built as more files as are the coordinates' blocks. Of course the setting for the container must be made after. Either linestrip or point can be appended, they depend by the final use.