2121from OCC .Core .BRepPrimAPI import BRepPrimAPI_MakeBox , BRepPrimAPI_MakeCone
2222from OCC .Core .Graphic3d import (Graphic3d_NOM_PLASTIC , Graphic3d_NOM_ALUMINIUM ,
2323 Graphic3d_TOSM_PBR , Graphic3d_TOSM_PBR_FACET ,
24- Graphic3d_TOSM_FRAGMENT , Graphic3d_TOSM_VERTEX ,
25- Graphic3d_PBRMaterial , Graphic3d_MaterialAspect )
24+ Graphic3d_TOSM_VERTEX ,
25+ Graphic3d_PBRMaterial , Graphic3d_MaterialAspect ,
26+ Graphic3d_BSDF , Graphic3d_Vec3 )
2627from OCC .Core .V3d import V3d_SpotLight , V3d_XnegYnegZpos , V3d_AmbientLight , V3d_DirectionalLight
27- from OCC .Core .Quantity import Quantity_Color , Quantity_NOC_WHITE , Quantity_NOC_CORAL2 , Quantity_NOC_BROWN , Quantity_NOC_GRAY
28+ from OCC .Core .Quantity import Quantity_Color , Quantity_NOC_WHITE , Quantity_NOC_CORAL2
2829from OCC .Core .BRepAlgoAPI import BRepAlgoAPI_Cut
2930from OCC .Core .gp import gp_Vec , gp_Pnt , gp_Dir
3031
4445# ambient light
4546ambient_light = V3d_AmbientLight (Quantity_Color (Quantity_NOC_WHITE ))
4647display .Viewer .AddLight (ambient_light )
47-
4848# directional light
4949dir_light = V3d_DirectionalLight (gp_Dir (0 ,0 ,1 ), Quantity_Color (Quantity_NOC_WHITE ))
5050display .Viewer .AddLight (dir_light )
51-
52- # create one spotlight
51+ # light
5352spot_light = V3d_SpotLight (gp_Pnt (- 100 , - 100 , 100 ),
5453 V3d_XnegYnegZpos , Quantity_Color (Quantity_NOC_WHITE ))
5554## display the spotlight in rasterized mode
5655display .Viewer .AddLight (spot_light )
5756
58- display .View .SetLightOn ()
57+ # first create the material for the bottle
58+ pbr_mat_1 = Graphic3d_PBRMaterial ()
59+ pbr_mat_1 .SetMetallic (0.8 )
60+ pbr_mat_1 .SetRoughness (0.5 )
61+ alu_pbr_aspect = Graphic3d_MaterialAspect (Graphic3d_NOM_ALUMINIUM )
62+ alu_pbr_aspect .SetPBRMaterial (pbr_mat_1 )
63+ alu_pbr_aspect .SetBSDF (Graphic3d_BSDF ().CreateMetallicRoughness (pbr_mat_1 ))
5964
60- # first create the PBR material
61- pbr_mat = Graphic3d_PBRMaterial ()
62- print (dir (pbr_mat ))
63- pbr_mat .SetMetallic (0.8 )
64- pbr_mat .SetRoughness (0.5 )
65- # modifies albedo color
66- #pbr_mat.SetColor(Quantity_Color(Quantity_NOC_GRAY))
6765
68- # then the material aspect
69- alu_pbr_aspect = Graphic3d_MaterialAspect (Graphic3d_NOM_ALUMINIUM )
70- alu_pbr_aspect .SetPBRMaterial (pbr_mat )
66+ # then the glass
67+ pbr_mat_2 = Graphic3d_PBRMaterial ()
68+ glass_pbr_aspect = Graphic3d_MaterialAspect (Graphic3d_NOM_PLASTIC )
69+ glass_pbr_aspect .SetPBRMaterial (pbr_mat_2 )
70+ # the BSDF glass
71+ weights = Graphic3d_Vec3 (0.5 , 6. , 1. )
72+ absorption_color = Graphic3d_Vec3 (0.8 , 0.8 , 0.8 )
73+ absorption_coef = 0.6
74+ refraction_index = 2.2
75+ glass_pbr_aspect .SetBSDF (Graphic3d_BSDF ().CreateGlass (weights , absorption_color , absorption_coef , refraction_index ))
7176
72- #print(dir(pbr_mat))
7377display .EnableAntiAliasing ()
7478display .DisplayShape (bottle , material = alu_pbr_aspect )
7579display .DisplayShape (table , material = Graphic3d_NOM_PLASTIC , color = Quantity_NOC_CORAL2 )
7680display .DisplayShape (translated_glass ,
77- material = Graphic3d_NOM_PLASTIC ,
78- color = Quantity_NOC_BROWN ,
79- transparency = 0.6 ,
81+ material = glass_pbr_aspect ,
82+ transparency = 0.8 ,
8083 update = True )
8184
8285def pbr (event = None ):
@@ -91,14 +94,6 @@ def phong(event=None):
9194 display .View .SetShadingModel (Graphic3d_TOSM_VERTEX )
9295 display .View .Redraw ()
9396
94- def gouraud (event = None ):
95- display .View .SetShadingModel (Graphic3d_TOSM_FRAGMENT )
96- display .View .Redraw ()
97-
98- def rasterization (event = None ):
99- display .SetRasterizationMode ()
100- display .View .Redraw ()
101-
10297def exit (event = None ):
10398 sys .exit (0 )
10499
@@ -107,8 +102,6 @@ def exit(event=None):
107102
108103if __name__ == '__main__' :
109104 add_menu ('PBR' )
110- add_function_to_menu ('PBR' , rasterization )
111- add_function_to_menu ('PBR' , gouraud )
112105 add_function_to_menu ('PBR' , phong )
113106 add_function_to_menu ('PBR' , pbr )
114107 add_function_to_menu ('PBR' , pbr_facet )
0 commit comments