All Projects → pmndrs → React Three Fiber

pmndrs / React Three Fiber

Licence: mit
🇨🇭 A React renderer for Three.js

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Three Fiber

React Particles Webgl
🔆 A 2D/3D particle library built on React, Three.js and WebGL
Stars: ✭ 330 (-97.95%)
Mutual labels:  fiber, 3d, threejs
Angular Template For Threejs
Angular Template For Three.js
Stars: ✭ 114 (-99.29%)
Mutual labels:  3d, threejs
Solar System Threejs
The Solar System: Modeled to scale with Three.js
Stars: ✭ 107 (-99.34%)
Mutual labels:  3d, threejs
Timeline
直观地显示各个历史时间段及历史地图。Visually display various historical time periods and historical maps.
Stars: ✭ 127 (-99.21%)
Mutual labels:  3d, threejs
Mini3d
3D Software Renderer in 700 Lines !!
Stars: ✭ 1,320 (-91.8%)
Mutual labels:  3d, renderer
React 3d Viewer
A 3D model viewer component based on react.js 一个基于react.js的组件化3d模型查看工具
Stars: ✭ 100 (-99.38%)
Mutual labels:  3d, threejs
Earthjs
D3 Earth JS
Stars: ✭ 128 (-99.2%)
Mutual labels:  3d, threejs
Vimeo Depth Player
A WebVR volumetric video renderer that uses color-depth based videos hosted on Vimeo.
Stars: ✭ 65 (-99.6%)
Mutual labels:  3d, threejs
Fabscanpi Server
FabScan Pi Open Source 3D Scanner - Server application
Stars: ✭ 137 (-99.15%)
Mutual labels:  3d, threejs
3d Force Graph
3D force-directed graph component using ThreeJS/WebGL
Stars: ✭ 2,386 (-85.18%)
Mutual labels:  3d, threejs
Andromeda
This is a WebGL recreation of the popular music video Gorillaz - Andromeda.
Stars: ✭ 145 (-99.1%)
Mutual labels:  3d, threejs
Three Forcegraph
Force-directed graph as a ThreeJS 3d object
Stars: ✭ 84 (-99.48%)
Mutual labels:  3d, threejs
Trails
Simple geometrical trail to attach to your Three.js objects
Stars: ✭ 79 (-99.51%)
Mutual labels:  3d, threejs
Giojs
🌏 A Declarative 3D Globe Data Visualization Library built with Three.js
Stars: ✭ 1,528 (-90.51%)
Mutual labels:  3d, threejs
Vanta
Animated 3D backgrounds for your website
Stars: ✭ 1,162 (-92.78%)
Mutual labels:  3d, threejs
Lba2remake
A Little Big Adventure 2 / Twinsen's Odyssey reimplementation in JavaScript / Three.js / React
Stars: ✭ 116 (-99.28%)
Mutual labels:  3d, threejs
Wechart
Create all the [ch]arts by cax or three.js - Cax 和 three.js 创造一切图[表]
Stars: ✭ 152 (-99.06%)
Mutual labels:  3d, threejs
Egjs View3d
Fast & customizable 3D model viewer for everyone
Stars: ✭ 34 (-99.79%)
Mutual labels:  3d, threejs
Aframe Forcegraph Component
Force-directed graph component for A-Frame
Stars: ✭ 60 (-99.63%)
Mutual labels:  3d, threejs
Tweetscape
A WebVR experience displaying tweets in real-time along a 3D timeline
Stars: ✭ 132 (-99.18%)
Mutual labels:  3d, threejs

react-three-fiber

Version Downloads Twitter Discord Open Collective ETH BTC

react-three-fiber is a React renderer for threejs.

Build your scene declaratively with re-usable, self-contained components that react to state, are readily interactive and can participate in React's ecosystem.

npm install three @react-three/fiber

Does it have limitations?

None. Everything that works in Threejs will work here without exception.

Is it slower than plain Threejs?

No. There is no overhead. Components render outside of React. It outperforms Threejs in scale due to Reacts scheduling abilities.

Can it keep up with frequent feature updates to Threejs?

Yes. It merely expresses Threejs in JSX: <mesh /> becomes new THREE.Mesh(), and that happens dynamically. If a new Threejs version adds, removes or changes features, it will be available to you instantly without depending on updates to this library.

What does it look like?

Let's make a re-usable component that has its own state, reacts to user-input and participates in the render-loop. (live demo).
import ReactDOM from 'react-dom'
import React, { useRef, useState } from 'react'
import { Canvas, useFrame } from '@react-three/fiber'

function Box(props) {
  // This reference gives us direct access to the THREE.Mesh object
  const ref = useRef()
  // Hold state for hovered and clicked events
  const [hovered, hover] = useState(false)
  const [clicked, click] = useState(false)
  // Subscribe this component to the render-loop, rotate the mesh every frame
  useFrame((state, delta) => (ref.current.rotation.x += 0.01))
  // Return the view, these are regular Threejs elements expressed in JSX
  return (
    <mesh
      {...props}
      ref={ref}
      scale={clicked ? 1.5 : 1}
      onClick={(event) => click(!clicked)}
      onPointerOver={(event) => hover(true)}
      onPointerOut={(event) => hover(false)}>
      <boxGeometry args={[1, 1, 1]} />
      <meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
    </mesh>
  )
}

ReactDOM.render(
  <Canvas>
    <ambientLight />
    <pointLight position={[10, 10, 10]} />
    <Box position={[-1.2, 0, 0]} />
    <Box position={[1.2, 0, 0]} />
  </Canvas>,
  document.getElementById('root'),
)
Show TypeScript example
npm install @types/three
import * as THREE from 'three'
import ReactDOM from 'react-dom'
import React, { useRef, useState } from 'react'
import { Canvas, useFrame } from '@react-three/fiber'

function Box(props: JSX.IntrinsicElements['mesh']) {
  const ref = useRef<THREE.Mesh>(null!)
  const [hovered, hover] = useState(false)
  const [clicked, click] = useState(false)
  useFrame((state, delta) => (ref.current.rotation.x += 0.01))
  return (
    <mesh
      {...props}
      ref={ref}
      scale={clicked ? 1.5 : 1}
      onClick={(event) => click(!clicked)}
      onPointerOver={(event) => hover(true)}
      onPointerOut={(event) => hover(false)}>
      <boxGeometry args={[1, 1, 1]} />
      <meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
    </mesh>
  )
}

ReactDOM.render(
  <Canvas>
    <ambientLight />
    <pointLight position={[10, 10, 10]} />
    <Box position={[-1.2, 0, 0]} />
    <Box position={[1.2, 0, 0]} />
  </Canvas>,
  document.getElementById('root'),
)

Live demo: https://codesandbox.io/s/icy-tree-brnsm?file=/src/App.tsx


Documentation, tutorials, examples

Visit docs.pmnd.rs

Fundamentals

You need to be versed in both React and Threejs before rushing into this. If you are unsure about React consult the official React docs, especially the section about hooks. As for Threejs, make sure you at least glance over the following links:

  1. Make sure you have a basic grasp of Threejs. Keep that site open.
  2. When you know what a scene is, a camera, mesh, geometry, material, fork the demo above.
  3. Look up the JSX elements that you see (mesh, ambientLight, etc), all threejs exports are native to three-fiber.
  4. Try changing some values, scroll through our Api to see what the various settings and hooks do.

Some reading material:

Ecosystem

How to contribute

If you like this project, please consider helping out. All contributions are welcome as well as donations to Opencollective, or in crypto BTC: 36fuguTPxGCNnYZSRdgdh6Ea94brCAjMbH, ETH: 0x6E3f79Ea1d0dcedeb33D3fC6c34d2B1f156F2682.

Backers

Thank you to all our backers! 🙏

Contributors

This project exists thanks to all the people who contribute.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].