Notifications
Clear all

[Closed] Create VRayPhysicalCamera from View?

Hallo Code-Gods,

i would like to create VRay Physical Cameras from View. If you are in the Viewport and hit Ctrl+C MAX creates a free camera from view…but how about a VRay cam? I allready figured out that the the camera creation is handled by the macro “Macro_ObjectsCameras.mcr”. BUt i didin´t get the clue on how i could modify the macro to create the desired VRayPhysicalCameras

could anyone help out here?

regards and thanks in advance

anselm

2 Replies

Hi.

Try this:

macroScript Camera_CreateVRayPhysicalCameraFromView
ButtonText:"Create VRayPhysicalCamera From View"
category:"Lights and Cameras" 
internalcategory:"Lights and Cameras" 
Tooltip:"Create VRayPhysicalCamera From View"
Icon:#("Cameras",3)
(
	fn calculateFOV film_width focal_length = (
		return 2.0 * atan (film_width / (2.0 * focal_length))
	)
	
	fn calculateFocalLength film_width fov = (
		return film_width / ( 2.0 * ( tan (fov / 2.0) ) )
	)

	on isEnabled do (
		return ( viewport.getType() == #view_persp_user )
	)

	on execute do
	( 
		local viewMat = viewport.getTM()
		local worldMat = inverse viewMat
	
		if viewport.getType() == #view_persp_user do (
			if (superClassOf selection[1]) == camera then (
				selection[1].transform = worldMat
				viewport.setCamera selection[1]
			)
			else (
				local viewFOV = getViewFOV()
				local newCamera = VRayPhysicalCamera isSelected:true
				newCamera.film_width = 0.036
				newCamera.focal_length = calculateFocalLength newCamera.film_width viewFOV
				newCamera.transform = worldMat
				viewport.setCamera newCamera
			)
		)	  
	)
)

Creating a vray physical camera from view requires a bit more work than a standard camera.

As vray camera specify the FOV using the film width and the focal length, you have to find a way to calculate the focal length given the viewport FOV and the film width (I use the default 0.036). So that’s what it does the function calculateFocalLength.

The view FOV to film_width/focal_length conversion is not entirely equivalent but almost! (maybe due to precision issues)

Hope that helps.

thanks bro! i owe you one!

the fov issue is not that important at the moment. i have to adapt the camera to real footage. so some tweaking is inavoidable i guess…

regards

anselmo