import * as THREE from "../../nodemodule/three/build/three.module.js"; import {OrbitControls} from "../../nodemodule/three/examples/jsm/controls/OrbitControls.js"; import View360 from "../modules/View360.mjs"; export default class AppThree{ constructor() { // Scène et renderer this.container = document.body; this.scene = new THREE.Scene(); this.mouse = new THREE.Vector2(); this.camera = new THREE.PerspectiveCamera( 72, window.innerWidth / window.innerHeight, 0.1, 200 ); this.renderer = new THREE.WebGLRenderer(); this.renderer.domElement.classList.add("renderer3"); //Créer le control this.controls = new OrbitControls(this.camera, this.renderer.domElement); this.onResize(); this.container.appendChild(this.renderer.domElement); this.controls.rotateSpeed = -0.4; this.controls.enableZoom = false; this.camera.position.set(-0.1, 0, 0); this.controls.update(); this.animate(); window.addEventListener("load", function() { window.addEventListener("resize", this.onResize); //this.container.addEventListener("pointermove", this.onMouseMove); }); } animate() { requestAnimationFrame(() => this.animate()); this.controls.update(); this.renderer.render(this.scene, this.camera); } initView(file,type='image'){ this.view = new View360(this.scene, this.container,file,type); this.view.createView(); } onMouseMove(e = false) { if (e) { var containerRect = this.container.getBoundingClientRect(); var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft, scrollTop = window.pageYOffset || document.documentElement.scrollTop; var posLeft = e.pageX - containerRect.left - scrollLeft, posTop = e.pageY - containerRect.top - scrollTop; mouse.copy(new THREE.Vector2( (posLeft / containerRect.width) * 2 - 1, -(posTop / containerRect.height) * 2 + 1)); } view.checkMouseRaycasterCollide(mouse, camera); } onResize() { this.renderer.setSize(this.container.clientWidth, this.container.clientHeight); this.camera.aspect = this.container.clientWidth / this.container.clientHeight; this.camera.updateProjectionMatrix(); } }