dimanche 21 octobre 2007



The second step of my work consisted in importing some 3D data in PostGIS. I decided to import data from the Collada format. Collada (COLLAborative Design Asset) is a 3D format which was initially developed by Sony. Indeed, it's the official format of the Playstation 3. Its aim is to be an exchange format. Most of 3d design software such as Blender, Maya, 3DSMax, can export collada. It is also used by GoogleEarth to represent 3d models with informations about colors or textures. In KMZ archives, you can find a kml file or a collada file.
So I developed a command which creates a SQL file from a collada file named collada2pgsql.

Here is the help of this command:


USAGE: collada2pgsql [options] colladafile [schema.]table

Set the SRID field. If not specified it defaults to -1.
Drops the table, then recreates it
with current collada file data.
Appends shape file into current ta
ble, must be exactly the same table schema.
!!!: The options -d and -a are mutually exclusive.

Specify the name of the geometry column (mostly useful in append mode).
Import collada file data with informations about textures.
Specify the directory where the textures will be stored.
default: '/tmp/textures'

Create a GiST index on the geometry column.
Display this help screen.


If the -g option is not given, the name of the geometry column will be 'the_geom'.

If the -t option is given, the import of the model will be done with information about textures: The user can specify the directory with -dir option, where he wants the textures to be stored (default : /tmp/textures). There also will be two others columns named 'the_texture' which contains the absolute path (or url) of a picture, and 'coorduv' which is a 2D geometry column giving relations between faces and textures.


Let's see an example with the collada file 'pompidou.dae' providing from a GoogleEarth KMZ archive. You can find a lot of these kind of archives here.
Here is the command I have to execute if I want to import it with textures, stored in /home/textures/pompidou and if I want a give the SRID 27582 to my geometry:


collada2pgsql -t -dir /home/mleserre/Desktop/textures/pompidou -s 27582 pompidou.dae mytable

by executing this command, you'll see this in your window:


version 1.4.1
building sql file...
file pompidou.sql has been created

You must execute it from the directory where the collada file stands.

If you don't precise the target directory for the textures , they will be stored in /tmp/textures:


collada2pgsql -t -s 27582 pompidou.dae mytable

Here is the result, in a SQL file named pompidou.sql:

Now, we just have to execute the following command where MABASE is the name of the database in which I want to import my geometries :


psql -U postgres MABASE < pompidou.sql

If you want to see what stands in mytable, just try this command, after connecting to MABASE:


SELECT summary(the_geom), the_texture, summary(coorduv) from mytable;


and you'll see that in your window:


1 commentaire:

Sjoerd a dit…


I'm currently working on 3D inside panoramic images using postgresql+postgis to serve 3D vector data using deegree-wfs.

I would like to populate the postgis DB more with some dae modules. Can you provide me a link to your conversion tool collada2pgsql?

Thanks a lot,