Notifications
Clear all

[Closed] Rotate UVWMap gizmo in world space about an arbitrary point

How to rotate the UVWMap gizmo in world space about an arbitrary point?
I found this code, by denisT, and change it, but the result is not what I want.
Starting situation:

What I want to achieve:

What the script below gives me:

The code:

(
 	delete $*
 	refObj = plane width:40 length:20 isSelected:true
 	addModifier refObj (uvwMap())
 	uvm = refObj.modifiers[1]
 	uvm.length = 20
 	uvm.width = 40
 	uvm.gizmo.position = [60,60,0] * inverse refObj.transform
 	--	in case of transition in world space the transition matrix is
 	gizmo_tm = (getModContextTM refObj uvm)
 	--
 	wt_tm = (inverse gizmo_tm) * refObj.objecttransform
 	--	the rotation matrix in world space is:
 	wr_tm = ((angleaxis -45 [0,0,1]) as quat) as matrix3
 	gr_tm = wt_tm * wr_tm * (inverse wt_tm)	
 	--as we have gr_tm the final rotated matrix in gizmo space is:
 	final_tm = gizmo_tm * gr_tm
 	--	if we need to rotate gizmo around center we have to rebuild the final matrix as:	
 	rotPoint = [40,60,0]
 	final_tm = matrix3 final_tm[1] final_tm[2] final_tm[3] rotPoint	--	gizmo_tm[4]	
 	uvm.gizmo.transform = final_tm
 )

Where I am wrong?

14 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

hopefully i didn’t forget anything:


 fn rotateUVWMapGizmo node modi angle center = 
(	
	context_to_world_matrix = inverse (getModContextTM node modi) * node.objecttransform
	
	inverse_space_matrix = inverse (transmatrix center)
	world_rotation_matrix = angle as matrix3
	
	modi.Gizmo.transform *= xformMat (xformMat world_rotation_matrix inverse_space_matrix) context_to_world_matrix
)

delete objects
p = plane pos:[-10,10,0] isselected:on
modi = UVWMap()
addmodifier p modi
rotateUVWMapGizmo p modi (angleaxis 45 z_axis) p.min
modpanel.setcurrentobject modi

Thank you. Works perfectly when the center of rotation is p.min, but with other coordinates the gizmo is not aligned to the center of rotation. For example

rotateUVWMapGizmo p modi (angleaxis 45 z_axis) [20,20,0]	--	p.min

the gizmo is away from [20,20,0].

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

i don’t see a problem. everything works as expected. where do you expect to see the gizmo after rotation on 45 deg about [20,20,0]?

The first and the second image in my first post – the gizmo have to be placed as in the second image. The point of rotation is [40,50,0]. The gizmo first have to be rotated and then moved, so the position will be as in the image?

Do you know why when I press the FIT button for the UVWMap the displayed values in the L/W/H spinners always are bigger then the actual size of the object?

2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

that’s the feature from the first days of max. doing that they try to fix a little slit between uvw shells (elements). so they specially do a little overlapping.

(@denist)
Joined: 11 months ago

Posts: 0

my function works absolutely correct. maybe you need something else.
my function rotates uvw gizmo in world space on specified angle (quat) about specified world point.

it seems like you want to move the gizmo first and after that rotate… well. it will be like this:


fn moveUVWMapGizmo node modi vector = 
(	
	context_to_world_matrix = (inverse (getModContextTM node modi)) * node.objecttransform
	world_translation_matrix = transmatrix vector
	modi.Gizmo.transform *= xformMat world_translation_matrix context_to_world_matrix
)

fn rotateUVWMapGizmo node modi angle center = 
(	
	context_to_world_matrix = (inverse (getModContextTM node modi)) * node.objecttransform
	
	inverse_space_matrix = inverse (transmatrix center)
	world_rotation_matrix = angle as matrix3

	modi.Gizmo.transform *= xformMat (xformMat world_rotation_matrix inverse_space_matrix) context_to_world_matrix
)

delete objects
p = plane length:20 width:20 pos:[-10,10,0] isselected:on
modi = UVWMap()
addmodifier p modi
moveUVWMapGizmo p modi [20,20,0]
rotateUVWMapGizmo p modi (angleaxis 45 z_axis) [20,20,0]
modpanel.setcurrentobject modi
point pos:[20,20,0]

Thank you. This works as I want.

So, I have to leave those L/W/H values untouched ? I mean, if I change them to be exactly as the size of the objects, this will causes problems or not?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

i was asking the same question 8-10 years ago. it might cause a problem… i decided just make this overlapping smaller

Thank you.

The padding you see is to prevent pixel bleed over when blurring is applied, much like padding in Render to Texture. The default of the fit is a 0.1% pad on the bounding box size. If the texture you apply back has no blurring, or is padded you are fine. If not then you may get unexpected pixels blurring over.

-Eric

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

true! i’ve just forget. that was exactly something about render and antialiasing…

PiXeL_MoNKeY, thank you.

Anither question – how to move the gizmo in the gizmo local space? When the gizmo is not rotated its local space match the object local space, but when the gizmo is rotated – how to move it in its local space?