Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions newton/_src/viewer/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ def log_mesh(
uvs: wp.array = None,
hidden=False,
backface_culling=True,
face_varying_uv=False,
):
pass

Expand Down
1 change: 1 addition & 0 deletions newton/_src/viewer/viewer_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def log_mesh(
uvs: wp.array = None,
hidden=False,
backface_culling=True,
face_varying_uv=False,
):
"""File viewer doesn't render meshes, so this is a no-op."""
pass
Expand Down
2 changes: 2 additions & 0 deletions newton/_src/viewer/viewer_gl.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def log_mesh(
uvs: wp.array = None,
hidden=False,
backface_culling=True,
face_varying_uv=False,
):
"""
Log a mesh for rendering.
Expand All @@ -212,6 +213,7 @@ def log_mesh(
uvs (wp.array, optional): Vertex UVs.
hidden (bool): Whether the mesh is hidden.
backface_culling (bool): Enable backface culling.
face_varying_uv (bool): Enable face varying UV.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the same docstring as for the other viewers?
Also here it would be good to clarify this flag is currently not used (always vertex-varying).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

"""
assert isinstance(points, wp.array)
assert isinstance(indices, wp.array)
Expand Down
2 changes: 2 additions & 0 deletions newton/_src/viewer/viewer_null.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def log_mesh(
uvs: wp.array = None,
hidden=False,
backface_culling=True,
face_varying_uv=False,
):
"""
No-op implementation for logging a mesh.
Expand All @@ -62,6 +63,7 @@ def log_mesh(
uvs: Texture coordinates (optional).
hidden: Whether the mesh is hidden.
backface_culling: Whether to enable backface culling.
face_varying_uv: Enable face varying UV (default: vertex varying).
"""
pass

Expand Down
3 changes: 3 additions & 0 deletions newton/_src/viewer/viewer_rerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def log_mesh(
uvs: wp.array = None,
hidden=False,
backface_culling=True,
face_varying_uv=False,
):
"""
Log a mesh to rerun for visualization.
Expand All @@ -97,8 +98,10 @@ def log_mesh(
indices (wp.array): Triangle indices (wp.uint32).
normals (wp.array, optional): Vertex normals (wp.vec3).
uvs (wp.array, optional): UV coordinates (wp.vec2).
uv_indices (wp.array, optional): Triangle indices (wp.uint32) for UVs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This argument doesn't exist here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

hidden (bool): Whether the mesh is hidden (unused).
backface_culling (bool): Whether to enable backface culling (unused).
face_varying_uv (bool): Whether to enable face varying UV (default: vertex varying).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe use a hyphen for "face-varying" and "vertex-varying".
Also here it would be good to clarify this flag is currently not used (always vertex-varying).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

"""
assert isinstance(points, wp.array)
assert isinstance(indices, wp.array)
Expand Down
30 changes: 23 additions & 7 deletions newton/_src/viewer/viewer_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def __init__(self, output_path, fps=60, up_axis="Z", num_frames=None):

# Create USD stage
self.stage = Usd.Stage.CreateNew(output_path)
self.stage.SetFramesPerSecond(fps)
self.stage.SetTimeCodesPerSecond(fps) # number of timeCodes per second for data storage
self.stage.SetFramesPerSecond(fps) # display frame rate (timeline FPS in DCC tools)
self.stage.SetStartTimeCode(0)

UsdGeom.SetStageUpAxis(self.stage, UsdGeom.Tokens.z)
Expand Down Expand Up @@ -133,6 +134,7 @@ def log_mesh(
uvs: wp.array = None,
hidden=False,
backface_culling=True,
face_varying_uv=False,
):
"""
Create a USD mesh prototype from vertex and index data.
Expand All @@ -145,7 +147,7 @@ def log_mesh(
uvs (wp.array, optional): UV coordinates as a warp array of wp.vec2.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify here the shape of these UV coordinates and how this is affected by face_varying_uv?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

hidden (bool, optional): If True, mesh will be hidden. Default is False.
backface_culling (bool, optional): If True, enable backface culling. Default is True.

face_varying_uv (bool, optional): If True, enable face varying UV. Default is False (vertex varying).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe use a hyphen for "face-varying" and "vertex-varying".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Returns:
str: The mesh prototype path.
"""
Expand All @@ -164,6 +166,25 @@ def log_mesh(
mesh_prim.GetFaceVertexCountsAttr().Set(face_vertex_counts)
mesh_prim.GetFaceVertexIndicesAttr().Set(indices_np)

# Set UVs if provided (do not set every frame)
if uvs is not None:
primvars_api = UsdGeom.PrimvarsAPI(mesh_prim)

# Get or create the 'st' primvar
if not primvars_api.GetPrimvar("st"):
st = primvars_api.CreatePrimvar("st", Sdf.ValueTypeNames.TexCoord2fArray, UsdGeom.Tokens.vertex)
else:
st = primvars_api.GetPrimvar("st")

st.Set(uvs.numpy().astype(np.float32))

if face_varying_uv:
assert len(uvs) == len(indices_np)
st.SetInterpolation(UsdGeom.Tokens.faceVarying)
else:
assert len(uvs) == len(points_np)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to raise a ValueError here with a useful error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Please take a look.

st.SetInterpolation(UsdGeom.Tokens.vertex)

# Store the prototype path
self._meshes[name] = mesh_prim

Expand All @@ -176,11 +197,6 @@ def log_mesh(
mesh_prim.GetNormalsAttr().Set(normals_np, self._frame_index)
mesh_prim.SetNormalsInterpolation(UsdGeom.Tokens.vertex)

# Set UVs if provided (simplified for now)
if uvs is not None:
# TODO: Implement UV support for USD meshes
pass

# how to hide the prototype mesh but not the instances in USD?
# mesh_prim.GetVisibilityAttr().Set("inherited" if not hidden else "invisible", self._frame_index)

Expand Down
Loading