--This Script converts an animated free camera into a GLOM camera array
--Written by Brad Thompson 
--Spitz, Inc.

if $ != undefined and classOf $.baseObject == Freecamera then 							--Check to make sure a free cam is selected
	(
	SourcePos = $.pos
	SourceRot = $.rotation
	frontcam = $
	$.fov = 90																			--Set the Selected Camera's FOV to 90
	daddy = frontcam.parent
	Dummy prefix:"GlomCameraDummy" rotation: SourceRot isSelected:on					--Create a Dummy at the camera's position
	$.parent = daddy
	GlomCameraDummy = $
	$.pos = SourcePos
	
	animPos = frontcam.pos.controller													--copy the pos and rot controllers from the frontcam
	animRot = frontcam.rotation.controller												--onto the glomcameradummy
	GlomCameraDummy.pos.controller = animPos
	GlomCameraDummy.pos.controller = copy GlomCameraDummy.pos.controller
	GlomCameraDummy.rotation.controller = AnimRot
	GlomCameraDummy.rotation.controller = copy GlomCameraDummy.rotation.controller
	deleteKeys frontcam.pos.controller #allkeys
	deleteKeys frontcam.rotation.controller #allkeys
	c = bezier_position()
	frontcam.pos.controller = c

	select frontcam
	$.parent = GlomCameraDummy
	GlomCameraDummyPos = GlomCameraDummy.pos
	GlomCameraDummyRot = GlomCameraDummy.rotation
	select frontcam
	frontcam.pos = GlomCameraDummyPos
	frontcam.rotation = GlomCameraDummyRot
																						--Parent the Frontcamera to the dummy
	instance $ prefix:"GlomCam_Left" isSelected:on										--Make a copy of frontcam
	in coordsys local Rotate $ 90 [0,1,0]												--Rotate it left 90 deg
	$.parent = GlomCameraDummy															--Parent it to the dummy

	select frontcam
	instance $ prefix:"GlomCam_Right" isSelected:on
	in coordsys local Rotate $ -90 [0,1,0]
	$.parent = GlomCameraDummy
	
	select frontcam
	instance $ prefix:"GlomCam_Back" isSelected:on
	in coordsys local Rotate $ 180 [0,1,0]
	$.parent = GlomCameraDummy

	select frontcam
	instance $ prefix:"GlomCam_Up" isSelected:on
	in coordsys local Rotate $ 90 [1,0,0]
	$.parent = GlomCameraDummy
	select GlomCameraDummy
	
	fn CreateMatMaterial = (															--Create the material for the matting hemi
		meditMaterials[24] = MatteShadow ()
		meditMaterials[24].opaqueAlpha = off	
		meditMaterials[24].name = "GLOMmat"
		)
	CreateMatMaterial()
	
	Sphere name: "GlomCameraMaskHemi" radius:2 smooth:on segs:8 chop:0 slice:off sliceFrom:0 sliceTo:0 pos: GlomCameraDummyPos rotation: GlomCameraDummyRot isSelected:on hemisphere:0.5 mapCoords:on recenter:off
	in coordsys local rotate $ (angleaxis 90 [1,0,0])
	$.material = meditMaterials[24]
	modPanel.addModToSelection (Normalmodifier ()) ui:on
	$.modifiers[#Normal].flip = on
	$.parent = GlomCameraDummy
	$.pos = GlomCameraDummyPos
	$.castShadows = off
	select GlomCameraDummy
	)
	
else print "Please select a free camera"