I'm hardly trying to extract data o polygons from Blender to PostGIS via Python. For the beginning I'm trying all this stuff with a simple cube. At all I want to get a pure POLYGON - GEOMETRY-Type in PostGIS which looks like POLYGON((x1 y1 z1, x2 y2 z2,.....)) I can read information from Blender in this way:
The vectors:
verts=[
<Vector (1.0000, 1.0000, -1.0000)> ,
<Vector (1.0000, -1.0000, -1.0000)> ,
<Vector (-1.0000, -1.0000, -1.0000)> ,
<Vector (-1.0000, 1.0000, -1.0000)> ,
<Vector (1.0000, 1.0000, 1.0000)> ,
<Vector (1.0000, -1.0000, 1.0000)> ,
<Vector (-1.0000, -1.0000, 1.0000)> ,
<Vector (-1.0000, 1.0000, 1.0000)> ,
]
and the faces (the numbers are the vertices which form a polygon):
faces = [
(0, 1, 2, 3)
(4, 7, 6, 5)
(0, 4, 5, 1)
(1, 5, 6, 2)
(2, 6, 7, 3)
(4, 0, 3, 7)
]
Now I don't know how to get this information into a POLYGON-GEOMETRY-structure to store it in PostgreSQL/PostGIS.
In the end I want a POLYGON((...)) for each face of the cube. And I want to do this for more complex 3D-models out of Blender. With POLYGON- or TIN-GEOMETRY.... But at first I need to know how to interact with the geometries with Python.
I hope you can get me a little further. I'm thankful for any hint. Thanks! J
I am not quite sure about the Blender's internal object model so I have created some dummy data for that. But I think the end result should be close to what you are looking for:
verts = [[1.0,-1.0,0.0]]*8
faces = [
(0, 1, 2, 3),
(4, 7, 6, 5),
(0, 4, 5, 1),
(1, 5, 6, 2),
(2, 6, 7, 3),
(4, 0, 3, 7),
]
# ---------------------------------------------
# PostGIS POLYGON data formatting happens next
for f in faces:
print("POLYGON((", end="")
for point in f:
v = verts[point]
print("{} {} {} ".format(v[0], v[1], v[2]), end="")
print("))")
# Will print....
# POLYGON((1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 ))
# POLYGON((1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 ))
# POLYGON((1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 ))
# POLYGON((1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 ))
# POLYGON((1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 ))
# POLYGON((1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 ))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.