Notifications
Clear all

[Closed] get/set back view by angle

I’m trying to figure out how to set the viewport to “back” based on the viewing angle. The problem is unlike left/right/front/etc. the back angle crease a value overflow when converted to euler, so something like this wont work:

viewAngle = (viewport.getTM()) as eulerAngles
if (viewAngle == (eulerAngles 90 -5.00896e-006 180)) do (actionMan.executeAction 0 "40064")

Is there a better way to deal with this then going into ‘back’ temporarily just to store the angle in whole before running the rest of the script?

1 Reply

i’ve just wrote this little toy. it might be helpful for who learns the max scripting and maybe useful as well

global ViewportHelpers
(
	struct ViewportHelpersStruct 
	(
	private 
		view_types = 
		#(
			#(#view_top, 	 z_axis),
			#(#view_bottom, -z_axis), 
			#(#view_back, 	 y_axis), 
			#(#view_front, 	-y_axis), 
			#(#view_right, 	 x_axis), 
			#(#view_left, 	-x_axis)
		),
	public
		epsilon = 0.25,
		fn vectorEqual v dir:-y_axis epsilon:0.25 = 1.0 - (dot v dir) < epsilon,
		fn snapViewport epsilon: = 
		(
			if epsilon == unsupplied do epsilon = this.epsilon
			local vp_dir = normalize (inverse (getViewTM()))[3]
			local view
			for v in view_types while view == undefined where (vectorEqual vp_dir dir:v[2] epsilon:epsilon) do viewport.setType (view = v[1])
			view
		)
	)
	ViewportHelpers = ViewportHelpersStruct()
	ok
)
/*
ViewportHelpers.snapViewport()
*/