Three.js SVG Extrusion (SVGLoader + ExtrudeGeometry)
Turn SVG paths into 3D solids in Three.js with SVGLoader and ExtrudeGeometry, keeping holes and fill colors, with depth, bevel and curve-detail controls and loading of your own SVG files.
Key topics: three.js svg, svgloader, extrudegeometry, svg to 3d, bevel, logo extrusion
Game Over
What this code does
- Parsing: `SVGLoader.parse` turns SVG markup into `ShapePath`s with their fill styles.
- Holes: `SVGLoader.createShapes` applies the fill rule, so inner contours (the gear's hole, the ring) cut through.
- Extrusion: `ExtrudeGeometry` sweeps each shape along +Z, with optional bevel thickness, size and segments.
- Coordinate Flip: SVG's y axis points down, so the group is mirrored and centred, then rendered double-sided.
- Curve Detail: `curveSegments` controls how finely arcs and Béziers are tessellated.
- Controls: sample SVG, depth, bevel options, curve segments, wireframe, spin and load your own .svg (read locally).
Related Demos
Continue Learning
JavaScript Implementation
import { SVGLoader } from 'three/examples/jsm/loaders/SVGLoader.js'
const svg = '<svg viewBox="0 0 120 120"><path fill="#facc15" d="M60 4 L74 44 L116 44 L82 69 L95 110 L60 85 L25 110 L38 69 L4 44 L46 44 Z"/></svg>'
const { paths } = new SVGLoader().parse(svg)
const group = new THREE.Group()
paths.forEach((path) => {
const material = new THREE.MeshStandardMaterial({ color: path.color })
SVGLoader.createShapes(path).forEach((shape) => {
const geometry = new THREE.ExtrudeGeometry(shape, { depth: 18, bevelEnabled: true, bevelThickness: 3, bevelSize: 2 })
group.add(new THREE.Mesh(geometry, material))
})
})
group.scale.set(0.03, -0.03, 0.03) // SVG y axis points down
scene.add(group)