Home Technical Talk

Max Rendering Help - Fit mesh to view

polycounter lvl 19
Offline / Send Message
TorQue[MoD] polycounter lvl 19
Hey all!

I'm trying to render out a scene in max to a specific frame size 1600 x 45 pixels.
My problem is getting the mesh in max to fit to the specified render area. I tried using the zoom extents button but that doesn't fit the specified window. Anyone know of a quick way to get a scene in max to fit a specific sized render area?

Thanks!

Replies

  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    usually with the [z]- key you can focus your selection to your current view. With [shift] + [F] you can switch the safeframe. It propably wont fit the view to a maximum but in that case you can always smoothly zoom in (ctrl + alt + right mouse button drag, or the magnify icon in the lower left corner of max).
    just a question why the strange resolution?
  • TorQue[MoD]
    Offline / Send Message
    TorQue[MoD] polycounter lvl 19
    Thanks for the reply renderhjs,
    Yeah, the Z key is the same as Zoom Extents and I've already got safe frame on. I need it to match exactly not just closely.

    The reason for the strange resolution is because I often use max to make animations for web related purposes.

    Anyone else know how to render only the selected objects exactly to a specified resolution?
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    maybe with a little bit maxscript :D ?

    here is a snippet I once wrote for someone that asked me how to create a cone that matches the camera with a pre- defined height.
    myCamera = selection[1];--the camera node
    _height = 128;--your input height
    
    -----------------------
    w = 2 * _height * tan(myCamera.fov/2);
    h = 2 * _height * tan(myCamera.fov/2) * renderHeight / renderWidth;
    
    camPyr = Pyramid widthsegs:1 depthSegs:1 heightsegs:1 width:w depth:h height:_height;
    camPyr.transform = selection[1].transform;
    camPyr.wirecolor = color 0 255 0
    
    addmodifier camPyr (xform());
    camPyr.xform.gizmo.position = [0,0, -_height];
    
    you could change the equation and with that calculate the distance the camera would need to be placed away from the object. Meaning that the width of your object is your input value and the distance between the camera and the object is the value to compute.

    Btw. is you camera aligned orthogonal or is it always freestyle perspective? - I rather assume its ortho so meaning that the camera probably is aligned on a axis or 2 with the object and that it just gets moved away to fit the object.
  • TorQue[MoD]
    Offline / Send Message
    TorQue[MoD] polycounter lvl 19
    I was actually just using the default camera rather than adding one to the scene.

    I actually just figured out a "good enough" fix by using the render region and then auto region to selected options in the render window. Its off by a single pixel around the entire object so its easy enough for me to crop later. I just wish there was a way to manually input numbers and have max auto fit to the size of the mesh provided they're the same.

    I know my way around max fairly well, but not enough to use scripting. Thanks for the suggestion anyway though, it'd probably work but I don't think I could manage it so for now I'll have to live with the 1 pixel margin of error.

    Thanks for the quick response though.
  • TorQue[MoD]
    Offline / Send Message
    TorQue[MoD] polycounter lvl 19
    Actually, I spoke too soon. That got the image to render at 1 pixel off, but it unfortunately didn't render out at 1600 x 45, it changed the resolution to 1291 x 37 for some odd reason.
    Trying again with a target camera...
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    he he while you are at fiddling things out in max GUI ways, I made this diagram
    mathtrigonometrymaxscri.png
    I am already fiddling a script...
  • TorQue[MoD]
    Offline / Send Message
    TorQue[MoD] polycounter lvl 19
    lol You rock man. 100 Points for most helpful forum member I've ever met.

    I actually managed to get it to work though by simply creating a target camera moving the camera and target to absolute 0 (along with the scene) and then simply sliding the camera back to whatever looked like it was pretty close and then adjusting the numbers numerically until the bright red background color that I used disappeared.

    Bit of a pain, but at least it worked.
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    I got it actually already working :D
    mathtrigonometryscript2j.png
    see the bounding box of the teapd? - it fits perfectly in the safe frame of the camera

    here is the script:
    cam = undefined;
    obj_source = undefined;
    width = 0;
    for o in selection do(
    	--print("obj "+o as string);
    	if ((SuperClassof o.baseObject) == camera)then(
    		cam = o;
    		print(" .. "+(SuperClassof o.baseObject) as string)
    	)else(
    		obj_source = o;
    		width = (o.max.x - o.min.x)/2;--bounding box width (x- axis)
    	)
    )
    height = width /  tan(cam.fov/2) ;
    cam.pos.y = obj_source.min.y - height;
    print("w "+height as string)
    

    running scripts in max is actually quite easy, simply hit [F11] to open up the maxscript listener - you get some console popping up. From there select
    File > New Script
    a new script window will appear, paste my script in it and hit [ctrl] + [e] to run it (it maxscript terms evaluate, alternativly you can find it either under file > evalzuate or in max 2009+ under tools > evaluate).

    the current script assumes that your projection direction of the camera is the same as the front view of max. If you need it from another axis (e.g top view behaviour) the ".x" related stuff needs to be changed (defines the width). Same for the ".y" camera related stuff.
  • TorQue[MoD]
    Offline / Send Message
    TorQue[MoD] polycounter lvl 19
    I'm using Max 2009 and the script doesn't work. It says unknown property "fov" in undefined.
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    because you did not selected a camera? - you need to select the object and the camera
  • TorQue[MoD]
    Offline / Send Message
    TorQue[MoD] polycounter lvl 19
    Oh, select the object and the camera first and then run the script? Ok cool.

    Thanks a million for your help man!
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    yeah ,- just to be clear

    this is roughly how the code works:
    1.) generates a temp variable for the camera and the reference object
    2.) loops through your selection (I just assume that you only selected those 2 objects)
    3.) within the selection check which one is the camera and which is the other one. If it is the object already calculate it's width of the bounding box (actually just 1/2 of see the illustration I made before)
    4.) after that I use trigonometry to calculate the height of the triangle (the distance between surface of the object and the camera position) - and apply it to the camera .y position. The
    "obj_source.min.y" actually represents the outer position of the bounding box of your object (so no the center of the object which is propably the default with your pivot).
  • SyncViewS
    Offline / Send Message
    SyncViewS polycounter lvl 13
    Hi,
    some time ago I wrote a script to get and set Editable Poly and Mesh dimensions in screen space, relative to active viewport. You can get "IC.SizeInScreen" in MaxScript page of IllusionCatalyst website.
Sign In or Register to comment.