-
Notifications
You must be signed in to change notification settings - Fork 87
USD-Exporting improvements #820
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
114330e
b88f243
de4d60e
da7f5aa
5b99bfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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 | ||
|
||
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). | ||
|
||
""" | ||
assert isinstance(points, wp.array) | ||
assert isinstance(indices, wp.array) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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. | ||
|
@@ -145,7 +147,7 @@ def log_mesh( | |
uvs (wp.array, optional): UV coordinates as a warp array of wp.vec2. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). | ||
|
||
Returns: | ||
str: The mesh prototype path. | ||
""" | ||
|
@@ -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) | ||
|
||
st.SetInterpolation(UsdGeom.Tokens.vertex) | ||
|
||
# Store the prototype path | ||
self._meshes[name] = mesh_prim | ||
|
||
|
@@ -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) | ||
|
||
|
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed