{"bugs":{"url":"https://github.com/drcmda/react-three-fiber/issues"},"dist":{"shasum":"4e4a3c658cd094e247e05df8e79823dc21ba172d","tarball":"https://registry.npmjs.org/react-three-fiber/-/react-three-fiber-2.0.0-beta.11.tgz","fileCount":13,"integrity":"sha512-36r8aKz53VDb6KdXV4ZqteDYl5+wftCbiysZNcUHyKV6ls3AT0wOaiyM1Fn3OavUZWmc8hmBqG1FHAU8p7m/CA==","signatures":[{"sig":"MEYCIQDRMjLYMzBzO86VnAPkkYQtID1F0RJs38LeJgIDr4yKuAIhAM59v63QSuuWjTHfMkokzt7/h/I5FhzcQZIqYtcEKGB2","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":286924,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJco5hRCRA9TVsSAnZWagAAcF8P/0To9RVoCd88rK7TZHk+\no/QCR+3l9oW32s0VaavXdLtBjxuA8gKJJmFr/gjb5i8EOQ/wRzW/cQQGNEY/\nKbM/N8xuCQZPxUM/luEbPVRIt1Plzb26lXX21jnmbvWD+paqfvsUvN9VnEkv\nloJ04123cNoZJz1qdHZoLQss0/mHYZS/BNkpnFVmAAu/w0povSKLl41s99Yr\n1gAd7Ho51/0xtfSTDIbSv/aqWBYBYlc6+xjQ4Zx58KETj2lR6fEz0/z+1yz2\nblJL5X0QlqAIAMl2V34cRlfcuMWkcfqjgSxUKXJJF2VUcazcqtBc9CaIU2nq\n07JzGocqPKUEtO2YVNeWTK7+rTfcFP6xzX40hKLrdl3Y2GTcBygUmNzTkx31\np0qTjv3OXJLeVfPgk4KwsDcEJKewqX1y9e9U2044RrSIcFFSudOy58nOT9HH\nEvDvz1wX+ZZG126gGnQqugsRLDTnQt1DRQTRl4GE7BQNF7QBPL/aXNz5alhG\npKAuAJklnfIAZ5YvPkao+sq4JIJVmeqHeB3eJPjqMr+g3QKyd+l2CcUKA1N1\nAzx66NbGIMPcaiHma1Gl+N67jAl/Bl84W2n4EsjejIBPZ49lLVUcaT+nJpXq\ngoyrPCIKouuqfr7EgqtLSgNrzuxb5KJevY/VbFTqNDilh3RCsiZ052Svj3rW\nT7yp\r\n=FDGD\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/kky7yk087v\"><img width=\"864\" src=\"https://i.imgur.com/jemlXzE.gif\" /></a>\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          attach=\"geometry\"\n          vertices={vertices.map(v => new THREE.Vector3(...v))}\n          onUpdate={self => (self.verticesNeedUpdate = true)}\n        />\n        <lineBasicMaterial attach=\"material\" color=\"black\" />\n      </line>\n      <mesh \n        onClick={e => console.log('click')} \n        onPointerOver={e => console.log('hover')} \n        onPointerOut={e => console.log('unhover')}>\n        <octahedronGeometry attach=\"geometry\" />\n        <meshBasicMaterial attach=\"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# Canvas\n\nThe `Canvas` object is your portal into Threejs. It renders Threejs elements, *not dom element*!\n\n```jsx\n<Canvas\n  children                      // Either a function child (which receives state) or regular children\n  gl                            // These props go into the webGL renderer\n  camera                        // And these go in to the default camera\n  pixelRatio = undefined        // You could provide window.devicePixelRatio if you like \n  invalidateFrameloop = false   // When true it only renders on changes, when false it's a game loop\n  onCreated />                  // Callback when vdom is ready, return a promise to prevent FOC\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`. Using the `attach` property objects bind automatically to their parent and are taken off it once they unmount.\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 attach=\"geometry\" args={[1, 16, 16]} />\n  <meshStandardMaterial attach=\"material\" color=\"indianred\" transparent />\n</mesh>\n```\n\nYou can nest primitive objects, which is good for awaiting async textures and such. You could use React-suspense if you wanted!\n\n```jsx\n<meshBasicMaterial attach=\"material\">\n  <texture attach=\"map\" format={THREE.RGBFormat} image={img} onUpdate={self => img && (self.needsUpdate = true)} />\n</meshBasicMaterial>\n```\n\nSometimes attaching isn't enough, for instance effects cling to an array called \"passes\" of a the parental effect-composer. In that case you use `attachArray` which adds the object to the target array and takes it out on unmount:\n\n```jsx\n<effectComposer>\n  <renderPass attachArray=\"passes\" />\n  <glitchPass attachArray=\"passes\" renderToScreen />\n</effectComposer>\n```\n\nYou can also attach to named parent properties using `attachObject={[target, name]}`, which adds the object and takes it out on unmount. The following adds a buffer-attribute to parent.attributes.position. \n\n```jsx\n<bufferGeometry>\n  <bufferAttribute attachObject={['attributes', 'position']} array={vertices} itemSize={3} />\n</bufferGeometry>\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. We support pointer events ([you need to polyfill them yourself](https://github.com/react-spring/pointer-events-polyfill)), clicks and wheel-scroll.\n\nAdditionally there's a special `onUpdate` that is called every time the object is updated with fresh props (as well as when it's first being created).\n\n```jsx\n<mesh\n  onClick={e => console.log('click')}\n  onWheel={e => console.log('wheel spins')}\n  onPointerUp={e => console.log('mouse button up')}\n  onPointerDown={e => console.log('mouse button down')}\n  onPointerOver={e => console.log('hover')}\n  onPointerOut={e => console.log('unhover')}\n  onPointerMove={e => console.log('mouse moves')}\n  onUpdate={self => console.log('props have been updated')}\n```\n\n#### Propagation and capturing\n\n```jsx\n  onPointerDown={e => {\n    // Only the mesh closest to the camera will be processed\n    e.stopPropagation()\n    // You may optionally capture the target\n    e.target.setPointerCapture(e.pointerId)\n  }}\n  onPointerUp={e => {\n    e.stopPropagation()\n    // Optionally release capture\n    e.target.releasePointerCapture(e.pointerId)\n  }}\n```\n\n# Hooks\n\nAll hooks can only be used *inside* the Canvas element because they rely on context updates!\n\n#### useThree()\n\n```jsx\nimport { useThree } from 'react-three-fiber'\n\nconst { \n  gl,               // WebGL renderer\n  canvas,           // canvas the dom element that was created\n  scene,            // Default scene\n  camera,           // Default camera\n  size,             // Bounds of the view (which stretches 100% and auto-adjusts)\n  viewport,         // Bounds of the viewport in 3d units\n  invalidate,       // Invalidates a single frame (for <Canvas invalidateFrameloop />)\n  setDefaultCamera  // Sets the default camera\n} = useThree()\n```\n\n#### useRender(callback, takeOver=false)\n\nIf you're running effects, postprocessings, controls, etc that need to get updated every frame, useRender gives you access to the render-loop. You receive the internal state as well, which is the same as what you would get from useThree.\n\n```jsx\nimport { useRender } from 'react-three-fiber'\n\n// Subscribes to the render-loop, gets cleaned up automatically when the component unmounts\nuseRender(state => console.log(\"i'm in the render-loop\"))\n\n// Add a \"true\" as the 2nd argument and you take over the render-loop completely\nuseRender(({ gl, scene, camera }) => gl.render(scene, camera), true)\n```\n\n#### useUpdate(callback, denpendencies, optionalRef=undefined)\n\nSometimes objects have to be updated imperatively. You could update the parts that you can access declaratively and then call `onUpdate={self => ...}`, or there's useUpdate.\n\n```jsx\nimport { useUpdate } from 'react-three-fiber'\n\nconst ref = useUpdate( \n  geometry => {\n    geometry.addAttribute('position', getCubeVertices(x, y, z))\n    geometry.attributes.position.needsUpdate = true\n    geometry.computeBoundingSphere()\n  }, \n  [x, y, z], // execute only if these properties change\n)\nreturn <bufferGeometry ref={ref} />\n```\n\n#### useResource(optionalRef=undefined)\n\n\nMaterials and such aren't normally re-created for every instance using it. You may want to share and re-use resources. This can be done imperatively simply by maintaining the object yourself, but it can also be done declaratively by using refs. `useResource` simply creates a ref and re-renders the component when it becomes available next frame. You can pass this reference on, or even channel it through a context provider.\n\n```jsx\nimport { useResource } from 'react-three-fiber'\n\nconst [ref, material] = useResource()\nreturn (\n  <meshBasicMaterial ref={ref} />\n  {material && (\n    <mesh material={material} />\n    <mesh material={material} />\n    <mesh material={material} />\n  )}\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 attach=\"geometry\" args={[1, 1]} />\n      <meshLambertMaterial attach=\"material\" transparent>\n        <primitive attach=\"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.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.render(), true)\n  return (\n    <effectComposer ref={composer} args={[gl]}>\n      <renderPass attachArray=\"passes\" args={[scene, camera]} />\n      <glitchPass attachArray=\"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 attach=\"geometry\" args={[shape, props]} />\n      <meshPhongMaterial attach=\"material\" />\n    </mesh>\n  )\n}\n```\n\nThen ...\n\n```jsx\n<Extrusion\n  start={[25, 25]}\n  paths={[[25, 25, 20, 0, 0, 0], [30, 0, 30, 35,30,35], [30, 55, 10, 77, 25, 95]]}\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 attach=\"geometry\" args={[3.8, 3.8]} />\n      <shaderMaterial\n        attach=\"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\n## Rendering only when needed\n\nBy default it renders like a game loop, which isn't that battery efficient. Switch on `invalidateFrameloop` to activate loop invalidation, which is automatic most of the time.\n\n```jsx\n<Canvas invalidateFrameloop ... />\n```\n\nSometimes you must be able to kick off frames manually, for instance when you're dealing with async stuff or camera controls:\n\n```jsx\nconst { invalidate } = useThree()\nconst texture = useMemo(() => loader.load(url1, invalidate), [url1])\n```\n\n## Switching the default renderer\n\nIf you want to exchange the default renderer you can. But, you will loose some of the functionality, like useRender, useThree, events, which is all covered in canvas.\n\n```jsx\nimport { render, unmountComponentAtNode } from 'react-three-fiber'\n\nconst renderer = new THREE.SVGRenderer()\nrenderer.setSize(window.innerWidth, window.innerHeight)\ndocument.body.appendChild(renderer.domElement)\nconst camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)\nconst scene = new THREE.Scene()\n\nrender((\n  <mesh>\n    <sphereGeometry name=\"geometry\" args={[1, 16, 16]} />\n    <meshBasicMaterial name=\"material\" />\n  </mesh>\n), scene)\n```\n","gitHead":"57f1cdfafeb090b7a9d4e2675c41b92071c5da83","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","pointer-events-polyfill":"^0.4.4-pre","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.11_1554225232521_0.44892201237285145","host":"s3://npm-registry-packages"},"_id":"react-three-fiber@2.0.0-beta.11","version":"2.0.0-beta.11"}