[Closed] Hiding objects outside camera cone
I use this script to create a frustum culling cone for my camera and I use the cone to hide faces of some object like ground with vol select and delete mesh operators.
But what I miss is a script to hide objects outside of the camera cone.
Does anyone know of such a script?
I know forest pack pro and vue Carbon Scatter do it but I would like to do it by maxscript.
Use this to get objects inside the cone, and then invert the selection.
http://forums.cgsociety.org/showpost.php?p=7225028&postcount=22
I found this one and it seems to work!
http://forums.cgsociety.org/showthread.php?f=98&t=740887&highlight=culling
I load it in the RPManager “Before:” script section that way it’s executed at every frame.
finally it was not working at everyframe, it just run the script on first frame. to make it run at everyframe at render time I had to use the callback command like this:
here is what it looks like in the before script and after script of RPManager:
before script:
callbacks.removescripts id:#hideNonVis
txt ="TestGeom=$capRock_* ---TESTED GEOMETRY"
txt +="TheCamera=$camC ---TESTED CAMERA"
txt +="DoCullPlane=undefined
"
txt +="infront=undefined
"
txt +="GetCameraDirections =undefined
"
txt +="fn infront TheCullPlanePos TheCullPlaneDir TesObjPosition = if (dot TheCullPlaneDir (normalize(TesObjPosition-TheCullPlanePos)))>=0 then true else false
"
txt +="fn DoCullPlane Passgeom TheCullPlanePos TheCullPlaneDir = (
"
txt +="local TestGeom=Passgeom
"
txt +="local Passgeom=#()
"
txt +="for testPlane in TestGeom do
"
txt +="(
"
txt +="local testTransform=testPlane.objecttransform
"
txt +="local vis=false
"
txt +="for p in testPlane.mesh.verts while not vis do vis = infront TheCullPlanePos TheCullPlaneDir (p.pos*testTransform)
"
txt +="if vis do append Passgeom testPlane
"
txt +=")
"
txt +="Passgeom
"
txt +=")
"
txt +="fn GetCameraDirections theCamera = (
"
txt +="local dirs=#()
"
txt +="local CamTR=TheCamera.objecttransform
"
txt +="local TheCullPlanePos=theCamera.objecttransform.position
"
txt +="local HFOV=theCamera.fov/2.0
"
txt +="local VFOV = atan(tan(HFOV)/((renderWidth as float)/renderHeight*renderPixelAspect))
"
txt +="local offset=1000
"
txt +="local w=Offset*(sin(HFOV)/sin(90-HFOV))
"
txt +="local h=Offset*(sin(VFOV)/sin(90-VFOV))
"
txt +="local TL=([-w,h,-offset]*CamTR)
"
txt +="local BR=([w,-h,-offset]*CamTR)
"
txt +="local TR=([w,h,-offset]*CamTR)
"
txt +="local BL=([-w,-h,-offset]*CamTR)
"
txt +="dirs[1]=TheCamera.dir * -1 --front
"
txt +="dirs[2]=cross (normalize (TL-TheCullPlanePos)) (normalize (TR-TheCullPlanePos)) --top
"
txt +="dirs[3]=cross (normalize (BR-TheCullPlanePos)) (normalize (BL-TheCullPlanePos)) --bottom
"
txt +="dirs[4]=cross (normalize (BL-TheCullPlanePos)) (normalize (TL-TheCullPlanePos)) --left
"
txt +="dirs[5]=cross (normalize (TR-TheCullPlanePos)) (normalize (BR-TheCullPlanePos)) --right
"
txt +="dirs
"
txt +=")
"
txt +="TheCameraPos=theCamera.objecttransform.position
"
txt +="directions=GetCameraDirections TheCamera
"
txt +="hide testgeom
"
txt +="testgeom.wirecolor=black
"
txt +="for testdir in directions while TestGeom.count >=1 do TestGeom=DoCullPlane TestGeom TheCameraPos TestDir
"
txt +="testgeom.wirecolor=green
"
txt +="unhide TestGeom
"
callbacks.addscript #preRender txt id:#hideNonVis
txt ="unhide TestGeom"
callbacks.addscript #postRender txt id:#hideNonVis
After script:
callbacks.removescripts id:#hideNonVis
unhide $capRock_*
there is also a callback feature in RPManager, but that one just ran the script randomly only on some frames…
The script is working but when I render a test frame, I sometimes get those errors. Does anyone can see why?
– Unkknown property: “objecttransform” in undefined
And after render: – No ““unhide”” function for undefined