0

I am trying implement frustum culling in maya , where I am turning Level of Detail to boundingbox [cmds.setAttr(object + '.overrideLevelOfDetail',0)] if they are not in the frustum of the selected camera : refer to the image for clear reference.

enter image description here

I have written this script till now, using this I can get the required result, but I want it to be dynamic, so if camera is moving it will set the display of objects depending upon their position as of now I need re run the script to be able to reflect the changes

Here is the code that I worked on till now : frustum culling maya

Any help would be appreciated

Thanks & Regards

EDIT :

change of camera location

still bbox after selecting objects

1 Answers1

0

You probably need to implement a event callback.. for example I changed your code a bit and added a timeChange callback. So when timeline moves it update proper.

def updateFrustum(arg):
    skip_meshes = ['camera1', 'front', 'persp', 'side', 'top']
    meshes = cmds.ls(type="transform")
    
    req_meshes = list(set(meshes) - set(skip_meshes))
    mesh_status = {}
    selected_cam = "camera1"
    for mesh in req_meshes:
        flag = in_frustum(selected_cam, mesh)
        if flag == 1:
            mesh_status[mesh] = True
        else:
            mesh_status[mesh] = False
    
    
    for key, value in mesh_status.items():
        if mesh_status[key] == True:
            cmds.setAttr(key + '.overrideEnabled', 1)
            cmds.setAttr(key + '.overrideLevelOfDetail',0)
        else:
            cmds.setAttr(key + '.overrideEnabled', 1)
            cmds.setAttr(key + '.overrideLevelOfDetail',1)
        cmds.select(key)        
    
    cmds.select(cl=True)

callback = OpenMaya.MEventMessage().addEventCallback( 'timeChanged', updateFrustum )
Achayan
  • 5,720
  • 2
  • 39
  • 61
  • Thanks for your response, but one thing tho , as of now it's working on the frame change is there anyway to do it such as if i change the camera location, it still works, as for now (refer to the image that i have added )youcan see even tho all of the objects are in the frustum of the selected camera but still they are in bounding box. – madara_was_right Apr 27 '23 at 08:24
  • That looks like a display issue, if you select those bbox object do you get back the shaded models ? – Achayan Apr 27 '23 at 16:58
  • No actually even if i select them they are still in bounding box , i have attached the image – madara_was_right Apr 28 '23 at 05:48