Add theme_3d_systems/static/src/js/three/three_core_loader.js
This commit is contained in:
parent
6c6124b7c8
commit
14ba6cd252
1 changed files with 42 additions and 0 deletions
42
theme_3d_systems/static/src/js/three/three_core_loader.js
Normal file
42
theme_3d_systems/static/src/js/three/three_core_loader.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
/**
|
||||
* Three.js Dynamic Lazy Loader for Odoo 19
|
||||
* Loads Three.js on demand without blocking critical page rendering.
|
||||
*/
|
||||
let threePromise = null;
|
||||
|
||||
export async function loadThree() {
|
||||
if (window.THREE) {
|
||||
return window.THREE;
|
||||
}
|
||||
if (threePromise) {
|
||||
return threePromise;
|
||||
}
|
||||
|
||||
threePromise = new Promise((resolve, reject) => {
|
||||
const script = document.createElement('script');
|
||||
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js';
|
||||
script.crossOrigin = 'anonymous';
|
||||
script.onload = () => {
|
||||
if (window.THREE) {
|
||||
resolve(window.THREE);
|
||||
} else {
|
||||
reject(new Error('Three.js failed to load properly.'));
|
||||
}
|
||||
};
|
||||
script.onerror = () => reject(new Error('Network error loading Three.js'));
|
||||
document.head.appendChild(script);
|
||||
});
|
||||
|
||||
return threePromise;
|
||||
}
|
||||
|
||||
export function isWebGLSupported() {
|
||||
try {
|
||||
const canvas = document.createElement('canvas');
|
||||
return !!(window.WebGLRenderingContext && (canvas.getContext('webgl') || canvas.getContext('experimental-webgl')));
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue