Rotate UVWmap by view angle of viewport

Hello everyone i have an idea for a script that would be very useful, but i dont know how to make it, i think it is a little bit challenging.
I would like to rotate the Uvwmap by the view angle of the viewport, for example 90 degree or 180 degree.

AttachmentSize
rotate_by_angle_view.jpg1.72 MB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Dragan_ilic's picture

Litte Error

Ok know i have tried to make it, it works but just for the first rotation, i dont know why :(
does anyone has an idea?

Rollout Uvrotroll "Rotate Uvwmap by viewangle"
(
fn Uvwmap_Rotate rotdeg =
	(
	if selection.count == 1 do
		(
		perspview = Inverse(getViewTM())
		perspdir = perspview.row3
 
				Gpersp = #(dot perspdir [1,0,0], dot perspdir [0,1,0], dot perspdir [0,0,1])
				Waxis = finditem Gpersp (amax Gpersp)
				Saxis = #([1,0,0],[0,1,0],[0,0,1])
				if Gpersp[Waxis] > 0 do rotdeg = -rotdeg
 
				for node in selection where isProperty node #uvwmap do
		(
 
			 node.uvwmap.gizmo.rotation = (angleaxis rotdeg Saxis[Waxis])
		)
		)
	)
 
 
	button rccw "rccw" pos:[5,10] height:20 width:35 
	button rcw "rcw" pos:[45,10] height:20 width:35 
	spinner rotsp "Deg" range:[0,360,90] fieldwidth:40 scale:1 pos:[85,12]
 
 
 
	on rcw pressed do if selection.count > 0 do undo on  Uvwmap_Rotate rotsp.value
	on rccw pressed do if selection.count > 0 do undo on  Uvwmap_Rotate -rotsp.value
 
)
 
 
 
createdialog Uvrotroll
jahman's picture

.

Shouldn't it be like this?

node.uvwmap.gizmo.rotation *= (angleaxis rotdeg Saxis[Waxis])
Dragan_ilic's picture

Thanks, now it continues the

Thanks, now it continues the function.
But if i rotate it from the Side and go to the topview its changing the axis.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.