Notifications
Clear all

[Closed] ZoomExtents properly, is possible?

Ok, in my machine no issue at all with Max Tool ZoomExtents.
But in other station that produce absolute arbitrary result.

On the right picture is desired result, and the wrong is on the left one.
The bad news is that this issue appear on station that I can’t test myself.

I make some extra calculations to supply zoom factor using viewport.zoom(),
but that not solve the problem at all, it fix only concrete cases.

So, I have no idea from where this “bug” may come.
I made an example code for testing though to illustrate this
and with hope to get some advice on how to solve it.

Thanks in advance!

(
	fn makeExampleObject = (
		local obj = Sphere name:"obj" isSelected:on
		obj.scale.z = 2
		rotate obj 90 y_axis
		ResetXForm obj
	)
	
	fn setupViewPort = (
		viewport.setLayout #layout_1 -- 1 viewport
		viewport.setType #view_front -- Front
		gw.setTransform (matrix3 1)
		backgroundColor = white
	)
	
	fn renderTester size = (
		renderWidth = int(size[1])
		renderHeight = int(size[2])
		
		local vpSize = getViewSize() -- view port size
		local rnSize = [renderWidth, renderHeight] -- render size
		local vpRatio = (vpSize[1] as float) / vpSize[2]
		local rnRatio = (rnSize[1] as float) / rnSize[2]
		local zoomFactor = rnRatio / vpRatio
		
		completeRedraw()
		max tool zoomextents; max tool zoomextents
		------------------------------------ HIDE NEXT FOR A 2ND TEST
		viewport.zoom zoomFactor ------------ ?... WHY EVER NEED THIS ?
		------------------------------------
		completeRedraw()
		
		local img = bitmap renderWidth renderHeight
		render to:img vfb:off -- render to bitmap
		img -- return bitmap
	)
	
	fn sheetComposer = (
		local arrSize, arrBmp, buffer, tmp
		arrSize = #([100, 50], [240, 320], [640, 480], [400, 480], [800, 768])
		arrBmp = for val in arrSize collect (renderTester val)
		buffer = bitmap 280 210 color:gray
		
		pasteBitmap arrBmp[1] buffer (box2 0 0 100 50) [10,10]
		tmp = bitmap 60 80; copy arrBmp[2] tmp
		pasteBitmap tmp buffer (box2 0 0 60 80) [120,10]
		
		tmp = bitmap 80 60; copy arrBmp[3] tmp
		pasteBitmap tmp buffer (box2 0 0 80 60) [190,10]
		
		tmp = bitmap 100 120; copy arrBmp[4] tmp
		pasteBitmap tmp buffer (box2 0 0 100 120) [10,70]
		
		tmp = bitmap 100 96; copy arrBmp[5] tmp
		pasteBitmap tmp buffer (box2 0 0 100 96) [120,100]
		
		free tmp
		for bm in arrBmp do free bm
		
		display buffer
	)
	
	fn cleanScene = (
		if isValidNode $obj do delete $obj
		clearUndoBuffer()
		viewport.ResetAllViews()
		setSaveRequired false
	)
	
	fn DebugTask = (
		gc(); resetMaxFile()
		makeExampleObject()
		setupViewPort()
		sheetComposer()
		cleanScene()
	)
	
	DebugTask() -- run whole task
)

2 Replies

I didn’t try / look at the code, but may its because of System Units, and the object being a different size in different max instances?

1 Reply
(@panayot)
Joined: 1 year ago

Posts: 0

Thanks for the reply.
Hmm, interesting, never thought about System Units, is they can affect zooming?

What I get from the report is that on widescreen resolution Max Tool ZoomExtents zoom-out too much and I need to fix that somehow with viewport.zoom() but not find yet good working algorithm.