prithivMLmods commited on
Commit
7dd0cf0
·
verified ·
1 Parent(s): eea07ca

update app

Browse files
Files changed (1) hide show
  1. app.py +33 -13
app.py CHANGED
@@ -275,7 +275,7 @@ def generate_3d(
275
  # 2. Process Mesh
276
  progress(0.7, desc="Processing Mesh...")
277
  mesh = outputs[0]
278
- # FIX: Aggressive simplification to prevent CUDA errors during post-processing
279
  mesh.simplify(1000000)
280
 
281
  # 3. Export to GLB
@@ -323,7 +323,7 @@ def generate_3d(
323
  timestamp = now.strftime("%Y-%m-%dT%H%M%S")
324
  glb_path = os.path.join(user_dir, f'trellis_output_{timestamp}.glb')
325
 
326
- # FIX: extension_webp=False ensures compatibility with Rerun/Standard Viewers
327
  glb.export(glb_path, extension_webp=False)
328
 
329
  # --- Rerun Visualization Logic ---
@@ -341,22 +341,42 @@ def generate_3d(
341
  rr.init("TRELLIS-3D-Viewer", recording_id=run_id, spawn=False)
342
  rec = rr
343
 
344
- # 1. CAMERA VIEW: Set View Coordinates (GLB is Right-Hand Y-Up)
345
- # This fixes the "rotated/sleeping model" issue in the viewer
346
  rec.log("world", rr.ViewCoordinates.RIGHT_HAND_Y_UP, static=True)
347
-
348
- # 2. SPECIAL FEATURES: Orientation Axes (Red=X, Green=Y, Blue=Z)
349
  try:
350
- # Arrows to show the origin
351
- rec.log("world/axes/x", rr.Arrows3D(vectors=[[0.6, 0, 0]], colors=[[255, 0, 0]]), static=True)
352
- rec.log("world/axes/y", rr.Arrows3D(vectors=[[0, 0.6, 0]], colors=[[0, 255, 0]]), static=True)
353
- rec.log("world/axes/z", rr.Arrows3D(vectors=[[0, 0, 0.6]], colors=[[0, 0, 255]]), static=True)
354
  except Exception:
355
- pass # Ignore if Arrows3D not available in this version
356
 
357
- # 3. Log the Model
358
- rec.log("world/model", rr.Asset3D(path=glb_path), static=True)
 
359
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
  # Save the Rerun recording (.rrd)
361
  rrd_path = os.path.join(user_dir, f'trellis_output_{timestamp}.rrd')
362
  rec.save(rrd_path)
 
275
  # 2. Process Mesh
276
  progress(0.7, desc="Processing Mesh...")
277
  mesh = outputs[0]
278
+ # Aggressive simplification to prevent CUDA errors during post-processing
279
  mesh.simplify(1000000)
280
 
281
  # 3. Export to GLB
 
323
  timestamp = now.strftime("%Y-%m-%dT%H%M%S")
324
  glb_path = os.path.join(user_dir, f'trellis_output_{timestamp}.glb')
325
 
326
+ # extension_webp=False ensures compatibility with Rerun/Standard Viewers
327
  glb.export(glb_path, extension_webp=False)
328
 
329
  # --- Rerun Visualization Logic ---
 
341
  rr.init("TRELLIS-3D-Viewer", recording_id=run_id, spawn=False)
342
  rec = rr
343
 
344
+ # 1. SETUP STATIC ENVIRONMENT
 
345
  rec.log("world", rr.ViewCoordinates.RIGHT_HAND_Y_UP, static=True)
346
+
347
+ # Log Axes Helpers (X=Red, Y=Green, Z=Blue)
348
  try:
349
+ rec.log("world/axes/x", rr.Arrows3D(vectors=[[0.5, 0, 0]], colors=[[255, 0, 0]]), static=True)
350
+ rec.log("world/axes/y", rr.Arrows3D(vectors=[[0, 0.5, 0]], colors=[[0, 255, 0]]), static=True)
351
+ rec.log("world/axes/z", rr.Arrows3D(vectors=[[0, 0, 0.5]], colors=[[0, 0, 255]]), static=True)
 
352
  except Exception:
353
+ pass
354
 
355
+ # 2. LOG MODEL (Static relative to its parent 'anchor')
356
+ # We place the model inside 'world/anchor/model' so we can rotate 'world/anchor'
357
+ rec.log("world/anchor/model", rr.Asset3D(path=glb_path), static=True)
358
 
359
+ # 3. CREATE ROTATION ANIMATION (Auto-Rotate)
360
+ # We animate the 'anchor' transform over a timeline
361
+ progress(0.98, desc="Generating Rotation Animation...")
362
+
363
+ num_frames = 240 # 240 frames for one full loop
364
+ for i in range(num_frames):
365
+ # Set the time cursor
366
+ rec.set_time_sequence("frame", i)
367
+
368
+ # Calculate rotation angle (0 to 360 degrees)
369
+ angle_rad = (i / num_frames) * 2 * np.pi
370
+
371
+ # Log the rotation transform for the anchor
372
+ # This rotates the model around the Y-axis
373
+ rec.log(
374
+ "world/anchor",
375
+ rr.Transform3D(
376
+ rotation=rr.RotationAxisAngle(axis=[0, 1, 0], radians=angle_rad)
377
+ )
378
+ )
379
+
380
  # Save the Rerun recording (.rrd)
381
  rrd_path = os.path.join(user_dir, f'trellis_output_{timestamp}.rrd')
382
  rec.save(rrd_path)