Guest User

Untitled

a guest
Feb 18th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. document.addEventListener("mousedown", function () {
  2. isMouseDown = true
  3. startX = event.pageX
  4. startY = event.pageY
  5. document.body.style.cursor = 'grabbing';
  6. })
  7.  
  8. document.addEventListener("mouseup", function () {
  9. isMouseDown = false
  10. document.body.style.cursor = 'grab';
  11. })
  12.  
  13. document.addEventListener("mousemove", function (event) {
  14. if (isMouseDown) {
  15. document.body.style.cursor = 'grabbing'
  16. }
  17.  
  18. aimX = ((window.innerWidth / 2) - event.pageX) * 0.35
  19. aimY = ((window.innerHeight / 2) - event.pageY) * 0.5
  20.  
  21. mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
  22. mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
  23.  
  24. raycaster.setFromCamera(mouse, camera)
  25.  
  26. const intersections = raycaster.intersectObjects(group.children)
  27.  
  28. if (intersections.length > 0) {
  29. if(projectHov){
  30. if (INTERSECTED != intersections[0].object) {
  31. if (INTERSECTED)
  32. INTERSECTED.material.color.setHex(INTERSECTED.currentHex);
  33. INTERSECTED = intersections[0].object;
  34. INTERSECTED.currentHex = INTERSECTED.material.color.getHex();
  35. //setting up new material on hover
  36. INTERSECTED.material.color.setHex( 0xadadad );
  37. if (INTERSECTED){
  38. if(projectHov){
  39. document.body.style.cursor = "pointer"
  40. }
  41. }
  42. }
  43. }
  44.  
  45. } else {
  46. if (INTERSECTED) INTERSECTED.material.color.setHex(INTERSECTED.currentHex);
  47. document.body.style.cursor = "grab";
  48. INTERSECTED = null;
  49. }
  50.  
  51. // Moving the objects ==========================
  52. if(isMouseDown) {
  53. let currentRotation = new THREE.Matrix4();
  54. currentRotation.makeRotationFromEuler(group.rotation);
  55.  
  56. let newEuler = new THREE.Euler(0, ((event.pageX - startX) + (event.pageY - startY)) / 325, 0);
  57. let newRotation = new THREE.Matrix4();
  58. newRotation.makeRotationFromEuler(newEuler);
  59.  
  60. let finalRotation = new THREE.Matrix4();
  61. finalRotation.multiplyMatrices(newRotation, currentRotation);
  62.  
  63. group.rotation.setFromRotationMatrix(finalRotation);
  64.  
  65. startX = event.pageX;
  66. startY = event.pageY;
  67. }
  68. })
  69. section.addEventListener('click', onDocumentMouseDown, false);
  70.  
  71. function onDocumentMouseDown(event) {
  72. event.preventDefault();
  73. mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
  74. mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
  75. raycaster.setFromCamera(mouse, camera);
  76. const intersections = raycaster.intersectObjects(objects)
  77.  
  78. // Animation =================================
  79. if (intersections.length > 0){
  80. if(projectHov){
  81. tl.play();
  82.  
  83. tl.to(backTag, 1, {
  84. delay: 1.25,
  85. autoAlpha:1,
  86. }, 0);
  87.  
  88. }
  89.  
  90. // Animation ===================================
  91. if (intersections[0].object == old ) {
  92. if(projectHov){
  93. tlOld.play();
  94. projectHov = false
  95. tlOld.to(old, 1.5, {three:{scaleX: 1.5, scaleY: 1.5, x:0, y:0, z:0}, ease:Power2.easeInOut}, 0);
  96. tlOld.to(fnup, 1, {three:{y:-4000, opacity: 0 }, ease:Power2.easeInOut}, 0);
  97. tlOld.to(alex, 1, {three:{y:-4000, opacity: 0 }, ease:Power2.easeInOut}, 0);
  98. tlOld.to(cam, 1, {three:{y:-4000, opacity: 0 }, ease:Power2.easeInOut}, 0);
  99. tlOld.to(mirrorCube, 1, {three:{y:-400, opacity: 0 }, ease:Power2.easeInOut}, 0);
  100. groupRotate = false
  101. }
  102.  
  103. }
Add Comment
Please, Sign In to add comment