BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/threecn/network-graph

NetworkGraph

threecn/network-graph
FreeComponent

A living plexus of drifting nodes that link up when close, fading from --primary to --muted-foreground.

Install it

npx shadcn@latest add https://threecn.dev/r/network-graph.json

Source

components/threecn/network-graph.tsxthreecn.dev/r/network-graph.json · first 6 KB
1"use client"
2
3import * as React from "react"
4import { useFrame } from "@react-three/fiber"
5import * as THREE from "three"
6
7import {
8 SceneContainer,
9 type SceneContainerProps,
10} from "@/components/threecn/scene-container"
11import {
12 useShadcnTheme,
13 type ThemeMode,
14} from "@/components/hooks/use-shadcn-theme"
15
16const RADIUS = 2.7
17
18function seedPositions(count: number) {
19 const positions = new Float32Array(count * 3)
20 for (let i = 0; i < count; i++) {
21 // Uniform-ish distribution inside a sphere.
22 const r = Math.cbrt(Math.random()) * RADIUS * 0.92
23 const theta = Math.random() * Math.PI * 2
24 const phi = Math.acos(2 * Math.random() - 1)
25 positions[i * 3] = r * Math.sin(phi) * Math.cos(theta)
26 positions[i * 3 + 1] = r * Math.sin(phi) * Math.sin(theta)
27 positions[i * 3 + 2] = r * Math.cos(phi)
28 }
29 return positions
30}
31
32function seedVelocities(count: number) {
33 const velocities = new Float32Array(count * 3)
34 for (let i = 0; i < velocities.length; i++) {
35 velocities[i] = (Math.random() - 0.5) * 0.35
36 }
37 return velocities
38}
39
40function Graph({
41 nodes,
42 linkDistance,
43 speed,
44 theme,
45}: {
46 nodes: number
47 linkDistance: number
48 speed: number
49 theme: ThemeMode
50}) {
51 const { primaryColor, mutedColor } = useShadcnTheme(theme)
52 const groupRef = React.useRef<THREE.Group>(null)
53 const pointGeoRef = React.useRef<THREE.BufferGeometry>(null)
54 const lineGeoRef = React.useRef<THREE.BufferGeometry>(null)
55 /** Node velocities, re-seeded whenever the position buffer is replaced. */
56 const velocitiesRef = React.useRef<{
57 key: THREE.BufferAttribute
58 values: Float32Array
59 } | null>(null)
60 const tmpColor = React.useMemo(() => new THREE.Color(), [])
61
62 const maxEdges = nodes * 8
63 const positions = React.useMemo(() => seedPositions(nodes), [nodes])
64 const linePositions = React.useMemo(
65 () => new Float32Array(maxEdges * 6),
66 [maxEdges]
67 )
68 const lineColors = React.useMemo(
69 () => new Float32Array(maxEdges * 6),
70 [maxEdges]
71 )
72
73 useFrame((_, delta) => {
74 const pointGeo = pointGeoRef.current
75 const lineGeo = lineGeoRef.current
76 if (!pointGeo || !lineGeo) return
77
78 const posAttr = pointGeo.getAttribute("position") as THREE.BufferAttribute
79 const pos = posAttr.array as Float32Array
80 if (!velocitiesRef.current || velocitiesRef.current.key !== posAttr) {
81 velocitiesRef.current = { key: posAttr, values: seedVelocities(nodes) }
82 }
83 const vel = velocitiesRef.current.values
84
85// … truncated

What it pulls in

npm packages

  • three
  • @react-three/fiber
  • @react-three/drei

Files it writes

  • components/threecn/network-graph.tsx
  • components/threecn/scene-container.tsx
  • components/hooks/use-shadcn-theme.ts

Facts

Registry
threecn
Type
registry:ui
Access
Free
Files written
3
Licence
MIT
First indexed
2026-08-03
Last confirmed
today

Go to the source

threecn.dev ln-dev7/threecn on GitHub Raw registry item This item as JSON

More from threecn

All 28 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
AuroraRibbonsaurora-ribbonsthreecnComponentsFree3 deps · 3 files
BoidsboidsthreecnComponentsFree3 deps · 3 files
ClothcloththreecnComponentsFree3 deps · 3 files
CrystalcrystalthreecnComponentsFree3 deps · 3 files
CubeWavecube-wavethreecnComponentsFree3 deps · 3 files
CurlFlowcurl-flowthreecnComponentsFree3 deps · 3 files
DnaHelixdna-helixthreecnComponentsFree3 deps · 3 files
FloatingCard3Dfloating-card-3dthreecnComponentsFree3 deps · 3 files
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex