Add theme_3d_systems/static/src/js/widgets/widget_3d_hero.js
This commit is contained in:
parent
14ba6cd252
commit
67f5eaa187
1 changed files with 39 additions and 0 deletions
39
theme_3d_systems/static/src/js/widgets/widget_3d_hero.js
Normal file
39
theme_3d_systems/static/src/js/widgets/widget_3d_hero.js
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import publicWidget from '@web/legacy/js/public/public_widget';
|
||||||
|
import { HeroNetworkScene } from '../three/hero_network_scene';
|
||||||
|
|
||||||
|
publicWidget.registry.Theme3DHero = publicWidget.Widget.extend({
|
||||||
|
selector: '.s_3d_hero',
|
||||||
|
disabledInEditableMode: false,
|
||||||
|
|
||||||
|
start: function () {
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
|
||||||
|
// Do not initialize heavy WebGL on reduced-motion preference or low-end mobile
|
||||||
|
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||||
|
if (prefersReducedMotion) return;
|
||||||
|
|
||||||
|
const container = this.el.querySelector('.hero-canvas-container');
|
||||||
|
if (container) {
|
||||||
|
const density = this.el.dataset.particleDensity || 'normal';
|
||||||
|
let count = 65;
|
||||||
|
if (density === 'low') count = 30;
|
||||||
|
if (density === 'high') count = 110;
|
||||||
|
|
||||||
|
this.sceneInstance = new HeroNetworkScene(container, {
|
||||||
|
particleCount: count,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
destroy: function () {
|
||||||
|
if (this.sceneInstance) {
|
||||||
|
this.sceneInstance.destroy();
|
||||||
|
this.sceneInstance = null;
|
||||||
|
}
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default publicWidget.registry.Theme3DHero;
|
||||||
Loading…
Reference in a new issue