Spaces:
Sleeping
Sleeping
Commit
·
33a8126
0
Parent(s):
first commit
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +2 -0
- Fast3Dcache +1 -0
- app.py +76 -0
- example_image/17.png +3 -0
- example_image/6.png +3 -0
- example_image/9.png +3 -0
- example_image/gou.png +3 -0
- example_image/typical_building_colorful_cottage.png +3 -0
- example_image/typical_creature_dragon.png +3 -0
- example_image/typical_creature_elephant.png +3 -0
- example_image/typical_creature_furry.png +3 -0
- example_image/typical_creature_quadruped.png +3 -0
- example_image/typical_creature_robot_crab.png +3 -0
- example_image/typical_creature_robot_dinosour.png +3 -0
- example_image/typical_creature_rock_monster.png +3 -0
- example_image/typical_humanoid_block_robot.png +3 -0
- example_image/typical_humanoid_dragonborn.png +3 -0
- example_image/typical_humanoid_dwarf.png +3 -0
- example_image/typical_humanoid_goblin.png +3 -0
- example_image/typical_humanoid_mech.png +3 -0
- example_image/typical_misc_crate.png +3 -0
- example_image/typical_misc_fireplace.png +3 -0
- example_image/typical_misc_lantern.png +3 -0
- example_image/typical_misc_magicbook.png +3 -0
- example_image/typical_misc_mailbox.png +3 -0
- example_image/typical_misc_monster_chest.png +3 -0
- example_image/typical_misc_phonograph.png +3 -0
- example_image/typical_misc_portal2.png +3 -0
- example_image/typical_misc_telephone.png +3 -0
- example_image/typical_misc_television.png +3 -0
- example_image/typical_misc_workbench.png +3 -0
- example_image/typical_vehicle_biplane.png +3 -0
- example_image/typical_vehicle_bulldozer.png +3 -0
- example_image/typical_vehicle_cart.png +3 -0
- example_image/typical_vehicle_excavator.png +3 -0
- example_image/typical_vehicle_helicopter.png +3 -0
- example_image/typical_vehicle_locomotive.png +3 -0
- example_image/typical_vehicle_pirate_ship.png +3 -0
- example_image/weatherworn_misc_paper_machine3.png +3 -0
- f3c/17_demo_trellis.glb +3 -0
- f3c/6_demo_trellis.glb +3 -0
- f3c/9_demo_trellis.glb +3 -0
- f3c/gou_demo_trellis.glb +3 -0
- f3c/typical_building_colorful_cottage_demo_trellis.glb +3 -0
- f3c/typical_creature_dragon_demo_trellis.glb +3 -0
- f3c/typical_creature_elephant_demo_trellis.glb +3 -0
- f3c/typical_creature_furry_demo_trellis.glb +3 -0
- f3c/typical_creature_quadruped_demo_trellis.glb +3 -0
- f3c/typical_creature_robot_crab_demo_trellis.glb +3 -0
- f3c/typical_creature_robot_dinosour_demo_trellis.glb +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.glb filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
Fast3Dcache
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Subproject commit 3058f3a0ef34bdce59626572b99aef556500f07e
|
app.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# 1. 定义文件夹路径
|
| 5 |
+
IMG_DIR = "example_image" # 你的图片文件夹名
|
| 6 |
+
MODEL_DIR = "f3c" # 你的模型文件夹名
|
| 7 |
+
|
| 8 |
+
# 2. 自动扫描并匹配文件
|
| 9 |
+
examples = []
|
| 10 |
+
|
| 11 |
+
# 检查文件夹是否存在,避免报错
|
| 12 |
+
if os.path.exists(IMG_DIR) and os.path.exists(MODEL_DIR):
|
| 13 |
+
# 获取所有 png 图片
|
| 14 |
+
image_files = sorted([f for f in os.listdir(IMG_DIR) if f.endswith('.png')])
|
| 15 |
+
|
| 16 |
+
for img_file in image_files:
|
| 17 |
+
# 获取不带后缀的文件名 (例如 "6" 或 "typical_creature_dragon")
|
| 18 |
+
base_name = os.path.splitext(img_file)[0]
|
| 19 |
+
|
| 20 |
+
# 构造对应的 GLB 文件名:规则是 "文件名_demo_trellis.glb"
|
| 21 |
+
expected_glb_name = f"{base_name}_demo_trellis.glb"
|
| 22 |
+
|
| 23 |
+
# 拼接完整路径
|
| 24 |
+
img_path = os.path.join(IMG_DIR, img_file)
|
| 25 |
+
glb_path = os.path.join(MODEL_DIR, expected_glb_name)
|
| 26 |
+
|
| 27 |
+
# 关键步骤:只有当对应的 3D 文件确实存在时,才添加到展示列表
|
| 28 |
+
if os.path.exists(glb_path):
|
| 29 |
+
examples.append({
|
| 30 |
+
"image": img_path,
|
| 31 |
+
"model": glb_path,
|
| 32 |
+
"label": base_name # 图片下方的文字标签
|
| 33 |
+
})
|
| 34 |
+
else:
|
| 35 |
+
# 如果没找到对应的模型,可以在后台打印一下,方便排查
|
| 36 |
+
print(f"⚠️ 未找到匹配模型: 图片 {img_file} -> 缺少 {expected_glb_name}")
|
| 37 |
+
|
| 38 |
+
print(f"✅ 成功加载了 {len(examples)} 组数据")
|
| 39 |
+
|
| 40 |
+
# 3. 定义点击事件:返回对应的模型路径
|
| 41 |
+
def display_model(evt: gr.SelectData):
|
| 42 |
+
if evt.index < len(examples):
|
| 43 |
+
return examples[evt.index]["model"]
|
| 44 |
+
return None
|
| 45 |
+
|
| 46 |
+
# 4. 构建界面
|
| 47 |
+
with gr.Blocks(title="3D Model Viewer") as demo:
|
| 48 |
+
gr.Markdown("## 3D Accelerated Instances Showcase")
|
| 49 |
+
gr.Markdown(f"点击左侧图片,右侧查看 3D 效果。共加载 {len(examples)} 个实例。")
|
| 50 |
+
|
| 51 |
+
with gr.Row():
|
| 52 |
+
# 左侧:图片画廊
|
| 53 |
+
with gr.Column(scale=1):
|
| 54 |
+
gallery = gr.Gallery(
|
| 55 |
+
value=[item["image"] for item in examples],
|
| 56 |
+
label="Instance Gallery",
|
| 57 |
+
columns=3, # 一行显示3张图
|
| 58 |
+
height=800, # 设置高度,图片多时会出现滚动条
|
| 59 |
+
object_fit="contain",
|
| 60 |
+
allow_preview=False # 禁止点击放大图片
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
# 右侧:3D 展示区
|
| 64 |
+
with gr.Column(scale=2):
|
| 65 |
+
model_3d = gr.Model3D(
|
| 66 |
+
clear_color=[0.2, 0.2, 0.2, 1.0], # 深灰色背景,看模型更清晰
|
| 67 |
+
label="3D Interactive View",
|
| 68 |
+
camera_position=(0, 0, 2.5) # 调整相机距离
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# 绑定交互
|
| 72 |
+
gallery.select(fn=display_model, outputs=model_3d)
|
| 73 |
+
|
| 74 |
+
# 启动
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
demo.launch()
|
example_image/17.png
ADDED
|
Git LFS Details
|
example_image/6.png
ADDED
|
Git LFS Details
|
example_image/9.png
ADDED
|
Git LFS Details
|
example_image/gou.png
ADDED
|
Git LFS Details
|
example_image/typical_building_colorful_cottage.png
ADDED
|
Git LFS Details
|
example_image/typical_creature_dragon.png
ADDED
|
Git LFS Details
|
example_image/typical_creature_elephant.png
ADDED
|
Git LFS Details
|
example_image/typical_creature_furry.png
ADDED
|
Git LFS Details
|
example_image/typical_creature_quadruped.png
ADDED
|
Git LFS Details
|
example_image/typical_creature_robot_crab.png
ADDED
|
Git LFS Details
|
example_image/typical_creature_robot_dinosour.png
ADDED
|
Git LFS Details
|
example_image/typical_creature_rock_monster.png
ADDED
|
Git LFS Details
|
example_image/typical_humanoid_block_robot.png
ADDED
|
Git LFS Details
|
example_image/typical_humanoid_dragonborn.png
ADDED
|
Git LFS Details
|
example_image/typical_humanoid_dwarf.png
ADDED
|
Git LFS Details
|
example_image/typical_humanoid_goblin.png
ADDED
|
Git LFS Details
|
example_image/typical_humanoid_mech.png
ADDED
|
Git LFS Details
|
example_image/typical_misc_crate.png
ADDED
|
Git LFS Details
|
example_image/typical_misc_fireplace.png
ADDED
|
Git LFS Details
|
example_image/typical_misc_lantern.png
ADDED
|
Git LFS Details
|
example_image/typical_misc_magicbook.png
ADDED
|
Git LFS Details
|
example_image/typical_misc_mailbox.png
ADDED
|
Git LFS Details
|
example_image/typical_misc_monster_chest.png
ADDED
|
Git LFS Details
|
example_image/typical_misc_phonograph.png
ADDED
|
Git LFS Details
|
example_image/typical_misc_portal2.png
ADDED
|
Git LFS Details
|
example_image/typical_misc_telephone.png
ADDED
|
Git LFS Details
|
example_image/typical_misc_television.png
ADDED
|
Git LFS Details
|
example_image/typical_misc_workbench.png
ADDED
|
Git LFS Details
|
example_image/typical_vehicle_biplane.png
ADDED
|
Git LFS Details
|
example_image/typical_vehicle_bulldozer.png
ADDED
|
Git LFS Details
|
example_image/typical_vehicle_cart.png
ADDED
|
Git LFS Details
|
example_image/typical_vehicle_excavator.png
ADDED
|
Git LFS Details
|
example_image/typical_vehicle_helicopter.png
ADDED
|
Git LFS Details
|
example_image/typical_vehicle_locomotive.png
ADDED
|
Git LFS Details
|
example_image/typical_vehicle_pirate_ship.png
ADDED
|
Git LFS Details
|
example_image/weatherworn_misc_paper_machine3.png
ADDED
|
Git LFS Details
|
f3c/17_demo_trellis.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0f6fe85f5566ee80f459d92357637be0183a34fc1ae11f529817f369218c5e2c
|
| 3 |
+
size 1798944
|
f3c/6_demo_trellis.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:131dc9b4549f5c62c4369afc43b142c9c5e296686eb1585e691463f42e4f5605
|
| 3 |
+
size 2477868
|
f3c/9_demo_trellis.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bf79395048f5e5d5a6033ef9212610eefb2eed713b4d44ed25d62ed5519a27f6
|
| 3 |
+
size 1959704
|
f3c/gou_demo_trellis.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6d977272fd6f4e8678eb4bd9cc18d6a65fc19a80c3d5383625c14a2ac3c1d4b2
|
| 3 |
+
size 2122956
|
f3c/typical_building_colorful_cottage_demo_trellis.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3b9c8dc1e74f22c256d9004fb48d848236c92ecfc99ffbec41aa19ef2a6f7179
|
| 3 |
+
size 3032008
|
f3c/typical_creature_dragon_demo_trellis.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:187bcd1605d5c4fb5cf82599d3c7acf4e95f5c976aaee19651284b903eff2efe
|
| 3 |
+
size 1797040
|
f3c/typical_creature_elephant_demo_trellis.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:25c6beb802db4dbea68ba9a2005a37b823e5ae84afc46b44642852b3bb74e080
|
| 3 |
+
size 2075016
|
f3c/typical_creature_furry_demo_trellis.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0dd1f347afe0670068c8a947e70b6ee5bfc3b8f465a789bba2089710ad9dfced
|
| 3 |
+
size 1839928
|
f3c/typical_creature_quadruped_demo_trellis.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:11ecc328b7dff5813908eebe951da6090ca839abcd3c5d7cbcffc0c561931d33
|
| 3 |
+
size 3168544
|
f3c/typical_creature_robot_crab_demo_trellis.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cebdb89255c746d5e57c15369c7953326b78e42bd3e99d50b05bc74446ac60e3
|
| 3 |
+
size 2813972
|
f3c/typical_creature_robot_dinosour_demo_trellis.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1eaf1efa8b85b7d3a1620f55a6011ca0d56b7f4dfbe19204258a29525eac19a2
|
| 3 |
+
size 1865552
|