Struct vsai_Thumbnails ( previous_settings=#(), previous_backgroundColor=undefined, previous_lights=#(), ml_dome=undefined, --isoCam=undefined, angleCam=undefined, polyCountTxt=undefined, fn ZoomExtents cam objs:$* = ( local factor = 1 local max2, fov, asp, v -- declare local variables fn maxof vals = (local v=vals[1]; for v1 in vals do (if v1 > v do v=v1);v) fov=0 -- initialize the fov value asp=1 in coordsys cam -- work in coordinate system of the camera ( for obj in objs where obj != cam do -- loop across all objects except the camera ( if obj.min.z >=0 do continue -- if object is behind camera, skip it -- get max value of the object's bounding box, correcting for the image aspect ratio -- in the y values v = maxof #((abs obj.max.x),(abs obj.min.x),(abs (obj.max.y*asp)),(abs (obj.min.y*asp))) fov = maxof #(fov,(2*atan(-v/obj.min.z))) -- increase fov if needed ) ) cam.fov=fov * factor -- set the camera's fov to the new fov value ), fn setup_isometric_view_old = ( viewport.ResetAllViews() viewport.setlayout #layout_1 angleCam = Freecamera fov:45 pos:[0,0,0] rotate angleCam (angleaxis 45 [0,0,1]) in coordsys local ( rotate angleCam (angleaxis 45 [1,0,0]) angleCam.pos.z = ( angleCam.pos.z + 250 ) ) viewport.setcamera angleCam ZoomExtents angleCam ), fn setup_isometric_view zoomfactor:2.5= ( disableSceneRedraw() objs=$* --fn CenterPt objs = (local totalPos=[0,0,0]; for obj in objs do totalPos = totalPos + obj.pos; avgPos = totalPos / selection.count; avgPos ) fn maxof vals = (local v=vals[1]; for v1 in vals do (if v1 > v do v=v1);v) --viewport.ResetAllViews() --viewport.setlayout #layout_1 angleCam = Freecamera fov:45 pos:[0,0,0] rotate angleCam (angleaxis 45 [0,0,1]) in coordsys angleCam ( rotate angleCam (angleaxis 45 [1,0,0]) angleCam.pos.z = ( angleCam.pos.z + 100 ) ) viewport.setcamera angleCam cam=angleCam local max2, fov, asp, v, dist vmax=0 -- declare local variables totalPos=[0,0,0] CenterOfSelection=[0,0,0] fov=0 -- initialize the fov value asp=1 in coordsys cam -- work in coordinate system of the camera ( for obj in objs where obj != cam do -- loop across all objects except the camera ( if obj.min.z >=0 do continue -- if object is behind camera, skip it -- get max value of the object's bounding box, correcting for the image aspect ratio -- in the y values v = maxof #((abs obj.max.x),(abs obj.min.x),(abs (obj.max.y*asp)),(abs (obj.min.y*asp))) vmax = maxof #(v,vmax) in coordsys world totalPos = totalPos + obj.center; CenterOfSelection = totalPos / objs.count -- fov = maxof #(fov,(2*atan(-v/obj.min.z))) -- increase fov if needed ) ) dist= (vmax/(sin(cam.fov/2))) format "dist: %\n" dist format "vmax: %\n" vmax in coordsys world cam.pos = CenterOfSelection in coordsys cam cam.pos.z = dist*((dist/vmax)/zoomfactor) enableSceneRedraw() ), fn hide_lights_and_cameras = ( hidebycategory.lights = true hidebycategory.cameras = true ), --snapshot of current vray settings fn save_vray_settings = ( --previous_settings=#() for i in (getpropnames vray) do ( val=getProperty renderers.current i if (classOf val)==String then val="\""+val+"\"" append previous_settings ( (i as string)+"="+(val as string) ) ) previous_backgroundColor=backgroundColor ), --snapshot of current light on/off settings fn save_light_state = ( for i in lights do ( try if i.on then append previous_lights i catch() try if i.enabled then append previous_lights i catch() ) for i in previous_lights do ( try i.on=false catch() try i.enabled=false catch() ) ), --restore of current light on/off settings fn restore_light_state = ( --restore lights for i in previous_lights do ( try i.on=true catch() try i.enabled=true catch() ) ), --restore original vray settings fn restore_vray_settings = ( for i in previous_settings do ( try execute ("renderers.current."+i) catch() ) backgroundColor=previous_backgroundColor ), fn apply_AO_dirtmap = ( -- almost completely ripped from Mrc Lorenz's vray Ambient Occlusion tool. -- http://plugins.angstraum.at/ local hcoverride=#() ml_dirtmaterial=VRayLightMtl() ml_dirtmaterial.color=(color 255 255 255) ml_dirtmaterial.texmap=VRayDirt() ml_dirtmaterial.texmap.radius=2540 ml_dirtmaterial.texmap.subdivs=24 append hcoverride "options_overrideMtl_on=true" append hcoverride "options_overrideMtl_mtl=ml_dirtmaterial" --apply overrides for i in hcoverride do ( try execute ("renderers.current."+i) catch() ) ), fn apply_vray_settings dr:false = ( -- almost completely ripped from Mrc Lorenz's vray Ambient Occlusion tool. -- http://plugins.angstraum.at/ local hcoverride=#() append hcoverride "gi_on=false" append hcoverride "imageSampler_type=1" append hcoverride "twoLevel_useQMCSamplerThresh=true" append hcoverride "qmc_earlyTermination_amount=0.85" append hcoverride "qmc_earlyTermination_threshold=0.001" append hcoverride "options_hiddenLights=false" append hcoverride "options_defaultLights=false" append hcoverride "options_reflectionRefraction=false" append hcoverride "system_region_x=16" append hcoverride "system_region_x=16" append hcoverride "colorMapping_type=1" append hcoverride "colorMapping_darkMult=1" append hcoverride "colorMapping_brightMult=1" append hcoverride "colorMapping_gamma=1" append hcoverride "environment_gi_on=false" drEnable = ("system_distributedRender=" + (dr as string)) append hcoverride drEnable backgroundColor = (color 128 128 128 0) for i in hcoverride do ( try execute ("renderers.current."+i) catch() ) ), fn create_skylight = ( ml_dome=VRayLight dome_spherical:off size0:0 size1:0 type:1 multiplier:1.3 on:on invisible:on subdivs:16 ), fn delete_temp_objects = ( try delete ml_dome catch() try delete isoCam catch() try delete angleCam catch() try delete polyCountTxt catch() ), fn render_thumbnail renderFileType rWidth rHeight= ( -- launches render through maxscript, which has the problem of sticking the render in the middle of the 2 monitors -- set up path to include the object and filename RenderFileName = replace maxfilename (maxfilename.count-2) 3 renderFileType Renderfile = (maxfilepath + RenderFileName) render outputwidth:rWidth outputheight:rHeight outputfile:RenderFile ), fn render_thumbnail2 renderFileType rWidth rHeight= ( --launches via normal render, TODO: save general settings first. renderHeight=rHeight renderWidth=rWidth RenderFileName = replace maxfilename (maxfilename.count-2) 3 renderFileType Renderfile = (maxfilepath + RenderFileName) rendStart=0 rendEnd=0 rendOutputFilename=RenderFile rendSaveFile=true rendUseNet=false SetQuietMode true max quick render ), fn ensureVray targetslot assign:false= ( try ( if (targetslot==1) then slot=renderers.production else slot=renderers.draft ) catch() --is vray even installed? a=(findItem RendererClass.classes vray) if (a!=0) then ( --detect if ANY VRay version is active if (findString (slot as string) "VRay"!=undefined) or (findString (slot as string) "V_Ray"!=undefined) then return true else ( if assign then ( b=renderer case targetslot of ( 1: ( renderer=#production renderers.production=RendererClass.classes[a]() ) 2: ( renderer=#draft renderers.draft=RendererClass.classes[a]() ) ) renderer=b return true ) ) ) return false ), fn ShowCountInCamera = ( WhiteMat=VRayLightMtl() WhiteMat.color=(color 255 255 255) WhiteMat.multiplier = 5 in coordsys angleCam polyCountTxt = text size:0.18 kerning:0 leading:0 isSelected:on pos:[0,-.5,-1.5] rotate polyCountTxt (angleaxis 45 [0,0,1]) in coordsys local rotate polyCountTxt (angleaxis 45 [1,0,0]) addmodifier polyCountTxt (UvwMap()) polyCountTxt.wirecolor = (color 255 255 255 0) scf=0 for i in $* do ( try ( tempfaces = getpolygoncount i scf += (tempfaces[1] as integer) )catch() ) polyCountTxt.text = ((scf as string) + " Faces") converttomesh polyCountTxt polyCountTxt.material = WhiteMat ), fn RenderIt ao:true filetype:"jpg" width:640 height:480 dr:"false"= ( setup_isometric_view() ensureVray 1 assign:true save_vray_settings() save_light_state() apply_vray_settings() ShowCountInCamera() if (ao) do apply_AO_dirtmap() if (ao==false) do create_skylight() render_thumbnail filetype width height restore_vray_settings() delete_temp_objects() restore_light_state() ) ) vt=vsai_Thumbnails() --zoomfactor: lower number = zoomed further out vt.setup_isometric_view zoomfactor:2.5 vt.ensureVray 1 assign:true vt.save_vray_settings() vt.save_light_state() vt.apply_vray_settings dr:true vt.ShowCountInCamera() vt.create_skylight() vt.render_thumbnail "jpg" 256 256 vt.restore_vray_settings() vt.delete_temp_objects() vt.restore_light_state()