Home Technical Talk

Help on Maxscript callback

greentooth
Offline / Send Message
Noors greentooth
Hi ! I'm trying to make a script that displays the drawcalls count of a selection.
It only works on editable poly for now. I'm looping through the mesh to get all mat id.
        global winWidth = (gw.getWinSizeX() / 2 - 20)
        global drawcalls = "Drawcalls: "
    
    fn GW_displayDrawCalls evt nodes=
    (
        
        fn getDrawCalls dc_selObj =
        (
            
        global_dc = 0

        for i = 1 to dc_selObj.count do 
            (
                dc_obj =dc_selObj[i]
                
                if classof dc_obj == editable_poly do 
                    (
                        if classof dc_obj.material == multimaterial do 
                            (
                                dc_idCount = 0
                                for i=1 to dc_obj.material.numSubs  do
                                (
                                    dc_obj.selectByMaterial i
                                    dc_faces = polyop.getFaceSelection dc_obj 
                                    if dc_faces.numberset != 0 do (dc_idCount+=1)
                                    
                                )
                                global_dc += dc_idCount
                            )
                        if classof dc_obj.material != multimaterial do 
                            (
                                global_dc+=1
                            )
                    )
            )
            gw.updatescreen()
            return "Drawcalls: "+ (global_dc as string) + " "
        )
    
    drawcalls = ((getDrawCalls selection) as string )
    
    )    
    callbackItem = undefined;
    gc()
    callbackItem = NodeEventCallback selectionChanged:GW_displayDrawCalls
    
    unregisterRedrawViewsCallback displayDrawCalls
    
    fn displayDrawCalls = 
    (
    gw.wtext [winWidth, 19, 20] (drawcalls) color: [229,204,25]
    )
    registerRedrawViewsCallback displayDrawCalls
        

The issue is my scene is slow when i select an object (complex object in a complex scene), eventhough i use a NodeEventCallback selectionChanged. It looks like the code is executed all the time instead of on selection change ?
Thanks for insight.

Replies

  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Took the code for a spin and it seems to run even if the selection really hasnt changed (ie you had Box001 selected and click on Box001 again) Maybe having a previous check so you're not running it if the selection really hasnt changed. Also didnt have much of a slowdown with about 1500 objects (simple box with some edge loops turbosmooth duplicated. Not best test case though :( ) Using 2011
  • Noors
    Options
    Offline / Send Message
    Noors greentooth
    Yeah, i think i had some other callbacks running there. I've edited the code anyway. I have a sort of lag before displaying, but i guess that's the delay for parsing the objects.
Sign In or Register to comment.