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

Update log_mesh and log_meshes docs. #1286

Merged
merged 1 commit into from
Feb 28, 2023
Merged
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
70 changes: 41 additions & 29 deletions rerun_py/rerun_sdk/rerun/log/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,58 @@

def log_mesh(
entity_path: str,
positions: npt.NDArray[np.float32],
positions: npt.ArrayLike,
*,
indices: Optional[npt.NDArray[np.uint32]] = None,
normals: Optional[npt.NDArray[np.float32]] = None,
albedo_factor: Optional[npt.NDArray[np.float32]] = None,
indices: Optional[npt.ArrayLike] = None,
normals: Optional[npt.ArrayLike] = None,
albedo_factor: Optional[npt.ArrayLike] = None,
timeless: bool = False,
) -> None:
"""
Log a raw 3D mesh by specifying its vertex positions, and optionally indices, normals and albedo factor.

The data is _always_ interpreted as a triangle list:

* `positions` is a flattened array of 3D points, i.e. its length must be divisible by 3.
* `positions` is a (potentially flattened) array of 3D points, i.e. the total number of elements must be divisible
by 3.
* `indices`, if specified, is a flattened array of indices that describe the mesh's faces,
i.e. its length must be divisible by 3.
* `normals`, if specified, is a flattened array of 3D vectors that describe the normal
for each vertex, i.e. its length must be divisible by 3 and more importantly it has to be
equal to the length of `positions`.
* `albedo_factor`, if specified, is either a linear, unmultiplied, normalized RGB (vec3) or
RGBA (vec4) value.
* `normals`, if specified, is a (potentially flattened) array of 3D vectors that describe the normal for each
vertex, i.e. the total number of elements must be divisible by 3 and more importantly, `len(normals)` should be
equal to `len(positions)`.
* `albedo_factor`, if specified, is either a linear, unmultiplied, normalized RGB (vec3) or RGBA (vec4) value.

Example:
-------
```
# A simple red triangle:
positions = np.array([0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0])
indices = np.array([0, 1, 2])
normals = np.array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0])
albedo_factor = np.array([1.0, 0.0, 0.0])
rerun.log_mesh(
"world/mesh",
positions = [
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0]
],
indices = [0, 1, 2],
normals = [
[0.0, 0.0, 1.0],
[0.0, 0.0, 1.0],
[0.0, 0.0, 1.0]
],
albedo_factor = [1.0, 0.0, 0.0],
)
```

Parameters
----------
entity_path:
Path to the mesh in the space hierarchy
positions:
A flattened array of 3D points
An array of 3D points
indices:
Optional flattened array of indices that describe the mesh's faces
Optional array of indices that describe the mesh's faces
normals:
Optional flattened array of 3D vectors that describe the normal of each vertices
Optional array of 3D vectors that describe the normal of each vertices
albedo_factor:
Optional RGB(A) color for the albedo factor of the mesh, aka base color factor.
timeless:
Expand All @@ -64,25 +75,26 @@ def log_mesh(
if not bindings.is_enabled():
return

positions = positions.flatten().astype(np.float32)
positions = np.asarray(positions, dtype=np.float32).flatten()

if indices is not None:
indices = indices.flatten().astype(np.uint32)
indices = np.asarray(indices, dtype=np.uint32).flatten()
Copy link
Member

Choose a reason for hiding this comment

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

What is the difference here? Does it now accept normal arrays where it before didn't?

I'm kind of vary of doing actual code changes this close to release

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, it accepts np.array([..]) as well as [..]

Choose a reason for hiding this comment

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

sudo tar -vcfz dvr_rdk_v1.tar.gz dvr_rdk/
add this to tar and APT plays into action than

awalsh128/cache-apt-pkgs-action#98
link would help you about the new version update asap

if normals is not None:
normals = normals.flatten().astype(np.float32)
normals = np.asarray(normals, dtype=np.float32).flatten()
if albedo_factor is not None:
albedo_factor = albedo_factor.flatten().astype(np.float32)
albedo_factor = np.asarray(albedo_factor, dtype=np.float32).flatten()

# Mesh arrow handling happens inside the python bridge
bindings.log_meshes(entity_path, [positions.flatten()], [indices], [normals], [albedo_factor], timeless)


def log_meshes(
entity_path: str,
position_buffers: Sequence[npt.NDArray[np.float32]],
position_buffers: Sequence[npt.ArrayLike],
*,
index_buffers: Sequence[Optional[npt.NDArray[np.uint32]]],
normal_buffers: Sequence[Optional[npt.NDArray[np.float32]]],
albedo_factors: Sequence[Optional[npt.NDArray[np.float32]]],
index_buffers: Sequence[Optional[npt.ArrayLike]],
normal_buffers: Sequence[Optional[npt.ArrayLike]],
albedo_factors: Sequence[Optional[npt.ArrayLike]],
timeless: bool = False,
) -> None:
"""
Expand Down Expand Up @@ -115,13 +127,13 @@ def log_meshes(
if not bindings.is_enabled():
return

position_buffers = [p.flatten().astype(np.float32) for p in position_buffers]
position_buffers = [np.asarray(p, dtype=np.float32).flatten() for p in position_buffers]
if index_buffers is not None:
index_buffers = [i.flatten().astype(np.uint32) if i else None for i in index_buffers]
index_buffers = [np.asarray(i, dtype=np.uint32).flatten() if i else None for i in index_buffers]
if normal_buffers is not None:
normal_buffers = [n.flatten().astype(np.float32) if n else None for n in normal_buffers]
normal_buffers = [np.asarray(n, dtype=np.float32).flatten() if n else None for n in normal_buffers]
if albedo_factors is not None:
albedo_factors = [af.flatten().astype(np.float32) if af else None for af in albedo_factors]
albedo_factors = [np.asarray(af, dtype=np.float32).flatten() if af else None for af in albedo_factors]

# Mesh arrow handling happens inside the python bridge
bindings.log_meshes(entity_path, position_buffers, index_buffers, normal_buffers, albedo_factors, timeless)