kaolin.io.materials

API

class kaolin.io.materials.Material

Bases: object

Abstract material definition class. Defines material inputs and methods to export material properties.

abstract read_from_obj(file_path)
abstract read_from_usd(file_path, scene_path, time=None)
abstract write_to_obj(obj_dir=None, texture_dir=None, texture_prefix='')
abstract write_to_usd(file_path, scene_path, bound_prims=None, time=None, texture_dir=None, texture_file_prefix='', **kwargs)
class kaolin.io.materials.PBRMaterial(diffuse_color=(0.5, 0.5, 0.5), roughness_value=0.5, metallic_value=0.0, specular_color=(0.0, 0.0, 0.0), diffuse_texture=None, roughness_texture=None, metallic_texture=None, specular_texture=None, normals_texture=None, displacement_texture=None, is_specular_workflow=False)

Bases: kaolin.io.materials.Material

Define a PBR material using USD Preview Surface. Usd Preview Surface (https://graphics.pixar.com/usd/docs/UsdPreviewSurface-Proposal.html) is a physically based surface material definition.

Parameters
  • diffuse_color (tuple of floats) – RGB values for Diffuse parameter (typically referred to as Albedo in a metallic workflow) in the range of (0.0, 0.0, 0.0) to (1.0, 1.0, 1.0). Default value is grey (0.5, 0.5, 0.5).

  • roughness_value (float) – Roughness value of specular lobe in range 0.0 to 1.0. Default value is 0.5.

  • metallic_value (float) – Typically set to 0.0 for non-metallic and 1.0 for metallic materials. Ignored if is_specular_workflow is True. Default value is 0.0.

  • specular_color (tuple of floats) – RGB values for Specular lobe. Ignored if is_specular_workflow is False. Default value is white (0.0, 0.0, 0.0).

  • diffuse_texture (torch.FloatTensor) – Texture for diffuse parameter, of shape (3, height, width).

  • roughness_texture (torch.FloatTensor) – Texture for roughness parameter, of shape (1, height, width).

  • metallic_texture (torch.FloatTensor) – Texture for metallic parameter, of shape (1, height, width). Ignored if is_specular_workflow is True.

  • specular_texture (torch.FloatTensor) – Texture for specular parameter, of shape (3, height, width). Ignored if is_specular_workflow is False.

  • normals_texture (torch.FloatTensor) – Texture for normal mapping of shape 3, height, width).Normals maps create the illusion of fine three-dimensional detail without increasing the number of polygons. Tensor values must be in the range of [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)].

  • is_specular_workflow (bool) – Determines whether or not to use a specular workflow. Default is False (use a metallic workflow).

read_from_usd(file_path, scene_path, texture_path=None, time=None)

Read material from USD.

Parameters
  • file_path (str) – Path to usd file (*.usd, *.usda).

  • scene_path (str) – Absolute path of UsdShade.Material prim within the USD file scene. Must be a valid Sdf.Path.

  • texture_path (str, optional) – Path to textures directory. If the USD has absolute paths to textures, set to an empty string. By default, the textures will be assumed to be under the same directory as the USD specified by file_path.

  • time (int, optional) – Positive integer indicating the time at which to retrieve parameters.

write_to_usd(file_path, scene_path, bound_prims=None, time=None, texture_dir='', texture_file_prefix='', shader='UsdPreviewSurface')

Write material to USD. Textures will be written to disk in the format {file_path}/{texture_dir}/{texture_file_prefix}{attr}.png where attr is one of [diffuse, roughness, metallic, specular, normals].

Parameters
  • file_path (str) – Path to usd file (*.usd, *.usda).

  • scene_path (str) – Absolute path of material within the USD file scene. Must be a valid Sdf.Path.

  • shader (str, optional) – Name of shader to write. If not provided, use UsdPreviewSurface.

  • bound_prims (list of Usd.Prim, optional) – If provided, bind material to each prim.

  • time (int, optional) – Positive integer defining the time at which the supplied parameters correspond to.

  • texture_dir (str, optional) – Subdirectory to store texture files. If not provided, texture files will be saved in the same directory as the USD file specified by file_path.

  • texture_file_prefix (str, optional) – String to be prepended to the filename of each texture file.