-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-viewer.html
More file actions
129 lines (113 loc) · 4.7 KB
/
Copy pathtest-viewer.html
File metadata and controls
129 lines (113 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Model Test</title>
<style>
body {
margin: 0;
padding: 20px;
font-family: Arial, sans-serif;
}
.model-container {
width: 400px;
height: 400px;
border: 2px solid #ccc;
margin: 20px auto;
background: #f5f5f5;
}
#status {
text-align: center;
margin: 20px;
padding: 10px;
background: #e0e0e0;
}
</style>
</head>
<body>
<h1 style="text-align: center;">3D Model Viewer Test</h1>
<div id="status">Lade Three.js...</div>
<div class="model-container" id="viewer"></div>
<script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.160.0/examples/js/loaders/GLTFLoader.js"></script>
<script>
const status = document.getElementById('status');
// Prüfe ob Three.js geladen ist
if (typeof THREE === 'undefined') {
status.textContent = 'FEHLER: THREE.js nicht geladen!';
status.style.background = '#ffcccc';
} else {
status.textContent = 'THREE.js erfolgreich geladen!';
status.style.background = '#ccffcc';
// Prüfe GLTFLoader
setTimeout(() => {
if (typeof THREE.GLTFLoader === 'undefined') {
status.textContent = 'FEHLER: GLTFLoader nicht geladen!';
status.style.background = '#ffcccc';
} else {
status.textContent = 'THREE.js und GLTFLoader geladen! Lade Modell...';
loadModel();
}
}, 500);
}
function loadModel() {
const container = document.getElementById('viewer');
const width = container.clientWidth;
const height = container.clientHeight;
// Scene
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf5f5f5);
// Camera
const camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000);
camera.position.set(0, 1, 3);
camera.lookAt(0, 0, 0);
// Renderer
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(width, height);
container.appendChild(renderer.domElement);
// Lights
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(5, 10, 7.5);
scene.add(directionalLight);
// Load Model
const loader = new THREE.GLTFLoader();
loader.load(
'models/3dIcons/d-3dicons-door-in.glb',
(gltf) => {
status.textContent = 'Modell erfolgreich geladen!';
status.style.background = '#ccffcc';
const model = gltf.scene;
// Center and scale model
const box = new THREE.Box3().setFromObject(model);
const center = box.getCenter(new THREE.Vector3());
const size = box.getSize(new THREE.Vector3());
const maxDim = Math.max(size.x, size.y, size.z);
const scale = 2 / maxDim;
model.scale.setScalar(scale);
model.position.sub(center.multiplyScalar(scale));
scene.add(model);
// Animation
function animate() {
requestAnimationFrame(animate);
model.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();
},
(progress) => {
const percent = (progress.loaded / progress.total * 100).toFixed(0);
status.textContent = `Lade Modell... ${percent}%`;
},
(error) => {
console.error('Fehler:', error);
status.textContent = 'FEHLER: ' + error.message;
status.style.background = '#ffcccc';
}
);
}
</script>
</body>
</html>