feat: Automatische Kameraanpassung für bessere Modellansicht und Import von Hemisphärenlicht
Some checks failed
Deploy to production / deploy (push) Failing after 1m35s
Some checks failed
Deploy to production / deploy (push) Failing after 1m35s
This commit is contained in:
@@ -401,6 +401,24 @@ export default {
|
||||
|
||||
this.scene.add(this.model);
|
||||
|
||||
// Auto-Kamera-Anpassung: Abstand so setzen, dass die modell-Höhe gut ins Bild passt
|
||||
try {
|
||||
const scaledSize = scaledBox.getSize(new modelRuntime.Vector3());
|
||||
if (this.camera) {
|
||||
const fovRad = (this.camera.fov * Math.PI) / 180;
|
||||
const desiredHeight = Math.max(scaledSize.y, scaledSize.z) * 1.15; // etwas Margin
|
||||
let distance = desiredHeight / (2 * Math.tan(fovRad / 2));
|
||||
if (!isFinite(distance) || distance <= 0) distance = 3;
|
||||
const camY = scaledCenter.y + Math.max(0.5, scaledSize.y * 0.15);
|
||||
const camZ = distance + 0.6; // kleiner Offset, damit etwas Raum vor dem Modell ist
|
||||
this.camera.position.set(0, camY, camZ);
|
||||
this.camera.lookAt(scaledCenter.x, scaledCenter.y, scaledCenter.z);
|
||||
this.onWindowResize();
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore camera auto-fit errors
|
||||
}
|
||||
|
||||
// Animationen laden falls vorhanden
|
||||
if (gltf.animations && gltf.animations.length > 0) {
|
||||
this.mixer = markRaw(new modelRuntime.AnimationMixer(this.model));
|
||||
|
||||
Reference in New Issue
Block a user