Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add USD Material import support #502

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading