Skip to content

Commit

Permalink
Brute-force fix for extra degree-of-freedom when setting up direction
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Dec 25, 2023
1 parent 42038ab commit 575b349
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
23 changes: 17 additions & 6 deletions src/viser/_message_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,23 @@ def rotate_between(before: onp.ndarray, after: onp.ndarray) -> tf.SO3:

R_threeworld_world = rotate_between(default_three_up, direction)

# If we set +Y to up, +X and +Z should face the camera.
# If we set +Z to up, +X and +Y should face the camera.
forward_wrt_world = R_threeworld_world.inverse() @ onp.array([1.0, 0.0, 1.0])
R_threeworld_world = R_threeworld_world @ rotate_between(
forward_wrt_world, onp.abs(forward_wrt_world)
)
# Rotate the world frame such that:
# If we set +Y to up, +X and +Z should face the camera.
# If we set +Z to up, +X and +Y should face the camera.
#
# This could be made more efficient...
thetas = onp.arange(360)
sums = [
onp.sum(
(tf.SO3.from_y_radians(theta) @ R_threeworld_world)
@ onp.array([-1.0, -1.0, -1.0])
)
for theta in thetas
]
best_theta = thetas[onp.argmax(sums)]

R_threeworld_world = tf.SO3.from_y_radians(best_theta) @ R_threeworld_world

if not onp.any(onp.isnan(R_threeworld_world.wxyz)):
# Set the orientation of the root node.
self._queue(
Expand Down
4 changes: 2 additions & 2 deletions src/viser/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function ViewerRoot() {
"": {
wxyz: (() => {
const quat = new THREE.Quaternion().setFromEuler(
new THREE.Euler(Math.PI / 2, Math.PI, Math.PI / 2),
new THREE.Euler(Math.PI / 2, Math.PI, -Math.PI / 2),
);
return [quat.w, quat.x, quat.y, quat.z];
})(),
Expand Down Expand Up @@ -213,7 +213,7 @@ function ViewerCanvas({ children }: { children: React.ReactNode }) {
);
return (
<Canvas
camera={{ position: [3.0, 3.0, 3.0] }}
camera={{ position: [-3.0, 3.0, -3.0] }}
gl={{ preserveDrawingBuffer: true }}
style={{
position: "relative",
Expand Down

0 comments on commit 575b349

Please sign in to comment.