prithivMLmods commited on
Commit
96a08db
·
verified ·
1 Parent(s): 7e3af3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -14
app.py CHANGED
@@ -190,17 +190,28 @@ def get_seed(randomize_seed: bool, seed: int) -> int:
190
  # --- Camera & Rotation Helpers ---
191
 
192
  def get_look_at_matrix(eye, target, up):
193
- """Calculate a Look-At rotation matrix."""
194
- z_axis = eye - target
195
- z_axis = z_axis / np.linalg.norm(z_axis)
 
 
 
 
 
 
196
 
197
- x_axis = np.cross(up, z_axis)
198
- x_axis = x_axis / np.linalg.norm(x_axis)
 
 
 
 
199
 
200
- y_axis = np.cross(z_axis, x_axis)
 
201
 
202
- # Create rotation matrix (3x3)
203
- rotation_matrix = np.column_stack([x_axis, y_axis, z_axis])
204
  return rotation_matrix
205
 
206
  def log_turntable_camera(rec, radius=2.0, height=0.5, num_frames=180):
@@ -210,10 +221,10 @@ def log_turntable_camera(rec, radius=2.0, height=0.5, num_frames=180):
210
  try:
211
  rec.log("/", rr.ViewCoordinates.RIGHT_HAND_Y_UP, static=True)
212
  except Exception:
213
- pass # Ignore if ViewCoordinates fails
214
 
215
  center = np.array([0.0, 0.0, 0.0])
216
- up_world = np.array([0.0, 1.0, 0.0]) # Y-up
217
 
218
  for i in range(num_frames):
219
  # Robust Time Setting with Fallback
@@ -222,7 +233,6 @@ def log_turntable_camera(rec, radius=2.0, height=0.5, num_frames=180):
222
  elif hasattr(rec, "set_time_seconds"):
223
  rec.set_time_seconds("sim_time", i * 0.1)
224
  else:
225
- # If no time setting method exists, animation is impossible.
226
  raise AttributeError("RecordingStream lacks set_time_sequence or set_time_seconds")
227
 
228
  # Calculate angle
@@ -235,7 +245,7 @@ def log_turntable_camera(rec, radius=2.0, height=0.5, num_frames=180):
235
 
236
  eye = np.array([cam_x, cam_y, cam_z])
237
 
238
- # Get rotation to look at center
239
  rot_mat = get_look_at_matrix(eye, center, up_world)
240
 
241
  # Log Camera Transform (Extrinsics)
@@ -248,12 +258,12 @@ def log_turntable_camera(rec, radius=2.0, height=0.5, num_frames=180):
248
  )
249
 
250
  # Log Camera Intrinsics (Pinhole)
 
251
  rec.log(
252
  "world/camera",
253
  rr.Pinhole(
254
  fov_y=math.radians(45),
255
  aspect_ratio=1.0,
256
- camera_axis_prefix="RUB",
257
  )
258
  )
259
 
@@ -434,9 +444,10 @@ def generate_3d(
434
  rr.Transform3D(translation=eye, mat3x3=get_look_at_matrix(eye, center, up)),
435
  static=True
436
  )
 
437
  rec.log(
438
  "world/camera",
439
- rr.Pinhole(fov_y=math.radians(45), aspect_ratio=1.0, camera_axis_prefix="RUB"),
440
  static=True
441
  )
442
 
 
190
  # --- Camera & Rotation Helpers ---
191
 
192
  def get_look_at_matrix(eye, target, up):
193
+ """
194
+ Calculate a Look-At rotation matrix.
195
+ Returns a matrix for a camera looking at 'target' from 'eye'
196
+ with a 'Right-Down-Forward' (RDF) coordinate system, which is standard
197
+ for Rerun pinholes when no axis prefix is specified.
198
+ """
199
+ # Forward vector (Z) points from eye to target
200
+ forward = target - eye
201
+ forward = forward / np.linalg.norm(forward)
202
 
203
+ # Right vector (X) is perpendicular to Up and Forward
204
+ right = np.cross(forward, up) # Note: cross order matters
205
+ if np.linalg.norm(right) < 1e-6:
206
+ # Handle degenerate case where forward ~= up
207
+ right = np.array([1.0, 0.0, 0.0])
208
+ right = right / np.linalg.norm(right)
209
 
210
+ # Down vector (Y) is perpendicular to Forward and Right
211
+ down = np.cross(forward, right)
212
 
213
+ # Rerun expects columns [X, Y, Z]
214
+ rotation_matrix = np.column_stack([right, down, forward])
215
  return rotation_matrix
216
 
217
  def log_turntable_camera(rec, radius=2.0, height=0.5, num_frames=180):
 
221
  try:
222
  rec.log("/", rr.ViewCoordinates.RIGHT_HAND_Y_UP, static=True)
223
  except Exception:
224
+ pass
225
 
226
  center = np.array([0.0, 0.0, 0.0])
227
+ up_world = np.array([0.0, 1.0, 0.0]) # World Up
228
 
229
  for i in range(num_frames):
230
  # Robust Time Setting with Fallback
 
233
  elif hasattr(rec, "set_time_seconds"):
234
  rec.set_time_seconds("sim_time", i * 0.1)
235
  else:
 
236
  raise AttributeError("RecordingStream lacks set_time_sequence or set_time_seconds")
237
 
238
  # Calculate angle
 
245
 
246
  eye = np.array([cam_x, cam_y, cam_z])
247
 
248
+ # Get rotation (RDF)
249
  rot_mat = get_look_at_matrix(eye, center, up_world)
250
 
251
  # Log Camera Transform (Extrinsics)
 
258
  )
259
 
260
  # Log Camera Intrinsics (Pinhole)
261
+ # Removed unsupported 'camera_axis_prefix'
262
  rec.log(
263
  "world/camera",
264
  rr.Pinhole(
265
  fov_y=math.radians(45),
266
  aspect_ratio=1.0,
 
267
  )
268
  )
269
 
 
444
  rr.Transform3D(translation=eye, mat3x3=get_look_at_matrix(eye, center, up)),
445
  static=True
446
  )
447
+ # Removed unsupported 'camera_axis_prefix'
448
  rec.log(
449
  "world/camera",
450
+ rr.Pinhole(fov_y=math.radians(45), aspect_ratio=1.0),
451
  static=True
452
  )
453