본문 바로가기
3Js

Raycaster() + gsap

by 영감은어디에 2024. 7. 19.

// raycaster 시작 
const raycaster = new THREE.Raycaster();
renderer.domElement.addEventListener('mousemove', onMouseMove)
function onMouseMove(e){
const mouse = {
    x : (e.clientX / renderer.domElement.clientWidth) * 2 - 1,
    y : -(e.clientY / renderer.domElement.clientHeight) * 2 + 1,
}
raycaster.setFromCamera(mouse, camera)
const intersects = raycaster.intersectObjects(scene.children, true);

if(intersects.length > 0){ // 마우스 인
    TweenMax.to( ObjGroup.rotation, 1, { //1초동안 ObjGroup을 
    x: Math.PI * 2,
    z: 1
    })
    TweenMax.to(ObjGroup.scale, 1, { 
    x: 1800,
    y: 1800,
    z: 1800
    })
} else { // 마우스 아웃
    TweenMax.to(ObjGroup.rotation, 1, {
    x: 0,
    z:0
    })
    TweenMax.to(ObjGroup.scale, 1, {
    x: 1500,
    y: 1500,
    z: 1500
    })
}
}// raycaster 끝