Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import React, { useState, useRef } from "react";
  2. import { OrbitControls} from "three/examples/jsm/controls/OrbitControls";
  3. import { Canvas, extend, useThree, useFrame} from "react-three-fiber";
  4. import { useSpring, a } from "react-spring/three";
  5. import "./App.css";
  6.  
  7. extend({ OrbitControls })
  8.  
  9. const Controls = () =>{
  10. const orbitRef = useRef();
  11. const { camera, gl} = useThree();
  12.  
  13. useFrame(()=>{
  14. orbitRef.current.update()
  15. })
  16.  
  17. return(
  18. <orbitControls autoRotate
  19. args={ [camera, gl.domElement]}
  20. ref={ orbitRef}
  21. />
  22. )
  23. }
  24.  
  25. // const plane = ()=>{
  26. // <mesh></mesh>
  27. // }
  28.  
  29. const Box = () => {
  30. // const meshRef = useRef();
  31. const [hovered, setHovered] = useState(false);
  32. const [active, setActive] = useState(false);
  33. const props = useSpring({
  34. scale: active ? [1.5, 1.5, 1.5] : [1.2, 1.2, 1.2],
  35. color: hovered ? "green" : "teal"
  36. });
  37.  
  38.  
  39. // useFrame(()=>{
  40. // meshRef.current.rotation.y += 0.01
  41. // })
  42.  
  43. console.log("hello");
  44.  
  45. return (
  46. <a.mesh
  47. // ref={meshRef}
  48. onPointerOver={() => setHovered(true)}
  49. onPointerOut={() => setHovered(false)}
  50. onClick={() => setActive(!active)}
  51. scale={props.scale}
  52. >
  53. <ambientLight />
  54. <spotLight position={[150, 150, 150]}/>
  55. <boxBufferGeometry attach="geometry" args={[1.2, 1.2, 1.2]} />
  56. <a.meshPhysicalMaterial attach="material" color={props.color} />
  57. </a.mesh>
  58. );
  59. };
  60.  
  61.  
  62.  
  63. export default () => (
  64. <Canvas>
  65.  
  66. <Controls />
  67. <Box />
  68. </Canvas>
  69. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement