Reaperxxxx commited on
Commit
d2b44a7
·
verified ·
1 Parent(s): 74e03b3

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +75 -69
index.html CHANGED
@@ -1,88 +1,94 @@
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" />
6
- <title>Element in front of camera</title>
7
  <style>
8
- body { margin: 0; overflow: hidden; background: #111; }
9
- #info {
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
- <div id="info">Use mouse / touch to orbit. The red square + green box are fixed to camera.</div>
 
 
24
 
25
- <!-- non-module scripts (works on static hosts) -->
26
- <script src="https://unpkg.com/three@0.165.0/build/three.min.js"></script>
27
- <script src="https://unpkg.com/three@0.165.0/examples/js/controls/OrbitControls.js"></script>
 
28
 
29
-
30
- <script type="module">
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 scene = new THREE.Scene();
36
- scene.background = new THREE.Color(0x111111);
 
 
37
 
38
- const camera = new THREE.PerspectiveCamera(70, innerWidth/innerHeight, 0.1, 1000);
39
- camera.position.set(0, 1.5, 4);
 
 
 
40
 
41
- const renderer = new THREE.WebGLRenderer({ antialias: true });
42
- renderer.outputColorSpace = THREE.SRGBColorSpace; // required for Safari color correctness
43
- renderer.setSize(innerWidth, innerHeight);
44
- document.body.appendChild(renderer.domElement);
45
 
46
- // light
47
- scene.add(new THREE.AmbientLight(0xffffff, 0.9));
48
- const dir = new THREE.DirectionalLight(0xffffff, 1);
49
- dir.position.set(5, 10, 5);
50
- scene.add(dir);
 
 
 
 
 
 
51
 
52
- // controls
53
- const controls = new OrbitControls(camera, renderer.domElement);
54
- controls.target.set(0, 1, 0);
 
 
 
 
55
 
56
- // test cube (bright and visible)
57
- const testCube = new THREE.Mesh(
58
- new THREE.BoxGeometry(0.5, 0.5, 0.5),
59
- new THREE.MeshStandardMaterial({ color: 0xff3333 })
60
- );
61
- camera.add(testCube);
62
- testCube.position.set(0, 0, -2);
63
- scene.add(camera);
64
 
65
- // load GLB
66
- const loader = new GLTFLoader();
67
- loader.load('map.glb', (gltf) => {
68
- const map = gltf.scene;
69
- map.traverse(o => {
70
- if (o.isMesh) {
71
- o.material.side = THREE.DoubleSide;
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
- function animate() {
81
- requestAnimationFrame(animate);
82
- controls.update();
83
- renderer.render(scene, camera);
84
- }
85
- animate();
 
 
 
 
 
 
 
 
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>