Re: Re: BTG to OBJ

"Dale E. Edmons" <[email protected]> Fri, 19 Nov 2004 01:56:51 -0800
Newsgroups gmane.games.flightgear.terragear.devel
Message-ID <[email protected]>
Dale E. Edmons wrote:

> senthil kumar wrote:
>
>> Hai Dale,
>>
>>                        I would like to convert terrain and airports 
>> into OBJ format. I feel that BTG and OBJ are similar but there is no 
>> "tf" (Triangle Fan), "pt" (Points) and "ts" (Triangle strips) in OBJ. 
>> Please help me in converting these points (pt, tf, ts in BTG) into 
>> OBJ file.
>>  
>
Well, I can't take any credit for the work but I was able to convert 
KSFO.btg.gz to KSFO.obj.  I have no way to check the validity of the 
results (PPE seems to be broken again).  Here is what you can do:

    1) download & build the cvs version of fgsd.  Make sure you get the 
branch: with-CGAL-3.
       Read in the .btg.gz file of interest and export it in Ascii 
(file->export, Ascii + Force).

    2) run gzip -d on the .asc.gz and then rename the file from .asc to 
.atg (I gave the Ascii file the wrong extension in FGSD).

    3) compile the utility one of the PLIB developers sent me (attached 
files) then run:
          plibconvert file.atg file.obj

    4) you now have a file.obj in your directory.  You'll have to take 
it from here.... :)

Alternate for 1) if downloading fgsd (with-CGAL-3 branch cvs) isn't 
possible then you can try:
    1) go to SimGear-0.3.x/simgear/io and copy decode_binobj.cxx to 
btg2ascii.cxx
    2) edit the file to removing everything starting at cout<< "# FGFS 
scenery....
    3) insert code that includes:   obj.write_ascii( argv[2] );
    4) compile (you can use decode_binobj.cxx directly if you back it up 
first etc...)

I haven't tried or written any code to test this Alternate but I'll be 
working on something similar.  I want to be able to convert to PLIB's 
.flt format.  I've only tested one file using plibconvert.  It worked 
(.ac to .flt) but there were no textures, just a wireframe.

The Ascii created by FGSD is actually fgfs coordinates converted to 
UTM.  The center of the first tile is written to local_offset and then 
the difference between local_offset and each vertex  is written to the 
vertex in the .asc.gz (.atg.gz except I got the name wrong).  If you 
*must* have flat map type coordinates use FGSD Ascii.  If you *must* 
have FlightGear coordinates, use the Alternate.

I hope this helps.  It's the best I can do on short notice.  I'll be 
continuing development in this area so keep posted.


Dale

_______________________________________________
Terragear-devel mailing list
[email protected]
http://mail.flightgear.org/mailman/listinfo/terragear-devel
2f585eeea02e2c79d7b1d8c4963bae2d
plibconvert.cxx (text/x-c++src, 2.4 KB)
// plibconvert.cxx
//
// Build with
// g++ -o plibconvert plibconvert.cxx -lplibssg -lplibsg -lplibul -lGL


#include <assert.h>
#include <stdio.h>
#include <plib/ssg.h>

int main(int argc, char *argv[])
{
  if (argc!=3)
  {
    fprintf(stderr,"Usage: %s source destination\n", argv[0]);
    exit(1);
  }
  assert(strcmp(argv[1], argv[2]));
  ssgAddModelFormat ( ".ssg",   ssgLoadSSG  , ssgSaveSSG ) ;

  ssgAddModelFormat ( ".3ds",   ssgLoad3ds  , ssgSave3ds ) ;
  ssgAddModelFormat ( ".ac" ,   ssgLoadAC3D , ssgSaveAC  ) ;
  ssgAddModelFormat ( ".ase",   ssgLoadASE  , ssgSaveASE ) ;
  ssgAddModelFormat ( ".dof",   ssgLoadDOF  , NULL       ) ;
  ssgAddModelFormat ( ".dxf",   ssgLoadDXF  , ssgSaveDXF ) ;
  ssgAddModelFormat ( ".obj",   ssgLoadOBJ  , ssgSaveOBJ ) ;
  ssgAddModelFormat ( ".tri",   ssgLoadTRI  , ssgSaveTRI ) ;
  ssgAddModelFormat ( ".md2",   ssgLoadMD2  , NULL       ) ;
  ssgAddModelFormat ( ".x"  ,   ssgLoadX    , ssgSaveX   ) ;
  ssgAddModelFormat ( ".flt",   ssgLoadFLT  , ssgSaveFLT ) ;
  ssgAddModelFormat ( ".strip", ssgLoadStrip, NULL       ) ;
  ssgAddModelFormat ( ".m"  ,   ssgLoadM    , ssgSaveM   ) ;
  ssgAddModelFormat ( ".off"  , ssgLoadOFF  , ssgSaveOFF ) ;
  ssgAddModelFormat ( ".atg"  , ssgLoadATG  , ssgSaveATG ) ;
  ssgAddModelFormat ( ".qhi"  , NULL        , ssgSaveQHI ) ;
  ssgAddModelFormat ( ".wrl",   ssgLoadVRML1, ssgSaveVRML1 ) ;
  ssgAddModelFormat ( ".mac",   NULL	    , ssgSaveSPX ) ;	// SPX-200, proprietary	--d.e.e.
  ssgAddModelFormat ( ".spx",   NULL	    , ssgSaveSPX ) ;	// SPX-200, proprietary	--d.e.e.
  ssgAddModelFormat ( ".iv",    ssgLoadIV   , ssgSaveIV  ) ;
  ssgAddModelFormat ( ".asc",   ssgLoadASC  , ssgSaveASC ) ;
//ssgAddModelFormat ( ".pov",   NULL        , ssgSavePOV ) ;
  

  ssgEntity *e = ssgLoad(argv[1]);
  e->print(stdout);
  ssgSave(argv[2], e);
}
/*
The advantage is that it is commandline based, and does not
need the gui and render context. As a downside: an extremely
weird bug (somewhere in plib) makes it that tuxedo.ac
conversion gives a different output with this tool, than in
ppe.

I think it is related to the fact that I try to skip
ssgInit(), so that I dont have to create a GL render context.
The problem manifests itself in all texture filenames being
the same, even if tuxedo.ac uses 2 different filenames.
It's not a bug in ssgSaveIV, because after loading the ac,
the ssgEntity::print() shows the messed up filenames,
before ssgSave is called.

  Bram
*/
Makefile (text/plain, 257 B)
all:	plibconvert

plibconvert:	plibconvert.o
	g++ -o plibconvert plibconvert.o -lplibssg -lplibsg -lplibul -lGL

plibconvert.o:	plibconvert.cxx
	g++ -c plibconvert.cxx

clean:
	-rm *.o  plibconvert a.out

install:
	cp plibconvert /home/dale/terra/tgfs/bin