{"bugs":{"url":"https://github.com/drcmda/react-three-fiber/issues"},"dist":{"shasum":"7997630585bae982e4b7ce8f345a56560a492b79","tarball":"https://registry.npmjs.org/react-three-fiber/-/react-three-fiber-2.0.0-beta.1.tgz","fileCount":13,"integrity":"sha512-6Ce5QIb7s+dbv1UOeIBQWsXhIfFcXx48GYLovl0nNJ6G4PVjIoHONGHXMLKNQ7SZw0L9CZPthz+EJEY7pw29RQ==","signatures":[{"sig":"MEUCIQDmO8GeowazYTvZ5AtWmVsSXHH9FGCt/grvUVSPGAn2gwIgVQAUM7OSON/mpUZl8RwzrREniWaeGrVGANnZestvT9w=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":275749,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcmkJwCRA9TVsSAnZWagAAstEQAJdv7oDgL4p9ADsFM500\nVRkSyhYvY2dqd4Fwho5YMBh83NFvXrOCYXMx8U2FEDhB3QW459YFHJIraJIz\n/EeS1cQ3Ld+TGa3nqgJtNUVbDbV7EIUzdFmDdNHo1unJzcV/Hf6qibCIVIWX\nd/G8rdamLb54Wiyc8E+c/ZgKz2f0rWouAA3oTWLnyD6CFX74ZX2uZm9xwxkK\nae7kWXSW3UuLobD4i8WRZPov4zUEEjjyaSBBn63tvqzWDiuP87tePau21pmN\npnVlw+QDBBgLyoPwpzByX03aERdxWkkjpXMIa5tr8ulgspTB04w7xN4qjZNx\nvbwJF3srEKbNOzhTI31eS6m99X/29hWOCqdqkLa6oRVMewqhieILXPS44dyx\ni7XJxnjiv/pAFwS/OFiXxzUnVgh2s26npj/uYvSH1LJ6ddTqABv8bvcpwgtO\nP3mhSiPo0kcZxDMQWbJ2oulz1EamH+tXVys/vaQO4IJPX/0oXTZgDGjODAdr\nkrK87Paqr0vvYPCj4uWgFI7T5Ythan3zVOQZGx2cm1dKeSTEDHIHOq+vEOtc\nvxJW4Z/tGp5vgmhwMmWokpjMfSm41WAVWaiMgPaI4pGoLfKdA9dXVwNprfwc\nk0gC/FE6p1S5axO+LCL2WwJkp+ySSST3lVSxd8EKh3hMBuYQkOp/JaEcGq5c\nYRiJ\r\n=itiJ\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.cjs.js","name":"react-three-fiber","husky":{"hooks":{"pre-commit":"lint-staged"}},"author":{"name":"Paul Henschel"},"module":"dist/index.js","readme":"<p align=\"center\">\n  <a href=\"https://codesandbox.io/embed/ly0oxkp899\"><img width=\"864\" src=\"https://i.imgur.com/vjmDwpS.gif\" /></a>\n  <a href=\"https://codesandbox.io/embed/9y8vkjykyy\"><img width=\"430\" src=\"https://i.imgur.com/tQi753C.gif\" /></a>\n  <a href=\"https://codesandbox.io/embed/y3j31r13zz\"><img width=\"430\" src=\"https://i.imgur.com/iFtjKHM.gif\" /></a>\n</p>\n<p align=\"middle\">\n  <i>These demos are real, you can click them! They contain the full code, too.</i>\n</p>\n\n    npm install react-three-fiber\n\nReact-three-fiber is a small React renderer for Three-js. Why, you might ask? React was made to drive complex tree structures, it makes just as much sense for Three as it makes for the Dom. Building a dynamic scene graph becomes so much easier because you can break it up into declarative, re-usable components with clean, reactive semantics. This also opens up the eco system, you can now apply generic packages for state, animation, gestures and so on.\n\n#### Difference to react-three, react-three-renderer, react-three-renderer-fiber\n\nThis is a small reconciler config with a few additions for interaction and hooks holding it all together. It does not know or care about Three internals, it uses heuristics for objects and attributes, so that we can get away without creating a strong dependency. Three is constantly changing, we don't want to rely on a specific version or chase their release cycle. This library works with version 1 as well as their latest. At the same time we don't want to alter any rules, if something works in Three in a specific way, it will be the same here.\n\n# How it looks like ...\n\nCopy the following into a project to get going. [Here's the same](https://codesandbox.io/s/rrppl0y8l4) running in a code sandbox.\n\n```jsx\nimport * as THREE from 'three'\nimport React from 'react'\nimport ReactDOM from 'react-dom'\nimport { Canvas } from 'react-three-fiber'\n\nfunction Thing({ vertices, color }) {\n  return (\n    <group ref={ref => console.log('we have access to the instance')}>\n      <line>\n        <geometry\n          name=\"geometry\"\n          vertices={vertices.map(v => new THREE.Vector3(...v))}\n          onUpdate={self => (self.verticesNeedUpdate = true)}\n        />\n        <lineBasicMaterial name=\"material\" color=\"black\" />\n      </line>\n      <mesh \n        onClick={e => console.log('click')} \n        onHover={e => console.log('hover')} \n        onUnhover={e => console.log('unhover')}>\n        <octahedronGeometry name=\"geometry\" />\n        <meshBasicMaterial name=\"material\" color=\"peachpuff\" opacity={0.5} transparent />\n      </mesh>\n    </group>\n  )\n}\n\nReactDOM.render(\n  <Canvas>\n    <Thing vertices={[[-1, 0, 0], [0, 1, 0], [1, 0, 0], [0, -1, 0], [-1, 0, 0]]} />\n  </Canvas>,\n  document.getElementById('root')\n)\n```\n\n# Objects and properties\n\nYou can use [Three's entire object catalogue and all properties](https://threejs.org/docs). When in doubt, always consult the docs.\n\n```jsx\n<mesh\n  visible\n  userData={{ test: \"hello\" }}\n  position={new THREE.Vector3(1, 2, 3)}\n  rotation={new THREE.Euler(0, 0, 0)}\n  geometry={new THREE.SphereGeometry(1, 16, 16)}\n  material={new THREE.MeshBasicMaterial({ color: new THREE.Color('indianred'), transparent: true })} />\n```\n\n#### Shortcuts and non-Object3D stow-away\n\nAll properties that have a `.set()` method (colors, vectors, euler, matrix, etc) can be given a shortcut. For example [THREE.Color.set](https://threejs.org/docs/index.html#api/en/math/Color.set) can take a color string, hence instead of `color={new THREE.Color('peachpuff')` you can do `color=\"peachpuff\"`. Some set-methods take multiple arguments (vectors for instance), in this case you can pass an array.\n\nYou can stow away non-Object3D primitives (geometries, materials, etc) into the render tree so that they become managed and reactive. They take the same properties they normally would, constructor arguments are passed with `args`. If you give them a name they attach automatically to their parent.\n\nThe following is the same as above, but it's leaner and critical properties aren't re-instanciated on every render.\n\n```jsx\n<mesh visible userData={{ test: \"hello\" }} position={[1, 2, 3]} rotation={[0, 0, 0]}>\n  <sphereGeometry name=\"geometry\" args={[1, 16, 16]} />\n  <meshStandardMaterial name=\"material\" color=\"indianred\" transparent />\n</mesh>\n```\n\nYou can nest primitive objects, good for awaiting async textures and such. You could use React-suspense if you wanted!\n\n```jsx\n<meshBasicMaterial name=\"material\">\n  <texture name=\"map\" format={THREE.RGBFormat} image={img} onUpdate={self => img && (self.needsUpdate = true)} />\n</meshBasicMaterial>\n```\n\n#### Piercing into nested properties\n\nIf you want to reach into nested attributes (for instance: `mesh.rotation.x`), just use dash-case:\n\n```jsx\n<mesh rotation-x={1} material-color=\"lightblue\" geometry-vertices={newVertices} />\n```\n\n#### Extending or using arbitrary objects\n\nWhen you need managed local (or custom/extended) objects, you can use the `primitive` placeholder.\n\n```jsx\nconst mesh = new THREE.Mesh()\nreturn <primitive object={mesh} />\n```\n\n# Events\n\nTHREE objects that implement their own `raycast` method (for instance meshes, lines, etc) can be interacted with by declaring events on the object. For now that's prop-updates (very useful for things like `verticesNeedUpdate`), hovering-state and clicks. Touch follows soon!\n\n```jsx\n<mesh\n  onClick={e => console.log('click')}\n  onHover={e => console.log('hover')}\n  onUnhover={e => console.log('unhover')}\n  onUpdate={self => console.log('props have been updated')}\n/>\n```\n\n# Gl data & hooking into the render loop\n\nSometimes you're running effects, postprocessing, etc that needs to get updated. You can fetch the renderer, the camera, scene, and a render-loop subscribe to do this. You can only use these hooks *inside* the Canvas render tree (they're context based)!\n\n```jsx\nimport { Canvas, useRender, useThree } from 'react-three-fiber'\n\nfunction App() {\n  // gl is the webgl-renderer\n  // canvas the dom element that was created\n  // size the bounds of the view (which stretches 100% and auto-adjusts)\n  // viewport is the calculated screen-size, it's a function\n  const { gl, canvas, scene, camera, size, viewport } = useThree()\n  // Subscribes to the render-loop, gets cleaned up automatically when the component unmounts\n  // Add a \"true\" as the 2nd argument and you take over the render-loop\n  useRender(({ gl, canvas, scene, camera }) => console.log(\"i'm in the render-loop\"))\n  return <group />\n}\n```\n\n# Receipes\n\n## Handling loaders\n\nYou can use Reacts built-in memoizing-features (as well as suspense) to build async dependence graphs.\n\n```jsx\nfunction Image({ url }) {\n  const texture = useMemo(() => new THREE.TextureLoader().load(url), [url])\n  return (\n    <mesh>\n      <planeBufferGeometry name=\"geometry\" args={[1, 1]} />\n      <meshLambertMaterial name=\"material\" transparent>\n        <primitive name=\"map\" object={texture} />\n      </meshLambertMaterial>\n    </mesh>\n  )\n}\n```\n\n## Dealing with effects (hijacking main render-loop)\n\nManaging effects can get quite complex normally. Drop the component below into a scene and you have a live effect. Remove it and everything is as it was without any re-configuration.\n\n```jsx\nimport { apply, Canvas, useRender, useThree } from 'react-three-fiber'\nimport { EffectComposer } from './postprocessing/EffectComposer'\nimport { RenderPass } from './postprocessing/RenderPass'\nimport { GlitchPass } from './postprocessing/GlitchPass'\n// Makes these objects available as native objects \"<renderPass />\" and so on\napply({ EffectComposer, RenderPass, GlitchPass })\n\nfunction Effects({ factor }) {\n  const { gl, scene, camera, size } = useThree()\n  const composer = useRef()\n  useEffect(() => void composer.current.obj.setSize(size.width, size.height), [size])\n  // This takes over as the main render-loop (when 2nd arg is set to true)\n  useRender(() => composer.current.obj.render(), true)\n  return (\n    <effectComposer ref={composer} args={[gl]}>\n      <renderPass name=\"passes\" args={[scene, camera]} />\n      <glitchPass name=\"passes\" factor={factor} renderToScreen />\n    </effectComposer>\n  )\n}\n```\n\n## Heads-up display (rendering multiple scenes)\n\n`useRender` allows components to hook into the render-loop, or even to take it over entirely. That makes it possible for one component to render over the content of another. The order of these operations is established by the scene-graph.\n\n```jsx\nfunction Content({ camera }) {\n  const scene = useRef()\n  useRender(({ gl }) => void ((gl.autoClear = true), gl.render(scene.current, camera)), true)\n  return <scene ref={scene}>{/* ... */}</scene>\n}\n\nfunction HeadsUpDisplay({ camera }) {\n  const scene = useRef()\n  useRender(({ gl }) => void ((gl.autoClear = false), gl.clearDepth(), gl.render(scene.current, camera)))\n  return <scene ref={scene}>{/* ... */}</scene>\n}\n\nfunction Main() {\n  const camera = useRef()\n  const { width, height } = useThree().size\n  return (\n    <>\n      <perspectiveCamera\n        ref={camera}\n        aspect={width / height}\n        radius={(width + height) / 4}\n        onUpdate={self => self.updateProjectionMatrix()}\n      />\n      {camera.current && (\n        <group>\n          <Content camera={camera.current} />\n          <HeadsUpDisplay camera={camera.current} />\n        </group>\n      )}\n    </>\n  )\n}\n```\n\n## Managing imperative code\n\nStick imperative stuff into useMemo and write out everything else declaratively. This is how you can quickly form reactive, re-usable components that can be bound to a store, graphql, etc.\n\n```jsx\nfunction Extrusion({ start = [0,0], paths, ...props }) {\n  const shape = useMemo(() => {\n    const shape = new THREE.Shape()\n    shape.moveTo(...start)\n    paths.forEach(path => shape.bezierCurveTo(...path))\n    return shape\n  }, [start, paths])\n\n  return (\n    <mesh>\n      <extrudeGeometry name=\"geometry\" args={[shape, props]} />\n      <meshPhongMaterial name=\"material\" />\n    </mesh>\n  )\n}\n```\n\nThen ...\n\n```jsx\n<Extrusion\n  start={[25, 25]}\n  paths={[\n    [25, 25, 20, 0, 0, 0],\n    [30, 0, 30, 35,30,35],\n    [30, 55, 10, 77, 25, 95],\n    [60, 77, 80, 55, 80, 35],\n    [80, 35, 80, 0, 50, 0],\n    [35, 0, 25, 25, 25, 25],\n  ]}\n  bevelEnabled\n  amount={8}\n  bevelSegments={2}\n  steps={2}\n  bevelSize={1}\n  bevelThickness={1} />\n```\n\n## ShaderMaterials\n\n```jsx\nfunction CrossFade({ url1, url2, disp }) {\n  const [texture1, texture2, dispTexture] = useMemo(() => {\n    const loader = new THREE.TextureLoader()\n    return [loader.load(url1), loader.load(url2), loader.load(disp)]\n  }, [url1, url2, disp])\n  return (\n    <mesh>\n      <planeBufferGeometry name=\"geometry\" args={[3.8, 3.8]} />\n      <shaderMaterial\n        name=\"material\"\n        args={[CrossFadeShader]}\n        uniforms-texture-value={texture1}\n        uniforms-texture2-value={texture2}\n        uniforms-disp-value={dispTexture}\n        uniforms-dispFactor-value={0.5}\n      />\n    </mesh>\n  )\n}\n```\n","gitHead":"d68d33b16c091c9eeba2e76748ecb30382904d0b","license":"MIT","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"rollup -c","prepare":"npm run build","prebuild":"rimraf dist"},"_npmUser":{"name":"drcmda","email":"drcmda@gmail.com"},"homepage":"https://github.com/drcmda/react-three-fiber#readme","keywords":["react","renderer","fiber","three","threejs"],"prettier":{"semi":false,"tabWidth":2,"printWidth":120,"singleQuote":true,"trailingComma":"es5","jsxBracketSameLine":true},"repository":{"url":"git+https://github.com/drcmda/react-three-fiber.git","type":"git"},"_npmVersion":"6.4.1","description":"React-fiber renderer for THREE.js","directories":{},"lint-staged":{"*.{js,}":["prettier --write","git add"]},"maintainers":[{"name":"drcmda","email":"drcmda@gmail.com"}],"sideEffects":false,"_nodeVersion":"11.1.0","dependencies":{"lodash-es":"^4.17.11","scheduler":"^0.13.3","@babel/runtime":"^7.3.4","react-reconciler":"^0.20.1","resize-observer-polyfill":"^1.5.1"},"_hasShrinkwrap":false,"readmeFilename":"readme.md","devDependencies":{"husky":"^1.3.1","rollup":"^1.4.1","prettier":"^1.16.4","typescript":"^3.3.3333","@babel/core":"7.3.4","lint-staged":"^8.1.5","@babel/preset-env":"7.3.4","@babel/preset-react":"7.0.0","rollup-plugin-babel":"^4.3.2","rollup-plugin-commonjs":"^9.2.1","@babel/preset-typescript":"^7.3.3","rollup-plugin-node-resolve":"^4.0.1","rollup-plugin-size-snapshot":"^0.8.0","@babel/plugin-transform-runtime":"7.3.4","@babel/plugin-transform-parameters":"7.3.3","@babel/plugin-proposal-do-expressions":"7.2.0","@babel/plugin-proposal-class-properties":"7.3.4","@babel/plugin-transform-modules-commonjs":"7.2.0","@babel/plugin-proposal-object-rest-spread":"7.3.4","@babel/plugin-transform-template-literals":"7.2.0","babel-plugin-transform-react-remove-prop-types":"^0.4.24"},"peerDependencies":{"react":">=16.8","three":">=0.100","react-dom":">=16.8"},"_npmOperationalInternal":{"tmp":"tmp/react-three-fiber_2.0.0-beta.1_1553613424116_0.03174423334569898","host":"s3://npm-registry-packages"},"_id":"react-three-fiber@2.0.0-beta.1","version":"2.0.0-beta.1"}