It is currently Thu, 14-12-17, 2:21 GMT

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Fri, 02-10-09, 16:09 GMT 
Offline
User avatar

Joined: Mon, 03-09-07, 23:01 GMT
Posts: 388
Location: Tuscany, Tyrrhenian Sea
Having spent some hours trying to learn more on Perl (BTW, very powerful language!) and analyzing phobos_cmod.pl I figured out a way to convert point clouds from .OBJ format to CMOD. When I render in .OBJ a set of data points I obtain (at least in my 3d modeller) a file so structured (here is shortening):

Code:
# File created by Luuv tsx 1.1.4
# Created on: Ott 02 14:31:18 2009
# Vertices: 26

v -43.4009 1.77351 -12.4959
v 9.63625 1.39427 16.1281
v -15.8813 15.4539 -32.2675
v -1.40235 -16.6047 -2.31708
v -0.807881 -12.1676 -2.18712
v -1.33854 1.64537 -15.2684
v -57.4847 4.01311 25.9169
v -1.72484 -15.9285 -2.09209
v -0.200683 -15.6711 -0.19031
v 0.13409 -14.9585 -2.46175
v 2.59238 13.124 9.64037
v 7.32817 6.11586 -14.5365
v 27.977 15.7262 22.3328
v -0.849096 -14.5154 -1.08298
v -0.211933 -13.5063 -0.949419
v -1.49628 -15.284 -0.183421
v -1.49917 -8.2716 -0.919193
v -0.353005 -10.311 -2.52
v -35.5242 8.8571 -14.1308
v 3.40951 -4.4969 1.38028
v 50.4466 11.9673 -8.6956
v -0.740291 -9.791 -0.768139
v -0.823455 -15.4874 -1.82547
v -0.8397 -14.8641 -0.255595
v -0.204464 -8.38986 -2.60387
v 0.750323 -15.3491 -1.51054


#                End of file


in which there are some comments about modeler or plugin. Now, when I apply this script:

Code:
#
# Author Fenerit <fenerit@interfree.it>
# Version 1.0, 02.10.2009

# Note: this Perl script is strongly based upon the phobos_cmod.pl
# script by Dr. Fridger Schrempp <www.celestialmatters.org>

# A prototype for converting .OBJ cloud points into
# proprietary Celestia CMOD format.

# Limitations: is required manual erasing of all that in the .OBJ file
# is not vertex related (headers, indent, comments).
#

open(CMOD, " > points2cmod.cmod") || die "Can not create points2cmod.cmod\n";

$l = 0;

while (<>) {

($vlett,$x,$y,$z) = split (" ",$_);

$vlett[$1] = $vlett; # index for .OBJ's letter text "v"
$x[$l] = $x;
$y[$l] = $y;
$z[$l] = $z;

$l++;
}

print CMOD "#celmodel__ascii\n";
print CMOD "\n";
print CMOD "material\n";
print CMOD "#texture0 \"your_texture.*\"\n";
print CMOD "#blend add\n";
print CMOD "#blend premultiplied\n";
print CMOD "diffuse 1 1 1\n";
print CMOD "#emissive 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;

print CMOD "\nvertices $vertexcount\n";

for ($index=0; $index < $vertexcount; $index++)
   {printf CMOD "%8.5f %8.5f %8.5f\n", $x[$index],$y[$index],$z[$index];}

print CMOD "\npoints 0 $vertexcount\n";

for ($index=0; $index < $vertexcount; $index++) # count n° points
   {printf CMOD "%6d\n", $i++;} # write n° points

print CMOD "\nend_mesh\n";


the output is so:

Code:
#celmodel__ascii

material
#texture0 "your_texture.*"
#blend add
#blend premultiplied
diffuse 1 1 1
#emissive 1 1 1
end_material

mesh
vertexdesc
position f3
#texcoord0 f2
end_vertexdesc

vertices 33
 0.00000  0.00000  0.00000
 0.00000  0.00000  0.00000
 0.00000 26.00000  0.00000
 0.00000  0.00000  0.00000
-43.40090  1.77351 -12.49590
 9.63625  1.39427 16.12810
-15.88130 15.45390 -32.26750
-1.40235 -16.60470 -2.31708
-0.80788 -12.16760 -2.18712
-1.33854  1.64537 -15.26840
-57.48470  4.01311 25.91690
-1.72484 -15.92850 -2.09209
-0.20068 -15.67110 -0.19031
 0.13409 -14.95850 -2.46175
 2.59238 13.12400  9.64037
 7.32817  6.11586 -14.53650
27.97700 15.72620 22.33280
-0.84910 -14.51540 -1.08298
-0.21193 -13.50630 -0.94942
-1.49628 -15.28400 -0.18342
-1.49917 -8.27160 -0.91919
-0.35301 -10.31100 -2.52000
-35.52420  8.85710 -14.13080
 3.40951 -4.49690  1.38028
50.44660 11.96730 -8.69560
-0.74029 -9.79100 -0.76814
-0.82346 -15.48740 -1.82547
-0.83970 -14.86410 -0.25560
-0.20446 -8.38986 -2.60387
 0.75032 -15.34910 -1.51054
 0.00000  0.00000  0.00000
 0.00000  0.00000  0.00000
 0.00000  0.00000  0.00000

points 0 33
     0
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32

end_mesh


Practically are computed also the comment line. Due to my ignorance in programming, I unable to erase and trim the redundant text both at init and at EOF! :cry: I say this because whether I manually erase them to obtain a structure likewise that:

Code:
v -43.4009 1.77351 -12.4959
v 9.63625 1.39427 16.1281
v -15.8813 15.4539 -32.2675
v -1.40235 -16.6047 -2.31708
v -0.807881 -12.1676 -2.18712
v -1.33854 1.64537 -15.2684
v -57.4847 4.01311 25.9169
v -1.72484 -15.9285 -2.09209
v -0.200683 -15.6711 -0.19031
v 0.13409 -14.9585 -2.46175
v 2.59238 13.124 9.64037
v 7.32817 6.11586 -14.5365
v 27.977 15.7262 22.3328
v -0.849096 -14.5154 -1.08298
v -0.211933 -13.5063 -0.949419
v -1.49628 -15.284 -0.183421
v -1.49917 -8.2716 -0.919193
v -0.353005 -10.311 -2.52
v -35.5242 8.8571 -14.1308
v 3.40951 -4.4969 1.38028
v 50.4466 11.9673 -8.6956
v -0.740291 -9.791 -0.768139
v -0.823455 -15.4874 -1.82547
v -0.8397 -14.8641 -0.255595
v -0.204464 -8.38986 -2.60387
v 0.750323 -15.3491 -1.51054


without spaces at init and at EOF, the result is so:

Code:
#celmodel__ascii

material
#texture0 "your_texture.*"
#blend add
#blend premultiplied
diffuse 1 1 1
#emissive 1 1 1
end_material

mesh
vertexdesc
position f3
#texcoord0 f2
end_vertexdesc

vertices 26
-43.40090  1.77351 -12.49590
 9.63625  1.39427 16.12810
-15.88130 15.45390 -32.26750
-1.40235 -16.60470 -2.31708
-0.80788 -12.16760 -2.18712
-1.33854  1.64537 -15.26840
-57.48470  4.01311 25.91690
-1.72484 -15.92850 -2.09209
-0.20068 -15.67110 -0.19031
 0.13409 -14.95850 -2.46175
 2.59238 13.12400  9.64037
 7.32817  6.11586 -14.53650
27.97700 15.72620 22.33280
-0.84910 -14.51540 -1.08298
-0.21193 -13.50630 -0.94942
-1.49628 -15.28400 -0.18342
-1.49917 -8.27160 -0.91919
-0.35301 -10.31100 -2.52000
-35.52420  8.85710 -14.13080
 3.40951 -4.49690  1.38028
50.44660 11.96730 -8.69560
-0.74029 -9.79100 -0.76814
-0.82346 -15.48740 -1.82547
-0.83970 -14.86410 -0.25560
-0.20446 -8.38986 -2.60387
 0.75032 -15.34910 -1.51054

points 0 26
     0
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25

end_mesh


which is what we need for put points in Celestia. Hope this thread might interesting someone.

EDIT LATER:

texcoord0 f2 may be commented (#texcoord0 f2).


Top
 Profile  
 
 Post subject:
PostPosted: Fri, 02-10-09, 22:48 GMT 
Offline
Site Admin
User avatar

Joined: Thu, 30-08-07, 22:52 GMT
Posts: 2726
Location: France, South, not far from Montpellier
Perso in such case, a quick conversion to 3DS in my modeler, then a cmod conversion via CmodTool and it's done.
But I agree a direct conversion via perl can be handy...


Top
 Profile  
 
 Post subject:
PostPosted: Fri, 02-10-09, 23:51 GMT 
Offline
Site Admin
User avatar

Joined: Fri, 31-08-07, 7:01 GMT
Posts: 4514
Location: Hamburg, Germany
ElChristou wrote:
Perso in such case, a quick conversion to 3DS in my modeler, then a cmod conversion via CmodTool and it's done.
But I agree a direct conversion via perl can be handy...


Wait a moment. We are talking about situations where ONLY the vertices are given, NOT the faces! How do you generate the faces after your quick conversion to 3DS in your modeler? That was the main purpose of my script.

Your modeler does not run on all OS, right? You probably use a VERY old version of CmodTools (1.0?) since it's not that easy to compile 3ds2cmod in Celestia 1.6.0 ;-)

A Perl script does NOT need any compilation after you made some quick changes and want to try them out. Perl is an interpreted language, still VERY fast. Perl is automatically implemented in MAC OS and Linux and can be easily installed in Windows...
The majority of the Celestia data base extraction (galaxies, globulars, binaries, stars) are ALL written in Perl for good reasons ;-) ...

Fridger


Top
 Profile  
 
 Post subject:
PostPosted: Sat, 03-10-09, 1:25 GMT 
Offline
Site Admin
User avatar

Joined: Thu, 30-08-07, 22:52 GMT
Posts: 2726
Location: France, South, not far from Montpellier
Right, Fenerit was taking about points only. Not sure about DW's CmodTools. As far as I know it's up to date with the tools available in Celestia source. Anyway I do agree Perl do have serious advantages... (of course once one is familiar with coding -- not my case unfortunately...)


Top
 Profile  
 
 Post subject:
PostPosted: Sat, 03-10-09, 11:59 GMT 
Offline
User avatar

Joined: Mon, 03-09-07, 23:01 GMT
Posts: 388
Location: Tuscany, Tyrrhenian Sea
t00fri wrote:
ElChristou wrote:
Perso in such case, a quick conversion to 3DS in my modeler, then a cmod conversion via CmodTool and it's done.
But I agree a direct conversion via perl can be handy...


Wait a moment. We are talking about situations where ONLY the vertices are given, NOT the faces! How do you generate the faces after your quick conversion to 3DS in your modeler? That was the main purpose of my script.

.
.

Fridger


Not only, but 3DS doesn't manage vertex anyhow. Modelers gets warnings whether one try to convert points in that format. For this OBJ is ideal. Again, it could to avoid the (in)famous 65k limit (which resemble the age of dinosaurs extinction :P ). In prospective, being here just points relate, without complete OBJ-CMOD conversion of ALL (faces, normals, etc..) my aim was that of to be ready for facing either a better Celestia vertex shader management or, more simply, the new particle engines, in which points could doing the part of a "general sketching" for the final particles rendering (together with others plains scientific data).


Top
 Profile  
 
 Post subject: New to perl
PostPosted: Fri, 09-10-09, 22:12 GMT 
Your code and its work looks interesting but I don't know perl that well. Can you point out some sites where I can learn more about it?


Top
  
 
 Post subject:
PostPosted: Sat, 10-10-09, 16:55 GMT 
Offline
User avatar

Joined: Mon, 03-09-07, 23:01 GMT
Posts: 388
Location: Tuscany, Tyrrhenian Sea
This site http://perldoc.perl.org/ is a Perl guide. It allow the download of it's HMTL pages.

_________________
Never at rest.


Top
 Profile  
 
 Post subject:
PostPosted: Mon, 16-11-09, 16:13 GMT 
Offline
User avatar

Joined: Mon, 03-09-07, 23:01 GMT
Posts: 388
Location: Tuscany, Tyrrhenian Sea
Time to update also this script. V.1.1. On the net I found an .OBJ vertex model in two version: one made with Lightwave and one with 3ds MAX.

LW version (shorten):

Code:
####
#
#   OBJ File Generated by LightWave3D
#   LightWave3D OBJ Export v2.2
#
####
#   Object: tree.obj
#
#                   Vertices: 482
#                     Points: 0
#                      Lines: 0
#                      Faces: 0
#                  Materials: 0
#
####

o tree.obj

#                Vertex list

v 2.657242 11.565883 1.947479
v 2.657242 11.343647 -0.308913
v 2.217041 11.343647 -0.265557
.
.
.

#                End of file


MAX version:

Code:
# Max2Obj Version 4.0 Mar 10th, 2001
#
mtllib ./tree.mtl
g
# object Tree01 to come ...
#
v  2.657242 11.565883 1.947479
v  2.657242 11.343647 -0.308913
v  2.217041 11.343647 -0.265557
.
.
.
# 482 vertices


g


The LW version add (16 comment lines + 1 uncomment) = 17 wrote lines at init of file and 1 at EOF. MAX version add 6 lines at init and 2 at end.
Now, since each 3d modeller ad its lines, the new script's version take in account this fact:

Code:
#    Author Fenerit <fenerit@interfree.it>
#    Version 1.1, 16.11.2009
#    This script convert an .OBJ vertex points file into an ascii CMOD format.
#   The resulting file can be loaded in Celestia as it is or previous conversion in binary form.
#   Acknowledgements: Dr. Fridger Schrempp <www.celestialmatters.org> for its basic routines.

#   USAGE:
#   1) Script and .OBJ' text files must be in the same folder;
#   2) Run the script. A new file called "points2cmod.cmod" will be created in the same folder;

   open(CMOD, " > points2cmod.cmod") || die "Can not create points2cmod.cmod\n";

   my $iof = 17;    # set the number of .OBJ's IOF text lines you want to skip (blank lines excluded);
   my $eof = 1;   # set the number of .OBJ's EOF text lines you want to skip (blank lines excluded);

   $l = 0;

   while (<>)
{
   next if (/^$/); # skip blank lines;
   
   ($vt,$x,$y,$z) = split (" ", $_);

   $vt[$1] = $vt; # index for .OBJ's letter text "v";
   $x[$l] = $x;
   $y[$l] = $y;
   $z[$l] = $z;

   $l++;
}

   print CMOD "#celmodel__ascii\n";
   print CMOD "\n";
   print CMOD "material\n";
   print CMOD "#texture0 \"your_texture.*\"\n";
   print CMOD "#blend add\n";
   print CMOD "#blend premultiplied\n";
   print CMOD "diffuse 1 1 1\n";
   print CMOD "#emissive 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;
   $tl = ($l - $iof) - $eof; # skip text/blank lines counting;

   print CMOD "\nvertices $tl\n";

   for ($index = $iof; ($index + $eof) < $vertexcount; $index++)
{   
   printf CMOD "%8.6f %8.6f %8.6f\n", ($x[$index],$y[$index],$z[$index]);
}

   printf CMOD "\npoints 0 $tl\n";

   for ($index = $iof; ($index + $eof) < $vertexcount; $index++) # count n° points;
{
   printf CMOD "%1d\n", $i++; # write n° points;
}

   print CMOD "\nend_mesh\n";

   print STDOUT "\n -- Done! The new Celestia CMOD model has now ", $tl, " vertex points --\n";


One can set the lines added by its favorite 3d modeler and they will be that whatever vertex has the model. Blank spaces will be skipped automatically. Is important that the blank lines to be not computed in. For LW example one would to set:

Code:
my $iof = 17;
my $eof = 1;   


and in MAX:

Code:
my $iof = 6;
my $eof = 2;   


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group