Skip to content

Commit

Permalink
Make USD and OBJ importers consistent for all properties, change hand…
Browse files Browse the repository at this point in the history
…ling of material assignments, fix bugs, add option to triangulate. (#724)

Non-backward compatible changes to OBJ importer, including:
  - renamed vertex_normals to normals and fixed doc
  (this value is normals array is not num_verts x 3, but num_normals x 3)
  - renamed face_normals to face_normals_idx, which is more accurate
  - changed material_order to material_assignments tensor with material_id per face
  - materials are now returned in alphabetical order
  - fixed handling of materials for non-homogeneous meshes
  - fixed skip handling of non-homogeneous meshes

Other changes to OBJ importer:
  - added option to triangulate
  - added handler to fill in missing materials
  - added material_name to materials

Non-backward compatible changes to USD importer, including:
  - changes material_order to material_assignments tensor with material_id per face
  (this is original USD repersentation)
  - materials are now returned in alphabetical order
  - removed deprecated handlers in kaolin.io.usd

Other changes to USD importer:
  - major refactoring of the USD importer code; multiple bug fixes; more robust tests
  - added material_name to materials
  - added option to triangulate
  - fixed a bug in USD importer handling of uvs in non-homogeneous meshes

Other changes:
  - deprecated heterogeneous_mesh_handler_naive_homogenize, renaming it mesh_handler_naive_triangulate
  (as it is not specific to heterogeneous mesh handling)
  - material assignments are now properly handled during triangulation
  - modified and simplified notebooks, given changes to API
  - added multi-object multi-material test file: amsterdam.obj, amsterdam.usd
  - modified notebooks and recipes to be more robust to missing data (e.g. shapenet)
  and to run both locally and on CI
  - added IO consistency checks for OBJ/USD for the new amsterdam mesh
  - removed heterogeneous_mesh_handler_empty, as we will no longer be able to support it with Mesh API

Signed-off-by: Maria Masha Shugrina <mshugrina@nvidia.com>
Co-authored-by: Maria Masha Shugrina <mshugrina@nvidia.com>
  • Loading branch information
shumash and Maria Masha Shugrina committed May 24, 2023
1 parent 75ca02c commit 1834e57
Show file tree
Hide file tree
Showing 41 changed files with 8,689 additions and 907 deletions.
2 changes: 2 additions & 0 deletions docs/modules/kaolin.io.obj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Functions
ignore_error_handler,
skip_error_handler,
default_error_handler,
create_missing_materials_error_handler,
MaterialError,
MaterialLoadError,
MaterialFileError,
Expand All @@ -29,3 +30,4 @@ Error Handler
.. autofunction:: ignore_error_handler
.. autofunction:: skip_error_handler
.. autofunction:: default_error_handler
.. autofunction:: create_missing_materials_error_handler
22 changes: 3 additions & 19 deletions docs/modules/kaolin.io.usd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ More tutorials and documentation can be found `here <https://graphics.pixar.com/
Viewing USD Files
~~~~~~~~~~~~~~~~~
USD files can be visualized with realtime pathtracing using the [Omniverse Kaolin App](https://docs.omniverse.nvidia.com/app_kaolin/app_kaolin/user_manual.html#training-visualizer).
Alternatively, you may use Pixar's USDView which can be obtained by visiting
`https://developer.nvidia.com/usd <https://developer.nvidia.com/usd>`_ and selecting the
Alternatively, you may use Pixar's USDView which can be obtained by visiting
`https://developer.nvidia.com/usd <https://developer.nvidia.com/usd>`_ and selecting the
corresponding platform under *.USD Pre-Built Libraries and Tools*.


Expand All @@ -35,20 +35,4 @@ Functions
.. automodule:: kaolin.io.usd
:members:
:exclude-members:
mesh_return_type,
heterogeneous_mesh_handler_empty,
heterogeneous_mesh_handler_naive_homogenize,
heterogeneous_mesh_handler_skip,
NonHomogeneousMeshError

Heterogeneous Mesh Handlers
---------------------------

.. autofunction:: heterogeneous_mesh_handler_empty
.. autofunction:: heterogeneous_mesh_handler_naive_homogenize
.. autofunction:: heterogeneous_mesh_handler_skip

Exceptions
----------

.. autoclass:: NonHomogeneousMeshError
mesh_return_type
19 changes: 4 additions & 15 deletions examples/recipes/preprocess/fast_mesh_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
# ==============================================================================================================

import argparse
import sys
import os
import torch

import kaolin as kal

parser = argparse.ArgumentParser(description='')
parser.add_argument('--shapenet-dir', type=str,
parser.add_argument('--shapenet-dir', type=str, default=os.getenv('KAOLIN_TEST_SHAPENETV2_PATH'),
help='Path to shapenet (v2)')
parser.add_argument('--cache-dir', type=str, default='/tmp/dir',
help='Path where output of the dataset is cached')
Expand Down Expand Up @@ -52,22 +52,11 @@ def preprocessing_transform(inputs):
uvs = torch.nn.functional.pad(mesh.uvs.unsqueeze(0) % 1, (0, 0, 0, 1)) * 2. - 1.
uvs[:, :, 1] = -uvs[:, :, 1]
face_uvs_idx = mesh.face_uvs_idx
materials_order = mesh.materials_order
face_material_idx = mesh.material_assignments
materials = [m['map_Kd'].permute(2, 0, 1).unsqueeze(0).float() / 255. if 'map_Kd' in m else
m['Kd'].reshape(1, 3, 1, 1)
for m in mesh.materials]

nb_faces = faces.shape[0]
num_consecutive_materials = \
torch.cat([
materials_order[1:, 1],
torch.LongTensor([nb_faces])
], dim=0)- materials_order[:, 1]

face_material_idx = kal.ops.batch.tile_to_packed(
materials_order[:, 0],
num_consecutive_materials
).squeeze(-1)

mask = face_uvs_idx == -1
face_uvs_idx[mask] = 0
face_uvs = kal.ops.mesh.index_vertices_by_faces(
Expand Down
4 changes: 3 additions & 1 deletion examples/recipes/preprocess/occupancy_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
# https://kaolin.readthedocs.io/en/latest/modules/kaolin.ops.mesh.html#triangular-meshes
# ==============================================================================================================

import os
import torch
import kaolin

mesh_path = "../../samples/sphere.obj" # Path to some .obj file with textures
FILE_DIR = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
mesh_path = os.path.join(FILE_DIR, os.pardir, os.pardir, "samples", "sphere.obj") # Path to some .obj file with textures
num_samples = 100000 # Number of sample points

# 1. Load a watertight mesh from obj file
Expand Down
Empty file added examples/tutorial/__init__.py
Empty file.

0 comments on commit 1834e57

Please sign in to comment.