@@ -522,7 +522,7 @@ class standardAttributes(baseObj):
522
522
['visible' ],
523
523
[]],
524
524
'compound' :[['pos' , 'color' , 'trail_color' ],
525
- ['axis' , 'size' , 'up' ],
525
+ ['axis' , 'size' , 'up' , 'origin' ],
526
526
['visible' , 'opacity' ,'shininess' , 'emissive' ,
527
527
'make_trail' , 'trail_type' , 'interval' , 'texture' ,
528
528
'retain' , 'trail_color' , 'trail_radius' , 'obj_idxs' , 'pickable' ],
@@ -1528,32 +1528,34 @@ def size(self,value): # compound axis and size don't interact
1528
1528
if not self ._constructing :
1529
1529
self .addattr ('size' )
1530
1530
1531
- def _world_zaxis (self ):
1532
- axis = self ._axis
1533
- up = norm (self ._up )
1534
- if abs (axis .dot (up )) / sqrt (axis .mag2 ) > 0.98 :
1535
- if abs (norm (axis ).dot (vector (- 1 ,0 ,0 ))) > 0.98 :
1536
- z_axis = axis .cross (vector (0 ,0 ,1 )).norm ()
1537
- else :
1538
- z_axis = axis .cross (vector (- 1 ,0 ,0 )).norm ()
1539
- else :
1540
- z_axis = axis .cross (up ).norm ()
1541
- return z_axis
1531
+ @property
1532
+ def origin (self ):
1533
+ return self ._origin
1534
+ @origin .setter
1535
+ def origin (self ,value ): # compound origin cannot be reset
1536
+ if not self ._constructing :
1537
+ raise AttributeError ('The compound "origin" attribute is read-only; change "pos" instead.' )
1538
+ self ._origin = value
1542
1539
1543
1540
def world_to_compound (self , v ):
1544
- axis = self ._axis
1545
- z_axis = self ._world_zaxis ()
1546
- y_axis = z_axis .cross (axis ).norm ()
1547
- x_axis = axis .norm ()
1548
- v = v - self ._pos
1549
- return vector (v .dot (x_axis ), v .dot (y_axis ), v .dot (z_axis ))
1541
+ v = v - self ._pos
1542
+ x_axis = self ._axis .hat
1543
+ y_axis = self ._up .hat
1544
+ z_axis = x_axis .cross (y_axis )
1545
+ ox = self ._size0 .x / self ._size .x # _size0 is the original size
1546
+ oy = self ._size0 .y / self ._size .y
1547
+ oz = self ._size0 .z / self ._size .z
1548
+ return self ._origin + vector (v .dot (x_axis )* ox , v .dot (y_axis )* oy , v .dot (z_axis )* oz )
1550
1549
1551
1550
def compound_to_world (self , v ):
1552
- axis = self ._axis
1553
- z_axis = self ._world_zaxis ()
1554
- y_axis = z_axis .cross (axis ).norm ()
1555
- x_axis = axis .norm ()
1556
- return self ._pos + (v .x * x_axis ) + (v .y * y_axis ) + (v .z * z_axis )
1551
+ v = v - self ._origin
1552
+ x_axis = self ._axis .hat
1553
+ y_axis = self ._up .hat
1554
+ z_axis = x_axis .cross (y_axis )
1555
+ ox = self ._size .x / self ._size0 .x # _size0 is the original size
1556
+ oy = self ._size .y / self ._size0 .y
1557
+ oz = self ._size .z / self ._size0 .z
1558
+ return self ._pos + v .x * ox * x_axis + v .y * oy * y_axis + v .z * oz * z_axis
1557
1559
1558
1560
class vertex (standardAttributes ):
1559
1561
def __init__ (self , ** args ):
@@ -3104,6 +3106,7 @@ def handle_event(self, evt): ## events and scene info updates
3104
3106
self .mouse .setpick ( evt )
3105
3107
self ._waitfor = True # what pick is looking for
3106
3108
elif ev == '_compound' : # compound, text, extrusion
3109
+ print ('compound event return' )
3107
3110
obj = self ._compound
3108
3111
p = evt ['pos' ]
3109
3112
if obj ._objName == 'text' :
@@ -3115,7 +3118,7 @@ def handle_event(self, evt): ## events and scene info updates
3115
3118
# on_change functions that detect changes in e.g. obj.pos.y
3116
3119
obj ._pos .value = list_to_vec (p )
3117
3120
s = evt ['size' ]
3118
- obj ._size .value = list_to_vec (s )
3121
+ obj ._size .value = obj . _size0 = list_to_vec (s )
3119
3122
obj ._axis .value = obj ._size ._x * norm (obj ._axis )
3120
3123
obj ._up .value = list_to_vec (evt ['up' ])
3121
3124
self ._waitfor = True # what compound and text and extrusion are looking for in _wait()
0 commit comments