Text3D
threecn/text-3dFreeComponent
Extruded, floating 3D text rendered with drei <Text3D>, colored with --primary.
Install it
npx shadcn@latest add https://threecn.dev/r/text-3d.jsonSource
1"use client"23import * as React from "react"4import { useFrame } from "@react-three/fiber"5import { Center, Text3D as DreiText3D } from "@react-three/drei"6import * as THREE from "three"78import {9 SceneContainer,10 type SceneContainerProps,11} from "@/components/threecn/scene-container"12import {13 useShadcnTheme,14 type ThemeMode,15} from "@/components/hooks/use-shadcn-theme"1617/**18 * Default typeface (three.js `typeface.json` format), served from the jsDelivr19 * npm mirror so the scene works out of the box. To go fully offline, drop a20 * font JSON in `/public/fonts` and pass it via the `font` prop, e.g.21 * `font="/fonts/inter_bold.json"`.22 */23const DEFAULT_FONT =24 "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/fonts/helvetiker_bold.typeface.json"2526type GlyphsProps = {27 text: string28 size: number29 depth: number30 font: string31 theme: ThemeMode32}3334function Glyphs({ text, size, depth, font, theme }: GlyphsProps) {35 const groupRef = React.useRef<THREE.Group>(null)36 const { primaryColor, foregroundColor } = useShadcnTheme(theme)3738 useFrame((state) => {39 const group = groupRef.current40 if (!group) return41 const t = state.clock.elapsedTime42 group.position.y = Math.sin(t * 0.9) * 0.1243 group.rotation.y = Math.sin(t * 0.4) * 0.1844 group.rotation.x = Math.cos(t * 0.3) * 0.0645 })4647 return (48 <group ref={groupRef}>49 <Center>50 <DreiText3D51 font={font}52 size={size}53 height={depth}54 curveSegments={8}55 bevelEnabled56 bevelThickness={0.02}57 bevelSize={0.012}58 bevelSegments={4}59 letterSpacing={-0.02}60 >61 {text}62 <meshStandardMaterial63 color={primaryColor}64 emissive={primaryColor}65 emissiveIntensity={0.18}66 metalness={0.55}67 roughness={0.25}68 />69 </DreiText3D>70 </Center>71 <ambientLight color={foregroundColor} intensity={0.05} />72 </group>73 )74}7576export type Text3DProps = {77 text: string78 size?: number79 depth?: number80 /** Path/URL to a three.js typeface JSON. Defaults to the bundled Inter Bold. */81 font?: string82 className?: string83 theme?: ThemeMode84 environment?: SceneContainerProps["environment"]85}8687/**88 * Extruded, slowly floating 3D text rendered with drei's `<Text3D>`. The89 * glyph material uses your `--primary` color.90 */91export function Text3D({92 text,93 size = 1,94 depth = 0.3,95 font = DEFAULT_FONT,96 className,97// … truncated
What it pulls in
npm packages
Files it writes
More from threecn
All 28 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| AuroraRibbonsaurora-ribbons | threecn | Components | Free | 3 deps · 3 files | |
| Boidsboids | threecn | Components | Free | 3 deps · 3 files | |
| Clothcloth | threecn | Components | Free | 3 deps · 3 files | |
| Crystalcrystal | threecn | Components | Free | 3 deps · 3 files | |
| CubeWavecube-wave | threecn | Components | Free | 3 deps · 3 files | |
| CurlFlowcurl-flow | threecn | Components | Free | 3 deps · 3 files | |
| DnaHelixdna-helix | threecn | Components | Free | 3 deps · 3 files | |
| FloatingCard3Dfloating-card-3d | threecn | Components | Free | 3 deps · 3 files |
