diff --git a/public/index.html b/public/index.html index feb479d76e80ccc2db2a676d3d1b08217d70fbea..f32aeabd8843f5b7d534e007a6caf25cbd0580a5 100644 --- a/public/index.html +++ b/public/index.html @@ -1,168 +1,268 @@ - + + - - - GeoVis AR Projekt - - - + + + 3D Modell Umschalter - Sonnenblume und Roboter + + - + + + + + + + + function onWindowResize() { + camera.aspect = window.innerWidth / window.innerHeight; + camera.updateProjectionMatrix(); + renderer.setSize(window.innerWidth, window.innerHeight); + } + + function loop() { + ThreeMeshUI.update(); + controls.update(); + renderer.render(scene, camera); + updateButtons(); + } + + function updateButtons() { + let intersect; + + if (mouse.x !== null && mouse.y !== null) { + raycaster.setFromCamera(mouse, camera); + intersect = raycast(); + } + + if (intersect && intersect.object.isUI) { + if (selectState) { + intersect.object.setState('selected'); + } else { + intersect.object.setState('hovered'); + } + } + + objsToTest.forEach((obj) => { + if ((!intersect || obj !== intersect.object) && obj.isUI) { + obj.setState('idle'); + } + }); + } + + function raycast() { + return objsToTest.reduce((closestIntersection, obj) => { + const intersection = raycaster.intersectObject(obj, true); + if (!intersection[0]) return closestIntersection; + if (!closestIntersection || intersection[0].distance < closestIntersection.distance) { + intersection[0].object = obj; + return intersection[0]; + } + return closestIntersection; + }, null); + } + +