Skip to content

Commit dbb1a6f

Browse files
committed
support separate objects
1 parent c774fd1 commit dbb1a6f

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

operators/mesh_earth_sphere.py

+23-20
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def lonlat2xyz(R, lon, lat):
1414
x = R * cos(lat) * cos(lon)
1515
y = R * cos(lat) * sin(lon)
1616
z = R *sin(lat)
17-
return (x, y, z)
17+
return Vector((x, y, z))
1818

1919

2020
class OBJECT_OT_earth_sphere(Operator):
@@ -27,28 +27,31 @@ class OBJECT_OT_earth_sphere(Operator):
2727

2828
def execute(self, context):
2929
scn = bpy.context.scene
30-
obj = bpy.context.view_layer.objects.active
31-
32-
if not obj:
33-
self.report({'INFO'}, "No active object")
34-
return {'CANCELLED'}
35-
36-
if obj.type != 'MESH':
37-
self.report({'INFO'}, "Selection isn't a mesh")
38-
return {'CANCELLED'}
30+
objs = bpy.context.selected_objects
3931

40-
w, h, thick = obj.dimensions
41-
if w > 360:
42-
self.report({'INFO'}, "Longitude exceed 360°")
43-
return {'CANCELLED'}
44-
if h > 180:
45-
self.report({'INFO'}, "Latitude exceed 360°")
32+
if not objs:
33+
self.report({'INFO'}, "No selected object")
4634
return {'CANCELLED'}
4735

48-
mesh = obj.data
49-
for vertex in mesh.vertices:
50-
lon, lat = vertex.co.x, vertex.co.y
51-
vertex.co = lonlat2xyz(self.radius, lon, lat)
36+
for obj in objs:
37+
if obj.type != 'MESH':
38+
log.warning("Object {} is not a mesh".format(obj.name))
39+
continue
40+
41+
w, h, thick = obj.dimensions
42+
if w > 360:
43+
log.warning("Longitude of object {} exceed 360°".format(obj.name))
44+
continue
45+
if h > 180:
46+
log.warning("Latitude of object {} exceed 180°".format(obj.name))
47+
continue
48+
49+
mesh = obj.data
50+
m = obj.matrix_world
51+
for vertex in mesh.vertices:
52+
co = m @ vertex.co
53+
lon, lat = co.x, co.y
54+
vertex.co = m.inverted() @ lonlat2xyz(self.radius, lon, lat)
5255

5356
return {'FINISHED'}
5457

0 commit comments

Comments
 (0)