Advertisement
Guest User

Untitled

a guest
Oct 9th, 2022
1,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.44 KB | None | 0 0
  1. -- =================================================================
  2. --
  3. -- Description : hipoly/lowpoly rock generator
  4. -- Date : 2010/06/29
  5. -- Last Update : 2010/06/29
  6. -- Author : Alessandro Ardolino
  7. --
  8. --this function contains the sequence to create an High Poly rock and a low poly normal mapped one
  9. --inspired by a tutorial by sascha henrichs - http://saschahenrichs.blogspot.com/
  10. --best results with default settings using meters as units
  11. -- =================================================================
  12.  
  13. --vars
  14. global lpNode = "rockLP001"
  15. global hpNode = "rock001"
  16. global aa_rockGen_dlg
  17. global createHProck
  18. global createLProck
  19. global macroCellularMap
  20.  
  21. spacing = 0.02
  22. out_fileName = (GetDir #image) + "\\nm.tga"
  23. mSize = 512
  24. padding = 4
  25.  
  26.  
  27.  
  28. fn createHProck =
  29. (
  30. --cubo
  31. rock = Box lengthsegs:5 widthsegs:5 heightsegs:5 length:2 width:2 height:2 mapcoords:on pos:[0,0,0] isSelected:on
  32. rock.name = uniqueName "rock"
  33. rock.wirecolor = color 115 115 115
  34.  
  35. aa_rockGen_dlg.hpPbar.value = 10
  36.  
  37. --speriphy
  38. modPanel.addModToSelection (Spherify ()) ui:on
  39.  
  40. aa_rockGen_dlg.hpPbar.value = 20
  41.  
  42. --turboSmooth
  43. modPanel.addModToSelection (TurboSmooth ()) ui:on
  44. rock.modifiers[#TurboSmooth].iterations = 4
  45. rock.modifiers[#TurboSmooth].useRenderIterations = on
  46. rock.modifiers[#TurboSmooth].renderIterations = 6
  47.  
  48. aa_rockGen_dlg.hpPbar.value = 30
  49.  
  50. --map cellular MACRO
  51. macroCellularMap = cellular()
  52. macroCellularMap.name = "macroCellularMap"
  53. macroCellularMap.coords.offset = [(random 1 200),0,(random 1 200)]
  54. macroCellularMap.size = 1.1
  55. macroCellularMap.spread = 1.5
  56. macroCellularMap.divColor1 = color 158 158 158
  57. macroCellularMap.divColor2 = color 112 112 112
  58. macroCellularMap.cellColor = color 0 0 0
  59.  
  60. aa_rockGen_dlg.hpPbar.value = 40
  61.  
  62. --displaceMacro1
  63. modPanel.addModToSelection (Displace ()) ui:on
  64. rock.modifiers[#Displace].name = "displaceMacro"
  65. rock.modifiers[#displaceMacro].maptype = 2
  66. rock.modifiers[#displaceMacro].strength = 1.3
  67.  
  68. aa_rockGen_dlg.hpPbar.value = 50
  69.  
  70. --apply the map
  71. rock.modifiers[#displaceMacro].map = macroCellularMap
  72.  
  73. aa_rockGen_dlg.hpPbar.value =60
  74.  
  75. --perlin Marble MEDIUM map
  76. mediumMarbleMap = perlinMarble()
  77. mediumMarbleMap.name = "mediumMarbleMap"
  78. mediumMarbleMap.size = 5
  79. mediumMarbleMap.level = 10
  80. mediumMarbleMap.color1 = color 190 190 190
  81. mediumMarbleMap.saturation1 = 80
  82. mediumMarbleMap.color2 = color 90 90 90
  83. mediumMarbleMap.saturation1 = 50
  84.  
  85. aa_rockGen_dlg.hpPbar.value = 70
  86.  
  87. --displaceMedium
  88. modPanel.addModToSelection (Displace ()) ui:on
  89. rock.modifiers[#Displace].name = "displaceMedium"
  90. rock.modifiers[#displaceMedium].maptype = 2
  91. rock.modifiers[#displaceMedium].strength = 0.06
  92. rock.modifiers[#displaceMedium].map = mediumMarbleMap
  93.  
  94. aa_rockGen_dlg.hpPbar.value = 80
  95.  
  96. --micro noise 1
  97. modPanel.addModToSelection (Noisemodifier ()) ui:on
  98. rock.modifiers[#Noise].name = "microNoise1"
  99. rock.modifiers[#microNoise1].scale = 20
  100. rock.modifiers[#microNoise1].fractal = on
  101. rock.modifiers[#microNoise1].roughness = 0.1
  102. rock.modifiers[#microNoise1].iterations = 10
  103. rock.modifiers[#microNoise1].strength = [0.5,0.5,0.5]
  104. rock.modifiers[#microNoise1].seed = 0
  105.  
  106. aa_rockGen_dlg.hpPbar.value = 90
  107.  
  108. --micro noise 2
  109. modPanel.addModToSelection (Noisemodifier ()) ui:on
  110. rock.modifiers[#Noise].name = "microNoise2"
  111. rock.modifiers[#microNoise2].scale = 1
  112. rock.modifiers[#microNoise2].fractal = on
  113. rock.modifiers[#microNoise2].roughness = 0
  114. rock.modifiers[#microNoise2].iterations = 10
  115. rock.modifiers[#microNoise2].strength = [0.1,0.1,0.1]
  116. rock.modifiers[#microNoise2].seed = 0
  117.  
  118. aa_rockGen_dlg.hpPbar.value = 100
  119.  
  120. --lattice
  121. modPanel.addModToSelection (FFD_2x2x2 ()) ui:on
  122.  
  123. deselect $*
  124.  
  125. return rock.name
  126. )
  127. --end fn
  128.  
  129.  
  130. --this function creates a low poly version of the selected rock and bake some textures on in
  131. --UV manipulation too...
  132. fn createLProck nome spacing =
  133. (
  134. --create the low poly mesh from the one just created
  135. deselect $*
  136. maxOps.CloneNodes (getnodebyname nome) offset:[0,0,0] newNodes: &rockLP
  137.  
  138. aa_rockGen_dlg.lpPbar.value = 10
  139.  
  140. deselect $*
  141. select rockLP
  142. $.name = uniqueName "rockLP"
  143. $.modifiers[#TurboSmooth].iterations = 0
  144.  
  145. aa_rockGen_dlg.lpPbar.value = 30
  146.  
  147. macros.run "Modifier Stack" "Convert_to_Poly"
  148. macros.run "PolyTools" "Smooth"
  149.  
  150. aa_rockGen_dlg.lpPbar.value = 50
  151.  
  152. --adjust the UV
  153. --add a UVW modifier
  154. modPanel.addModToSelection (Unwrap_UVW ()) ui:on
  155. --relax
  156. $.modifiers[#Unwrap_UVW].relaxByFaceAngle 100.0 0.0 0.1 false
  157. --pack islands
  158. $.modifiers[#Unwrap_UVW].pack 1 spacing true true true
  159. --scale UVs
  160. $.modifiers[#unwrap_uvw].unwrap.edit ()
  161. actionMan.executeAction 0 "40021" -- Selection: Select All
  162. $.modifiers[#unwrap_uvw].unwrap2.setFreeFormMode on
  163. $.modifiers[#unwrap_uvw].unwrap2.ScaleSelectedXY 0.95 0.95 [0.5,0.5,0]
  164.  
  165. aa_rockGen_dlg.lpPbar.value = 100
  166.  
  167. return $.name
  168. )
  169.  
  170.  
  171.  
  172. --bake the normal map
  173. fn bakeNmap lp padding mSize hpNode out_fileName =
  174. (
  175. --set scanline as render engine
  176. renderers.production = RendererClass.classes[1]()
  177.  
  178. select lp
  179. if($.modifiers[#Projection] == undefined) then
  180. (
  181. --add a projection modifier
  182. modPanel.addModToSelection (Projection ()) ui:on
  183. $.modifiers[#Projection].addObjectNode (getnodebyname hpNode)
  184. $.modifiers[#Projection].autowrapCage()
  185. --$.modifiers[#Projection].pushValue = 0.5
  186. )
  187.  
  188. --Clear all render elements
  189. lp.iNodeBakeProperties.removeAllBakeElements()
  190.  
  191. --create the normal map bake element
  192. nmBakeElement = normalsmap()
  193. nmBakeElement.outputSzX = nmBakeElement.outputSzY = mSize
  194. nmBakeElement.fileType = out_fileName
  195. nmBakeElement.fileName = filenameFromPath nmBakeElement.fileType
  196. nmBakeElement.filterOn = true
  197. nmBakeElement.enabled = true --enable baking
  198.  
  199. --Preparing the object (lp) for baking:
  200. lp.INodeBakeProperties.addBakeElement nmBakeElement --add first element
  201. lp.INodeBakeProperties.bakeEnabled = true --enabling baking
  202. lp.INodeBakeProperties.bakeChannel = 1 --channel to bake
  203. lp.INodeBakeProperties.nDilations = padding
  204.  
  205. --projection
  206. lp.INodeBakeProjProperties.enabled = true
  207. lp.INodeBakeProjProperties.projectionMod = lp.modifiers[#Projection]
  208. lp.INodeBakeProjProperties.normalSpace = #tangent
  209. lp.INodeBakeProjProperties.useCage = true
  210.  
  211. deselect $*
  212. select lp
  213.  
  214. --run the renderer
  215. render rendertype:#bakeSelected vfb:off progressBar:true outputSize:[mSize,mSize] outputfile: nmBakeElement.fileName
  216.  
  217. --create and assign the new material and normal map
  218. m = standardMaterial()
  219. $.material = m
  220. --m.DirectX_Manager.enabled = on
  221. m.bumpMapAmount = 100
  222. nm = Normal_Bump ()
  223. nmFile = bitmaptexture()
  224. nmFile.filename = out_fileName
  225. nm.normal_map = nmFile
  226. m.bumpMap = nm
  227.  
  228. meditMaterials[1] = m
  229. meditMaterials[1].DirectX_Manager.dxStdMat = on
  230. enableHardwareMaterial m true
  231. showHWTextureMap m true
  232. )
  233.  
  234.  
  235. --bake the AO map
  236. fn bakeAOmap lp padding mSize hpNode out_fileName maxDistance samples spread =
  237. (
  238. --set mental ray as render engine
  239. renderers.production = RendererClass.classes[4]()
  240.  
  241. select lp
  242. if($.modifiers[#Projection] == undefined) then
  243. (
  244. --add a projection modifier
  245. modPanel.addModToSelection (Projection ()) ui:on
  246. )
  247. $.modifiers[#Projection].addObjectNode (getnodebyname hpNode)
  248. $.modifiers[#Projection].autowrapCage()
  249. --$.modifiers[#Projection].pushValue = 0.5
  250.  
  251. --Clear all render elements
  252. $.iNodeBakeProperties.removeAllBakeElements()
  253.  
  254. --create the AO map bake element
  255. AOmBakeElement = Ambient_Occlusion()
  256. AOmBakeElement.outputSzX = AOmBakeElement.outputSzY = mSize
  257. AOmBakeElement.fileType = out_fileName
  258. AOmBakeElement.fileName = filenameFromPath AOmBakeElement.fileType
  259. AOmBakeElement.filterOn = true
  260. AOmBakeElement.enabled = true --enable baking
  261. AOmBakeElement.maxDistance = maxDistance
  262. AOmBakeElement.samples = samples
  263. AOmBakeElement.spread = spread
  264.  
  265. --Preparing the object (lp) for baking:
  266. $.INodeBakeProperties.addBakeElement AOmBakeElement --add first element
  267. $.INodeBakeProperties.bakeEnabled = true --enabling baking
  268. $.INodeBakeProperties.bakeChannel = 1 --channel to bake
  269. $.INodeBakeProperties.nDilations = padding
  270.  
  271. --projection
  272. $.INodeBakeProjProperties.enabled = true
  273. $.INodeBakeProjProperties.projectionMod = $.modifiers[#Projection]
  274. $.INodeBakeProjProperties.normalSpace = #tangent
  275. $.INodeBakeProjProperties.useCage = true
  276.  
  277. deselect $*
  278. select lp
  279.  
  280. --run the renderer
  281. render rendertype:#bakeSelected vfb:off progressBar:true outputSize:[mSize,mSize] outputfile: AOmBakeElement.fileName
  282. )
  283.  
  284.  
  285. fn showHelp =
  286. (
  287. try(destroyDialog helpRlt)catch()
  288. --create rollout
  289. rollout helpRlt "aaRockGen help" width:256 height:260
  290. (
  291. GroupBox grp8 "aa_rockGen help" pos:[8,8] width:240 height:240
  292. label lbl1 "copyright 2010 Alessandro Ardolino" pos:[41,224] width:176 height:16
  293. label lbl4 "procedural rock generator for production and real time environments." pos:[16,24] width:224 height:32
  294.  
  295. label lbl6 "1 - create a hi-poly rock" pos:[16,56] width:224 height:16
  296. label lbl7 "2 - tweak the hi-poly rock parameters " pos:[16,72] width:224 height:16
  297. label lbl8 "3 - create a low-poly version, the spacing value refers to UV island spacing" pos:[16,88] width:224 height:32
  298. label lbl9 "4 - choose which kind of map baking. Please note that only one map can be baked each time" pos:[16,117] width:224 height:40
  299. label lbl10 "NOTE: be sure to set the path every time the script is launched" pos:[16,160] width:224 height:32
  300. label lbl18 "if you use this script, and find it useful, just drop an email: me@aardolino.com" pos:[16,192] width:224 height:32
  301. )
  302. createDialog helpRlt
  303. )
  304.  
  305.  
  306. --create UI
  307. try(destroyDialog aa_rockGen_dlg )catch()
  308.  
  309. rollout aa_rockGen_dlg "aaRockGen - 1.0"
  310. (
  311. --all the groupbox here
  312. groupbox hpGBox "High Poly Rock" pos:[4,4] width:130 height:80
  313. groupbox lpGBox "Low Poly Rock" pos:[4,90] width:130 height:100
  314. groupbox bakeGBox "Bake Settings" pos:[4,195] width:130 height:246
  315.  
  316. groupbox hpOpzGBox "High Poly Rock settings" pos:[140,4] width:130 height:365
  317. groupbox helpGBox "Help" pos:[140,370] width:130 height:71
  318.  
  319. --all the widget here
  320. --hprock
  321. button hpRock "create" width:116 height:32 pos:[12,20]
  322. progressBar hpPbar color:red width:116 pos:[12,60]
  323.  
  324. --lprock
  325. spinner islandSpacing "spacing:" range:[0,10,0.02] scale:0.01 type:#float width:98 pos:[30,108]
  326. button lpRock "create" width:116 height:32 pos:[12,129]
  327. progressBar lpPbar color:green width:116 pos:[12,168]
  328.  
  329. --bake tex
  330. checkbox nmap_cbox "normal map" checked:true tooltip:"bake normal map" pos:[12,215]
  331. checkbox ao_cbox "AO map" checked:false tooltip:"bake ambient occlusion" pos:[12,235]
  332.  
  333. edittext outputPathTxt text:out_fileName pos:[12,255] width:110
  334. button outputPath "set output path" width: 116 height:16 pos:[12,280]
  335.  
  336. spinner tSize "map size:" range:[0,4096,512] type:#integer width:98 pos:[30,300]
  337. button s128 "128" width: 52 height:16 pos:[12,320]
  338. button s256 "256" width: 52 height:16 pos:[75,320]
  339. button s512 "512" width: 52 height:16 pos:[12,340]
  340. button s1024 "1024" width: 52 height:16 pos:[75,340]
  341. button s2048 "2048" width: 52 height:16 pos:[12,358]
  342. button s4096 "4096" width: 52 height:16 pos:[75,358]
  343. spinner paddingSpinner "padding:" range:[0,32,4] type:#integer width:96 pos:[30,380]
  344.  
  345. button bakeTextures "bake textures" width:116 height:32 pos:[12,402]
  346.  
  347. --hp rock settings
  348. --presets
  349. button stdButton "basic rock" width:116 height:32 pos:[148,20]
  350. button boulderButton "boulder" width:116 height:32 pos:[148,56]
  351. button erodedButton "eroded rock" width:116 height:32 pos:[148,92]
  352. button roseButton "sand rose" width:116 height:32 pos:[148,128]
  353.  
  354. --parametri
  355. spinner viewportIt "viewport detail:" range:[1,10,4] type:#integer width:50 pos:[210,168]
  356. spinner renderIt "render detail:" range:[1,10,6] type:#integer width:50 pos:[210,190]
  357. spinner roughnessS "roughness:" range:[1.0,40.0,20.0] scale:0.1 type:#float width:70 pos:[190,212]
  358.  
  359. radiobuttons cellType labels:#("circular", "chips") pos:[148, 234]
  360. checkbox fractal_cbox "fractal" checked:false pos:[148,255]
  361. spinner fIterations "Iter:" range:[0,10,3] type:#integer width:40 pos:[220,255]
  362. colorpicker cellColor "cell color:" color:[0,0,0] pos:[160,278]
  363. --low mid high
  364. spinner lowS "L:" range:[0.0,1.0,0.0] scale:0.01 type:#float width:60 pos:[178,304]
  365. spinner midS "M:" range:[0.0,1.0,0.5] scale:0.01 type:#float width:60 pos:[178,324]
  366. spinner highS "H:" range:[0.0,1.0,1.0] scale:0.01 type:#float width:60 pos:[178,344]
  367.  
  368. --help
  369. label help "aa_rockGen 1.0" align:#left width:116 height:22 pos:[148,384]
  370. button helpB "help" width:116 height:32 pos:[148,402]
  371.  
  372. on stdButton pressed do
  373. (
  374. cellType.state = 1
  375. macroCellularMap.type = 0
  376. cellColor.color = color 0 0 0
  377. macroCellularMap.cellColor = color 0 0 0
  378. fractal_cbox.checked = false
  379. macroCellularMap.fractal = off
  380. lowS.value = 0.0
  381. midS.value = 0.5
  382. highS.value = 1.0
  383. macroCellularMap.lowThresh = 0.0
  384. macroCellularMap.midThresh = 0.5
  385. macroCellularMap.highThresh = 1.0
  386. )
  387.  
  388. on boulderButton pressed do
  389. (
  390. cellType.state = 2
  391. macroCellularMap.type = 1
  392. cellColor.color = color 190 190 190
  393. macroCellularMap.cellColor = color 190 190 190
  394. fractal_cbox.checked = true
  395. macroCellularMap.fractal = on
  396. fIterations.value = 1
  397. macroCellularMap.iteration = 1
  398. lowS.value = 0.0
  399. midS.value = 0.5
  400. highS.value = 1.0
  401. macroCellularMap.lowThresh = 0.0
  402. macroCellularMap.midThresh = 0.5
  403. macroCellularMap.highThresh = 1.0
  404. )
  405.  
  406. on erodedButton pressed do
  407. (
  408. cellType.state = 1
  409. macroCellularMap.type = 0
  410. cellColor.color = color 0 0 0
  411. macroCellularMap.cellColor = color 0 0 0
  412. fractal_cbox.checked = true
  413. macroCellularMap.fractal = on
  414. fIterations.value = 3
  415. macroCellularMap.iteration = 3
  416. lowS.value = 0.0
  417. midS.value = 0.5
  418. highS.value = 1.0
  419. macroCellularMap.lowThresh = 0.0
  420. macroCellularMap.midThresh = 0.5
  421. macroCellularMap.highThresh = 1.0
  422. )
  423.  
  424. on roseButton pressed do
  425. (
  426. cellType.state = 2
  427. macroCellularMap.type = 1
  428. cellColor.color = color 0 0 0
  429. macroCellularMap.cellColor = color 0 0 0
  430. fractal_cbox.checked = false
  431. macroCellularMap.fractal = off
  432. lowS.value = 0.0
  433. midS.value = highS.value = 1.0
  434. macroCellularMap.lowThresh = 0.0
  435. macroCellularMap.midThresh = macroCellularMap.highThresh = 1.0
  436. )
  437.  
  438. on viewportIt changed val do
  439. (
  440. deselect $*
  441. select (getNodeByName hpNode)
  442. $.modifiers[#TurboSmooth].iterations = val
  443. )
  444.  
  445. on renderIt changed val do
  446. (
  447. deselect $*
  448. select (getNodeByName hpNode)
  449. $.modifiers[#TurboSmooth].renderIterations = val
  450. )
  451.  
  452. on roughnessS changed val do
  453. (
  454. deselect $*
  455. select (getNodeByName hpNode)
  456. $.modifiers[#microNoise1].scale = val
  457. )
  458.  
  459. on cellType changed val do
  460. (
  461. if(val == 1) then
  462. macroCellularMap.type = 0
  463. else
  464. macroCellularMap.type = 1
  465. )
  466.  
  467. on fIterations changed val do
  468. (macroCellularMap.iteration = val)
  469.  
  470. on fractal_cbox changed val do
  471. (
  472. if(val == true) then
  473. macroCellularMap.fractal = on
  474. else
  475. macroCellularMap.fractal = off
  476. )
  477.  
  478. on cellColor changed val do
  479. (macroCellularMap.cellColor = val)
  480.  
  481. on lowS changed val do
  482. (macroCellularMap.lowThresh = val)
  483.  
  484. on midS changed val do
  485. (macroCellularMap.midThresh = val)
  486.  
  487. on highS changed val do
  488. (macroCellularMap.highThresh = val)
  489.  
  490. on hpRock pressed do
  491. (hpNode = createHProck())
  492.  
  493. on lpRock pressed do
  494. (
  495. lpNode = createLProck hpNode spacing
  496. deselect $*
  497. )
  498.  
  499. on bakeTextures pressed do
  500. (
  501. if (nmap_cbox.checked == true) then
  502. (
  503. bakeNmap (getnodebyname lpNode) padding mSize hpNode out_fileName
  504. )
  505. if(ao_cbox.checked == true)then
  506. (
  507. bakeAOmap (getnodebyname lpNode) padding mSize hpNode out_fileName 0.0 32 0.99
  508. )
  509. )
  510.  
  511. on outputPath pressed do
  512. (
  513. out_fileName = GetSaveFileName types:"*.tga|*.tga|All Files (*.*)|*.*|"
  514. outputPathTxt.text = out_fileName
  515. )
  516.  
  517. on islandSpacing changed val do
  518. (spacing = val)
  519.  
  520. on paddingSpinner changed val do
  521. (padding = val)
  522.  
  523. on s128 pressed do
  524. (mSize = 128; tSize.value = 128)
  525. on s256 pressed do
  526. (mSize = 256; tSize.value = 256)
  527. on s512 pressed do
  528. (mSize = 512; tSize.value = 512)
  529. on s1024 pressed do
  530. (mSize = 1024; tSize.value = 1024)
  531. on s2048 pressed do
  532. (mSize = 2048; tSize.value = 2048)
  533. on s4096 pressed do
  534. (mSize = 4096; tSize.value = 4096)
  535.  
  536. on helpB pressed do
  537. (showHelp())
  538. )
  539.  
  540. createDialog aa_rockGen_dlg 274 446
  541.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement