home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / share / k3d / scripts / RenderManScript / tribble.py
Encoding:
Python Source  |  2008-01-23  |  1.5 KB  |  73 lines

  1. #python
  2.  
  3. # Load this script into a K-3D RenderManScript object to create
  4. # what is either a Tribble or a really bad-hair-day ...
  5.  
  6. import k3d
  7. k3d.check_node_environment(locals(), "RenderManScript")
  8.  
  9. import sys
  10. import ri
  11. from ri import *
  12. from random import *
  13. from cgtypes import vec3
  14. from noise import vsnoise
  15. from sl import mix
  16.  
  17. message = """You're probably trying to run this script manually, which won't work - this script is meant to be loaded into a RenderManScript node, where it will be run at render-time.
  18.  
  19. Use the Create > RenderMan > RenderManScript menu item to create the node, then load this file into its Script property."""
  20.  
  21. try:
  22.       Archive
  23. except:
  24.       k3d.ui.error_message(message)
  25.       raise
  26.  
  27.  
  28. # Redirect output to our RIB archive
  29. ri._ribout = open(Archive, "w")
  30.  
  31. body_size = 5
  32. lumpyness = 1
  33. hair_length = 2
  34. hair_count = 10000
  35. hair_wavyness = 1
  36.  
  37. control_point_counts = []
  38. control_points = []
  39. widths = []
  40.  
  41. seed(12345)
  42.  
  43. for i in range(hair_count):
  44.     control_point_counts.append(4)
  45.  
  46.     v = vec3(random() - 0.5, random() - 0.5, random() - 0.5).normalize()
  47.  
  48.     p1 = v * body_size
  49.     p1 += vsnoise(p1) * lumpyness
  50.  
  51.     p4 = p1 + v * hair_length
  52.     p4 += vsnoise(p4) * hair_wavyness
  53.  
  54.     p2 = mix(p1, p4, 0.2)
  55.     p2 += vsnoise(p2)
  56.  
  57.     p3 = mix(p1, p4, 0.8)
  58.     p3 += vsnoise(p3)
  59.  
  60.     control_points.append(p1)
  61.     control_points.append(p2)
  62.     control_points.append(p3)
  63.     control_points.append(p4)
  64.  
  65.     widths.append(0.08)
  66.     widths.append(0.01)
  67.  
  68. RiSurface("k3d_hair")
  69. RiCurves(RI_CUBIC, control_point_counts, RI_NONPERIODIC, "P", control_points, "width", widths)
  70.  
  71. ri._ribout.flush()
  72.  
  73.