Notifications
Clear all

[Closed] UVW Acquire

I’m trying to script the “Acquire Absolute” function in a UVWMap, but am having trouble aligning the gizmos properly, I can get position somewhat okay, but even in the most basic scenario where the objects are not rotated, source gizmo is not offset, etc. I can’t get the targetGizmo to match the rotation of the sourceGizmo.

(Specifically in that case, why doesn’t $.modifiers[1].gizmo.transform.rotation = sourceObject.modifiers[1].gizmo.transform.rotation work?)

I’m doing this because I have a whole lot of items I have to do this on (hence getting the source object name from an array below) At this point I’m not even worried about cases where the UVWMap on the source object is offset or rotated from the primary object (trying to keep it simple at the moment)

As you can tell I’m quite novice at scripting so can anyone point me in the correct direction?


modPanel.addModToSelection (UVWMap()) ui:on
sourceObject = getNodeByName fileList[i]
 
sourceMatrix = sourceObject.transform 
targetMatrix = $.transform
 
testmatrix = sourceMatrix
testmatrix.pos = testmatrix.pos - targetMatrix.pos
 
 
$.modifiers[1].length = sourceObject.modifiers[1].length
$.modifiers[1].width = sourceObject.modifiers[1].width
 
-- Sets TargetObject's UVWMap gizmo to same position as SourceObject
$.modifiers[1].gizmo.transform = testmatrix
 

8 Replies
1 Reply
(@snipeyx)
Joined: 11 months ago

Posts: 0

Just an FYI on this, I was explaining the problem to one of our programmers yesterday, and right as I was getting to the point where it didnt work, it started working. (Still not sure what I was doing before, can only account it to lack of sleep)

I was able to set the rotation of the gizmo properly, and then instead of setting the gizmo’s entire transformation matrix, I just set it’s position. (I did this because the rotation seemed to be about the object’s pivot, so I rotated it first the set it’s position.)

The script still doesn’t account for either source or target objects being rotated, but that is not a problem for the situations I am using it in.

So do you want World Space Position/Orientation instead of Local Space? By default the gizmo coordinates are in local coord and not world. You can convert the local to world coord if needed.

-Eric

yes, I just want to match the “acquire absolute” ability, so the target gizmo would match the source gizmo perfectly regardless of any parent object transforms.

*Create a Teapot01
*Add UVW Map modifier
*Change as you wish (set it to Cylinder, change size, transform the gizmo…
*Create a second Teapot, transform as you wish – move, rotate, scale…

Below are the examples for Absolute and Relative “Acquire UVW Map” – feel free to modify to fit your needs…


  --absolute
  (
  	obj1 = $Teapot01
  	obj2 = $Teapot02
  	map1 = obj1.uvw_mapping
  	map2 = uvwmap()
  	addModifier obj2 map2
  	classof obj2 --hack to force stack update
  	
  	map2.maptype = map1.maptype 
  	
  	map2.width = map1.width 
  	map2.length = map1.length
  	map2.height = map1.height 
  
  	--gizmo's transform would be the map1's gizmo transformed into world space by multiplying with the
  	--object1's transformation matrix, then transformed from world into object space of the second object
  	--by multiplying with the inverse of the object 2's transform:
  	map2.gizmo.transform = (map1.gizmo.transform * obj1.objecttransform) * inverse obj2.objecttransform
  )	
  	
  --relative
  (
  	obj1 = $Teapot01
  	obj2 = $Teapot02
  	map1 = obj1.uvw_mapping
  	map2 = uvwmap()
  	addModifier obj2 map2
  	classof obj2
  
  	map2.maptype = map1.maptype 
  	
  	map2.width = map1.width 
  	map2.length = map1.length
  	map2.height = map1.height 
  --same transform of the gizmo in object space as in the other object
  	map2.gizmo.transform = map1.gizmo.transform
  )
  
  
  

Basically it should be something like:

$.uvw_mapping.gizmo.transform = ((sourceObject.uvw_mapping.gizmo.transform * sourceObject.transform) * (inverse $.transform))

This will convert the local to world.

To convert from local to world coordinates, you multiply the local coordinates by the node’s objecttransform matrix. To convert from world to local coordinates, you multiple the world coordinates by the inverse of the node’s objecttransform matrix.
However I was running into some offset issues in my tests.

    -Eric

Edit: Bobo answered the issue on the offset, I forgot the gizmo transform times the object transform.

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Initially I used the node transform (because the objecttransform is the same if the pivot has not been offset). I changed my code to use objecttransform to take into account changed pivot transforms…

Awesome guys, thanks much for the help to both!

Bobo, it seems that i’m also having the Offset issue and don’t know how to get that fix. Could you give me a hand with this?