Advertisement
joch1175

rman_particles.py

Sep 29th, 2020 (edited)
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.31 KB | None | 0 0
  1. # rman_particles.py
  2. import sys
  3. import math
  4. import random
  5. import gen_points
  6.  
  7. def writePointInfo(rib_path, num, p_data, p_color, p_size, bbox_size):
  8.     f = open(rib_path, 'w')
  9.     f.write('#bbox: '+', '.join(map(str,bbox_size))+'\n')
  10.  
  11.     # Write point position information
  12.     f.write('Points "P" [\n')
  13.     for x,y,z in p_data:
  14.         f.write('%f %f %f\n' % (x,y,z))
  15.     f.write(']\n')
  16.  
  17.     # Write point size information
  18.     f.write('"width" [\n')
  19.     for n in range (num):
  20.         f.write('%f\n' % random.uniform(p_size[0], p_size[1]))
  21.     f.write(']\n')
  22.  
  23.     # Write point color information
  24.     f.write('"varying color tint" [\n')
  25.     for r,g,b in p_color:
  26.         f.write('%f %f %f\n' % (r,g,b))
  27.     f.write(']\n')
  28.     f.close()
  29.  
  30. def writeSphere(rib_path, num, radius, p_size=[0.1, 0.1], hsv_range=[0, 360, 100, 100, 100, 100]):
  31.     # Call gen_point.py
  32.     p_data = gen_points.sphere (num, radius)
  33.     p_color = gen_points.rand_rgb(num, hsv_range)
  34.  
  35.     # Set bbox information
  36.     bbox_size = [-radius, -radius, -radius, radius, radius, radius]
  37.  
  38.     # Write into file
  39.     writePointInfo(rib_path, num, p_data, p_color, p_size, bbox_size)
  40.     print ('Sphere generated successfully.\n')
  41.  
  42. def writeCylinder(rib_path, num, radius, height, p_size=[0.1, 0.1], hsv_range=[0, 360, 100, 100, 100, 100]):
  43.     # Call gen_point.py
  44.     p_data = gen_points.cylinder (num, radius, height)
  45.     p_color = gen_points.rand_rgb(num, hsv_range)
  46.  
  47.     # Set bbox information
  48.     bbox_size = [-radius, -height/2, -radius, radius, height/2, radius]
  49.  
  50.     # Write into file
  51.     writePointInfo(rib_path, num, p_data, p_color, p_size, bbox_size)
  52.     print ('Cylinder generated successfully.\n')
  53.  
  54. def writeCone(rib_path, num, radius, height, p_size=[0.1, 0.1], hsv_range=[0, 360, 100, 100, 100, 100]):
  55.     # Call gen_point.py
  56.     p_data = gen_points.cone (num, radius, height)
  57.     p_color = gen_points.rand_rgb(num, hsv_range)
  58.  
  59.     # Set bbox information
  60.     bbox_size = [-radius, -height/2, -radius, radius, height/2, radius]
  61.  
  62.     # Write into file
  63.     writePointInfo(rib_path, num, p_data, p_color, p_size, bbox_size)
  64.     print ('Cone generated successfully.\n')
  65.  
  66. def writeCubic(rib_path, num, side, p_size=[0.1, 0.1], hsv_range=[0, 360, 100, 100, 100, 100]):
  67.     # Call gen_point.py
  68.     p_data = gen_points.cubic (num, side)
  69.     p_color = gen_points.rand_rgb(num, hsv_range)
  70.  
  71.     # Set bbox information
  72.     bbox_size = [-side/2, -side/2, -side/2, side/2, side/2, side/2]
  73.  
  74.     # Write into file
  75.     writePointInfo(rib_path, num, p_data, p_color, p_size, bbox_size)
  76.     print ('Cubic generated successfully.\n')
  77.  
  78. if __name__=='__main__':
  79.     # File Attribute
  80.     shape = 'cubic'
  81.     rib_path = shape + 'Particle.rib'
  82.  
  83.     # Particle number/Size: [Size_Min, Size_Max]
  84.     num = 10000
  85.     p_size = [0.1, 0.7]
  86.  
  87.     # Cubic/Sphere/Cylinder/Cone variables
  88.     side = 5       
  89.     radius = 15
  90.     height = 25
  91.  
  92.     # Wave/Ripple variables
  93.     length = 10    
  94.     width = 10
  95.     wave_n = 5
  96.     wave_h = 1
  97.  
  98.     # HSV Color Range: [H_Min, H_Max, S_Min, S_Max, V_Min, V_Max]
  99.     hsv_range = [0, 360, 60, 80, 80, 100]
  100.  
  101.     if shape.lower() == 'cubic':
  102.         writeCubic(rib_path, num, side, p_size, hsv_range)
  103.     elif shape.lower() == 'sphere':
  104.         writeSphere(rib_path, num, radius, p_size, hsv_range)
  105.     elif shape.lower() == 'cylinder':
  106.         writeCylinder(rib_path, num, radius, height, p_size, hsv_range)
  107.     elif shape.lower() == 'cone':
  108.         writeCone(rib_path, num, radius, height, p_size, hsv_range)
  109.     else:
  110.         print ('No such shape.\n')
  111.         sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement