--AlignViewToFace - RightClick Menu - Artbot Special Edition 
--Version 0.231 RCSE
--Started: 11/19/99
--Started: 12/19/99
--by Borislav Petrov
--http.//gfxcentral.com/bobo/
--REQUIRES MOUSTRK.DLX EXTENSION TO BE INSTALLED UNDER PLUGINS!


--Copy this filto your \Scripts\Startup directory.
--Restart MAX
--Select a geometry object
--Right-click, select "Align View To Face" from context menu
--Click LMB or click and drag on the object's surface to specify face normal
--Right-click to confirm.
--A new User View will be aligned to the normal you specified.
--Click outside of Geometry to cancel.

RcMenu AlignViewRCMenu 
(

fn flt_SingleGeometry = 
(
(selection.count == 1) and (Not (KeyBoard.controlPressed)) and (superclassof selection[1] == GeometryClass) and (classof selection[1] != TargetObject) 
)

MenuItem mi_alignview2face "Align View To Face" filter:flt_SingleGeometry

on mi_alignview2face picked do 
(
obj = $
max_size = ((obj.max.x-obj.min.x) + (obj.max.y-obj.min.y) + (obj.max.z-obj.min.z) )/3.0
tob = Targetobject ()
global cam = TargetCamera target:tob

fn get_normal_function msg ir obj faceNum shift ctrl alt =
(
if msg == #mouseMove then
	(
	if ir != undefined then
	(
	cam.pos = ir.pos + (ir.dir*max_size)
	cam.target.pos = ir.pos
	)
	else
	(
	delete cam
	)
	)
if msg != #mousePoint then 
	(
	return #continue
	)
	else 
	(
	viewport.setCamera cam
	redrawViews()
	viewport.setType #view_iso_user	
	delete cam	
	return #end
	)
)

try
(
a = mouseTrack on:obj trackCallBack:get_normal_function
)
catch
(
messagebox "This Script Requires the MouseTrack.DLX MAXScript Extension!\n(But this error message might mean something else went wrong...:o)" title:"Bobo Says..."
)

)--end on
)--end menu

RegisterRightClickMenu AlignViewRCMenu