vis_pbr_spheres.tcl 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Script demonstrating PBR metallic-roughness material properties
  2. #Category: Visualization
  3. #Title: PBR metallic-rougness spheres
  4. pload XDE OCAF MODELING VISUALIZATION
  5. psphere s 0.35
  6. catch { Close D }
  7. XNewDoc D
  8. # grid of spheres
  9. set THE_UPPER 6
  10. foreach i [list 0 3] {
  11. set aPrefix ""
  12. set aColor "GRAY80"
  13. if { $i != 0 } {
  14. set aPrefix "g_";
  15. set aColor "CCB11D"
  16. }
  17. set aColShapes {}
  18. for { set m 0 } { $m <= $THE_UPPER } { incr m } {
  19. set aRowShapes {}
  20. for { set r 0 } { $r <= $THE_UPPER } { incr r } {
  21. set aName ${aPrefix}m${m}r${r}
  22. copy s $aName
  23. lappend aRowShapes $aName
  24. ttranslate $aName ${r} ${i} ${m}
  25. }
  26. set aName ${aPrefix}m${m}
  27. compound {*}$aRowShapes $aName
  28. lappend aColShapes $aName
  29. }
  30. set aName ${aPrefix}spheres
  31. compound {*}$aColShapes $aName
  32. set aLabName "Gray Spheres"
  33. if { $i != 0 } { set aLabName "Golden Spheres" }
  34. set aLabComp [XAddShape D $aName 0]
  35. SetName D $aLabComp $aLabName
  36. for { set m 0 } { $m <= $THE_UPPER } { incr m } {
  37. set aMet [expr 100 * ${m}/$THE_UPPER]
  38. set aName ${aPrefix}m${m}
  39. XAddComponent D $aLabComp $aName
  40. set aLabCompCol [XFindShape D $aName]
  41. SetName D $aLabCompCol "${aPrefix}m${aMet}%"
  42. SetName D {*}[XFindComponent D $aName] "${aPrefix}m${aMet}%"
  43. for { set r 0 } { $r <= $THE_UPPER } { incr r } {
  44. set aRoug [expr 100 * ${r}/$THE_UPPER]
  45. set aName ${aPrefix}m${m}r${r}
  46. XAddComponent D $aLabCompCol $aName
  47. set aLab [XFindComponent D $aName]
  48. SetName D {*}$aLab "${aPrefix}m${aMet}%_r${aRoug}%"
  49. XAddVisMaterial D $aName -baseColor $aColor -metallic ${m}/$THE_UPPER -roughness ${r}/$THE_UPPER
  50. XSetVisMaterial D {*}$aLab $aName
  51. }
  52. }
  53. }
  54. set aLab [XFindShape D s]
  55. SetName D {*}$aLab "Sphere"
  56. XGetAllVisMaterials D
  57. # labels
  58. text2brep tm "Metal" -plane 0 -1 0 0 0 -1 -height 0.5 -pos -0.5 0 6.5 -halign left -valign top -font monospace
  59. text2brep tnm "Non-metal" -plane 0 -1 0 0 0 -1 -height 0.5 -pos -0.5 0 -0.5 -halign right -valign top -font monospace
  60. text2brep ts "Smooth" -plane 0 -1 0 1 0 0 -height 0.5 -pos -0.5 0 -0.5 -halign left -valign top -font monospace
  61. text2brep tr "Rough" -plane 0 -1 0 1 0 0 -height 0.5 -pos 6.5 0 -0.5 -halign right -valign top -font monospace
  62. compound tm tnm ts tr labs
  63. set aLab [XAddShape D labs 0]
  64. SetName D $aLab "Labels"
  65. XAddComponent D $aLab tm
  66. XAddComponent D $aLab tnm
  67. XAddComponent D $aLab ts
  68. XAddComponent D $aLab tr
  69. SetName D {*}[XFindComponent D tm] "Metal"
  70. SetName D [XFindShape D tm] "Metal"
  71. SetName D {*}[XFindComponent D tnm] "Non-metal"
  72. SetName D [XFindShape D tnm] "Non-metal"
  73. SetName D {*}[XFindComponent D ts] "Smooth"
  74. SetName D [XFindShape D ts] "Smooth"
  75. SetName D {*}[XFindComponent D tr] "Rough"
  76. SetName D [XFindShape D tr] "Rough"
  77. # Ray-Tracing doesn't work with Compatible Profile on macOS
  78. if { $::tcl_platform(os) == "Darwin" } { vcaps -core }
  79. vclear
  80. vinit View1 -width 768 -height 768
  81. vfront
  82. vrenderparams -shadingModel PBR
  83. vlight -change 0 -intensity 2.5
  84. XDisplay -dispMode 1 D
  85. vcamera -ortho
  86. vfit