3dsvg

中文文档
0.2.1发布于 2026/04/09MITTypeScriptES Module近 30 天下载 2985

The easiest way to turn SVGs into interactive React 3D components

原始使用文档
文档目录17 节
  1. Install
  2. Quick Start
  3. Demo & Editor
  4. Props
  5. Content
  6. Shape
  7. Material
  8. Texture
  9. Lighting
  10. Camera
  11. Interaction
  12. Animation
  13. Intro
  14. Layout
  15. Events
  16. Available Fonts
  17. License

3dsvg

3dsvg

The easiest way to turn SVGs into interactive React 3D components.

License: MIT npm npm bundle size

Install

npm install 3dsvg

Peer dependencies: react, react-dom, three, @react-three/fiber, @react-three/drei

Quick Start

import { SVG3D } from "3dsvg";

// 3D text
<SVG3D text="Hello" animate="spin" />

// SVG from your public folder
<SVG3D svg="/logo.svg" material="gold" animate="float" />

// Inline SVG markup
<SVG3D svg='<svg viewBox="0 0 24 24"><path d="M12 2L2 7l10 5 10-5z"/></svg>' />

// Remote URL
<SVG3D svg="https://cdn.example.com/icon.svg" material="metal" />

Next.js — wrap with next/dynamic for SSR safety:

const SVG3D = dynamic(
  () => import("3dsvg").then((m) => ({ default: m.SVG3D })),
  { ssr: false }
);

Demo & Editor

Design 3D objects visually and export embed code at 3dsvg.design.

Props

Content

Provide either text or svg. If both are given, svg takes priority.

PropTypeDefaultDescription
textstring—Text to render in 3D
fontstring"DM Sans"Google Font name (see available fonts)
svgstring—SVG markup or URL (/logo.svg, https://..., ./path.svg)

Shape

PropTypeDefaultDescription
depthnumber1Extrusion depth (0.5 = flat, 10 = very deep)
smoothnessnumber0.2Curve and bevel quality, 0–1
colorstring"#ffffff"Base color (hex)

Material

PropTypeDefaultDescription
materialMaterialPreset"default"Material preset (see below)
metalnessnumber—Override preset metalness (0–1)
roughnessnumber—Override preset roughness (0–1)
opacitynumber—Override preset opacity (0–1)
wireframebooleanfalseWireframe rendering mode

Material presets:

PresetMetalnessRoughnessNotes
default0.150.35Balanced starting point
plastic0.00.3Smooth, non-reflective
metal0.90.2Brushed metal
glass0.10.05Transparent with refraction
rubber0.00.9Matte, soft
chrome1.00.05Mirror-like reflections
gold1.00.25Gold tint applied automatically
clay0.01.0Fully matte
emissive0.00.5Self-illuminated glow
holographic0.80.1Transparent with clearcoat

Texture

PropTypeDefaultDescription
texturestring—Image URL to map onto the 3D surface
textureRepeatnumber1How many times the texture tiles
textureRotationnumber0Texture rotation in radians
textureOffset[number, number][0, 0]UV offset [x, y]

When a texture is set, the base color is overridden to white so the texture renders at full fidelity.

Lighting

PropTypeDefaultDescription
lightPosition[number, number, number][5, 8, 5]Key light position [x, y, z]
lightIntensitynumber1.2Key light brightness
ambientIntensitynumber0.3Ambient fill light
shadowbooleantrueShow contact shadows

Camera

PropTypeDefaultDescription
rotationXnumber0Initial X rotation (radians)
rotationYnumber0Initial Y rotation (radians)
zoomnumber8Camera distance
fovnumber50Field of view (degrees)

The camera automatically adjusts on narrow/portrait viewports — it zooms out proportionally so the 3D object always fits within the visible area.

Interaction

PropTypeDefaultDescription
interactivebooleantrueMaster toggle — false disables drag, zoom, and orbit
cursorOrbitbooleantrueObject subtly follows the cursor
orbitStrengthnumber0.15How strongly the object follows the cursor (radians)
draggablebooleantrueAllow drag to rotate
scrollZoombooleanfalseAllow scroll to zoom (off by default so embeds don't hijack page scroll)
resetOnIdlebooleanfalseReturn to default position after inactivity
resetDelaynumber2Seconds before reset triggers

Animation

PropTypeDefaultDescription
animateAnimationType"none"Loop animation type (see below)
animateSpeednumber1Speed multiplier
animateReversebooleanfalseReverse direction

Animation types: none · spin · float · pulse · wobble · spinFloat · swing

Intro

PropTypeDefaultDescription
introstring"zoom"Intro animation: zoom · fade · none
introDurationnumber2.5Duration in seconds
introFromobject{ zoom: 18, opacity: 0 }Starting state
introToobject{ zoom: 8, opacity: 1 }Ending state

Layout

PropTypeDefaultDescription
widthstring | number"100%"Container width
heightstring | number"100%"Container height
backgroundstring"transparent"Canvas background color
classNamestring—CSS class on the wrapper div

Events

PropTypeDescription
onReady() => voidFires when WebGL context is ready and first frame is rendered
onAnimationComplete() => voidFires when the intro animation finishes
onLoadingChange(loading: boolean, progress: number) => voidFires during geometry processing with loading state and progress (0-100). Use this to show custom loading UI.

Geometry processing is asynchronous — complex SVGs are processed in batches to keep the browser responsive. The onLoadingChange callback lets you track progress and show a loading indicator:

<SVG3D
  svgString={complexSvg}
  onLoadingChange={(loading, progress) => {
    if (loading) console.log(`Processing: ${progress}%`);
    else console.log("Done");
  }}
/>

Available Fonts

DM Sans · Bebas Neue · Playfair Display · Righteous · Black Ops One · Permanent Marker · Rubik Mono One · Pacifico · Oswald · Archivo Black

License

MIT — Renato Costa

Made in Blueberry 🫐

版本与发布记录

3dsvg 共发布 5 个版本,首次发布于 2026/04/03;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.2.1latest2026/04/096 个月前
0.2.02026/04/096 个月前
0.1.22026/04/037 个月前
0.1.12026/04/037 个月前
0.1.02026/04/037 个月前

关于 3dsvg 的常见问题

3dsvg 是什么?

The easiest way to turn SVGs into interactive React 3D components

如何安装 3dsvg?

在项目目录运行 npm install 3dsvg,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18)、react-dom(>=18)、three(>=0.160.0)、@react-three/fiber(>=9)、@react-three/drei(>=10)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

3dsvg 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

3dsvg 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

3dsvg 可以商用吗?

3dsvg 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

3dsvg 的下载量有多少?

根据 npm 官方下载统计,3dsvg 在 2026/10/04 – 2026/11/02 这 30 天内被下载 2,985 次,日均约 100 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

3dsvg 还在维护吗?

最新版本 0.2.1 发布于 2026/04/09(6 个月前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2026/04/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。