From 8c41a263b8c9aaba2ed242d0abaf03480a50eb1d Mon Sep 17 00:00:00 2001 From: Matthew Tancik Date: Fri, 27 Jan 2023 13:56:19 -0800 Subject: [PATCH 1/4] Fix normal orientation loss (#1298) Co-authored-by: Abhik Ahuja --- nerfstudio/model_components/losses.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nerfstudio/model_components/losses.py b/nerfstudio/model_components/losses.py index 9624ad02d..7fcfe0419 100644 --- a/nerfstudio/model_components/losses.py +++ b/nerfstudio/model_components/losses.py @@ -193,7 +193,7 @@ def orientation_loss( """ w = weights n = normals - v = viewdirs + v = viewdirs * -1 n_dot_v = (n * v[..., None, :]).sum(axis=-1) return (w[..., 0] * torch.fmin(torch.zeros_like(n_dot_v), n_dot_v) ** 2).sum(dim=-1) From 867ed48f307fb5937046164a27eda5f3d22f80ef Mon Sep 17 00:00:00 2001 From: Matthew Tancik Date: Sun, 29 Jan 2023 09:05:07 -0800 Subject: [PATCH 2/4] Tancik/protobuf version req update (#1303) * Fix normal orientation loss * Update protobuf req --------- Co-authored-by: Abhik Ahuja --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e0cc30cfb..10942cf21 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ dependencies = [ "opencv-python==4.6.0.66", "Pillow>=9.3.0", "plotly>=5.7.0", - "protobuf<=3.20.3.*,!=3.20.0", + "protobuf<=3.20.3", "pymeshlab>=2022.2.post2", "pyngrok>=5.1.0", "python-socketio>=5.7.1", From 91d61162b77d6101ac5abacc3ddd14107cad9bba Mon Sep 17 00:00:00 2001 From: MaroonAmor Date: Sun, 29 Jan 2023 11:22:10 -0600 Subject: [PATCH 3/4] Corrected the order of texture arguments (#1300) corrected the order of texture arguments --- scripts/texture.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/texture.py b/scripts/texture.py index ec6545b87..702242ef2 100644 --- a/scripts/texture.py +++ b/scripts/texture.py @@ -56,10 +56,10 @@ class TextureMesh: # texture the mesh with NeRF and export to a mesh.obj file # and a material and texture file texture_utils.export_textured_mesh( - mesh, - pipeline, - self.px_per_uv_triangle, - self.output_dir, + mesh=mesh, + pipeline=pipeline, + output_dir=self.output_dir, + px_per_uv_triangle=self.px_per_uv_triangle, unwrap_method=self.unwrap_method, num_pixels_per_side=self.num_pixels_per_side, ) From 61dc520e17fb38beefaf2fb7288c4355ec353fb7 Mon Sep 17 00:00:00 2001 From: Matthew Tancik Date: Mon, 30 Jan 2023 10:55:13 -0800 Subject: [PATCH 4/4] Add sphere collider (#1310) Co-authored-by: David McAllister --- .../model_components/scene_colliders.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/nerfstudio/model_components/scene_colliders.py b/nerfstudio/model_components/scene_colliders.py index bf3ccd1b9..a36edfb38 100644 --- a/nerfstudio/model_components/scene_colliders.py +++ b/nerfstudio/model_components/scene_colliders.py @@ -108,6 +108,65 @@ class AABBBoxCollider(SceneCollider): return ray_bundle +@torch.jit.script +def _intersect_with_sphere( + rays_o: torch.Tensor, rays_d: torch.Tensor, center: torch.Tensor, radius: float = 1.0, near_plane: float = 0.0 +): + a = (rays_d * rays_d).sum(dim=-1, keepdim=True) + b = 2 * (rays_o - center) * rays_d + b = b.sum(dim=-1, keepdim=True) + c = (rays_o - center) * (rays_o - center) + c = c.sum(dim=-1, keepdim=True) - radius**2 + + # clamp to near plane + nears = (-b - torch.sqrt(torch.square(b) - 4 * a * c)) / (2 * a) + fars = (-b + torch.sqrt(torch.square(b) - 4 * a * c)) / (2 * a) + + nears = torch.clamp(nears, min=near_plane) + fars = torch.maximum(fars, nears + 1e-6) + + nears = torch.nan_to_num(nears, nan=0.0) + fars = torch.nan_to_num(fars, nan=0.0) + + return nears, fars + + +class SphereCollider(SceneCollider): + """Module for colliding rays with the scene box to compute near and far values. + + Args: + center: center of sphere to intersect [3] + redius: radius of sphere to intersect + near_plane: near plane to clamp to + """ + + def __init__(self, center: torch.Tensor, radius: float, near_plane: float = 0.0, **kwargs) -> None: + super().__init__(**kwargs) + self.center = center + self.radius = radius + self.near_plane = near_plane + + def set_nears_and_fars(self, ray_bundle: RayBundle) -> RayBundle: + """Intersects the rays with the scene box and updates the near and far values. + Populates nears and fars fields and returns the ray_bundle. + + Args: + ray_bundle: specified ray bundle to operate on + """ + self.center = self.center.to(ray_bundle.origins.device) + near_plane = self.near_plane if self.training else 0 + nears, fars = _intersect_with_sphere( + rays_o=ray_bundle.origins, + rays_d=ray_bundle.directions, + center=self.center, + radius=self.radius, + near_plane=near_plane, + ) + ray_bundle.nears = nears + ray_bundle.fars = fars + return ray_bundle + + class NearFarCollider(SceneCollider): """Sets the nears and fars with fixed values.