Builds Three.js scenes through React components and renderer-owned JSX elements.
Downloads / mo 35.7M
Stars 33.8K
Last release 9.8.2
License MIT
Runs on Three.js Strengths Builds scenes with reusable components . Describe meshes, lights, and materials directly in JSX. Updates objects during rendered frames . Use useFrame to update scene objects in the render loop. Limitations Hooks need canvas context . Call useThree and useFrame inside Canvas descendants. React majors must match . Pair the renderer major with its supported React major. $ npm install @react-three/fiber three Copy
import { Canvas } from '@react-three/fiber';
export default function App() {
return <Canvas style={{ height: 400 }}><mesh><boxGeometry /><meshNormalMaterial /></mesh></Canvas>;
}
@react-three/fiber examples From open-source projects on GitHub export function useCubeCamera({ resolution = 256, near = 0.1, far = 1000, envMap, fog }: CubeCameraOptions = {}) {
const gl = useThree(({ gl }) => gl)
const scene = useThree(({ scene }) => scene)
const fbo = useMemo(() => {
const fbo = new WebGLCubeRenderTarget(resolution)
fbo.texture.type = HalfFloatType
return fbo
}, [resolution])
useEffect(() => {
return () => {
fbo.dispose()
}
}, [fbo])
const camera = useMemo(() => new THREE.CubeCamera(near, far, fbo), [near, far, fbo])
let originalFog
let originalBackground
const update = React.useCallback(() => {
originalFog = scene.fog
originalBackground = scene.background
scene.background = envMap || originalBackground
scene.fog = fog || originalFog
camera.update(gl, scene)
scene.fog = originalFog
scene.background = originalBackground
}, [gl, scene, camera])
return {
fbo,
camera,
update,
}
}
Show full example Adds loaders, controls, and reusable scene helpers to React Three Fiber.
Downloads / mo 23.5M
Stars 10.2K
Last release 10.7.9
License MIT
Runs on React Three Fiber Strengths Loads GLTF scenes through useGLTF . Use the helper instead of wiring useLoader and GLTFLoader directly. Controls manage updates and cleanup . Camera controls update automatically and remove themselves on unmount. Limitations Requires React Three Fiber . Add these helpers to an existing Fiber scene. Compressed models fetch a decoder . Self-host Draco binaries when external decoder requests are unsuitable. $ npm install @react-three/drei three @react-three/fiber Copy
import { Canvas } from '@react-three/fiber';
import { CameraControls } from '@react-three/drei';
export default function App() {
return <Canvas style={{ height: 400 }}><CameraControls /><mesh><boxGeometry /><meshNormalMaterial /></mesh></Canvas>;
}
@react-three/drei examples From open-source projects on GitHub function Model({url}: {url: string}) {
const {nodes} = useGLTF(url) as any
return (
<group rotation={[-Math.PI / 2, 0, 0]} position={[0, -7, 0]} scale={7}>
<group rotation={[Math.PI / 13.5, -Math.PI / 5.8, Math.PI / 5.6]}>
<e.mesh
theatreKey="Example Namespace / Thingy"
receiveShadow
castShadow
geometry={nodes.planet001.geometry}
material={nodes.planet001.material}
/>
<e.mesh
theatreKey="Example Namespace / Debris 2"
receiveShadow
castShadow
geometry={nodes.planet002.geometry}
material={nodes.planet002.material}
/>
<e.mesh
theatreKey="Debris 1"
geometry={nodes.planet003.geometry}
material={nodes.planet003.material}
/>
</group>
</group>
)
}
Show full example Adds spring animation support to react-three-fiber.
Downloads / mo 9.2M
Stars 29.3K
Last release 10.1.2
License MIT $ npm install @react-spring/three three @react-three/fiber Copy
import { Canvas } from '@react-three/fiber';
import { animated, useSpring } from '@react-spring/three';
function Box() {
const { scale } = useSpring({ from: { scale: 0 }, to: { scale: 1 } });
return <animated.mesh scale={scale}><boxGeometry /><meshNormalMaterial /></animated.mesh>;
}
export default function App() {
return <Canvas style={{ height: 400 }}><Box /></Canvas>;
}
@react-spring/three examples From open-source projects on GitHub export default function RawPillar({
style,
length,
envMap,
hover,
...props
}: RawPillarProps & RawPillarMeshProps) {
const pillarSpring = useSpring({
color: style.color,
opacity: style.opacity ?? 1,
config: {
tension: 150,
},
});
return (
<animated.mesh {...props}>
<boxGeometry args={[length, 1, length]} />
<animated.meshStandardMaterial
color={hover ? "#ff8787" : pillarSpring.color}
transparent
opacity={pillarSpring.opacity}
metalness={style.metalness ?? 0}
roughness={style.roughness ?? 1}
envMap={envMap}
/>
{props.children}
</animated.mesh>
);
}
Show full example Wraps the postprocessing library for React and @react-three/fiber.
Downloads / mo 5.5M
Stars 1.7K
Last release 3.2.2
License MIT $ npm install @react-three/postprocessing three @react-three/fiber postprocessing Copy
import { Canvas } from '@react-three/fiber';
import { Bloom, EffectComposer } from '@react-three/postprocessing';
export default function App() {
return (
<Canvas style={{ height: 400 }}>
<mesh><boxGeometry /><meshBasicMaterial color="orange" /></mesh>
<EffectComposer><Bloom luminanceThreshold={0} /></EffectComposer>
</Canvas>
);
}
@react-three/postprocessing examples From open-source projects on GitHub function Effects({ focusTarget, hasFocus }) {
const { camera } = useThree();
const depthOfFieldRef = useRef();
useFrame(() => {
if (!depthOfFieldRef.current) return;
if (!hasFocus) {
depthOfFieldRef.current.bokehScale = 0; // no planet in focus → no blur
return;
}
const d = camera.position.distanceTo(focusTarget); // closer ⇒ stronger blur
const scale = THREE.MathUtils.clamp(12 - d * 0.75, 0, 12);
depthOfFieldRef.current.bokehScale = scale;
});
return (
<EffectComposer>
<DepthOfField
ref={depthOfFieldRef}
focusDistance={0}
focalLength={0.02}
height={480}
bokehScale={0} // initial value; updated each frame
target={focusTarget}
/>
<Bloom
luminanceThreshold={0}
luminanceSmoothing={0.25}
intensity={1.75}
mipmapBlur
/>
</EffectComposer>
);
}
Show full example Renders 3D force-directed graphs as a React component.
Downloads / mo 1.5M
Stars 3.4K
Last release 1.29.2
License MIT $ npm install react-force-graph-3d Copy
import ForceGraph3D from 'react-force-graph-3d';
export default function App() {
const data = {
nodes: [{ id: 'a' }, { id: 'b' }],
links: [{ source: 'a', target: 'b' }],
};
return <ForceGraph3D graphData={data} width={600} height={400} />;
}
react-force-graph-3d examples From open-source projects on GitHub const handleFocusButtonClick = (node: CustomNode) => {
const newHighlightNodes = new Set<CustomNode>();
newHighlightNodes.add(node);
node.neighbors?.forEach((neighbor) => newHighlightNodes.add(neighbor));
node.links?.forEach((link) => highlightLinks.add(link));
setHighlightNodes(newHighlightNodes);
setHoverNode(node);
if (graphRef.current) {
if (graphType === "2d") {
graphRef.current.centerAt(node.x, node.y, 1000);
graphRef.current.zoom(8, 1000);
} else {
graphRef.current.cameraPosition(
{ x: node.x, y: node.y, z: 300 }, // new position
{ x: node.x, y: node.y, z: 0 }, // lookAt
3000 // ms transition duration
);
}
}
// Simulate mouse hover on the focused node
setTimeout(() => {
handleNodeHover(node);
}, 1000); // Adjust delay as needed
setRightDrawerOpen(false);
};
Show full example Renders globe data visualizations in React with ThreeJS and WebGL.
Downloads / mo 969.0K
Stars 1.5K
Last release 2.38.0
License MIT $ npm install react-globe.gl Copy
import Globe from 'react-globe.gl';
export default function App() {
const points = [{ lat: 37.77, lng: -122.42 }];
return <Globe pointsData={points} pointAltitude={0.08} width={600} height={400} />;
}
react-globe.gl examples From open-source projects on GitHub export function useGlobeInteraction(
globeRef: React.MutableRefObject<GlobeMethods | undefined>,
visitedCountries: VisitedCountry[],
clickedCountry: ClickedCountry | null,
setClickedCountry: (country: ClickedCountry | null) => void,
) {
const [selectedId, setSelectedId] = useState<string | null>(null);
const [hoverId, setHoverId] = useState<string | null>(null);
const handlePolygonClick = useCallback(
(polygon: unknown) => {
const feature = polygon as CountryFeature;
const id = feature.id?.toString() ?? "";
setSelectedId(id);
setClickedCountry(null);
const controls = globeRef.current?.controls?.();
if (controls) controls.autoRotate = false;
const countryName = feature.properties?.name ?? "Unknown";
const flagEmoji = feature.properties?.flagEmoji ?? null;
const isVisited = visitedCountries.some(
(country) => country.name === countryName,
);
const [lngRaw, latRaw] = geoCentroid(feature);
const lat = Number.isFinite(latRaw) ? latRaw : undefined;
const lng = Number.isFinite(lngRaw) ? lngRaw : undefined;
if (
globeRef.current?.pointOfView &&
lat !== undefined &&
lng !== undefined
) {
globeRef.current.pointOfView(
{ lat, lng, altitude: 1.6 },
GLOBE_ANIMATION_DURATION_MS,
);
setTimeout(() => {
if (globeRef.current) {
const coords = globeRef.current.getScreenCoords(lat, lng);
if (coords) {
setClickedCountry({
name: countryName,
flagEmoji,
position: { x: coords.x, y: coords.y },
isVisited,
});
}
}
}, GLOBE_ANIMATION_DURATION_MS);
}
},
[globeRef, visitedCountries, setClickedCountry],
);
const handlePolygonHover = useCallback((polygon: unknown | null) => {
const feature = (polygon ?? undefined) as CountryFeature | undefined;
setHoverId(feature?.id?.toString() ?? null);
}, []);
const polygonLabel = useCallback(
(polygon: unknown) => {
const feature = polygon as CountryFeature;
const name = feature.properties?.name ?? "Unknown";
const iso = feature.properties?.iso2 ?? "N/A";
return hoverId === feature.id?.toString()
? `<div style="padding: 6px 8px;">
<strong style="font-size: 13px;">${name}</strong><br />
<span style="font-size: 11px; opacity: 0.7;">ISO: ${iso}</span>
</div>`
: "";
},
[hoverId],
);
return {
selectedId,
hoverId,
handlePolygonClick,
handlePolygonHover,
polygonLabel,
};
}
Show full example Adds Rapier physics to React.
Downloads / mo 847.9K
Stars 1.7K
Last release 2.2.0
License MIT $ npm install @react-three/rapier three @react-three/fiber Copy
import { Suspense } from 'react';
import { Canvas } from '@react-three/fiber';
import { Physics, RigidBody } from '@react-three/rapier';
export default function App() {
return (
<Canvas style={{ height: 400 }}>
<Suspense fallback={null}>
<Physics><RigidBody><mesh><boxGeometry /><meshNormalMaterial /></mesh></RigidBody></Physics>
</Suspense>
</Canvas>
);
}
@react-three/rapier examples From open-source projects on GitHub export function GroundPlane({ position, material, size }: GroundPlaneProps) {
const isPlaying = useEditorStore((s) => s.isPlaying);
const s = size ?? 5000;
const pos: [number, number, number] = position ?? [0, -0.1, 0];
const plane = (
<mesh rotation={[-Math.PI / 2, 0, 0]} position={pos} receiveShadow>
<planeGeometry args={[s, s]} />
<meshStandardMaterial
color={material?.color ?? "#4CAF50"}
metalness={material?.metalness ?? 0}
roughness={material?.roughness ?? 0.9}
side={THREE.DoubleSide}
/>
</mesh>
);
if (!isPlaying) return plane;
return (
<RigidBody type="fixed" position={pos} colliders={false}>
<mesh rotation={[-Math.PI / 2, 0, 0]} receiveShadow>
<planeGeometry args={[s, s]} />
<meshStandardMaterial
color={material?.color ?? "#4CAF50"}
metalness={material?.metalness ?? 0}
roughness={material?.roughness ?? 0.9}
side={THREE.DoubleSide}
/>
</mesh>
<CuboidCollider args={[s / 2, 0.01, s / 2]} position={[0, 0, 0]} />
</RigidBody>
);
}
Show full example Embeds exported Spline scenes and connects their interactions to React.
Downloads / mo 683.9K
Stars 1.4K
Last release 4.2.0
License MIT
Runs on Spline runtime Strengths Embeds visually authored scenes . Export a Spline scene and load its URL in React. Triggers authored animation events . Trigger an editor-defined animation event from a React button. Limitations Models need the editor first . Import raw models into Spline before exporting a React scene. $ npm install @splinetool/react-spline Copy
import Spline from '@splinetool/react-spline';
export default function App() {
return <Spline scene="https://prod.spline.design/6Wq1Q7YGyM-iab9i/scene.splinecode" />;
}
@splinetool/react-spline examples From open-source projects on GitHub export function SplineScene({ scene, className }: SplineSceneProps) {
return (
<SplineErrorBoundary>
<Suspense
fallback={
<div className="w-full h-full flex items-center justify-center">
<span className="loader"></span>
</div>
}
>
<Spline
scene={scene}
className={className}
/>
</Suspense>
</SplineErrorBoundary>
)
}
Show full example