Spaces:
Sleeping
Sleeping
Update exporters/webgl_exporter.py
Browse files- exporters/webgl_exporter.py +39 -5
exporters/webgl_exporter.py
CHANGED
|
@@ -5,20 +5,47 @@ WEBGL_TEMPLATE = """<!DOCTYPE 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://
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
scene.add(object);
|
| 20 |
-
camera.position.z =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
function animate() {
|
| 23 |
requestAnimationFrame(animate);
|
| 24 |
object.rotation.y += 0.01;
|
|
@@ -26,6 +53,13 @@ WEBGL_TEMPLATE = """<!DOCTYPE html>
|
|
| 26 |
}
|
| 27 |
animate();
|
| 28 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
</script>
|
| 30 |
</body>
|
| 31 |
</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://cdnjs.cloudflare.com/ajax/libs/three.js/r128/examples/js/loaders/OBJLoader.js"></script>
|
| 9 |
+
<style>
|
| 10 |
+
body { margin: 0; overflow: hidden; }
|
| 11 |
+
canvas { display: block; }
|
| 12 |
+
</style>
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
<script>
|
| 16 |
const scene = new THREE.Scene();
|
| 17 |
+
scene.background = new THREE.Color(0xf0f0f0);
|
| 18 |
+
|
| 19 |
const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
|
| 20 |
+
const renderer = new THREE.WebGLRenderer({antialias: true});
|
| 21 |
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 22 |
document.body.appendChild(renderer.domElement);
|
| 23 |
+
|
| 24 |
+
// ์กฐ๋ช
์ถ๊ฐ
|
| 25 |
+
const ambientLight = new THREE.AmbientLight(0x404040, 1.5);
|
| 26 |
+
scene.add(ambientLight);
|
| 27 |
+
|
| 28 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
|
| 29 |
+
directionalLight.position.set(1, 1, 1);
|
| 30 |
+
scene.add(directionalLight);
|
| 31 |
+
|
| 32 |
+
// ๋ชจ๋ธ ๋ก๋
|
| 33 |
+
const loader = new THREE.OBJLoader();
|
| 34 |
+
loader.load('{model_path}', (object) => {
|
| 35 |
scene.add(object);
|
| 36 |
+
camera.position.z = 5;
|
| 37 |
+
|
| 38 |
+
// ์ค๋ธ์ ํธ ์ค์ฌ ๊ณ์ฐ
|
| 39 |
+
const box = new THREE.Box3().setFromObject(object);
|
| 40 |
+
const center = box.getCenter(new THREE.Vector3());
|
| 41 |
+
const size = box.getSize(new THREE.Vector3());
|
| 42 |
|
| 43 |
+
// ์นด๋ฉ๋ผ ์์น ์กฐ์
|
| 44 |
+
const maxDim = Math.max(size.x, size.y, size.z);
|
| 45 |
+
camera.position.z = center.z + maxDim * 2;
|
| 46 |
+
camera.lookAt(center);
|
| 47 |
+
|
| 48 |
+
// ์ ๋๋ฉ์ด์
|
| 49 |
function animate() {
|
| 50 |
requestAnimationFrame(animate);
|
| 51 |
object.rotation.y += 0.01;
|
|
|
|
| 53 |
}
|
| 54 |
animate();
|
| 55 |
});
|
| 56 |
+
|
| 57 |
+
// ๋ฐ์ํ ํฌ๊ธฐ ์กฐ์
|
| 58 |
+
window.addEventListener('resize', () => {
|
| 59 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 60 |
+
camera.updateProjectionMatrix();
|
| 61 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 62 |
+
});
|
| 63 |
</script>
|
| 64 |
</body>
|
| 65 |
</html>"""
|