Advertisement
Guest User

trefoil tube surface w/ PlotOptiX

a guest
Jun 1st, 2022
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon May 30 00:07:10 2022
  4. """
  5. import numpy as np
  6. from numpy import cos
  7. from numpy import sin
  8. from numpy import sqrt
  9.  
  10. # docs, examples: https://plotoptix.rnd.team
  11. from plotoptix import TkOptiX
  12. from plotoptix.utils import make_color
  13. from plotoptix.materials import m_plastic
  14.  
  15. def trefoil(u, v, r):
  16.     q = 8.0 * cos(3*u) + 17.0
  17.     p = 6.0 * cos(3*u)
  18.     qq = q**2
  19.     pp = p**2
  20.     dc = r * cos(v)
  21.     ds = r * sin(v)
  22.     L = sqrt(q*pp+qq)
  23.     Xuv = sin(u) + 2.0*sin(2*u) -  ( (4.0*sin(2*u)-sin(u))/sqrt(q) ) * dc +\
  24.         ( (p * (4.0*cos(2*u) + cos(u)) ) / L ) * ds
  25.     Yuv = cos(u) - 2.0*cos(2*u) +  ( (cos(u)+4.0*cos(2*u))/sqrt(q) ) * dc -\
  26.         ( (p * (sin(u) - 4.0*sin(2*u)) ) / L ) * ds    
  27.     Zuv = (q/L) * ds  - 2.0*sin(3*u)
  28.     return np.array([Xuv, Yuv, Zuv], dtype=np.float32)
  29.  
  30. r = (0.0, 2.0*np.pi)
  31. n = 500
  32.  
  33. i = np.linspace(r[0], r[1], n)
  34.  
  35. U, V = np.meshgrid(i, i)
  36. S = np.swapaxes(trefoil(U, V, 3.0/4.0), 0, 2)
  37.  
  38. rt = TkOptiX(width=800, height=600)
  39.  
  40. rt.set_param(min_accumulation_step=2,
  41.              max_accumulation_frames=2000,
  42.              light_shading="Hard")
  43. rt.set_uint("path_seg_range", 6, 15)
  44.  
  45. rt.setup_material("plastic", m_plastic)
  46.  
  47. exposure = 0.8; gamma = 2.2
  48. rt.set_float("tonemap_exposure", exposure)
  49. rt.set_float("tonemap_gamma", gamma)
  50. rt.add_postproc("Gamma")
  51.  
  52. rt.set_background(0)
  53. rt.set_ambient(0.15)
  54.  
  55. rt.set_surface("surface", S, c=0.94, make_normals=True, mat="plastic")
  56.  
  57. rt.set_data("plane", geom="Parallelograms",
  58.             pos=[[-10, -5, -16]], u=[200, 0, 0], v=[0, 0, 200],
  59.             c=make_color([0.1, 0.2, 0.3], exposure=exposure, gamma=gamma))
  60.  
  61. rt.setup_camera("cam1", cam_type="DoF",
  62.                 eye=[0, 10, 10], target=[0, 0, 0], up=[0, 1, 0],
  63.                 aperture_radius=0.3, aperture_fract=0.2,
  64.                 focal_scale=0.99, fov=35)
  65.  
  66. rt.setup_light("light1", pos=[-15, 20, 15], color=8, radius=6)
  67.  
  68. rt.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement