Reaperxxxx commited on
Commit
c78a17b
·
verified ·
1 Parent(s): 9a341f9

Create view.html

Browse files
Files changed (1) hide show
  1. view.html +131 -0
view.html ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title>Three.js Character + Map</title>
6
+ <style>
7
+ body {
8
+ margin: 0;
9
+ overflow: hidden;
10
+ background: #000;
11
+ }
12
+ </style>
13
+
14
+ <!-- Import map setup -->
15
+ <script type="importmap">
16
+ {
17
+ "imports": {
18
+ "three": "https://cdn.jsdelivr.net/npm/three@0.128.0/build/three.module.js",
19
+ "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.128.0/examples/jsm/"
20
+ }
21
+ }
22
+ </script>
23
+ </head>
24
+ <body>
25
+ <script type="module">
26
+ import * as THREE from 'three';
27
+ import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
28
+
29
+ let scene, camera, renderer, character, mapScene;
30
+
31
+ init();
32
+ animate();
33
+
34
+ function init() {
35
+ scene = new THREE.Scene();
36
+ scene.background = new THREE.Color(0x1a1a2e);
37
+ scene.fog = new THREE.Fog(0x1a1a2e, 5, 50);
38
+
39
+ camera = new THREE.PerspectiveCamera(
40
+ 75,
41
+ window.innerWidth / window.innerHeight,
42
+ 0.01,
43
+ 50
44
+ );
45
+ camera.position.set(0, 2, 5);
46
+
47
+ renderer = new THREE.WebGLRenderer({ antialias: true });
48
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
49
+ renderer.setSize(window.innerWidth, window.innerHeight);
50
+ renderer.shadowMap.enabled = true;
51
+ document.body.appendChild(renderer.domElement);
52
+
53
+ // --- Lighting setup (same as your original) ---
54
+ scene.add(new THREE.AmbientLight(0xffffff, 0.7));
55
+
56
+ const dirLight1 = new THREE.DirectionalLight(0xffffff, 0.8);
57
+ dirLight1.position.set(20, 20, 20);
58
+ dirLight1.castShadow = true;
59
+ scene.add(dirLight1);
60
+
61
+ const dirLight2 = new THREE.DirectionalLight(0xffffff, 0.6);
62
+ dirLight2.position.set(-20, 15, -20);
63
+ scene.add(dirLight2);
64
+
65
+ const dirLight3 = new THREE.DirectionalLight(0xffffff, 0.5);
66
+ dirLight3.position.set(0, 20, -20);
67
+ scene.add(dirLight3);
68
+
69
+ const pointLight1 = new THREE.PointLight(0xffffff, 0.5, 50);
70
+ pointLight1.position.set(10, 10, 10);
71
+ scene.add(pointLight1);
72
+
73
+ const pointLight2 = new THREE.PointLight(0xffffff, 0.5, 50);
74
+ pointLight2.position.set(-10, 10, -10);
75
+ scene.add(pointLight2);
76
+
77
+ const pointLight3 = new THREE.PointLight(0xffffff, 0.4, 50);
78
+ pointLight3.position.set(0, 5, 0);
79
+ scene.add(pointLight3);
80
+
81
+ // --- Load Map ---
82
+ const loader = new GLTFLoader();
83
+ loader.load('./map.glb', (gltf) => {
84
+ mapScene = gltf.scene;
85
+ mapScene.scale.set(-1, 1, 1);
86
+ scene.add(mapScene);
87
+
88
+ mapScene.traverse((child) => {
89
+ child.castShadow = true;
90
+ child.receiveShadow = true;
91
+ });
92
+ console.log('🗺️ Map loaded');
93
+ });
94
+
95
+ // --- Load Character ---
96
+ const charLoader = new GLTFLoader();
97
+ charLoader.load('./character.glb', (gltf) => {
98
+ character = gltf.scene;
99
+ character.scale.set(1, 1, 1);
100
+ character.position.set(0, 0, 0);
101
+ scene.add(character);
102
+
103
+ character.traverse((child) => {
104
+ child.castShadow = true;
105
+ child.receiveShadow = true;
106
+ });
107
+
108
+ // Optional: Log bones
109
+ gltf.scene.traverse((obj) => {
110
+ if (obj.isBone) console.log('🦴 Bone:', obj.name);
111
+ });
112
+
113
+ console.log('🧍 Character loaded');
114
+ });
115
+
116
+ window.addEventListener('resize', onWindowResize);
117
+ }
118
+
119
+ function onWindowResize() {
120
+ camera.aspect = window.innerWidth / window.innerHeight;
121
+ camera.updateProjectionMatrix();
122
+ renderer.setSize(window.innerWidth, window.innerHeight);
123
+ }
124
+
125
+ function animate() {
126
+ requestAnimationFrame(animate);
127
+ renderer.render(scene, camera);
128
+ }
129
+ </script>
130
+ </body>
131
+ </html>