Skip to content

Commit

Permalink
Add USD Material import support (#502)
Browse files Browse the repository at this point in the history
Signed-off-by: JF Lafleche <jlafleche@nvidia.com>
  • Loading branch information
Jean-Francois-Lafleche committed Dec 20, 2021
1 parent b848d4d commit 5d55562
Show file tree
Hide file tree
Showing 21 changed files with 1,936 additions and 452 deletions.
32 changes: 32 additions & 0 deletions docs/modules/kaolin.io.materials.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.. _kaolin.io.materials:

kaolin.io.materials
===================

.. currentmodule:: kaolin.io.materials

API
---

Functions

===================

API
---

.. automodule:: kaolin.io.materials
:members:
:exclude-members:
MaterialError,
MaterialLoadError,
MaterialFileError,
MaterialNotFoundError

Exceptions
----------

.. autoclass:: MaterialError
.. autoclass:: MaterialLoadError
.. autoclass:: MaterialFileError
.. autoclass:: MaterialNotFoundError
8 changes: 0 additions & 8 deletions docs/modules/kaolin.io.obj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,3 @@ Error Handler

.. autofunction:: skip_error_handler
.. autofunction:: default_error_handler

Exceptions
----------

.. autoclass:: MaterialError
.. autoclass:: MaterialLoadError
.. autoclass:: MaterialFileError
.. autoclass:: MaterialNotFoundError
531 changes: 460 additions & 71 deletions kaolin/io/materials.py

Large diffs are not rendered by default.

25 changes: 7 additions & 18 deletions kaolin/io/obj.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
# Copyright (c) 2019, 20-21, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -20,30 +20,19 @@
import torch
from PIL import Image

from kaolin.io.materials import MaterialLoadError, MaterialFileError, MaterialNotFoundError


return_type = namedtuple('return_type',
['vertices', 'faces', 'uvs', 'face_uvs_idx', 'materials',
'materials_order', 'vertex_normals', 'face_normals'])


class MaterialError(Exception):
pass


class MaterialLoadError(MaterialError):
pass


class MaterialFileError(MaterialError):
pass


class MaterialNotFoundError(MaterialError):
pass

def ignore_error_handler(error, **kwargs):
"""Simple error handler to use in :func:`load_obj` that ignore all errors"""
pass


def skip_error_handler(error, **kwargs):
"""Simple error handler to use in :func:`load_obj` that skips all errors
and logs them as warnings."""
Expand Down Expand Up @@ -82,7 +71,7 @@ def import_mesh(path, with_materials=False, with_normals=False,
- **uvs** (torch.Tensor): of shape (num_uvs, 2)
- **face_uvs_idx** (torch.LongTensor): of shape (num_faces, face_size)
- **materials** (list of dict): a list of materials (see return values of :func:`load_mtl`)
- **materials_orders** (torch.LongTensor): of shape (num_same_material_groups, 2)
- **materials_order** (torch.LongTensor): of shape (num_same_material_groups, 2)
showing the order in which materials are used over **face_uvs_idx** and the first indices
in which they start to be used. A material can be used multiple times.
- **vertex_normals** (torch.Tensor): of shape (num_vertices, 3)
Expand All @@ -105,7 +94,7 @@ def import_mesh(path, with_materials=False, with_normals=False,
vertex_normals = []
# 3 values per face
face_normals = []
textures = []
# textures = []
mtl_path = None
materials_order = []
materials_dict = {}
Expand Down

0 comments on commit 5d55562

Please sign in to comment.