feat: Füge Lazy-Loading und zusätzliche Props für Character3D-Komponente hinzu
All checks were successful
Deploy to production / deploy (push) Successful in 1m55s

This commit is contained in:
Torsten Schulz (local)
2026-05-21 08:52:25 +02:00
parent 7b56388bee
commit 3df7abe628
2 changed files with 54 additions and 5 deletions

View File

@@ -65,6 +65,10 @@ export default {
type: Boolean,
default: false
}
,lazy: {
type: Boolean,
default: false
}
},
data() {
return {
@@ -83,6 +87,8 @@ export default {
threeLoaders: null,
threeModelRuntime: null
,resizeObserver: null
,intersectionObserver: null
,isVisible: false
};
},
computed: {
@@ -150,11 +156,42 @@ export default {
}
},
async mounted() {
await this.init3D();
await this.loadModel();
// Ensure renderer has correct size if the container became visible after mount
this.onWindowResize();
this.animate();
const container = this.$refs.container;
if (this.lazy && typeof window !== 'undefined' && 'IntersectionObserver' in window && container) {
// Defer initialization until the element is in viewport
this.intersectionObserver = new window.IntersectionObserver((entries) => {
for (const entry of entries) {
if (entry.isIntersecting) {
this.isVisible = true;
// start 3D when visible
this.intersectionObserver.disconnect();
this.intersectionObserver = null;
(async () => {
await this.init3D();
await this.loadModel();
this.onWindowResize();
this.animate();
})();
break;
}
}
}, { threshold: 0.1 });
try {
this.intersectionObserver.observe(container);
} catch (e) {
// fallback to immediate init
await this.init3D();
await this.loadModel();
this.onWindowResize();
this.animate();
}
} else {
await this.init3D();
await this.loadModel();
// Ensure renderer has correct size if the container became visible after mount
this.onWindowResize();
this.animate();
}
},
beforeUnmount() {
this.cleanup();
@@ -512,6 +549,12 @@ export default {
} catch (e) {}
this.resizeObserver = null;
}
if (this.intersectionObserver) {
try {
this.intersectionObserver.disconnect();
} catch (e) {}
this.intersectionObserver = null;
}
}
}
};

View File

@@ -318,6 +318,9 @@
<Character3D
:gender="child.gender"
:age="child.age"
:lightweight="true"
:noBackground="true"
:lazy="true"
/>
</div>
</div>
@@ -392,6 +395,9 @@
<Character3D
:gender="lover.gender"
:age="lover.age"
:lightweight="true"
:noBackground="true"
:lazy="true"
/>
</div>
</div>