Update index.html
Browse files- index.html +75 -69
index.html
CHANGED
|
@@ -1,88 +1,94 @@
|
|
| 1 |
-
<!
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
-
<meta charset="
|
| 5 |
-
<meta name="viewport" content="width=device-width,initial-scale=1"
|
| 6 |
-
<title>
|
| 7 |
<style>
|
| 8 |
-
body { margin:
|
| 9 |
-
|
| 10 |
-
position: absolute;
|
| 11 |
-
left: 12px;
|
| 12 |
-
top: 12px;
|
| 13 |
-
color: #ddd;
|
| 14 |
-
font-family: Arial, sans-serif;
|
| 15 |
-
z-index: 2;
|
| 16 |
-
background: rgba(0,0,0,0.3);
|
| 17 |
-
padding: 6px 8px;
|
| 18 |
-
border-radius: 6px;
|
| 19 |
-
}
|
| 20 |
</style>
|
| 21 |
</head>
|
| 22 |
<body>
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
import * as THREE from 'https://unpkg.com/three@0.165.0/build/three.module.js';
|
| 32 |
-
import { GLTFLoader } from 'https://unpkg.com/three@0.165.0/examples/jsm/loaders/GLTFLoader.js';
|
| 33 |
-
import { OrbitControls } from 'https://unpkg.com/three@0.165.0/examples/jsm/controls/OrbitControls.js';
|
| 34 |
|
| 35 |
-
const
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
-
//
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
//
|
| 53 |
-
const
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
-
//
|
| 66 |
-
const
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
o.material.metalness = 0;
|
| 73 |
-
o.material.roughness = 1;
|
| 74 |
-
}
|
| 75 |
-
});
|
| 76 |
-
scene.add(map);
|
| 77 |
-
console.log('✅ GLB loaded');
|
| 78 |
-
}, undefined, (e) => console.error('❌', e));
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
</script>
|
| 87 |
</body>
|
| 88 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>FBX Viewer</title>
|
| 7 |
<style>
|
| 8 |
+
body { margin:0; overflow:hidden; background:#111; }
|
| 9 |
+
canvas { display:block; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
</style>
|
| 11 |
</head>
|
| 12 |
<body>
|
| 13 |
+
<script src="https://unpkg.com/three@0.165.0/build/three.min.js"></script>
|
| 14 |
+
<script src="https://unpkg.com/three@0.165.0/examples/js/controls/OrbitControls.js"></script>
|
| 15 |
+
<script src="https://unpkg.com/three@0.165.0/examples/js/loaders/FBXLoader.js"></script>
|
| 16 |
|
| 17 |
+
<script>
|
| 18 |
+
// --- Basic scene ---
|
| 19 |
+
const scene = new THREE.Scene();
|
| 20 |
+
scene.background = new THREE.Color(0x111111);
|
| 21 |
|
| 22 |
+
const camera = new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 0.1, 1000);
|
| 23 |
+
camera.position.set(0, 2, 5);
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
const renderer = new THREE.WebGLRenderer({ antialias:true });
|
| 26 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 27 |
+
renderer.outputColorSpace = THREE.SRGBColorSpace; // for Safari
|
| 28 |
+
document.body.appendChild(renderer.domElement);
|
| 29 |
|
| 30 |
+
// --- Lights ---
|
| 31 |
+
scene.add(new THREE.AmbientLight(0xffffff, 1));
|
| 32 |
+
const dirLight = new THREE.DirectionalLight(0xffffff, 1);
|
| 33 |
+
dirLight.position.set(5,10,7);
|
| 34 |
+
scene.add(dirLight);
|
| 35 |
|
| 36 |
+
// --- Controls ---
|
| 37 |
+
const controls = new THREE.OrbitControls(camera, renderer.domElement);
|
| 38 |
+
controls.target.set(0,1,0);
|
| 39 |
+
controls.update();
|
| 40 |
|
| 41 |
+
// --- FBX Loader ---
|
| 42 |
+
const loader = new THREE.FBXLoader();
|
| 43 |
+
loader.load(
|
| 44 |
+
'model.fbx', // <-- put your FBX file here, in same folder
|
| 45 |
+
function(object) {
|
| 46 |
+
object.traverse((child) => {
|
| 47 |
+
if (child.isMesh) {
|
| 48 |
+
child.material.side = THREE.DoubleSide; // ensures no faces are invisible
|
| 49 |
+
}
|
| 50 |
+
});
|
| 51 |
+
scene.add(object);
|
| 52 |
|
| 53 |
+
// Auto-center camera
|
| 54 |
+
const box = new THREE.Box3().setFromObject(object);
|
| 55 |
+
const center = box.getCenter(new THREE.Vector3());
|
| 56 |
+
const size = box.getSize(new THREE.Vector3());
|
| 57 |
+
const maxDim = Math.max(size.x, size.y, size.z);
|
| 58 |
+
const fov = camera.fov * (Math.PI/180);
|
| 59 |
+
const cameraZ = Math.abs(maxDim / Math.sin(fov/2));
|
| 60 |
|
| 61 |
+
camera.position.set(center.x, center.y + maxDim/4, cameraZ);
|
| 62 |
+
camera.lookAt(center);
|
| 63 |
+
controls.target.copy(center);
|
| 64 |
+
controls.update();
|
| 65 |
+
},
|
| 66 |
+
(xhr) => console.log(`Loading FBX: ${(xhr.loaded/xhr.total*100).toFixed(2)}%`),
|
| 67 |
+
(err) => console.error('Error loading FBX', err)
|
| 68 |
+
);
|
| 69 |
|
| 70 |
+
// --- Floor / reference ---
|
| 71 |
+
const floor = new THREE.Mesh(
|
| 72 |
+
new THREE.PlaneGeometry(20,20),
|
| 73 |
+
new THREE.MeshStandardMaterial({ color:0x222222, roughness:1 })
|
| 74 |
+
);
|
| 75 |
+
floor.rotation.x = -Math.PI/2;
|
| 76 |
+
scene.add(floor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
+
// --- Animate ---
|
| 79 |
+
function animate() {
|
| 80 |
+
requestAnimationFrame(animate);
|
| 81 |
+
controls.update();
|
| 82 |
+
renderer.render(scene, camera);
|
| 83 |
+
}
|
| 84 |
+
animate();
|
| 85 |
+
|
| 86 |
+
// --- Handle resize ---
|
| 87 |
+
window.addEventListener('resize', () => {
|
| 88 |
+
camera.aspect = window.innerWidth/window.innerHeight;
|
| 89 |
+
camera.updateProjectionMatrix();
|
| 90 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 91 |
+
});
|
| 92 |
</script>
|
| 93 |
</body>
|
| 94 |
</html>
|