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
All checks were successful
Deploy to production / deploy (push) Successful in 1m55s
This commit is contained in:
@@ -65,6 +65,10 @@ export default {
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
}
|
}
|
||||||
|
,lazy: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -83,6 +87,8 @@ export default {
|
|||||||
threeLoaders: null,
|
threeLoaders: null,
|
||||||
threeModelRuntime: null
|
threeModelRuntime: null
|
||||||
,resizeObserver: null
|
,resizeObserver: null
|
||||||
|
,intersectionObserver: null
|
||||||
|
,isVisible: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -150,11 +156,42 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
await this.init3D();
|
const container = this.$refs.container;
|
||||||
await this.loadModel();
|
if (this.lazy && typeof window !== 'undefined' && 'IntersectionObserver' in window && container) {
|
||||||
// Ensure renderer has correct size if the container became visible after mount
|
// Defer initialization until the element is in viewport
|
||||||
this.onWindowResize();
|
this.intersectionObserver = new window.IntersectionObserver((entries) => {
|
||||||
this.animate();
|
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() {
|
beforeUnmount() {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
@@ -512,6 +549,12 @@ export default {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
this.resizeObserver = null;
|
this.resizeObserver = null;
|
||||||
}
|
}
|
||||||
|
if (this.intersectionObserver) {
|
||||||
|
try {
|
||||||
|
this.intersectionObserver.disconnect();
|
||||||
|
} catch (e) {}
|
||||||
|
this.intersectionObserver = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -318,6 +318,9 @@
|
|||||||
<Character3D
|
<Character3D
|
||||||
:gender="child.gender"
|
:gender="child.gender"
|
||||||
:age="child.age"
|
:age="child.age"
|
||||||
|
:lightweight="true"
|
||||||
|
:noBackground="true"
|
||||||
|
:lazy="true"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -392,6 +395,9 @@
|
|||||||
<Character3D
|
<Character3D
|
||||||
:gender="lover.gender"
|
:gender="lover.gender"
|
||||||
:age="lover.age"
|
:age="lover.age"
|
||||||
|
:lightweight="true"
|
||||||
|
:noBackground="true"
|
||||||
|
:lazy="true"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user