Skip to content

Commit

Permalink
Z up config option
Browse files Browse the repository at this point in the history
  • Loading branch information
ramenguy99 committed Sep 2, 2023
1 parent 6a430cc commit 811c216
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
3 changes: 3 additions & 0 deletions aitviewer/aitvconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ backface_culling: True
background_color: [1.0, 1.0, 1.0, 1.0]
window_type: "pyqt5"

# Viewer defaults to Y up, set to true for Z up.
z_up: False

# Server for remote connections.
server_enabled: False
server_port: 8417
4 changes: 2 additions & 2 deletions aitviewer/renderables/plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def __init__(
v1 = np.array([1, 0, 0], dtype=np.float32)
v2 = np.array([0, 0, 1], dtype=np.float32)
elif plane == "xy":
v1 = np.array([1, 0, 0], dtype=np.float32)
v2 = np.array([0, 1, 0], dtype=np.float32)
v1 = np.array([0, 1, 0], dtype=np.float32)
v2 = np.array([1, 0, 0], dtype=np.float32)
else:
# plane == "yz"
v1 = np.array([0, 1, 0], dtype=np.float32)
Expand Down
3 changes: 2 additions & 1 deletion aitviewer/renderables/point_clouds.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
from moderngl_window.opengl.vao import VAO

from aitviewer.configuration import CONFIG as C
from aitviewer.scene.node import Node
from aitviewer.shaders import (
get_fragmap_program,
Expand Down Expand Up @@ -54,7 +55,7 @@ def __init__(

self.vao = VAO("points", mode=moderngl.POINTS)

if z_up:
if z_up and not C.z_up:
self.rotation = np.matmul(np.array([[1, 0, 0], [0, 0, 1], [0, -1, 0]]), self.rotation)

@property
Expand Down
2 changes: 1 addition & 1 deletion aitviewer/renderables/smpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def __init__(
else:
global_oris = np.tile(np.eye(3), self.joints.shape[:-1])[np.newaxis]

if self._z_up:
if self._z_up and not C.z_up:
self.rotation = np.matmul(np.array([[1, 0, 0], [0, 0, 1], [0, -1, 0]]), self.rotation)

self.rbs = RigidBodies(self.joints, global_oris, length=0.1, gui_affine=False, name="Joint Angles")
Expand Down
17 changes: 11 additions & 6 deletions aitviewer/scene/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ def __init__(
cols,
rows,
fov=45,
world_up=None,
near=None,
far=None,
viewer=None,
Expand All @@ -723,7 +724,11 @@ def __init__(
positions.shape[0] == 1 or targets.shape[0] == 1 or positions.shape[0] == targets.shape[0]
), f"position and target array shape mismatch: {positions.shape} and {targets.shape}"

self._world_up = np.array([0.0, 1.0, 0.0])
if world_up:
self._world_up = world_up
else:
self._world_up = np.array([0.0, 0.0, 1.0]) if C.z_up else np.array([0.0, 1.0, 0.0])

self._targets = targets
super(PinholeCamera, self).__init__(position=position, n_frames=targets.shape[0], viewer=viewer, **kwargs)

Expand Down Expand Up @@ -862,9 +867,9 @@ def __init__(self, fov=45, orthographic=None, znear=None, zfar=None):
self.ortho_size = 1.0 if orthographic is None else orthographic

# Default camera settings.
self._position = np.array([0.0, 0.0, 2.5])
self._position = np.array([0.0, 2.5, 0.0]) if C.z_up else np.array([0.0, 0.0, 2.5])
self._target = np.array([0.0, 0.0, 0.0])
self._up = np.array([0.0, 1.0, 0.0])
self._up = np.array([0.0, 0.0, 1.0]) if C.z_up else np.array([0.0, 1.0, 0.0])

self.ZOOM_FACTOR = 4
self.ROT_FACTOR = 0.0025
Expand Down Expand Up @@ -904,7 +909,7 @@ def control_mode(self, mode):
if mode not in self._control_modes:
raise ValueError(f"Invalid camera mode: {mode}")
if mode == "first_person" or mode == "turntable":
self.up = (0, 1, 0)
self.up = (0, 0, 1) if C.z_up else (0, 1, 0)
self._control_mode = mode

def copy(self):
Expand Down Expand Up @@ -1052,8 +1057,8 @@ def rotate_azimuth(self, angle):
if np.abs(angle) < 1e-8:
return
cam_pose = np.linalg.inv(self.view_matrix)
y_axis = cam_pose[:3, 1]
rot = rotation_matrix(angle, y_axis, self.target)
up_axis = cam_pose[:3, 1]
rot = rotation_matrix(angle, up_axis, self.target)
self.position = _transform_vector(rot, self.position)

def _rotation_from_mouse_delta(self, mouse_dx: int, mouse_dy: int):
Expand Down
13 changes: 8 additions & 5 deletions aitviewer/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ def __init__(self, **kwargs):
Light.facing_origin(
light_color=(1.0, 1.0, 1.0),
name="Back Light",
position=(0.0, 10.0, -15.0),
position=(0.0, -15.0, 10.0) if C.z_up else (0.0, 10.0, -15.0),
shadow_enabled=False,
)
)
self.lights.append(
Light.facing_origin(
light_color=(1.0, 1.0, 1.0),
name="Front Light",
position=(0.0, 10.0, 15.0),
position=(0.0, 15.0, 10.0) if C.z_up else (0.0, 10.0, 15.0),
)
)
self.add(*self.lights)
Expand All @@ -61,7 +61,9 @@ def __init__(self, **kwargs):
self.origin = CoordinateSystem(name="Origin", length=0.1, gui_affine=False, gui_material=False)
self.add(self.origin)

self.floor = ChessboardPlane(100.0, 200, (0.9, 0.9, 0.9, 1.0), (0.82, 0.82, 0.82, 1.0), name="Floor")
self.floor = ChessboardPlane(
100.0, 200, (0.9, 0.9, 0.9, 1.0), (0.82, 0.82, 0.82, 1.0), "xy" if C.z_up else "xz", name="Floor"
)
self.floor.material.diffuse = 0.1
self.add(self.floor)

Expand Down Expand Up @@ -233,8 +235,9 @@ def bounds_without_floor(self):
def auto_set_floor(self):
"""Finds the minimum lower bound in the y coordinate from all the children bounds and uses that as the floor"""
if self.floor is not None and len(self.nodes) > 0:
self.floor.position[1] = self.current_bounds[1, 0]
self.floor.update_transform()
axis = 2 if C.z_up else 1
self.floor.position[axis] = self.current_bounds[axis, 0]
self.floor.update_transform(parent_transform=self.model_matrix)

def auto_set_camera_target(self):
"""Sets the camera target to the average of the center of all objects in the scene"""
Expand Down

0 comments on commit 811c216

Please sign in to comment.