xinjie.wang
commited on
Commit
·
9b4a1c9
1
Parent(s):
a7e4fb5
Add application file
Browse files
app.py
CHANGED
@@ -8,30 +8,40 @@ def greet(n):
|
|
8 |
return f"Hello {zero + n} Tensor"
|
9 |
|
10 |
|
11 |
-
|
12 |
-
model3d = LitModel3D(label="MESH", exposure=10, height=300)
|
13 |
-
model3d = gr.Model3D(label="MESH2", height=300)
|
14 |
-
model3d = gr.Model3D(label="GS2", height=300)
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
demo.load(
|
17 |
-
|
18 |
() => {
|
19 |
-
|
20 |
-
const
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
}
|
31 |
"""
|
32 |
)
|
33 |
|
34 |
|
35 |
-
|
36 |
if __name__ == "__main__":
|
37 |
demo.launch()
|
|
|
8 |
return f"Hello {zero + n} Tensor"
|
9 |
|
10 |
|
11 |
+
import gradio as gr
|
|
|
|
|
|
|
12 |
|
13 |
+
with gr.Blocks() as demo:
|
14 |
+
gr.Markdown("## 3D Model Viewer")
|
15 |
+
model = gr.Model3D(
|
16 |
+
value="https://modelviewer.dev/shared-assets/models/Astronaut.glb", # 示例模型
|
17 |
+
clear_color=(0.9, 0.9, 0.9, 1) # 先设置亮色背景提升基础亮度
|
18 |
+
)
|
19 |
+
|
20 |
demo.load(
|
21 |
+
js="""
|
22 |
() => {
|
23 |
+
// 等待组件加载完成(避免选择器找不到元素)
|
24 |
+
const observer = new MutationObserver(() => {
|
25 |
+
const viewer = document.querySelector('[data-testid="model3d-component"] .model-viewer');
|
26 |
+
if (viewer) {
|
27 |
+
const scene = viewer.modelView.scene;
|
28 |
+
observer.disconnect(); // 找到后停止观察
|
29 |
+
|
30 |
+
// 添加环境光(白色,强度 1.5)
|
31 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 1.5);
|
32 |
+
scene.add(ambientLight);
|
33 |
+
|
34 |
+
// 添加方向光(从右上方照射,模拟自然光)
|
35 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 1.8);
|
36 |
+
directionalLight.position.set(8, 10, 5); // 调整光源位置
|
37 |
+
scene.add(directionalLight);
|
38 |
+
}
|
39 |
+
});
|
40 |
+
observer.observe(document.body, { childList: true, subtree: true });
|
41 |
}
|
42 |
"""
|
43 |
)
|
44 |
|
45 |
|
|
|
46 |
if __name__ == "__main__":
|
47 |
demo.launch()
|