dev-bjoern commited on
Commit
0ad1e20
Β·
1 Parent(s): b8dd3b4

Fix upside-down mesh rotation, add 3D preview

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -112,6 +112,10 @@ def reconstruct_body(image: np.ndarray) -> tuple:
112
  # Create trimesh mesh
113
  mesh = trimesh.Trimesh(vertices=vertices, faces=faces)
114
 
 
 
 
 
115
  # Save GLB
116
  output_dir = tempfile.mkdtemp()
117
  glb_path = f"{output_dir}/body_{uuid.uuid4().hex[:8]}.glb"
@@ -128,17 +132,19 @@ def reconstruct_body(image: np.ndarray) -> tuple:
128
  # Gradio Interface
129
  with gr.Blocks(title="SAM 3D Body MCP") as demo:
130
  gr.Markdown("# 🧍 SAM 3D Body MCP Server\n**Image β†’ 3D Human Mesh (GLB)**")
131
-
132
  with gr.Row():
133
  with gr.Column():
134
  input_image = gr.Image(label="Input Image", type="numpy")
135
  btn = gr.Button("🎯 Reconstruct", variant="primary")
136
-
137
  with gr.Column():
138
- output_file = gr.File(label="3D Mesh (GLB)")
 
139
  status = gr.Textbox(label="Status")
140
-
141
- btn.click(reconstruct_body, inputs=[input_image], outputs=[output_file, status])
 
142
 
143
  gr.Markdown("""
144
  ---
 
112
  # Create trimesh mesh
113
  mesh = trimesh.Trimesh(vertices=vertices, faces=faces)
114
 
115
+ # Rotate 180Β° around X-axis to fix upside-down orientation
116
+ rotation = trimesh.transformations.rotation_matrix(np.pi, [1, 0, 0])
117
+ mesh.apply_transform(rotation)
118
+
119
  # Save GLB
120
  output_dir = tempfile.mkdtemp()
121
  glb_path = f"{output_dir}/body_{uuid.uuid4().hex[:8]}.glb"
 
132
  # Gradio Interface
133
  with gr.Blocks(title="SAM 3D Body MCP") as demo:
134
  gr.Markdown("# 🧍 SAM 3D Body MCP Server\n**Image β†’ 3D Human Mesh (GLB)**")
135
+
136
  with gr.Row():
137
  with gr.Column():
138
  input_image = gr.Image(label="Input Image", type="numpy")
139
  btn = gr.Button("🎯 Reconstruct", variant="primary")
140
+
141
  with gr.Column():
142
+ output_model = gr.Model3D(label="3D Preview")
143
+ output_file = gr.File(label="Download GLB")
144
  status = gr.Textbox(label="Status")
145
+
146
+ btn.click(reconstruct_body, inputs=[input_image], outputs=[output_model, status])
147
+ output_model.change(lambda x: x, inputs=[output_model], outputs=[output_file])
148
 
149
  gr.Markdown("""
150
  ---