Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #Andrew Grace
  2. #12/5/18
  3.  
  4. import viz
  5. import vizshape
  6. from PIL import Image
  7.  
  8. viz.go(viz.ANAGLYPHIC)
  9. view = viz.MainView.setPosition([0, 1, -1])
  10.  
  11. #This snippet is only for viewing in CAVE:
  12. #------------------------------------------
  13. # import vizconnect
  14. # CONFIG_FILE = "E:\\VizardProjects\\_CaveConfigFiles\\vizconnect_config_CaveFloor+ART_headnode.py"
  15. # #CONFIG_FILE = "E:\\VizardProjects\\_CaveConfigFiles\\vizconnect_config_CaveCeiling+ART_headnode.py"
  16. # vizconnect.go(CONFIG_FILE)
  17. #------------------------------------------
  18.  
  19. viewPoint = vizconnect.addViewpoint(pos=[0,1,-1]) #inside the sphere
  20. viewPoint.add(vizconnect.getDisplay())
  21. vizconnect.resetViewpoints()
  22.  
  23. viz.clearcolor(viz.GRAY)
  24.  
  25. #Open a 3D 360 image. Left eye is top half of image, right eye is bottom half
  26. image = Image.open("render_het_0005_3d_2to1_4k.jpg")
  27. image_size = list(image.size)
  28. w, h = image_size
  29.  
  30. print(image_size)
  31.  
  32. #Cropping photo to get images corresponding to left and right eyes
  33. #These are both half-height
  34. image_left = image.crop ( (0, 0, w, h//2) )
  35. image_right = image.crop ( (0, h//2, w, h) )
  36.  
  37. #Resize to full height
  38. image_left = image_left.resize ( image_size, Image.ANTIALIAS)
  39. image_right = image_right.resize ( image_size, Image.ANTIALIAS)
  40.  
  41.  
  42. def setupSphereForEye(image, eye=None):
  43. image_size = list(image.size)
  44.  
  45. sphere = vizshape.addSphere(radius=20, pos=[0,0,0])
  46. tex = viz.addBlankTexture (size=image_size, type=viz.TEX_2D, format=viz.TEX_RGB)
  47. tex.setImageData(data=image.tobytes(), size=image_size, format=viz.TEX_RGB)
  48.  
  49. #Additional hints for Vizard about the sphere object
  50. sphere.cullFace(viz.GL_BACK)
  51. sphere.disable(viz.LIGHTING) #Show texture at full color, no shadows or shading
  52. sphere.enable(viz.FLIP_POLYGON_ORDER) #NORMALS FLIPPED
  53. sphere.setEuler([0,0,180]) #fix upside down texture
  54.  
  55. sphere.texture(tex)
  56. sphere.renderToEye(eye)
  57.  
  58. return sphere
  59.  
  60. sphere_left = setupSphereForEye (image=image_left, eye=viz.LEFT_EYE)
  61. sphere_right = setupSphereForEye (image=image_right, eye=viz.RIGHT_EYE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement