saving a geometry in postgis from blender

653 Views Asked by At

Say I have a cube or more complex closed triangulated object in Blender, how would I be able to store this in postgis?

Postgis stores 3D geometry via well-known text (wkt) as a polyhedral or tin. Is there any way to get a blender object into postgis?

1

There are 1 best solutions below

2
sambler On

You read blenders data and create insert statements for postgresql. As blender contains a python interpreter, you can run a python script in blender that sends the data to postgresql.

The first step is installing a python postgresql module, such as psycopg that can be used within blender. There are several options for this, including adding a path to sys.path.

Once you can run a python script in blender that can talk to a postgresql server, read blenders mesh data to generate the insert statements.

pg_insert = 'INSERT INTO mytable (v_loc) VALUES ('
for v in obj.data.vertices:
    pg_insert += 'POINT({} {} {}),'.format(v.co.x, v.co.y, v.co.z)
pg_insert += ');'