CMOD structure

All about models for Celestia. How-to, programs, work in progress...
Avatar
Topic author
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 11 months

CMOD structure

Post #1by Chuft-Captain » 25.09.2012, 14:50

I would like to rotate a single mesh (through 45 degrees) in a CMOD model.

Obviously, if I could convert the CMOD and make the modification in for example Anim8tor, that would be the easiest way to approach it.
But, as far as I know, there's no tools out there to convert CMOD's into 3ds or any other format that can be loaded into a modelling tool. (The only tool I'm aware of that loads CMOD's is Chris' cmodview utility).
(If anyone knows of a [ CMOD -> other modelling format ] conversion utility, then please let me know, and the remainder of this post will then become moot. :) )

Assuming there is no such tool, then that option's not available.
So, as it's such a simple transformation, I thought I would tackle it by editing the ascii CMOD directly and applying a little simple trigonometry to selected vertices.

There's quite a good Backus Naur description of the CMOD structure here: http://www.lns.cornell.edu/~seb/celestia/cmod_format.html, however, it doesn't document exactly what the eight values of each vertex represents.
All it has on this aspect is:

Code: Select all

              <vertex_pool>         ::= vertices <count>
                                         { <float> }

(I'm assuming that we're dealing with a -1 to +1 normalized 3D space and that the X,Y,Z coordinates of each vertex is represented by at least 3 of those values. )

The question I have though, is:
Which of the eight values represents the X, Y, and Z positions respectively? Here's the very simple example used in that WIKI page:

Code: Select all

mesh
vertexdesc
position f3
normal f3
texcoord0 f2
end_vertexdesc

vertices 6
0 0 0 0 0 1 0 0
1 1 0 0 0 1 1 1
0 1 0 0 0 1 0 1
0 1 0 0 0 -1 0 1
1 1 0 0 0 -1 1 1
0 0 0 0 0 -1 0 0

trilist 0 3
0 1 2
trilist 1 3
3 4 5

end_mesh


In order to do the transform, I need to know which values represent which axis.
If I want to rotate in the Z-axis (X-Y plane) then I only need to modify the X and Y values, if in the X-axis, then only the Y-Z values are modified,.. etc...
(I'm assuming that I won't have to make any changes to the trilists.)

Can anyone elaborate on the definitions of these 8 attributes? (and incidentally, why are there 8, rather than just 3?.. what do the other 5 represent?)

Cheers
CC
Last edited by Chuft-Captain on 27.09.2012, 01:18, edited 1 time in total.
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Re: CMOD structure

Post #2by selden » 25.09.2012, 19:23

Sorry: I dunno which coordinate is supposed to be which axis. I usually modify the rotation code in my CMOD generation programs until the object is oriented the way "it should be" in Celestia.

The uses of the values are specified by the vertexdesc block which is included in your example above. It specifies what values are being provided and their order.
vertexdesc
position f3 # position of vertex in 3-space [in the model's own coordinate system]
normal f3 # direction of vertex's surface normal
texcoord0 f2 # xy position within the surface texture image which is placed at this vertex
end_vertexdesc
Selden

Avatar
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 8 months
Location: Thyrrenian sea

Re: CMOD structure

Post #3by Fenerit » 25.09.2012, 22:41

The vertex semantic should be:
vertex position (xyz) | normals of (xyz) | texture coordinates (xy) | tangents of (xyz)

options are: ...| pointsize(float) | pointcolor(rgba)

The vertex orientation shifts y <-> z axis; that is, if a CMOD model is converted like it is, should be ready for Lightwave's axis orientation, while if you want the 3DStudio MAX or Blender orientation, you must shift the y <-> z axis in seat of conversion; or at least, does re-orient the model within the 3D modeler itself.

-
Never at rest.
Massimo

Avatar
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 8 months
Location: Thyrrenian sea

Re: CMOD structure

Post #4by Fenerit » 26.09.2012, 00:05

The rotation about the shift y <-> z axis is matter of -x vertex.
Never at rest.
Massimo

Avatar
Topic author
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 11 months

Re: CMOD structure

Post #5by Chuft-Captain » 27.09.2012, 00:36

selden wrote:Sorry: I dunno which coordinate is supposed to be which axis. I usually modify the rotation code in my CMOD generation programs until the object is oriented the way "it should be" in Celestia.

The uses of the values are specified by the vertexdesc block which is included in your example above. It specifies what values are being provided and their order.
vertexdesc
position f3 # position of vertex in 3-space [in the model's own coordinate system]
normal f3 # direction of vertex's surface normal
texcoord0 f2 # xy position within the surface texture image which is placed at this vertex
end_vertexdesc
Sorry guys, I should have been clearer in my original post. - I'm trying to rotate only a single mesh (one of many individual meshes in the CMOD), rather than rotate the entire model.
ie. I want to change the orientation of that single part of the model relative to it's other parts.
(This has nothing at all to do with the known issue regarding 3DS versus CMOD orientation in Celestia.)

However, your explanation is still helpful, because I now have clicked as to what those descriptions mean. (f3 means: 3 x floats, etc.. thus 8 floats altogether. :) )
I also found by experimentation that the first 3 represent X,Y,Z positions (where X is horizontal, Y is vertical, and Z is out of the screen, when the model is first opened with cmodviewer.), and I was able to rotate the simple triangle above thru 45 degrees.
Clearly though, I'll have to perform the equivalent transformation on the normals as well.
(Might get away with not rotating the texture coordinates, but I suspect I will probably have to reposition those as well.)

Incidentally, I couldn't work out why there were 6 vertices for a single triangle, then I realized it was double sided.
One side:

Code: Select all

0 0 0 0 0 1 0 0
1 1 0 0 0 1 1 1
0 1 0 0 0 1 0 1

... and the other side with it's normals reversed:

Code: Select all

0 1 0 0 0 -1 0 1
1 1 0 0 0 -1 1 1
0 0 0 0 0 -1 0 0


Getting there....

The key thing, for a more complicated mesh than this extremely simple test case, will be to make sure that the phase of the chosen TRIG function is correct so that all the vertices end up in the appropriate quadrant.

Cheers
CC

PS. FWIW, here's the example above, with the addition of a duplicate rotated thru 45 degrees in the Y-axis. - position and normals only.
(Save as a CMOD and open with cmodviewer)

Code: Select all

#celmodel__ascii

mesh
vertexdesc
position f3
normal f3
texcoord0 f2
end_vertexdesc

vertices 6
0 0 0 0 0 1 0 0
1 1 0 0 0 1 1 1
0 1 0 0 0 1 0 1
0 1 0 0 0 -1 0 1
1 1 0 0 0 -1 1 1
0 0 0 0 0 -1 0 0

trilist 0 3
0 1 2
trilist 1 3
3 4 5

end_mesh


mesh
vertexdesc
position f3
normal f3
texcoord0 f2
end_vertexdesc

vertices 6
0 0 0 -0.707 0 0.707 0 0
0.707 1 0.707 -0.707 0 0.707 1 1
0 1 0 -0.707 0 0.707 0 1
0 1 0 0.707 0 -0.707 0 1
0.707 1 0.707 0.707 0 -0.707 1 1
0 0 0 0.707 0 -0.707 0 0

trilist 0 3
0 1 2
trilist 1 3
3 4 5

end_mesh


triangle-test.JPG
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS


Return to “Modelling”