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"; // Scène et renderer const container = document.body; const scene = new THREE.Scene(); const mouse = new THREE.Vector2(); const camera = new THREE.PerspectiveCamera( 72, window.innerWidth / window.innerHeight, 0.1, 200 ); const renderer = new THREE.WebGLRenderer(); renderer.domElement.classList.add("renderer3"); //Créer le control const controls = new OrbitControls(camera, renderer.domElement); onResize(); container.appendChild(renderer.domElement); controls.rotateSpeed = -0.4; controls.enableZoom = false; camera.position.set(-0.1, 0, 0); controls.update(); function animate() { requestAnimationFrame(animate); controls.update(); renderer.render(scene, camera); } animate(); let view = new View360(scene, container); view.createView(); function onResize() { renderer.setSize(container.clientWidth, container.clientHeight); camera.aspect = container.clientWidth / container.clientHeight; camera.updateProjectionMatrix(); } function onMouseMove(e = false) { if (e) { var containerRect = 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); } window.addEventListener("load", function() { window.addEventListener("resize", onResize); container.addEventListener("pointermove", onMouseMove); });