auto region - BB

I have a job where auto region would be the best solution to render, but it doesn’t work over BB… :frowning:
it has been discussed on area. http://area.autodesk.com/forum/autodesk-3ds-max/maxscript/using-maxscript-to-make-auto-region-selected-in-net-render-mode

I have no knowledge in coding and making scripts. can anybody help to make such a script? I have not to render an animation, so the region has not to follow anything.

thanks.

best regards
themaxxer

Not exactly sure what you are doing, but sounds like it’s something VraySphereFade could handle.

thanks for helping. but auto region is better for this I have tried the vrayspherefade.
I have made “mask” objects for the regions, so the only thing is missing is the script to select the object before rendering.

if someone could help I am willing to pay for the work. pm me, please

best regards
themaxxer

anyone?

best regards
themaxxer

Are you still looking for a solution to this?

I have made it with “old-style” crop. :slight_smile:
…but if you have some ideas, then YES. it could be very handy.

best regards

After doing a bit of reading it appears that some features in Max are buggy and others are badly implemented - difficult to believe I know :slight_smile:
Unfortunately for us two of these features are pre-render scripts and auto region. There are other ways to do this I think…

Ok, I’ve got something working if anyone would like to test it.
Run the script then select an object and press the ‘set region’ button. At the moment it only works for single objects and doesn’t work if pixel aspect is set to something other than 1 in render settings. Both of these can limitations can be lifted with a bit more work if required.

(
try (destroyDialog BBautoRegion) catch ()

rollout BBautoRegion "AutoRegion 1.0"
(
	fn bb2rect =
	(
		renderSceneDialog.close()
		vpSize = getViewSize()
		BBmask = $
		gw.setTransform(Matrix3 1)
		gwMin = gw.wTransPoint BBmask.center
		gwMax =  gw.wTransPoint BBmask.center
		objBB = nodeGetBoundingBox BBmask (Matrix3 1) --get selection BB in worldspace co-ordsys

		for zi = 1 to 2 do
		(
			for yi = 1 to 2 do
			(
				for xi = 1 to 2 do
				(
					gw.setTransform(Matrix3 1)
					wsPt = point3 obJBB[xi][1] objBB[yi][2] objBB[zi][3]
					gwPnt = gw.wTransPoint wsPt

					if (gwPnt.x < gwMin.x) then
					(
						if (gwPnt.x > 0) then (gwMin.x = gwPnt.x) else (gwMin.x = 0) --set gwMin.x
					)
					if (gwPnt.y < gwMin.y) then
					(
						if (gwPnt.y > 0) then (gwMin.y = gwPnt.y) else (gwMin.y = 0) --set gwMin.y
					)
					if (gwPnt.x > gwMax.x) then
					(
						if (gwPnt.x < vpSize.x) then (gwMax.x = gwPnt.x) else (gwMax.x = vpSize.x) --set gwMax.x
					)
					if (gwPnt.y > gwMax.y) then
					(
						if (gwPnt.y < vpSize.y) then (gwMax.y = gwPnt.y) else (gwMax.y = vpSize.y) --set gwMax.x
					)
				) --end x loop
			) --end y loop
		) --end z loop

		if getRendImageAspect() < (vpSize.x/vpSize.y) then
		(
			roScale = (renderHeight/vpSize.y)
			roPad = ((vpSize.x*roScale)-(renderWidth))/2
			roRegion = box2 (point2 ((gwMin.x*roScale)-roPad) (gwMin.y*roScale)) (point2 ((gwMax.x*roScale)-roPad) (gwMax.y*roScale))
		)
		else
		(
			roScale = (renderWidth/vpSize.x)
			roPad = ((vpSize.y*roScale)-(renderHeight))/2
			roRegion = box2 (point2 (gwMin.x*roScale) ((gwMin.y*roScale)-roPad)) (point2 (gwMax.x*roScale) ((gwMax.y*roScale)-roPad))
		)

		EditRenderRegion.IsEditable = true
		if viewport.activeViewport != 0 then viewport.setRegionRect viewport.activeViewport roRegion
		EditRenderRegion.UpdateRegion()
		setRenderType #region
		renderSceneDialog.open()
	)--end fn bb2rect

	button setRegion "Set Region"

		on setRegion pressed do
		(
			if selection.count == 1 then
			(
				unregisterRedrawViewsCallback bb2rect
				registerRedrawViewsCallback bb2rect
				redrawViews()
				unregisterRedrawViewsCallback bb2rect
				redrawViews()
			)
		)
	)--end rollout
createDialog BBautoRegion
)

wow, it’s alway stunning for me that someone find ways to get a result only with some code. :slight_smile:
great I will test it for sure.

thanks for your effort and I will reply if it’s working for what I need it.

best regards
themaxxer

Your are the man Daniel!! you should collect all your scripts around the forum in a pack and share (or sell) :wink:

thank you very much for sharing

I’m glad it’s useful to you.

Here’s a later version that works with multiple object selections:

try (destroyDialog BBautoRegion) catch ()

rollout BBautoRegion "AutoRegion"
(
	local sfState
	local selChanged

	on BBautoRegion open do
	(
		sfState = displaySafeFrames
		displaySafeFrames = true
		unregisterRedrawViewsCallback bb2rect
	)

	on BBautoRegion close do
	(
		displaySafeFrames = BBautoRegion.sfState
		unregisterRedrawViewsCallback bb2rect
		BBautoRegion.selChanged = undefined
		gc light:true
	)

	fn bb2rect =
	(
		if $ != undefined then
		(
			renderSceneDialog.close()
			vpSize = getViewSize()
			gw.setTransform(Matrix3 1)
			sel = getCurrentselection() as array
			BBmask = sel[1]
			gwMin = gw.wTransPoint BBmask.center
			gwMax =  gw.wTransPoint BBmask.center

			for BBmask in sel do
			(
				objBB = nodeGetBoundingBox BBmask (Matrix3 1) --get selection BB in worldspace co-ordsys
				for zi = 1 to 2 do
				(
					for yi = 1 to 2 do
					(
						for xi = 1 to 2 do
						(
							gw.setTransform(Matrix3 1)
							wsPt = point3 obJBB[xi][1] objBB[yi][2] objBB[zi][3]
							gwPnt = gw.wTransPoint wsPt

							if (gwPnt.x < gwMin.x) then
							(
								if (gwPnt.x > 0) then (gwMin.x = gwPnt.x) else (gwMin.x = 0) --set gwMin.x
							)
							if (gwPnt.y < gwMin.y) then
							(
								if (gwPnt.y > 0) then (gwMin.y = gwPnt.y) else (gwMin.y = 0) --set gwMin.y
							)
							if (gwPnt.x > gwMax.x) then
							(
								if (gwPnt.x < vpSize.x) then (gwMax.x = gwPnt.x) else (gwMax.x = vpSize.x) --set gwMax.x
							)
							if (gwPnt.y > gwMax.y) then
							(
								if (gwPnt.y < vpSize.y) then (gwMax.y = gwPnt.y) else (gwMax.y = vpSize.y) --set gwMax.x
							)
						) --end x loop
					) --end y loop
				)--end z loop
			)--end o loop

			if getRendImageAspect() < (vpSize.x/vpSize.y) then
			(
				roScale = (renderHeight/vpSize.y)
				roPad = ((vpSize.x*roScale)-(renderWidth))/2
				roRegion = box2 (point2 ((gwMin.x*roScale)-roPad) (gwMin.y*roScale)) (point2 ((gwMax.x*roScale)-roPad) (gwMax.y*roScale))
			)
			else
			(
				roScale = (renderWidth/vpSize.x)
				roPad = ((vpSize.y*roScale)-(renderHeight))/2
				roRegion = box2 (point2 (gwMin.x*roScale) ((gwMin.y*roScale)-roPad)) (point2 (gwMax.x*roScale) ((gwMax.y*roScale)-roPad))
			)

			EditRenderRegion.IsEditable = true
			if viewport.activeViewport != 0 then viewport.setRegionRect viewport.activeViewport roRegion
			EditRenderRegion.UpdateRegion()
			setRenderType #region
			renderSceneDialog.open() --need test for previous state
			displaySafeFrames  = true --need test for previous state
		)
	)--end fn bb2rect

	fn autobb2rect ev nd =
	(
		registerRedrawViewsCallback bb2rect
		redrawViews()
		unregisterRedrawViewsCallback bb2rect
		redrawViews()
	)

	button setRegion "Set Region" pos:[5,10]
	checkButton autoRegion "Auto Region" pos:[80,10]

		on setRegion pressed do
		(
			if selection.count == 1 then
			(
				autobb2rect 1 1
			)
		)

		on autoRegion changed state do
		(
			if state == true then
			(
				autobb2rect 1 1
				BBautoRegion.selChanged = NodeEventCallback mouseUp:true selectionChanged:autobb2rect --all:autobb2rect
			)
			else
			(
				selChanged = undefined
				gc light:true
			)
		)
	)--end rollout
createDialog BBautoRegion

I’m not any of my scripts are worth selling. I started a page on Scriptspot about 2 years ago but I have posted anything on there yet. Hopefully I’ll have time to upload something soon.

Thaaaank Daniel, could you please explain which is the difference between the “set region” (the only button in previous version) and “auto region”?

Will stay tunned to your scriptspot account :wink:

Best regards,

They both do the same thing (set the renderer to region and set the region to the current selection) apart from while ‘auto region’ is pressed the region is automatically redrawn if the selection changes or is moved.