PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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