shin0624 commited on
Commit
3dfd27c
·
verified ·
1 Parent(s): 02b2e22

WebGL 출력

Browse files
Files changed (1) hide show
  1. exporters/webgl_exporter.py +40 -0
exporters/webgl_exporter.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ WEBGL_TEMPLATE = """<!DOCTYPE html>
4
+ <html>
5
+ <head>
6
+ <title>3D Factory Map</title>
7
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
8
+ <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/loaders/OBJLoader.js"></script>
9
+ </head>
10
+ <body>
11
+ <script>
12
+ const scene = new THREE.Scene();
13
+ const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
14
+ const renderer = new THREE.WebGLRenderer();
15
+ renderer.setSize(window.innerWidth, window.innerHeight);
16
+ document.body.appendChild(renderer.domElement);
17
+
18
+ new THREE.OBJLoader().load('{model_path}', (object) => {
19
+ scene.add(object);
20
+ camera.position.z = 300;
21
+
22
+ function animate() {
23
+ requestAnimationFrame(animate);
24
+ object.rotation.y += 0.01;
25
+ renderer.render(scene, camera);
26
+ }
27
+ animate();
28
+ });
29
+ </script>
30
+ </body>
31
+ </html>"""
32
+
33
+ def export_to_webgl(obj_path, output_dir):
34
+ os.makedirs(output_dir, exist_ok=True)
35
+ html_path = os.path.join(output_dir, "viewer.html")
36
+
37
+ with open(html_path, 'w') as f:
38
+ f.write(WEBGL_TEMPLATE.format(model_path=os.path.basename(obj_path)))
39
+
40
+ return html_path