Skip to content

Commit

Permalink
Added helper class to manage PBR properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
guaje committed Jan 28, 2022
1 parent cb20572 commit 1fdcb58
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 48 deletions.
57 changes: 24 additions & 33 deletions docs/examples/viz_pbr_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,18 @@


def change_slice_metallic(slider):
global pbr_params, sphere
pbr_params['metallic'] = slider.value
sphere.GetProperty().SetMetallic(pbr_params['metallic'])
global pbr_params
pbr_params.metallic = slider.value


def change_slice_roughness(slider):
global pbr_params, sphere
pbr_params['roughness'] = slider.value
sphere.GetProperty().SetRoughness(pbr_params['roughness'])
global pbr_params
pbr_params.roughness = slider.value


def change_slice_anisotropy(slider):
global pbr_params, sphere
pbr_params['anisotropy'] = slider.value
sphere.GetProperty().SetAnisotropy(pbr_params['anisotropy'])
global pbr_params
pbr_params.anisotropy = slider.value


def change_slice_anisotropy_direction_x(slider):
Expand All @@ -61,34 +58,28 @@ def change_slice_anisotropy_direction_z(slider):


def change_slice_anisotropy_rotation(slider):
global pbr_params, sphere
pbr_params['anisotropy_rotation'] = slider.value
sphere.GetProperty().SetAnisotropyRotation(
pbr_params['anisotropy_rotation'])
global pbr_params
pbr_params.anisotropy_rotation = slider.value


def change_slice_coat_strength(slider):
global pbr_params, sphere
pbr_params['coat_strength'] = slider.value
sphere.GetProperty().SetCoatStrength(pbr_params['coat_strength'])
global pbr_params
pbr_params.coat_strength = slider.value


def change_slice_coat_roughness(slider):
global pbr_params, sphere
pbr_params['coat_roughness'] = slider.value
sphere.GetProperty().SetCoatRoughness(pbr_params['coat_roughness'])
global pbr_params
pbr_params.coat_roughness = slider.value


def change_slice_base_ior(slider):
global pbr_params, sphere
pbr_params['base_ior'] = slider.value
sphere.GetProperty().SetBaseIOR(pbr_params['base_ior'])
global pbr_params
pbr_params.base_ior = slider.value


def change_slice_coat_ior(slider):
global pbr_params, sphere
pbr_params['coat_ior'] = slider.value
sphere.GetProperty().SetCoatIOR(pbr_params['coat_ior'])
global pbr_params
pbr_params.coat_ior = slider.value


"""
Expand Down Expand Up @@ -227,22 +218,22 @@ def win_callback(obj, event):
"""

slider_slice_metallic = ui.LineSlider2D(
initial_value=pbr_params['metallic'], max_value=1, length=195,
initial_value=pbr_params.metallic, max_value=1, length=195,
text_template='{value:.1f}')
slider_slice_roughness = ui.LineSlider2D(
initial_value=pbr_params['roughness'], max_value=1, length=195,
initial_value=pbr_params.roughness, max_value=1, length=195,
text_template='{value:.1f}')
slider_slice_anisotropy = ui.LineSlider2D(
initial_value=pbr_params['anisotropy'], max_value=1, length=195,
initial_value=pbr_params.anisotropy, max_value=1, length=195,
text_template='{value:.1f}')
slider_slice_anisotropy_rotation = ui.LineSlider2D(
initial_value=pbr_params['anisotropy_rotation'], max_value=1, length=195,
initial_value=pbr_params.anisotropy_rotation, max_value=1, length=195,
text_template='{value:.1f}')
slider_slice_coat_strength = ui.LineSlider2D(
initial_value=pbr_params['coat_strength'], max_value=1, length=195,
initial_value=pbr_params.coat_strength, max_value=1, length=195,
text_template='{value:.1f}')
slider_slice_coat_roughness = ui.LineSlider2D(
initial_value=pbr_params['coat_roughness'], max_value=1, length=195,
initial_value=pbr_params.coat_roughness, max_value=1, length=195,
text_template='{value:.1f}')

"""
Expand All @@ -268,10 +259,10 @@ def win_callback(obj, event):
"""

slider_slice_base_ior = ui.LineSlider2D(
initial_value=pbr_params['base_ior'], min_value=1, max_value=2.3,
initial_value=pbr_params.base_ior, min_value=1, max_value=2.3,
length=195, text_template='{value:.02f}')
slider_slice_coat_ior = ui.LineSlider2D(
initial_value=pbr_params['coat_ior'], min_value=1, max_value=2.3,
initial_value=pbr_params.coat_ior, min_value=1, max_value=2.3,
length=195, text_template='{value:.02f}')

"""
Expand Down
147 changes: 132 additions & 15 deletions fury/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,120 @@
from fury.lib import VTK_OBJECT, calldata_type


class __PBRParams:
"""Helper class to manage PBR parameters.
Attributes
----------
actor_properties : vtkProperty
The actor properties.
Parameters
----------
metallic : float
Metallic or non-metallic (dielectric) shading computation value. Values
must be between 0.0 and 1.0.
roughness : float
Parameter used to specify how glossy the actor should be. Values must
be between 0.0 and 1.0.
anisotropy : float
Isotropic or anisotropic material parameter. Values must be between
0.0 and 1.0.
anisotropy_rotation : float
Rotation of the anisotropy around the normal in a counter-clockwise
fashion. Values must be between 0.0 and 1.0. A value of 1.0 means a
rotation of 2 * pi.
coat_strength : float
Strength of the coat layer. Values must be between 0.0 and 1.0 (0.0
means no clear coat will be modeled).
coat_roughness : float
Roughness of the coat layer. Values must be between 0.0 and 1.0.
base_ior : float
Index of refraction of the base material. Default is 1.5. Values must
be between 1.0 and 2.3.
coat_ior : float
Index of refraction of the coat material. Default is 1.5. Values must
be between 1.0 and 2.3.
"""
def __init__(self, actor_properties, metallic, roughness,
anisotropy, anisotropy_rotation, coat_strength,
coat_roughness, base_ior, coat_ior):
self.__actor_properties = actor_properties
self.__actor_properties.SetMetallic(metallic)
self.__actor_properties.SetRoughness(roughness)
self.__actor_properties.SetAnisotropy(anisotropy)
self.__actor_properties.SetAnisotropyRotation(
anisotropy_rotation)
self.__actor_properties.SetCoatStrength(coat_strength)
self.__actor_properties.SetCoatRoughness(coat_roughness)
self.__actor_properties.SetBaseIOR(base_ior)
self.__actor_properties.SetCoatIOR(coat_ior)

@property
def metallic(self):
return self.__actor_properties.GetMetallic()

@metallic.setter
def metallic(self, metallic):
self.__actor_properties.SetMetallic(metallic)

@property
def roughness(self):
return self.__actor_properties.GetRoughness()

@roughness.setter
def roughness(self, roughness):
self.__actor_properties.SetRoughness(roughness)

@property
def anisotropy(self):
return self.__actor_properties.GetAnisotropy()

@anisotropy.setter
def anisotropy(self, anisotropy):
self.__actor_properties.SetAnisotropy(anisotropy)

@property
def anisotropy_rotation(self):
return self.__actor_properties.GetAnisotropyRotation()

@anisotropy_rotation.setter
def anisotropy_rotation(self, anisotropy_rotation):
self.__actor_properties.SetAnisotropyRotation(anisotropy_rotation)

@property
def coat_strength(self):
return self.__actor_properties.GetCoatStrength()

@coat_strength.setter
def coat_strength(self, coat_strength):
self.__actor_properties.SetCoatStrength(coat_strength)

@property
def coat_roughness(self):
return self.__actor_properties.GetCoatRoughness()

@coat_roughness.setter
def coat_roughness(self, coat_roughness):
self.__actor_properties.SetCoatRoughness(coat_roughness)

@property
def base_ior(self):
return self.__actor_properties.GetBaseIOR()

@base_ior.setter
def base_ior(self, base_ior):
self.__actor_properties.SetBaseIOR(base_ior)

@property
def coat_ior(self):
return self.__actor_properties.GetCoatIOR()

@coat_ior.setter
def coat_ior(self, coat_ior):
self.__actor_properties.SetCoatIOR(coat_ior)


def manifest_pbr(actor, metallic=0, roughness=.5, anisotropy=0,
anisotropy_rotation=0, coat_strength=0, coat_roughness=0,
base_ior=1.5, coat_ior=2):
Expand Down Expand Up @@ -44,21 +158,24 @@ def manifest_pbr(actor, metallic=0, roughness=.5, anisotropy=0,
try:
prop.SetInterpolationToPBR()

pbr_params = {'metallic': metallic, 'roughness': roughness,
'anisotropy': anisotropy,
'anisotropy_rotation': anisotropy_rotation,
'coat_strength': coat_strength,
'coat_roughness': coat_roughness,
'base_ior': base_ior, 'coat_ior': coat_ior}

prop.SetMetallic(pbr_params['metallic'])
prop.SetRoughness(pbr_params['roughness'])
prop.SetAnisotropy(pbr_params['anisotropy'])
prop.SetAnisotropyRotation(pbr_params['anisotropy_rotation'])
prop.SetCoatStrength(pbr_params['coat_strength'])
prop.SetCoatRoughness(pbr_params['coat_roughness'])
prop.SetBaseIOR(pbr_params['base_ior'])
prop.SetCoatIOR(pbr_params['coat_ior'])
#pbr_params = {'metallic': metallic, 'roughness': roughness,
# 'anisotropy': anisotropy,
# 'anisotropy_rotation': anisotropy_rotation,
# 'coat_strength': coat_strength,
# 'coat_roughness': coat_roughness,
# 'base_ior': base_ior, 'coat_ior': coat_ior}

pbr_params = __PBRParams(prop, metallic, roughness, anisotropy,
anisotropy_rotation, coat_strength,
coat_roughness, base_ior, coat_ior)
#prop.SetMetallic(pbr_params['metallic'])
#prop.SetRoughness(pbr_params['roughness'])
#prop.SetAnisotropy(pbr_params['anisotropy'])
#prop.SetAnisotropyRotation(pbr_params['anisotropy_rotation'])
#prop.SetCoatStrength(pbr_params['coat_strength'])
#prop.SetCoatRoughness(pbr_params['coat_roughness'])
#prop.SetBaseIOR(pbr_params['base_ior'])
#prop.SetCoatIOR(pbr_params['coat_ior'])
return pbr_params
except AttributeError:
warnings.warn(
Expand Down

0 comments on commit 1fdcb58

Please sign in to comment.