Creating a 3D Mars Model from USGS ISIS3 Data

All about models for Celestia. How-to, programs, work in progress...
Avatar
cartrite
Posts: 1827
Joined: 15.09.2005
With us: 15 years 9 months
Location: Pocono Mountains, Pennsylvania, USA

Post #21by cartrite » 08.06.2021, 16:20

What you need is a raw file of 16bit signed integers each number represents a height value. Tif is an image which may be rgb or rgba. These files may contain 8 bit numbers representing a color. That file may be a geotiff. You would need GDAL to process it. I tried to export it with ISIS and it only gave me grayscale or rgb, rgba options.


crop https://isis.astrogeology.usgs.gov/Application/presentation/Tabbed/crop/crop.html
reduce https://isis.astrogeology.usgs.gov/Application/presentation/Tabbed/reduce/reduce.htm
isis2raw https://isis.astrogeology.usgs.gov/Application/pr ... /Tabbed/isis2raw/isis2raw.html

With crop your sample value would be 1 your number of samples would be 1/2 of the line. Your line would start at 1 and the number of lines would be be half the lines. Then you crop the second file by sample =16385 number of samples would be 32768 for a 32k image. Lines would stay the same. Then 3rd file would start with sample back to 1 number of lines 16384. Line would start at 8192 number of lines 8192.

Do the same for your texture and normalmap. But you shouldn't need a normalmap. The model will be 3d. I have cmodsphere built on linux and windows. It is part of compiling Celestia. I'm about to process the mars image and I let you know what I find out.
AMD A4-9125 RADEON R3, 4 COMPUTE CORES 2C+2G 2.30 GHz AMD Radeon(TM) R3 Graphics Running on Windows 10 and OpenSuse 15.2

Avatar
Topic author
CM1215 M
Posts: 219
Joined: 30.08.2017
Age: 19
With us: 3 years 9 months
Location: Ohio, U. S. A.

Post #22by CM1215 » 08.06.2021, 19:59

So, should I first reduce the size of the .cub heightmap to 32k using the reduce program before cropping it? Or is the cropping supposed to precede the reduction in size? Based on your instructions, I am assuming the former is the case.

So I'll need four crops, one from sample 1 to 16384 and line 1 to 8192, another from sample 16385 to 32768 and line 1 to 8192, another from sample 1 to 16384 and line 8193 to 16384, and a last one from sample 16385 to 32768 and line 8193 to 16384. Please do correct me if I misread your instructions.

The primary reason I desired a normalmap was because it would be able to show more detail than all but the biggest and most detailed models. However, if the model is going to include all the details of the 32k heightmap, then a normalmap will indeed be unnecessary. I am afraid, though, that this model will be a massive file as a result.

Also, my attempt to build cmodsphere was unsuccessful. Could you send me your Windows build of cmodsphere?
CM1215: Celestial master in learning.

Avatar
cartrite
Posts: 1827
Joined: 15.09.2005
With us: 15 years 9 months
Location: Pocono Mountains, Pennsylvania, USA

Post #23by cartrite » 08.06.2021, 20:50

What build environment are you using? With windows I'm using Visual Studio. I would suggest building Celestia. The tools are built as well. Just need to turn them on in CMakeLists.txt. Top Celestia folder. Anyhow, I'm trying to get an installer built that will install Celestia on a windows system. Should get it done before the end of this week.

I am attempting to run cmodsphere on a txt file of the mars file. I found that isis2ascii was needed? So far I have not succeeded. I have the original Mola map scaled down to 4096x2048 and it is still too big. It's running as I type this. Just looked at the properties of the file and it is over 7 gb. Unless you got a lot of ram, this will never work.
AMD A4-9125 RADEON R3, 4 COMPUTE CORES 2C+2G 2.30 GHz AMD Radeon(TM) R3 Graphics Running on Windows 10 and OpenSuse 15.2

Avatar
Topic author
CM1215 M
Posts: 219
Joined: 30.08.2017
Age: 19
With us: 3 years 9 months
Location: Ohio, U. S. A.

Post #24by CM1215 » 08.06.2021, 21:09

cartrite wrote:What build environment are you using?
I was using MINGW64. Attempting to compile with tools enabled caused a multitude of errors that I don't quite remember.

cartrite wrote:I am attempting to run cmodsphere on a txt file of the mars file. I found that isis2ascii was needed? So far I have not succeeded. I have the original Mola map scaled down to 4096x2048 and it is still too big. It's running as I type this. Just looked at the properties of the file and it is over 7 gb. Unless you got a lot of ram, this will never work.
I couldn't imaging trying to create a 3d model with the detail of a 32k normalmap. I was considering using a version downscaled to 8k, but given the trouble you're having with a 4k version, that may be impossible. However, my home computer has 16 GB of RAM, so it might be somewhat capable of such a task.

If cmodsphere is insufficient, is there another method of transforming a heightmap into a spherical 3D model?
CM1215: Celestial master in learning.

Avatar
cartrite
Posts: 1827
Joined: 15.09.2005
With us: 15 years 9 months
Location: Pocono Mountains, Pennsylvania, USA

Post #25by cartrite » 08.06.2021, 23:57

When Celestialmatters forum went down, a lot of information was lost for good. for ever. here is the math. it is embedded in this file .

Code: Select all

#!BPY

"""
Name: 'ZFold'
Blender: 233
Group: 'Import'
Tooltip: 'Adjust Z length and folds a plane'
"""

#--------------------------------------------------
# By Toti

#--------------------------------------------------
# Change these constants accordingly to your data, BUT ADD A DECIMAL PART:

SATMAXRADIUS   = 110.0      #in km. from Celestia
DELTAHEIGHT      = 16.0      #in km, from Galileo's site (NASA)

#--------------------------------------------------
# Do not change these constants:

MAXN   = -1000000000000
MINN   = 1000000000000

#--------------------------------------------------
# Here starts the code:

import Blender
import math
from Blender import NMesh, Object

satMinRadius   = SATMAXRADIUS-DELTAHEIGHT

obj         = Object.GetSelected()
meshName      = obj[0].data.name
mesh         = NMesh.GetRaw(meshName)

vq   = 0
min   = MINN
max   = MAXN
for v in mesh.verts:
   if  v.co[2] >= max:
      max = v.co[2]
   if v.co[2] <= min:
      min = v.co[2]
   vq   += 1

origDeltaZ   = max-min
finalDeltaZ   = DELTAHEIGHT / satMinRadius   
factor   = finalDeltaZ / origDeltaZ

print "\n\nSatellite info"
print "   Maximum radius: %s" % SATMAXRADIUS
print "   Minimum radius: %s" % satMinRadius
print "   Delta altitude: %s" % DELTAHEIGHT
print "Original mesh info"
print "   Delta altitude: %s" % origDeltaZ
print "Final mesh info"
print "   Delta altitude: %s" % finalDeltaZ
print "Correction factor used: %s" % factor
print "Vertices processed %s" % vq

for v in mesh.verts:
   v.co[2] = (v.co[2] - min) * factor

NMesh.PutRaw(mesh, meshName)
Blender.Redraw()

#--------------------------------------------------
# This performs the actual sphere transform. This is Anthony C. D'Agostino original code:

# Copyright (c) 2000 Anthony C. D'Agostino
# http://ourworld.compuserve.com/homepages/scorpius
# scorpius@compuserve.com
# October 5, 2000
# Displacement Mapping Suite (Version 1.0)


for vertex in mesh.verts:
    theta  = vertex.co[0] * math.pi     # range was [-1, 1] now [-pi, pi]
    phi    = vertex.co[1] * math.pi/2   # range was [-1, 1] now [-pi/2, pi/2]
    radius = vertex.co[2] + 1

    x = radius*math.cos(phi)*math.cos(theta)
    y = radius*math.cos(phi)*math.sin(theta)
    z = radius*math.sin(phi)

    vertex.co[0] = x
    vertex.co[1] = y
    vertex.co[2] = z

NMesh.PutRaw(mesh, meshName)
Blender.Redraw()
This was written for blender an old version, but math is math. What is still missing is the texture coords. cmodsphere does not produce them.

Added after 1 minute 26 seconds:
But Blender does.
AMD A4-9125 RADEON R3, 4 COMPUTE CORES 2C+2G 2.30 GHz AMD Radeon(TM) R3 Graphics Running on Windows 10 and OpenSuse 15.2

Avatar
Topic author
CM1215 M
Posts: 219
Joined: 30.08.2017
Age: 19
With us: 3 years 9 months
Location: Ohio, U. S. A.

Post #26by CM1215 » 09.06.2021, 01:56

So this is a script written for an older Blender version. Can this be used to transform a heightmap into a spherical mesh? What Blender version does this work for?

I am not very good with Blender, so I don't know how to put this script into action, if that's your plan.
CM1215: Celestial master in learning.

Avatar
cartrite
Posts: 1827
Joined: 15.09.2005
With us: 15 years 9 months
Location: Pocono Mountains, Pennsylvania, USA

Post #27by cartrite » 09.06.2021, 09:03

viewtopic.php?f=2&t=5356&p=39715&hilit=zfold#p39715 Take a look at this page. Blender can make it easy to do what you want to do. The basics are there. Look at this. I used cmodfix to turn a celestia model "vesta" from binary to ascii. The following is the start of that model.

Code: Select all

#celmodel__ascii

material
end_material

mesh
vertexdesc
position f3
normal f3
texcoord0 f2
end_vertexdesc

vertices 2699
-64.7666 158.896 -177.945 -0.254989 0.722714 -0.642389 0.3056 -0.7222
Look at that. Does it mean anything to you? It's the start of a model file your trying to produce. The list of numbers is related to the header above. The first 3 are position. The next 3 are for the normal's. Light direction. The last 2 are texture coords. Where the pixel is drawn. Complicated? :wink:
I wish that the CelestialMatters forum was still with us. Fridger wrote a perl script that does exactly what you want to do. But ....... I did this before. I'll do it again. Just need some more time to remember.
AMD A4-9125 RADEON R3, 4 COMPUTE CORES 2C+2G 2.30 GHz AMD Radeon(TM) R3 Graphics Running on Windows 10 and OpenSuse 15.2

Avatar
Topic author
CM1215 M
Posts: 219
Joined: 30.08.2017
Age: 19
With us: 3 years 9 months
Location: Ohio, U. S. A.

Post #28by CM1215 » 09.06.2021, 15:09

I attempted to process the mars heightmap using the script and the instructions you linked to above, however two problems arise:
1. The "Noise" button doesn't displace the mesh.
2. The script errors with the following message:

Code: Select all

Traceback (most recent call last):
  File "<string>", line 50, in ?
ZeroDivisionError: float division


I was using the Blender version indicated by the script (Blender 2.33).

Added after 3 hours 11 minutes:
Here are some topics in the Celestia Forums that might be of use to you as you remember how you did everything.

https://celestia.space/forum/viewtopic.php?t=8861
https://celestia.space/forum/viewtopic.php?f=5&t=9708

Unfortunately, the topic from the Celestial Matters forum that appears to me to be the one you were speaking of is not available in the archive.
CM1215: Celestial master in learning.

Avatar
cartrite
Posts: 1827
Joined: 15.09.2005
With us: 15 years 9 months
Location: Pocono Mountains, Pennsylvania, USA

Post #29by cartrite » 09.06.2021, 22:58

If you noticed the dates from the post it was 15 years ago. :wink: I still remember some of it but the thing is, more recently, I used a script written by Fridger and all the discussions were posted on CelestialMatters which apparently no longer exists. I could have sworn that it was part of the tools in Celestia. I also look though F-Tex tools also written by Fridger.

With Blender you should be able to accomplish what you want. I still have the cmod exporter written for Blender. The version of Blender you used is quite old. The latest version now is 2.8. Anyhow what I remember from those days is I subdivided the plane many more times. The reason you probably got the divide by zero error is because the plane was not displaced. And I'm not sure why that happened. I'm back at work for the rest of the week so I will look into updating the zfold script and the cmod exporter for Blender 2.8 this weekend.My work week started today and ends on Saturday evening.

Added after 3 hours 23 minutes:
OK, My memory is starting to return. I found this thread. https://celestia.space/forum/viewtopic.php?f=5&t=16195 I was looking though the files of my computer and found the perl script Fridger wrote. Unfortunately I now remember it was written for Phobos. Here is a link to the file he wrote it for. It's called m1phobos.tab. https://sbn.psi.edu/pds/resource/oshape.html You can open this in a text editor like notepad. You can see that the file lists lat and long coordinates with a height value. What I can remember doing now is writing a similar script that doesn't need the lat long coords. I calculated them based on which
'pixel' was being read. This was from pixel resolution in the map. This way I was able to use an ascii file with only numbers in the form of mars's radius in height values. Which is what I created last night. I don't have this script on my current computer I'm using. That computer is a PC and it's in storage miles away from where I currently live. But I should be able to write it again. Possibly this weekend.

Added after 3 minutes 15 seconds:
Here is the script that creates a Phobos model

Code: Select all

#!/usr/bin/perl
#
# Author Dr. Fridger Schrempp
# Version 1.0, 23.9.2009
#
open(CMOD, " > phobos_ascii.cmod") || die "Can not create phobos_ascii.cmod\n";

$pi = 3.14159265359;
$m = 90;
$mm = 2 * $m + 1;
#
# Read-in the generalized Phobos elevation map (m1phobos.tab),
# [lat, long, radius(lat,long)] , lat=-90 + 2*$i, long = 2*$j,
# $i = 0..90, $j = 0..180. South pole<=> $i=0, North pole <=> $i=90,
# 2 degree mesh
#
$l = 0;
while (<>) {

($lat,$long,$radius) = split (" ",$_);

# Polar angle $theta in radian

$theta = $pi/180.0 * ($lat - 90);

# Azimuthal angle $phi in radian

$phi = $pi/180.0 * $long;
 
# Convert to Carthesian coordinates ([km])
# Note: Celestia involves z <=> y exchange convention!

$x[$l] = $radius * cos($phi) * sin($theta);
$z[$l] = $radius * sin($phi) * sin($theta);
$y[$l] = $radius * cos($theta);

# 2D Texture coordinates ($s,$t):

$s[$l] = 0.5 * (1 - $phi/$pi);
$t[$l] = 1 - $theta/$pi;

$l++;
}

print CMOD "#celmodel__ascii\n";
print CMOD "\n";
print CMOD "material\n";
print CMOD "texture0 \"phobos.jpg\"\n";
print CMOD "diffuse 1 1 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 "texcoord0 f2\n";
print CMOD "end_vertexdesc\n";

$vertexcount = $l; # = $mm *($m + 1) = 16471
print CMOD "\nvertices $vertexcount\n";
#
# Print out vertices
#
for ($index=0; $index < $vertexcount; $index++){
   printf CMOD "%8.5f  %8.5f  %8.5f %8.5f %8.5f\n", $x[$index],$y[$index],$z[$index],$s[$index],$t[$index];
}

#
# Next, generate triangular faces
#
# First, calculate $facecount: Count in (i,j) cylindrical map with
# (2*$m + 1)*($m + 1) = 16471 vertices: it contains 2*$m * ($m-2)
# non-degenerate quadrilinear faces = 4*$m*($m-2) non-degenerate
# triangular faces and in addition 2*$m non-degenerate triangles from
# $i=0 row (South pole) and 2*$m such triangles from the $i=$m row
# (North pole). Altogether gives $facecount = 4 * $m * ($m -1) = 32040
#
# The 2*$m /degenerate/ triangles both in the $i=0 and $i=$m rows are
# left out!
#
$facecount = 4 * $m * ($m - 1);
$trival    = 3 * $facecount;

print CMOD "\ntrilist 0 $trival\n";
for ($i = 0; $i < $m; $i++){   
   for ($j = 0; $j < 2 * $m; $j++){
      $l1 = $mm * $i + $j;
      $l2 = $l1 + 1;
      $l4 = $l1 + $mm;
      $l3 = $l4 + 1;
      if ($i == 0) {printf CMOD "%6d  %6d  %6d\n",$l1,$l4,$l3;}
      elsif ($i == $m-1){printf CMOD "%6d  %6d  %6d\n",$l1,$l3,$l2;}
      else{printf CMOD "%6d  %6d  %6d\n%6d  %6d  %6d\n",$l1,$l3,$l2,$l1,$l4,$l3;}      
   }   
}   
print CMOD "\nend_mesh\n";



Added after 20 minutes 19 seconds:
I just ran it and produced a model of Phobos. I used this command on linux.

Code: Select all

/phobos_cmod.pl < m1phobos.tab
Here is the beginning of the file

Code: Select all

#celmodel__ascii

material
texture0 "phobos.jpg"
diffuse 1 1 1
end_material

mesh
vertexdesc
position f3
texcoord0 f2
end_vertexdesc

vertices 16471
 0.00000  -8.37260   0.00000  0.50000  2.00000
 .....................
  16287   16469   16288
 16288   16470   16289

end_mesh
When I get this done, you'll need to repeat that header 4 times for each cropped model tile and assign the texture of your choice. This is a single mesh model. You'll need to repeat the section above starting with material and all the numbers until end_mesh.

Added after 1 minute 17 seconds:
Then you'll have a single model with 4 meshes and 4 textures.

Added after 31 minutes 40 seconds:
Actually that was a bad example. This would be a better one. An ascii version of one of my mars models.

Code: Select all

#celmodel__ascii

material
diffuse 0.878431 0.878431 0.878431
specular 0.498039 0.498039 0.498039
texture0 "mars.*"
normalmap "mars-norm.*"
specularmap "spec.*"
end_material

material
diffuse 0.878431 0.878431 0.878431
specular 0.498039 0.498039 0.498039
texture0 "mons.*"
normalmap "mons-norm.*"
specularmap "tex-spec.*"
end_material

material
diffuse 0.878431 0.878431 0.878431
specular 0.498039 0.498039 0.498039
texture0 "valles.*"
normalmap "valless-norm.*"
specularmap "tex-spec.*"
end_material

mesh
vertexdesc
position f3
normal f3
texcoord0 f2
tangent f3
end_vertexdesc

vertices 33398
-0.276371 -0.314521 0.911074 -0.283303 -0.307809 0.908291 0.703125 0.601563 0.954877 -0.00238351 0.296991
Notice that I have 3 meshes. My material list are at the beginning of the file. You'll need to do something similar. But for 4 materials. Then My first mesh. Followed by end_mesh Then the next mesh and so on.

Added after 5 minutes 48 seconds:
Also each mesh should have it's trilist

Code: Select all

trilist 0 190464
14443 26153 16588 16589 16591 14442 26153 18560 16305 16303 16589 26152


Added after 32 minutes 49 seconds:
I created this video about 13 years ago of one of my mars models.https://www.youtube.com/watch?v=zmrJYZxJmtY
AMD A4-9125 RADEON R3, 4 COMPUTE CORES 2C+2G 2.30 GHz AMD Radeon(TM) R3 Graphics Running on Windows 10 and OpenSuse 15.2

Avatar
Topic author
CM1215 M
Posts: 219
Joined: 30.08.2017
Age: 19
With us: 3 years 9 months
Location: Ohio, U. S. A.

Post #30by CM1215 » 10.06.2021, 13:34

So it appears you have a good idea of the steps that must be taken to produce this high-definition model of Mars. While you work on rewriting your script, I'll try subdividing the plane many more times in Blender to see if I can get it to be displaced properly.

Also, thank you for the help you've given me thus far. It's been greatly appreciated!

cartrite wrote:I created this video about 13 years ago of one of my mars models.https://www.youtube.com/watch?v=zmrJYZxJmtY
That model looks incredible! What was the resolution of the texture you used? 32k? 64k? More?
CM1215: Celestial master in learning.

Avatar
Goofy
Posts: 279
Joined: 30.08.2011
With us: 9 years 9 months
Location: Italy

Post #31by Goofy » 10.06.2021, 13:59

Hi Cartrite.
If I don't mistake that should be your wonderful Vallis Marineris model, that I should have somewhere in my Celestia backups, is it that one? :think:
Bye

Goofy :smile:
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB

Avatar
cartrite
Posts: 1827
Joined: 15.09.2005
With us: 15 years 9 months
Location: Pocono Mountains, Pennsylvania, USA

Post #32by cartrite » 10.06.2021, 19:14

No. I call that one h344. The name of the group of files I used from Mars Express mission. The mesh from h344 was added to valles marinaris.

Added after 41 seconds:
marinates. Was added to Mars.
AMD A4-9125 RADEON R3, 4 COMPUTE CORES 2C+2G 2.30 GHz AMD Radeon(TM) R3 Graphics Running on Windows 10 and OpenSuse 15.2

Avatar
Goofy
Posts: 279
Joined: 30.08.2011
With us: 9 years 9 months
Location: Italy

Post #33by Goofy » 11.06.2021, 09:29

Oh, thank you.
It's very nice :) j
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB

Avatar
cartrite
Posts: 1827
Joined: 15.09.2005
With us: 15 years 9 months
Location: Pocono Mountains, Pennsylvania, USA

Post #34by cartrite » 12.06.2021, 03:45

Youall can play with this while I work on this. It may take a while.
3dmars-h344.zip
(24.44 MiB) Downloaded 12 times
Have fun. :hi:

Added after 6 minutes 9 seconds:
To get this to work you got to edit data/solarsys.ssc file.

Code: Select all

"Mars" "Sol"
{
    Class       "planet"
    #Texture     "mars.*"
    #BumpMap     "marsbump.*"
    #BumpHeight  2.5
    # NormalMap "mars-normal.*"
    Color       [ 1.0 0.75 0.7 ]
    Radius      3396.2
    Oblateness  0.00589
    Atmosphere

Bye

Added after 3 minutes 17 seconds:
Put # to comment out those lines above.
AMD A4-9125 RADEON R3, 4 COMPUTE CORES 2C+2G 2.30 GHz AMD Radeon(TM) R3 Graphics Running on Windows 10 and OpenSuse 15.2

Avatar
cartrite
Posts: 1827
Joined: 15.09.2005
With us: 15 years 9 months
Location: Pocono Mountains, Pennsylvania, USA

Post #35by cartrite » 13.06.2021, 22:07

The model I uploaded a few posts ago works great on linux. But I just tried it with windows 10 and it never loads. So something is really wrong with windows code.
AMD A4-9125 RADEON R3, 4 COMPUTE CORES 2C+2G 2.30 GHz AMD Radeon(TM) R3 Graphics Running on Windows 10 and OpenSuse 15.2


Return to “Modelling”

Who is online