@@ -14,7 +14,7 @@ def lonlat2xyz(R, lon, lat):
14
14
x = R * cos (lat ) * cos (lon )
15
15
y = R * cos (lat ) * sin (lon )
16
16
z = R * sin (lat )
17
- return ( x , y , z )
17
+ return Vector (( x , y , z ) )
18
18
19
19
20
20
class OBJECT_OT_earth_sphere (Operator ):
@@ -27,28 +27,31 @@ class OBJECT_OT_earth_sphere(Operator):
27
27
28
28
def execute (self , context ):
29
29
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
39
31
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" )
46
34
return {'CANCELLED' }
47
35
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 )
52
55
53
56
return {'FINISHED' }
54
57
0 commit comments