CMOD to OBJ+MTL converter

Here you find pointers to utilities that help you create addons for Celestia.
Topic author
ajtribick
Developer
Posts: 1855
Joined: 11.08.2003
With us: 20 years 8 months

CMOD to OBJ+MTL converter

Post #1by ajtribick » 10.04.2021, 17:09

I've put together a CMOD to Wavefront OBJ+MTL converter. It's still very preliminary and probably full of bugs (as distinct from limitations caused by the file formats not supporting identical feature sets) but I managed to load the result of converting the default ISS model into Blender. You will need to compile it from source yourself (C#/.NET 5.0).

https://github.com/ajtribick/cmodconvert

Hope this is useful for some people.
Last edited by ajtribick on 11.04.2021, 13:32, edited 1 time in total.

Topic author
ajtribick
Developer
Posts: 1855
Joined: 11.08.2003
With us: 20 years 8 months

Post #2by ajtribick » 11.04.2021, 10:18

While the CMOD ASCII format is documented, as far as I'm aware this hasn't been done for the binary format. I've included the places in the Celestia code base where the enums are defined.

Values are stored in a little-endian format.

Tokens are 16-bit integers. The values are defined in modelfile.h, the equivalents to the CMOD ASCII keywords are as follows:

1001 - material
1002 - end_material
1003 - diffuse
1004 - specular
1005 - specpower
1006 - opacity
1007 - texture
1009 - mesh
1010 - end_mesh
1011 - vertexdesc
1012 - end_vertexdesc
1013 - vertices
1014 - emissive
1015 - blend

Texture semantics are 16-bit integers. These correspond to the numeric values at the end of the "texture" and "texcoord" tokens in the ASCII file. Texture semantics are defined in material.h as follows:

0 - diffuse (texture0, texcoord0)
1 - normal (texture1, texcoord1)
2 - specular (texture2, texcoord2)
3 - emissive (texture3, texcoord3)

Data types (used in the material definitions) are 16-bit integers. The values are defined in modelfile.h:

1 - float1
2 - float2
3 - float3
4 - float4
5 - string
6 - uint32
7 - color

Blend modes are 16-bit integers. The values are defined in material.h, the equivalents to CMOD ASCII keywords are as follows:

0 - normal
1 - add
2 - premultiplied

Vertex attribute semantics are 16-bit integers. The values are defined in mesh.h, the equivalents to CMOD ASCII keywords are as follows:

0 - position
1 - color0
2 - color1
3 - normal
4 - tangent
5 - texcoord0
6 - texcoord1
7 - texcoord2
8 - texcoord3
9 - pointsize
10 - no ASCII equivalent (nextposition) - is this used?
11 - no ASCII equivalent (scalefactor) - is this used?

Vertex attribute formats are 16-bit integers. The values are defined in mesh.h, the equivalents to CMOD ASCII keywords and the corresponding data format are as follows:

0 - f1 - 1×32-bit float value
1 - f2 - 2×32-bit float values
2 - f3 - 3×32-bit float values
3 - f4 - 4×32-bit float values
4 - ub4 - 4×unsigned bytes

Primitive types are 16-bit integers. The values are defined in mesh.h, the equivalents to CMOD ASCII keywords are as follows:

0 - trilist
1 - tristrip
2 - trifan
3 - linelist
4 - linestrip
5 - points
6 - sprites

Overall file structure is essentially the same as a CMOD ASCII file, encoded as follows:

  • 16-byte header "#celmodel_binary" (ASCII encoded)
  • One or more materials (see below)
  • One or more meshes (see below)

Materials are encoded as follows:

  • Token "material" (1001)
  • One or more of the following properties:
    • Token "diffuse" (1003), data type "color" (7), followed by 3×32-bit float values r, g, b.
    • Token "specular" (1004), data type "color" (7), followed by 3×32-bit float values r, g, b.
    • Token "specpower" (1005), data type "float1" (1), followed by a 32-bit float value.
    • Token "opacity" (1006), data type "float1" (1), followed by a 32-bit float value.
    • Token "texture" (1007), texture semantic, data type "string" (5), followed by unsigned 16-bit integer length value, followed by specified number of ASCII-encoded bytes.
    • Token "emissive" (1014), data type "color" (7), followed by 3×32-bit float values r, g, b.
    • Token "blend" (1015), followed by a blend mode.
  • Token "end_material" (1002)

Meshes are encoded as follows:

  • Token "mesh" (1009)
  • Vertex description
    • Token "vertexdesc" (1011)
    • One or more vertex description entries, each of which consists of:
      • Vertex attribute semantic
      • Vertex attribute format
    • Token "end_vertexdesc" (1012)
  • Vertex data, consisting of:
    • Token "vertices" (1013)
    • Unsigned 32-bit integer vertex count
    • vertex count×vertex data in format given by the vertex description.
  • One or more primitives, each of which consists of:
    • Primitive type
    • 32-bit unsigned integer material index
    • 32-bit unsigned integer index count
    • index count×32-bit unsigned integer vertex indices
  • Token "end_mesh" (1010)

Topic author
ajtribick
Developer
Posts: 1855
Joined: 11.08.2003
With us: 20 years 8 months

Post #3by ajtribick » 22.04.2021, 19:01

Made a few minor changes and cleanup (the main difference from the end-user perspective is that the correct version gets displayed if you pass in the --version parameter). New version is v0.1.0-beta3.

For those who don't want to compile it themselves, I've added a cross-platform framework-dependent binary on the release page, this can be run (assuming you have the .NET 5.0 runtime installed and present in your path) using:

Code: Select all

dotnet CmodConvert.dll [options]


As indicated by the "beta" in the version number, I consider this code as being in a "prerelease" state. Make sure to read the README file.

NASA_SimGuy
Posts: 24
Joined: 18.10.2018
With us: 5 years 6 months

Post #4by NASA_SimGuy » 14.07.2021, 15:19

I read one of Chris' post that there is a CMOD ascii to binary converter called Cmodview. I tried the URL but it is no longer available. Does someone have this or something comparable? I am using Windows.

Avatar
SevenSpheres
Moderator
Posts: 820
Joined: 08.10.2019
With us: 4 years 7 months

Post #5by SevenSpheres » 14.07.2021, 15:35

NASA_SimGuy wrote:I read one of Chris' post that there is a CMOD ascii to binary converter called Cmodview. I tried the URL but it is no longer available. Does someone have this or something comparable? I am using Windows.

The cmodview download link is here.
My Addons: viewtopic.php?f=23&t=19978 • Discord server admin
Celestia versions: 1.5.1, 1.6.1, 1.6.2, 1.7.0, and some unofficial versions like Celestia-ED

NASA_SimGuy
Posts: 24
Joined: 18.10.2018
With us: 5 years 6 months

Post #6by NASA_SimGuy » 14.07.2021, 16:58

It appears that the link is broke:

Information
The selected attachment does not exist anymore.

Do you have a zip file you can post?

Avatar
SevenSpheres
Moderator
Posts: 820
Joined: 08.10.2019
With us: 4 years 7 months

Post #7by SevenSpheres » 14.07.2021, 17:07

NASA_SimGuy wrote:It appears that the link is broke:

So it is... Here's the zip file; I'll see if I can get the link fixed.
cmodview.zip
(5.44 MiB) Downloaded 2104 times


Update: the above zip file is now linked from the Utilities page.
My Addons: viewtopic.php?f=23&t=19978 • Discord server admin
Celestia versions: 1.5.1, 1.6.1, 1.6.2, 1.7.0, and some unofficial versions like Celestia-ED

Topic author
ajtribick
Developer
Posts: 1855
Joined: 11.08.2003
With us: 20 years 8 months

Post #8by ajtribick » 14.11.2021, 12:40

Created v0.1.0 release version, the only change is it now uses .NET 6.0 (LTS).
https://github.com/ajtribick/cmodconvert/releases/tag/v0.1.0


Return to “Utilities”