/src/examples/Level2/Display/enviroment_mapping.py

http://pythonocc.googlecode.com/ · Python · 67 lines · 26 code · 10 blank · 31 comment · 0 complexity · 32d8d68d835de1d0a6c32b4400e65981 MD5 · raw file

  1. #!/usr/bin/env python
  2. ##Copyright 2009-2011 Thomas Paviot (tpaviot@gmail.com) & Jelle Feringa (jelleferinga@gmail.com)
  3. ##
  4. ##This file is part of pythonOCC.
  5. ##
  6. ##pythonOCC is free software: you can redistribute it and/or modify
  7. ##it under the terms of the GNU Lesser General Public License as published by
  8. ##the Free Software Foundation, either version 3 of the License, or
  9. ##(at your option) any later version.
  10. ##
  11. ##pythonOCC is distributed in the hope that it will be useful,
  12. ##but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ##GNU Lesser General Public License for more details.
  15. ##
  16. ##You should have received a copy of the GNU Lesser General Public License
  17. ##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
  18. '''
  19. example adapted from code posted by Fotios:
  20. http://www.opencascade.org/org/forum/thread_17520/
  21. '''
  22. from OCC.BRepPrimAPI import *
  23. from OCC.Display.SimpleGui import *
  24. display, start_display, add_menu, add_function_to_menu = init_display()
  25. from OCC.AIS import *
  26. from OCC.Visual3d import *
  27. from OCC.Graphic3d import *
  28. from OCC.Aspect import *
  29. # Construct a primitive
  30. box = BRepPrimAPI_MakeBox(1,1,1).Shape()
  31. #===============================================================================
  32. # This is how to set the spherical dynamic texcoord generation in the view
  33. #===============================================================================
  34. view = display.View.View().GetObject()
  35. vw_mng = view.ViewManager()
  36. # build enviroment texture
  37. texture = Graphic3d_TextureEnv(vw_mng,
  38. Graphic3d_NOT_ENV_CLOUDS
  39. )
  40. display.View.SetTextureEnv(texture.GetHandle())
  41. display.View.Redraw()
  42. #===============================================================================
  43. # And this is hot to enable spherical dynamic texture to an object
  44. #===============================================================================
  45. mat_asp = Graphic3d_MaterialAspect(Graphic3d_NOM_SILVER)
  46. mat_asp.SetEnvReflexion(1)
  47. mat_asp.SetReflectionModeOn(True)
  48. mat_asp.SetShininess(1)
  49. mat_asp.SetSpecular(1)
  50. box_ais = display.DisplayShape(box, mat_asp).GetObject()
  51. attributes = box_ais.Attributes().GetObject()
  52. shd_asp = attributes.ShadingAspect().GetObject()
  53. shd_asp.SetMaterial(mat_asp, Aspect_TOFM_FRONT_SIDE)
  54. box_ais.Redisplay(False)
  55. start_display()