Swizzle properties for Mathutils.Vector #18678

Closed
opened 2009-05-03 14:13:33 +02:00 by Alex Fraser · 5 comments
Member

%%%Allows access to elements of vectors in any order. The getter functions all return a Vector object with the new arrangement of axes. For example:

  vec = Mathutils.Vector([1,2,3])
  print vec.zxy
# prints "[3.000000, 1.000000, 2.000000](vector)"

Setters can take a vector, list or scalar as the value. If the value is scalar, it is copied to all axes listed in the swizzle. If an axis appears more than once in the swizzle, the final occurrance is the one that determines its value.

  vec = Blender.Mathutils.Vector([1, 2, 3, 4])
  vec.xxxx = 10
  print vec
# prints "[10.000000, 2.000000, 3.000000, 4.000000](vector)"

If value is a vector or list this operates like an array copy, except that the destination is effectively re-ordered as defined by the swizzle. At most min(len(source), len(dest)) values will be copied.

  vec.zxy = [1, 2, 3]
  print vec
# prints "[2.000000, 3.000000, 1.000000, 4.000000](vector)"
  vec.zxy = Blender.Mathutils.Vector([1, 2, 3, 5000])
  print vec
# prints "[2.000000, 3.000000, 1.000000, 4.000000](vector)"

This can be used to rotate axes in wonderful ways!

  vec = Blender.Mathutils.Vector([1, 2, 3, 4])
  vec.wxzy = vec.yzxw
  print vec
# prints "3.000000, 4.000000, 1.000000, 2.000000](vector)"

More information on swizzling is available here:
http://en.wikipedia.org/wiki/Swizzling_(computer_graphics)

See attached TestVector.blend for a set of unit tests. Tested so far on an Intel Core 2 Duo.%%%

%%%Allows access to elements of vectors in any order. The getter functions all return a Vector object with the new arrangement of axes. For example: ``` vec = Mathutils.Vector([1,2,3]) print vec.zxy ``` # prints "[3.000000, 1.000000, 2.000000](vector)" Setters can take a vector, list or scalar as the value. If the value is scalar, it is copied to all axes listed in the swizzle. If an axis appears more than once in the swizzle, the final occurrance is the one that determines its value. ``` vec = Blender.Mathutils.Vector([1, 2, 3, 4]) ``` ``` vec.xxxx = 10 ``` ``` print vec ``` # prints "[10.000000, 2.000000, 3.000000, 4.000000](vector)" If value is a vector or list this operates like an array copy, except that the destination is effectively re-ordered as defined by the swizzle. At most min(len(source), len(dest)) values will be copied. ``` vec.zxy = [1, 2, 3] ``` ``` print vec ``` # prints "[2.000000, 3.000000, 1.000000, 4.000000](vector)" ``` vec.zxy = Blender.Mathutils.Vector([1, 2, 3, 5000]) ``` ``` print vec ``` # prints "[2.000000, 3.000000, 1.000000, 4.000000](vector)" This can be used to rotate axes in wonderful ways! ``` vec = Blender.Mathutils.Vector([1, 2, 3, 4]) ``` ``` vec.wxzy = vec.yzxw ``` ``` print vec ``` # prints "3.000000, 4.000000, 1.000000, 2.000000](vector)" More information on swizzling is available here: http://en.wikipedia.org/wiki/Swizzling_(computer_graphics) See attached TestVector.blend for a set of unit tests. Tested so far on an Intel Core 2 Duo.%%%
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'

%%%Attached an update that works better with python initialization%%%

%%%Attached an update that works better with python initialization%%%
Author
Member

%%%Made the interface a little cleaner: got rid of the Vector_MixedGetSeter structure; using global arrays instead. Now Vector_AppendSwizzleGetseters and Vector_DelGetseters access these globals directly and take no arguments.%%%

%%%Made the interface a little cleaner: got rid of the Vector_MixedGetSeter structure; using global arrays instead. Now Vector_AppendSwizzleGetseters and Vector_DelGetseters access these globals directly and take no arguments.%%%

%%%applied in svn with some changes,
didnt get your Swizzle_v3.patch, funnily enough I also removed the Vector_MixedGetSeter structure

  • fools never differ :)%%%
%%%applied in svn with some changes, didnt get your Swizzle_v3.patch, funnily enough I also removed the Vector_MixedGetSeter structure - fools never differ :)%%%

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#18678
No description provided.