Announcement

Collapse
No announcement yet.

Controlling VrayObjectProperties in Xrefs?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #61
    Ill check over the weekend, and try to test when I can, But ill def give it a go in Monday!

    Cheers

    Comment


    • #62
      Got it working, need to quickly test with Grouped objects.
      Colin Senner

      Comment


      • #63
        Used my lunch break and did it, I will post it tonight when I get off.
        Colin Senner

        Comment


        • #64
          NOT COMPLETE, testable though

          ok here it is for testing, rushed the end, bound to be problems.

          Create these files in the maxscript new script window and save them with the correct filenames:

          MPManager_v1.0.ms
          Code:
          -- Rollouts
          global rlt_MPManager
          -- Functions
          global loadRolloutPosition
          global saveRolloutPosition
          global loadLayerListBox
          global MPMsetupMattePass
          global resetMatteObjects
          global isOnMatteLayer
          global MPMSetupMatteXrefs
          global resetMatteXrefObjects
          global MPMLoadFunctionsFile
          global writeFunctionFile
          -- Variables
          global selectedLayerNameArray = #()
          global MPManagerINIFile = (getDir #scripts + "\\MPManager.ini")
          global AlphaContribution = -1.0
          global Shadows = false
          global AffectAlpha = false
          global Brightness = 1.0
          global ReflectionAmt = 1.0
          global RefractionAmt = 1.0
          global GIAmt = 1.0
          global noGI = true
          global MPMFunctionsFilename = "MPManager_Functions.ms"
          ----
          persistent global MPMFunctionsFile = ""
          persistent global overrideWrappers = false
          persistent global overrideXRefs = true
          persistent global g_layerNameArr = ""
          persistent global g_optionsArr = #()
          
          --fileIn "Q:/Colin/MPManager/MPManager_Functions.ms"
          
          if (rlt_MPManager != undefined) then destroyDialog rlt_MPManager
          
          /************************************************************************************************************/
          /* loadRolloutPosition -- loads the ini file and sets the position of the rollout*/
          fn loadRolloutPosition theRlt theINIFile = (
              if (doesFileExist theINIFile) and (hasINISetting theINIFile theRlt.name "pos_x") and (hasINISetting theINIFile theRlt.name "pos_y") then (
                  local thePos = point2 0 0
                  thePos.x = (getINISetting theINIFile theRlt.name "pos_x") as float
                  thePos.y = (getINISetting theINIFile theRlt.name "pos_y") as float
                  setDialogPos theRlt thePos
              ) else (    -- ini file doesn't exist, create it
                  saveRolloutPosition theRlt theINIFile
              )
          )
          
          /* saveRolloutPosition -- saves the position of the rollout in the ini file */
          fn saveRolloutPosition theRlt theINIFile = (
              local thePos = getDialogPos theRlt
              try (
                  setINISetting theINIFile theRlt.name "pos_x" (thePos.x as string)
                  setINISetting theINIFile theRlt.name "pos_y" (thePos.y as string)
              ) catch ( messageBox ("Unable to write correctly to the file "+theINIFile+".") beep:false )
          )
          
          -- Returns the Functions File
          fn MPMLoadFunctionsFile theINIFile = (
              local functionFilePath = ""
              
              if (doesFileExist theINIFile) then (    -- INI file exists
                  if (hasINISetting theINIFile "functions" "path") then (    -- Functions path exists, fill the function variable
                      if not(doesFileExist (p = getINISetting theINIFile "functions" "path")) then (
                          -- The file linked to the functions path does not exist
                          print "1"
                          writeFunctionFile MPManagerINIFile
                      )
                  ) else (    -- Functions path keys don't exist, ask user to find them and write them
                      print "2"
                      writeFunctionFile MPManagerINIFile
                  )            
              ) else (    -- INI file doesn't exist
                  print "3"
                  writeFunctionFile MPManagerINIFile
              )
              
              /* FIX FIX FIX */
              try ( 
                  MPMFunctionsFile = getINISetting theINIFile "functions" "path" 
                  fileIn MPMFunctionsFile
              ) catch ()
          )
          
          fn writeFunctionFile theINIFile = (
              local functionFilePath = ""
              
              messageBox ("You are about to locate the "+MPMFunctionsFilename+" file.\n\nPlease note: for network rendering, this file MUST be visible to the render nodes\n    using the same path that is located in your "+MPManagerINIFile+" file.\n\nIf the file is not there currently, please cancel and save it to the network now.\n") beep:false
              if ((f = getOpenFileName caption:("Locate the "+MPMFunctionsFilename+" file.") filename:MPMFunctionsFilename) != undefined) then (
                  print "writefunctionfile 1"
                  try (
                      setINISetting theINIFile "functions" "path" f
                      return true
                  ) catch ( return false )
              ) else return false
          )
          
          /************************************************************************************************************/
          rollout rlt_MPManager "MPManager v1.0" (
              multiListBox mlst_Layers "Layers of non-Matte objects:" items:#() height:17 width:160 offset:[0,5]
              
              groupBox grp_MatteProperties "Matte object properties" width:180 height:240 offset:[170,-247]
              spinner spn_alphaContribution "Alpha Contribution  " range:[-1,1,-1] type:#float fieldWidth:35 offset:[-7,-224]
              
              groupBox grp_DirectLight "Direct light" width:160 height:80 offset:[180,0]
              checkbox chk_Shadows "" offset:[310,-70]
              label lbl_Shadows "Shadows" offset:[104,-19]
              checkbox chk_AffectAlpha "" offset:[310,0]
              label lbl_AffectAlpha "Affect Alpha" offset:[97,-19]
              spinner spn_brightness "Brightness  " range:[0,1,1] type:#float fieldWidth:35 offset:[-14,2]
              
              groupBox grp_RRGI "Reflection/Refraction/GI" width:160 height:110 offset:[180,6]
              spinner spn_reflection "Reflection Amount " range:[0,1,1] type:#float fieldWidth:35 offset:[-15,-94]
              spinner spn_refraction "Refraction Amount " range:[0,1,1] type:#float fieldWidth:35 offset:[-15,0]
              spinner spn_gi "GI Amount " range:[0,1,1] type:#float fieldWidth:35 offset:[-15,0]
              label lbl_noGI "No GI on other mattes" offset:[80,0]
              checkbox chk_noGI "" offset:[312,-17] checked:true
              
              --groupBox grp_Setup "Setup" offset:[0,17] width:130 height:50
              checkBox chk_oVRayMtlWrapper "Override VRayOverrideMtls to Matte" offset:[0,19] enabled:false
              checkBox chk_oXRefs "Override XRefs" checked:overrideXRefs enabled:true
              
              button btn_Setup "Setup Matte Pass" offset:[0,5] align:#left
              button btn_Reset "Reset Pass" offset:[-30,-27] 
          
              fn loadLayerListBox = (
                  theItems = for i=0 to layerManager.count-1 collect (layerManager.getLayer i).name
                  mlst_Layers.items = theItems
              )
          
              fn updateSelectedLayerNameArray = (
                  local layersSel = mlst_Layers.selection as array
                  selectedLayerNameArray = for i = 1 to layersSel.count collect mlst_Layers.items[layersSel[i]]    
              )
              
              on btn_Setup pressed do (
                  local selectedLayerNameAsString = ""
                  updateSelectedLayerNameArray()
                  
                  -- Separates the Array into strings to pass to MPMsetupMattePass
                  for l in selectedLayerNameArray do selectedLayerNameAsString += (l + ";")
          
                  g_layerNameArr = selectedLayerNameAsString
                  g_optionsArr = #(AlphaContribution,Shadows,AffectAlpha,Brightness,ReflectionAmt,RefractionAmt,GIAmt,noGI)
                  
                  MPMsetupMattePass g_layerNameArr oWrappers:overrideWrappers oXrefs:overrideXrefs optionsArr:g_optionsArr
              )
              
              on btn_Reset pressed do (
                  resetMatteObjects objects
                  if (overrideXRefs) then resetMatteXrefObjects()
              )
              
              on spn_alphaContribution changed val do AlphaContribution = val
              on chk_Shadows changed state do Shadows = state
              on chk_AffectAlpha changed state do AffectAlpha = state
              on spn_brightness changed val do Brightness = val
              on spn_reflection changed val do ReflectionAmt = val
              on spn_refraction changed val do RefractionAmt = val
              on spn_gi changed val do GIAmt = val
              on chk_noGI changed state do noGI = state
              on chk_oVRayMtlWrapper changed state do overrideWrappers = state
              on chk_oXRefs changed state do overrideXRefs = state
              
              on rlt_MPManager open do (
                  clearListener()
                  loadRolloutPosition rlt_MPManager MPManagerINIFile
                  MPMLoadFunctionsFile MPManagerINIFile
                  print "MPManager Loaded..."
                  loadLayerListBox()
              )
              
              on rlt_MPManager close do (
                  saveRolloutPosition rlt_MPManager MPManagerINIFile
                  if (queryBox "Reset all objects to original settings?" title:"Reset All objects?" beep:false) then (
                      resetMatteObjects objects
                      if (overrideXRefs) then resetMatteXrefObjects()
                  )
              )
          )
          createDialog rlt_MPManager 373 335
          Last edited by MoonDoggie; 27-10-2008, 10:51 AM.
          Colin Senner

          Comment


          • #65
            MPManager_Functions.ms

            Code:
            fn loadRolloutPosition theRlt theINIFile = (
                if (doesFileExist theINIFile) and (hasINISetting theINIFile theRlt.name "pos_x") and (hasINISetting theINIFile theRlt.name "pos_y") then (
                    local thePos = point2 0 0
                    thePos.x = (getINISetting theINIFile theRlt.name "pos_x") as float
                    thePos.y = (getINISetting theINIFile theRlt.name "pos_y") as float
                    setDialogPos theRlt thePos
                ) else (    -- ini file doesn't exist, create it
                    saveRolloutPosition theRlt theINIFile
                )
            )
            
            fn saveRolloutPosition theRlt theINIFile = (
                local thePos = getDialogPos theRlt
                try (
                    setINISetting theINIFile theRlt.name "pos_x" (thePos.x as string)
                    setINISetting theINIFile theRlt.name "pos_y" (thePos.y as string)
                ) catch ( messageBox ("Unable to write correctly to the file "+theINIFile+".") beep:false )
            )
            
            fn isOnMatteLayer matteLayerArr theobj = (
                if (idx = findItem matteLayerArr theobj.layer.name) == 0 then true else false
            )
            
            fn MPMsetupMattePass theLayerNames oWrappers:false oXrefs:true optionsArr:#(AlphaContribution,Shadows,AffectAlpha,Brightness,ReflectionAmt,RefractionAmt,GIAmt,noGI) = (
                if (theLayerNames != "") and (theLayerNames != undefined) then (
                    local layerNamesArr = filterString theLayerNames ";"
                    local matteObjectsArr = #()
                    local nonMatteObjectsArr = #()
            
                    g_layerNameArr = layerNamesArr
                    g_optionsArr = optionsArr
                    
                    -- Making sure options array is valid
                    if     ((optionsArr[1] >= -1.0) and (optionsArr[1] <= 1.0)) and ((optionsArr[2] == true) or (optionsArr[2] == false)) and ((optionsArr[3] == true) or (optionsArr[3] == false)) and ((optionsArr[4] >= 0) and (optionsArr[4] <= 1.0)) and ((optionsArr[5] >= 0) and (optionsArr[5] <= 1.0)) and ((optionsArr[6] >= 0) and (optionsArr[6] <= 1.0)) and ((optionsArr[7] >= 0) and (optionsArr[7] <= 1.0)) and ((optionsArr[8] == true) or (optionsArr[8] == false)) then (
            
                        for o in objects do (
                            for l in layerNamesArr where (l != "") and (l != undefined) do (
                                if (o.layer.name == l) then
                                    append nonMatteObjectsArr o
                                else
                                    append matteObjectsArr o
                            )
                        ) /* done separating */
                        
                        resetMatteObjects nonMatteObjectsArr
                        resetMatteXrefObjects()
                        
                        for o in matteObjectsArr do (
                            setUserProp o "VRay_Matte_Enable" on
                            setUserProp o "VRay_Matte_Alpha" optionsArr[1]
                            setUserProp o "VRay_Matte_Shadows" optionsArr[2]
                            setUserProp o "VRay_Matte_ShadowAlpha" optionsArr[3]
                            setUserProp o "VRay_Matte_ShadowBrightness" optionsArr[4]
                            setUserProp o "VRay_Matte_ReflectionAmount" optionsArr[5]
                            setUserProp o "VRay_Matte_RefractionAmount" optionsArr[6]
                            setUserProp o "VRay_Matte_GIAmount" optionsArr[7]
                            setUserProp o "VRay_Matte_GI_OtherMattes" optionsArr[8]
                        ) /* done setting up matte objects */
                                   
                        if oXrefs then (
                            print "...Overriding XRefs"        
                            MPMSetupMatteXrefs layerNamesArr optionsArr
                            
                            -- Setup Callback Mechanism
                            callbacks.removeScripts id:#MPMOverrideXrefs
                            --callbacks.addScript #preRenderFrame "format \"g_layerNameArr: %\n\" g_layerNameArr" id:#MPMOverrideXrefs
                            --callbacks.addScript #preRenderFrame "format \"g_optionsArr: %\n\" g_optionsArr" id:#MPMOverrideXrefs
                            
                            -- Ridiculous workaround
                            local to_exec = "fileIn \"" + MPMFunctionsFile + "\""
                            ----------------------
                            
                            callbacks.addScript #preRender to_exec id:#MPMOverrideXrefs persistent:true
                            callbacks.addScript #preRender "MPMSetupMatteXrefs g_layerNameArr g_optionsArr" id:#MPMOverrideXrefs persistent:true
                        ) else print "...Not Overriding XRefs"
                        
                        true
                    ) else ( 
                        print "!!! Options Array not valid, needs 8 arguments with values between those listed in the script"
                        false
                    )
                ) else ( 
                    print "!!! Please specify the Layer Names to generate a matte pass."
                    false
                )
            )
            
            fn MPMSetupMatteXrefs layNameArr theOptionsArr = (
                if (local xrefCount = xrefs.getXRefFileCount()) != 0 then (
                    
                    /*try ( deleteFile "Q:/Colin/MPManager/XrefWrite.txt" ) catch ()
                    fs = openFile "Q:/Colin/MPManager/XrefWrite.txt" mode:"w+"
                    
                    format "layNameArr: %\n" layNameArr to:fs
                    format "theOptionsArr: %\n" (theOptionsArr as string) to:fs
                    format "xrefCount: %\n" (xrefCount as string) to:fs*/
                    
                    for i = 1 to xrefCount do (    -- get each xref scene in file
                        local xrscene = xrefs.getXRefFile i    -- xrscene is set to the xref scene file
                        
                        /*format "xrscene: %\n" xrscene to:fs
                        format "xrscene.tree.children: %\n" (xrscene.tree.children as string) to:fs*/
                        --format "layNameArr: %\n" layNameArr
                        --format "theOptionsArr: %\n" theOptionsArr
                        for x in (xrscene.tree.children) do (    -- for each object in the xref
                            if (isOnMatteLayer layNameArr x) then (
                                try (
                                    setUserProp x "VRay_Matte_Enable" on
                                    setUserProp x "VRay_Matte_Alpha" theOptionsArr[1]
                                    setUserProp x "VRay_Matte_Shadows" theOptionsArr[2]
                                    setUserProp x "VRay_Matte_ShadowAlpha" theOptionsArr[3]
                                    setUserProp x "VRay_Matte_ShadowBrightness" theOptionsArr[4]
                                    setUserProp x "VRay_Matte_ReflectionAmount" theOptionsArr[5]
                                    setUserProp x "VRay_Matte_RefractionAmount" theOptionsArr[6]
                                    setUserProp x "VRay_Matte_GIAmount" theOptionsArr[7]
                                    setUserProp x "VRay_Matte_GI_OtherMattes" theOptionsArr[8]
                                    
                                    --format "+ Object % as a matte object\n" x.name to:fs
                                ) catch ()
                            ) else (    -- else object is non-matte
                                try (
                                    resetMatteObjects x
                                    --format "- Object % as non-matte object\n" x.name to:fs
                                ) catch ()
                            )
                        )    -- end each object
                    )    -- end all xrefs done
                    -- close fs        
                )    -- end xref file count
            )
            
            fn resetMatteObjects objArr = (
                for o in objArr do (
                    setUserProp o "VRay_Matte_Enable" off
                    setUserProp o "VRay_Matte_Alpha" 1.0
                    setUserProp o "VRay_Matte_Shadows" off
                    setUserProp o "VRay_Matte_ShadowAlpha" off
                    setUserProp o "VRay_Matte_ShadowBrightness" 1.0
                    setUserProp o "VRay_Matte_ReflectionAmount" 1.0
                    setUserProp o "VRay_Matte_RefractionAmount" 1.0
                    setUserProp o "VRay_Matte_GIAmount" 1.0
                    setUserProp o "VRay_Matte_GI_OtherMattes" true
                )
            )
            
            fn resetMatteXrefObjects = (
                if (local xrefCount = xrefs.getXRefFileCount()) != 0 then (
                    for i = 1 to xrefCount do (    -- get each xref scene in file
                        local xrscene = xrefs.getXRefFile i    -- xrscene is set to the xref scene file
                        
                        for x in (xrscene.tree.children) do (    -- for each object in the xref
                            setUserProp x "VRay_Matte_Enable" off
                            setUserProp x "VRay_Matte_Alpha" 1.0
                            setUserProp x "VRay_Matte_Shadows" off
                            setUserProp x "VRay_Matte_ShadowAlpha" off
                            setUserProp x "VRay_Matte_ShadowBrightness" 1.0
                            setUserProp x "VRay_Matte_ReflectionAmount" 1.0
                            setUserProp x "VRay_Matte_RefractionAmount" 1.0
                            setUserProp x "VRay_Matte_GIAmount" 1.0
                            setUserProp x "VRay_Matte_GI_OtherMattes" true
                        )
                    )
                )
                callbacks.removeScripts id:#MPMOverrideXrefs
            )
            
            (
                MPMsetupMattePass g_layerNameArr oWrappers:overrideWrappers oXrefs:overrideXRefs optionsArr:g_optionsArr
            )
            Last edited by MoonDoggie; 27-10-2008, 10:52 AM.
            Colin Senner

            Comment


            • #66
              Very nice, liking the method you have used to locate the function ms. Just finished a quick test with Xref's. I get this error when I first try to make a matte with an xref layer.

              Is this an easy fix? Ill test it on Monday when this is working.
              Attached Files

              Comment


              • #67
                Easy fix, I quickly commented out all the stuff and missed that one line. Code updated.
                Colin Senner

                Comment


                • #68
                  Cool, I just tried again, and have another two bugs.

                  I cant upload an image now, but its on line 144 of MPManager_v1.0.ms when setting the pass
                  also when closing the script down, line 172 of MPManager_v1.0.ms.

                  Cheers

                  Comment


                  • #69
                    Sorry about that, I rushed off before I got a chance to make sure. I'll update the code in a sec with corrections. Post a SS if you get a chance.
                    Colin Senner

                    Comment


                    • #70
                      updated script, sorry about those typos
                      Colin Senner

                      Comment


                      • #71
                        Also, I have not tested it but I doubt it currently works perfectly with grouped objects. I will update it here while I'm on my lunch break! give me a few.
                        Colin Senner

                        Comment


                        • #72
                          Cheers Buddy, Ill re-test the code now but without grouped objects.

                          edit:
                          Sweet, it works!! not tested with net rendering yet, but Ill let you know................

                          edit:
                          I'm going to upload a zip with some files so we are testing with the same scene. Its a 3ds max 2008 file with two xref files and a holder with two objects in.

                          Its near all working, but some combinations of layers don't work. I'm trying to work out what it is. I think they will all work if you only select one layer to matte, but with more then one, and with one in the scene and an xref, they don't always work.
                          Attached Files
                          Last edited by m_hinks; 28-10-2008, 03:45 AM.

                          Comment


                          • #73
                            Downloaded your scene, I'll check it when I take a lunch break. Also I'll do grouped objects tonight, easy to do, just haven't done it yet.
                            Colin Senner

                            Comment


                            • #74
                              I can't network render the scene because I'm missing VRay_ExtraTex (we are still on SP1 which might be the case), either way, it renders without it fine.
                              Colin Senner

                              Comment


                              • #75
                                Oh ok, yeah just ditch the ExtraTex. So the scene is all working on network, with groups, and xrefs? Sounds like its ready for my live project im starting next week!

                                Did you manage to re-create the bug I found where is you select a layer in the scene, and a layer in an xref, only one of them renders?

                                Comment

                                Working...
                                X