update
Browse files- Anymate/utils/ui_utils.py +12 -2
- Convert.py +24 -0
- app.py +57 -31
Anymate/utils/ui_utils.py
CHANGED
@@ -246,7 +246,17 @@ def process_input(mesh_file):
|
|
246 |
return None, None, None, None, None, None, None, None
|
247 |
|
248 |
# make folder for tmp files
|
249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
|
251 |
normalized_mesh = normalize_mesh(trimesh.load(mesh_file))
|
252 |
# normalized_mesh = normalize_mesh(obj2mesh(mesh_file))
|
@@ -261,7 +271,7 @@ def process_input(mesh_file):
|
|
261 |
|
262 |
# print(pc.shape, pc.max(dim=0), pc.min(dim=0))
|
263 |
|
264 |
-
return normalized_mesh_file,
|
265 |
|
266 |
|
267 |
def get_model(checkpoint):
|
|
|
246 |
return None, None, None, None, None, None, None, None
|
247 |
|
248 |
# make folder for tmp files
|
249 |
+
if mesh_file.endswith('.obj'):
|
250 |
+
os.makedirs(f"Anymate/tmp/{mesh_file.split('/')[-1].replace('.obj', '')}", exist_ok=True)
|
251 |
+
else:
|
252 |
+
os.makedirs(f"Anymate/tmp/{mesh_file.split('/')[-1].replace('.glb', '')}", exist_ok=True)
|
253 |
+
abs_path = os.path.abspath(mesh_file)
|
254 |
+
|
255 |
+
os.system(f"python Convert.py --path {abs_path}")
|
256 |
+
|
257 |
+
mesh_file = abs_path.replace('.glb', '.obj')
|
258 |
+
while not os.path.exists(mesh_file):
|
259 |
+
time.sleep(1)
|
260 |
|
261 |
normalized_mesh = normalize_mesh(trimesh.load(mesh_file))
|
262 |
# normalized_mesh = normalize_mesh(obj2mesh(mesh_file))
|
|
|
271 |
|
272 |
# print(pc.shape, pc.max(dim=0), pc.min(dim=0))
|
273 |
|
274 |
+
return normalized_mesh_file, None, None, None, pc
|
275 |
|
276 |
|
277 |
def get_model(checkpoint):
|
Convert.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import bpy
|
3 |
+
import mathutils
|
4 |
+
from Anymate.blender_script import load_object, save_mesh
|
5 |
+
from Anymate.utils.render_utils import empty
|
6 |
+
|
7 |
+
|
8 |
+
def parse_args():
|
9 |
+
parser = argparse.ArgumentParser(description='Anymate rendering script')
|
10 |
+
parser.add_argument('--path', type=str, required=True, help='Path to the model file')
|
11 |
+
return parser.parse_args()
|
12 |
+
|
13 |
+
args = parse_args()
|
14 |
+
|
15 |
+
print(f"Starting converting {args.path} to obj format...")
|
16 |
+
|
17 |
+
# empty the scene
|
18 |
+
empty()
|
19 |
+
|
20 |
+
# load the glb file
|
21 |
+
load_object(args.path)
|
22 |
+
|
23 |
+
# save the mesh
|
24 |
+
save_mesh(args.path.replace('.glb', '.obj'))
|
app.py
CHANGED
@@ -31,7 +31,15 @@ def get_all_results(mesh_file, pc, eps=0.03, min_samples=1):
|
|
31 |
with gr.Blocks() as demo:
|
32 |
gr.Markdown("""
|
33 |
# Anymate: Auto-rigging 3D Objects
|
34 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
""")
|
36 |
|
37 |
pc = gr.State(value=None)
|
@@ -46,38 +54,28 @@ with gr.Blocks() as demo:
|
|
46 |
# model_skinning = gr.State(value=model_skinning)
|
47 |
|
48 |
with gr.Row():
|
49 |
-
with gr.Column():
|
50 |
# Input section
|
51 |
-
gr.Markdown("
|
52 |
mesh_input = gr.Model3D(label="Input 3D Mesh", clear_color=[0.0, 0.0, 0.0, 0.0])
|
53 |
|
|
|
54 |
# Sample 3D objects section
|
55 |
-
gr.Markdown("
|
56 |
sample_objects_dir = './samples'
|
57 |
sample_objects = [os.path.join(sample_objects_dir, f) for f in os.listdir(sample_objects_dir)
|
58 |
-
if f.endswith('.
|
59 |
sample_objects.sort()
|
|
|
60 |
|
61 |
-
|
62 |
-
label="
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
)
|
67 |
-
|
68 |
-
load_sample_btn = gr.Button("Load Sample")
|
69 |
-
|
70 |
-
with gr.Column():
|
71 |
-
# Output section
|
72 |
-
gr.Markdown("### Output (wireframe display mode)")
|
73 |
-
mesh_output = gr.Model3D(label="Output 3D Mesh", clear_color=[0.0, 0.0, 0.0, 0.0], display_mode="wireframe")
|
74 |
-
|
75 |
-
with gr.Column():
|
76 |
-
# Output section
|
77 |
-
gr.Markdown("### (solid display mode & blender file)")
|
78 |
-
mesh_output2 = gr.Model3D(label="Output 3D Mesh", clear_color=[0.0, 0.0, 0.0, 0.0], display_mode="solid")
|
79 |
-
|
80 |
-
blender_file = gr.File(label="Output Blender File", scale=1)
|
81 |
|
82 |
# Checkpoint paths
|
83 |
# joint_models_dir = 'Anymate/checkpoints/joint'
|
@@ -131,15 +129,33 @@ with gr.Blocks() as demo:
|
|
131 |
|
132 |
# process_skin_btn = gr.Button("Process", scale=0.3)
|
133 |
|
|
|
|
|
|
|
|
|
|
|
134 |
with gr.Row():
|
135 |
# load_all_btn = gr.Button("Load all models", scale=1)
|
136 |
process_all_btn = gr.Button("Run all models", scale=1)
|
137 |
# download_btn = gr.DownloadButton("Blender File Not Ready", scale=0.3)
|
138 |
# blender_file = gr.File(label="Blender File", scale=1)
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
mesh_input.change(
|
145 |
process_input,
|
@@ -147,10 +163,12 @@ with gr.Blocks() as demo:
|
|
147 |
outputs=[normalized_mesh_file, mesh_output, mesh_output2, blender_file, pc]
|
148 |
)
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
|
|
|
|
154 |
).then(
|
155 |
process_input,
|
156 |
inputs=mesh_input,
|
@@ -188,6 +206,10 @@ with gr.Blocks() as demo:
|
|
188 |
# )
|
189 |
|
190 |
process_all_btn.click(
|
|
|
|
|
|
|
|
|
191 |
get_all_results,
|
192 |
inputs=[normalized_mesh_file, pc, eps, min_samples],
|
193 |
outputs=[]
|
@@ -199,6 +221,10 @@ with gr.Blocks() as demo:
|
|
199 |
prepare_blender_file,
|
200 |
inputs=[normalized_mesh_file],
|
201 |
outputs=blender_file
|
|
|
|
|
|
|
|
|
202 |
)
|
203 |
|
204 |
if __name__ == "__main__":
|
|
|
31 |
with gr.Blocks() as demo:
|
32 |
gr.Markdown("""
|
33 |
# Anymate: Auto-rigging 3D Objects
|
34 |
+
Welcome to the interactive demo for **[Anymate](https://anymate3d.github.io/)**, a breakthrough in automatic 3D object rigging!
|
35 |
+
This demo is based on our research paper: 📄 **[Anymate: A Dataset and Baselines for Learning 3D Object Rigging](https://arxiv.org/abs/2505.06227)**
|
36 |
+
🚀 **How It Works**
|
37 |
+
1. **Upload** your 3D mesh (`.obj` or `.glb` format) or select a sample object from the gallery.
|
38 |
+
2. Click **"Run All Models"** to automatically generate rigging.
|
39 |
+
3. **Download** your animatable object as a `.blender` file—ready for animation!
|
40 |
+
|
41 |
+
✨ No manual rigging, no hassle—just drag, drop, and animate.
|
42 |
+
📌 *Tip: Check out our [project page](https://anymate3d.github.io/) for datasets, code, and more!*
|
43 |
""")
|
44 |
|
45 |
pc = gr.State(value=None)
|
|
|
54 |
# model_skinning = gr.State(value=model_skinning)
|
55 |
|
56 |
with gr.Row():
|
57 |
+
with gr.Column(scale=0.33):
|
58 |
# Input section
|
59 |
+
gr.Markdown("## Input")
|
60 |
mesh_input = gr.Model3D(label="Input 3D Mesh", clear_color=[0.0, 0.0, 0.0, 0.0])
|
61 |
|
62 |
+
with gr.Column(scale=0.67):
|
63 |
# Sample 3D objects section
|
64 |
+
gr.Markdown("## Select to load sample objects")
|
65 |
sample_objects_dir = './samples'
|
66 |
sample_objects = [os.path.join(sample_objects_dir, f) for f in os.listdir(sample_objects_dir)
|
67 |
+
if f.endswith('.png') and os.path.isfile(os.path.join(sample_objects_dir, f))]
|
68 |
sample_objects.sort()
|
69 |
+
print(len(sample_objects))
|
70 |
|
71 |
+
sample_gallery = gr.Gallery(
|
72 |
+
label="Sample Objects",
|
73 |
+
value=sample_objects,
|
74 |
+
columns=5,
|
75 |
+
object_fit="contain",
|
76 |
+
height="200px",
|
77 |
+
allow_preview=False
|
78 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
# Checkpoint paths
|
81 |
# joint_models_dir = 'Anymate/checkpoints/joint'
|
|
|
129 |
|
130 |
# process_skin_btn = gr.Button("Process", scale=0.3)
|
131 |
|
132 |
+
with gr.Row():
|
133 |
+
# Parameters for DBSCAN clustering algorithm used to adjust joint clustering
|
134 |
+
eps = gr.Number(label="Epsilon", value=0.03, interactive=True, info="Controls the maximum distance between joints in a cluster")
|
135 |
+
min_samples = gr.Number(label="Min Samples", value=1, interactive=True, info="Minimum number of joints required to form a cluster")
|
136 |
+
|
137 |
with gr.Row():
|
138 |
# load_all_btn = gr.Button("Load all models", scale=1)
|
139 |
process_all_btn = gr.Button("Run all models", scale=1)
|
140 |
# download_btn = gr.DownloadButton("Blender File Not Ready", scale=0.3)
|
141 |
# blender_file = gr.File(label="Blender File", scale=1)
|
142 |
|
143 |
+
with gr.Row():
|
144 |
+
gr.Markdown("## Output")
|
145 |
+
with gr.Row():
|
146 |
+
with gr.Column():
|
147 |
+
# Output section
|
148 |
+
gr.Markdown("#### (wireframe display mode)")
|
149 |
+
mesh_output = gr.Model3D(label="Output 3D Mesh", clear_color=[0.0, 0.0, 0.0, 0.0], display_mode="wireframe")
|
150 |
+
|
151 |
+
with gr.Column():
|
152 |
+
# Output section
|
153 |
+
gr.Markdown("#### (solid display mode)")
|
154 |
+
mesh_output2 = gr.Model3D(label="Output 3D Mesh", clear_color=[0.0, 0.0, 0.0, 0.0], display_mode="solid")
|
155 |
+
with gr.Column():
|
156 |
+
# Output section
|
157 |
+
gr.Markdown("#### (blender file)")
|
158 |
+
blender_file = gr.File(label="Output Blender File")
|
159 |
|
160 |
mesh_input.change(
|
161 |
process_input,
|
|
|
163 |
outputs=[normalized_mesh_file, mesh_output, mesh_output2, blender_file, pc]
|
164 |
)
|
165 |
|
166 |
+
def get_select_object(evt: gr.SelectData):
|
167 |
+
return f'./samples/sample{evt.index+1}.obj'
|
168 |
+
sample_gallery.select(
|
169 |
+
fn=get_select_object,
|
170 |
+
inputs=None,
|
171 |
+
outputs=mesh_input
|
172 |
).then(
|
173 |
process_input,
|
174 |
inputs=mesh_input,
|
|
|
206 |
# )
|
207 |
|
208 |
process_all_btn.click(
|
209 |
+
fn=lambda: gr.Button(value="Processing...", interactive=False),
|
210 |
+
inputs=[],
|
211 |
+
outputs=[process_all_btn]
|
212 |
+
).then(
|
213 |
get_all_results,
|
214 |
inputs=[normalized_mesh_file, pc, eps, min_samples],
|
215 |
outputs=[]
|
|
|
221 |
prepare_blender_file,
|
222 |
inputs=[normalized_mesh_file],
|
223 |
outputs=blender_file
|
224 |
+
).then(
|
225 |
+
lambda: gr.Button(value="Run all models", interactive=True),
|
226 |
+
inputs=[],
|
227 |
+
outputs=[process_all_btn]
|
228 |
)
|
229 |
|
230 |
if __name__ == "__main__":
|