Advertisement
Lucas_3D

Edit Material Modifier

Jun 14th, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. /*
  2. the prerender callback only works with production rendering, I guess activeShade rendering isn't classed as rendering.
  3. */
  4. FN ApplyEditMaterials=
  5. (
  6. --print "PreRender callback for applyEditMaterials() has been intiated"
  7. for i in geometry where i.modifiers.count > 0 do
  8. (
  9. --print "there are modifiers"
  10. for m in i.modifiers where m.name == "Edit Material" do
  11. (
  12. if (classof i.mat == ai_standard_surface) do
  13. (
  14. --print "there is a standardSurface"
  15. if i.mat.base_color_shader != undefined do
  16. (
  17. --print "there is something in the base color"
  18. if i.mat.base_color_shader.name != "oslCCPlug" do --YOU NEED TO CHECK THE NAME OF THE PLUG NOW!
  19. (
  20. --print "Now editing the material"
  21. oslCC = osl_UberColorCorrect name:"oslCC"
  22. oslCCPlug = MultiOutputChannelTexmapToTexmap outputChannelIndex:1 name:"oslCCPlug" --plugs the output into the base color
  23. oslGetAtt = osl_GetAttribute Attribute:"brightness" FltDef:1.0 AddPrefix:1 name:"oslGetAtt"
  24. oslGetAttPlug = MultiOutputChannelTexmapToTexmap outputChannelIndex:2 --plugs the float val into the brightness
  25. oslCC.input_map = i.mat.base_color_shader --we move in the original shader into the oslCC
  26. i.mat.base_color_shader = oslCCPlug
  27. oslCCPlug.source_map = oslCC
  28. oslCC.Brightness_map = oslGetAttPlug
  29. oslGetAttPlug.source_map = oslGetAtt
  30. )
  31. )
  32. )
  33. )
  34. )
  35. )
  36.  
  37. FN DelUserProp obj propertyToDelete =
  38. (
  39. allUserProp = getUserPropBuffer obj
  40. deleteString = (propertyToDelete + " = " + (getUserProp obj propertyToDelete as string))
  41. newUserProp = substituteString allUserProp deleteString ""
  42. setUserPropBuffer obj newUserProp
  43. )
  44.  
  45. FN EditMaterialDeleted =
  46. (
  47. if ((callbacks.notificationParam())[2].name == "Edit Material") do
  48. (
  49. DelUserProp (callbacks.notificationParam())[1] "brightness"
  50. )
  51. )
  52.  
  53. callbacks.addScript #preRender "applyEditMaterials()" id:#editMaterial
  54. --callbacks.removeScripts #preRender id:#editMaterial --I guess you'd never disable this callback, because you can always create the edit material modifier
  55.  
  56. callbacks.addScript #postModifierDeleted "EditMaterialDeleted()" id:#editMaterialDeleted
  57. --callbacks.removeScripts #postModifierDeleted id:#editMaterialDeleted
  58.  
  59. plugin modifier editMaterial
  60. name:"Edit Material"
  61. classID:#(0x43044e75, 0x72d69ab8) --genclassid()
  62. extends:EmptyModifier replaceUI:true
  63. (
  64. parameters main rollout:params
  65. (
  66. brightness type:#float default:1.0 ui:brightness
  67. on brightness set val do
  68. (
  69. --print "updated"
  70. --print val
  71. -- for i in geometry where i.modifiers["Edit Material"] == selection[1].modifiers["Edit Material"] do
  72. -- (
  73. -- --print i
  74. -- setUserProp i "brightness" val
  75. -- )
  76. theArr = (refs.dependentNodes selection[1].modifiers["Edit Material"])
  77. try --without the try I get No "map" function for undefined when adding the modifier...
  78. (
  79. for i in theArr do
  80. (
  81. setUserProp i "brightness" val
  82. )
  83. )catch()
  84. )
  85. )
  86. rollout params "Edit Material"
  87. (
  88. spinner brightness "Brightness: " type:#float range:[-100.0,100.0,1.0]
  89. )
  90. )
  91. /*
  92. --this doesn't work, It doesn't create the array as a plugin.
  93. for i in (refs.dependentNodes selection[1].modifiers["Edit Material"]) do
  94. (
  95. setUserProp i "brightness" val
  96. )
  97. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement