@json-render/react-three-fiber
React Three Fiber renderer for json-render. 19 built-in 3D components.
Two Entry Points
| Entry Point |
Exports |
Use For |
@json-render/react-three-fiber/catalog |
threeComponentDefinitions |
Catalog schemas (no R3F dependency, safe for server) |
@json-render/react-three-fiber |
threeComponents, ThreeRenderer, ThreeCanvas, schemas |
R3F implementations and renderer |
Usage Pattern
Pick the 3D components you need from the standard definitions:
import { defineCatalog } from "@json-render/core";
import { schema } from "@json-render/react/schema";
import { threeComponentDefinitions } from "@json-render/react-three-fiber/catalog";
import { defineRegistry } from "@json-render/react";
import { threeComponents, ThreeCanvas } from "@json-render/react-three-fiber";
// Catalog: pick definitions
const catalog = defineCatalog(schema, {
components: {
Box: threeComponentDefinitions.Box,
Sphere: threeComponentDefinitions.Sphere,
AmbientLight: threeComponentDefinitions.AmbientLight,
DirectionalLight: threeComponentDefinitions.DirectionalLight,
OrbitControls: threeComponentDefinitions.OrbitControls,
},
actions: {},
});
// Registry: pick matching implementations
const { registry } = defineRegistry(catalog, {
components: {
Box: threeComponents.Box,
Sphere: threeComponents.Sphere,
AmbientLight: threeComponents.AmbientLight,
DirectionalLight: threeComponents.DirectionalLight,
OrbitControls: threeComponents.OrbitControls,
},
});
Rendering
ThreeCanvas (convenience wrapper)
<ThreeCanvas
spec={spec}
registry={registry}
shadows
camera={{ position: [5, 5, 5], fov: 50 }}
style={{ width: "100%", height: "100vh" }}
/>
Manual Canvas setup
import { Canvas } from "@react-three/fiber";
import { ThreeRenderer } from "@json-render/react-three-fiber";
<Canvas shadows>
<ThreeRenderer spec={spec} registry={registry}>
{/* Additional R3F elements */}
</ThreeRenderer>
</Canvas>
Available Components (19)
Primitives (7)
Box -- width, height, depth, material
Sphere -- radius, widthSegments, heightSegments, material
Cylinder -- radiusTop, radiusBottom, height, material
Cone -- radius, height, material
Torus -- radius, tube, material
Plane -- width, height, material
Capsule -- radius, length, material
All primitives share: position, rotation, scale, castShadow, receiveShadow, material.
Lights (4)
AmbientLight -- color, intensity
DirectionalLight -- position, color, intensity, castShadow
PointLight -- position, color, intensity, distance, decay
SpotLight -- position, color, intensity, angle, penumbra
Other (8)
Group -- container with position/rotation/scale, supports children
Model -- GLTF/GLB loader via url prop
Environment -- HDRI environment map (preset, background, blur, intensity)
Fog -- linear fog (color, near, far)
GridHelper -- reference grid (size, divisions, color)
Text3D -- SDF text (text, fontSize, color, anchorX, anchorY)
PerspectiveCamera -- camera (position, fov, near, far, makeDefault)
OrbitControls -- orbit controls (enableDamping, enableZoom, autoRotate)
Shared Schemas
Reusable Zod schemas for custom 3D catalog definitions:
import { vector3Schema, materialSchema, transformProps, shadowProps } from "@json-render/react-three-fiber";
import { z } from "zod";
// Custom 3D component
const myComponentDef = {
props: z.object({
...transformProps,
...shadowProps,
material: materialSchema.nullable(),
myCustomProp: z.string(),
}),
description: "My custom 3D component",
};
Material Schema
materialSchema = z.object({
color: z.string().nullable(), // default "#ffffff"
metalness: z.number().nullable(), // default 0
roughness: z.number().nullable(), // default 1
emissive: z.string().nullable(), // default "#000000"
emissiveIntensity: z.number().nullable(), // default 1
opacity: z.number().nullable(), // default 1
transparent: z.boolean().nullable(), // default false
wireframe: z.boolean().nullable(), // default false
});
Spec Format
3D specs use the standard json-render flat element format:
{
"root": "scene",
"elements": {
"scene": {
"type": "Group",
"props": { "position": [0, 0, 0] },
"children": ["light", "box"]
},
"light": {
"type": "AmbientLight",
"props": { "intensity": 0.5 },
"children": []
},
"box": {
"type": "Box",
"props": {
"position": [0, 0.5, 0],
"material": { "color": "#4488ff", "metalness": 0.3, "roughness": 0.7 }
},
"children": []
}
}
}
Dependencies
Peer dependencies required:
@react-three/fiber >= 8.0.0
@react-three/drei >= 9.0.0
three >= 0.160.0
react ^19.0.0
zod ^4.0.0
1---2name: react-three-fiber3description: React Three Fiber 3D renderer for json-render. Use when working with @json-render/react-three-fiber, building 3D scenes from JSON specs, rendering meshes/lights/models/environments, or integrating Three.js with json-render catalogs.4---56# @json-render/react-three-fiber78React Three Fiber renderer for json-render. 19 built-in 3D components.910## Two Entry Points1112| Entry Point | Exports | Use For |13|-------------|---------|---------|14| `@json-render/react-three-fiber/catalog` | `threeComponentDefinitions` | Catalog schemas (no R3F dependency, safe for server) |15| `@json-render/react-three-fiber` | `threeComponents`, `ThreeRenderer`, `ThreeCanvas`, schemas | R3F implementations and renderer |1617## Usage Pattern1819Pick the 3D components you need from the standard definitions:2021```typescript22import { defineCatalog } from "@json-render/core";23import { schema } from "@json-render/react/schema";24import { threeComponentDefinitions } from "@json-render/react-three-fiber/catalog";25import { defineRegistry } from "@json-render/react";26import { threeComponents, ThreeCanvas } from "@json-render/react-three-fiber";2728// Catalog: pick definitions29const catalog = defineCatalog(schema, {30 components: {31 Box: threeComponentDefinitions.Box,32 Sphere: threeComponentDefinitions.Sphere,33 AmbientLight: threeComponentDefinitions.AmbientLight,34 DirectionalLight: threeComponentDefinitions.DirectionalLight,35 OrbitControls: threeComponentDefinitions.OrbitControls,36 },37 actions: {},38});3940// Registry: pick matching implementations41const { registry } = defineRegistry(catalog, {42 components: {43 Box: threeComponents.Box,44 Sphere: threeComponents.Sphere,45 AmbientLight: threeComponents.AmbientLight,46 DirectionalLight: threeComponents.DirectionalLight,47 OrbitControls: threeComponents.OrbitControls,48 },49});50```5152## Rendering5354### ThreeCanvas (convenience wrapper)5556```tsx57<ThreeCanvas58 spec={spec}59 registry={registry}60 shadows61 camera={{ position: [5, 5, 5], fov: 50 }}62 style={{ width: "100%", height: "100vh" }}63/>64```6566### Manual Canvas setup6768```tsx69import { Canvas } from "@react-three/fiber";70import { ThreeRenderer } from "@json-render/react-three-fiber";7172<Canvas shadows>73 <ThreeRenderer spec={spec} registry={registry}>74 {/* Additional R3F elements */}75 </ThreeRenderer>76</Canvas>77```7879## Available Components (19)8081### Primitives (7)82- `Box` -- width, height, depth, material83- `Sphere` -- radius, widthSegments, heightSegments, material84- `Cylinder` -- radiusTop, radiusBottom, height, material85- `Cone` -- radius, height, material86- `Torus` -- radius, tube, material87- `Plane` -- width, height, material88- `Capsule` -- radius, length, material8990All primitives share: `position`, `rotation`, `scale`, `castShadow`, `receiveShadow`, `material`.9192### Lights (4)93- `AmbientLight` -- color, intensity94- `DirectionalLight` -- position, color, intensity, castShadow95- `PointLight` -- position, color, intensity, distance, decay96- `SpotLight` -- position, color, intensity, angle, penumbra9798### Other (8)99- `Group` -- container with position/rotation/scale, supports children100- `Model` -- GLTF/GLB loader via url prop101- `Environment` -- HDRI environment map (preset, background, blur, intensity)102- `Fog` -- linear fog (color, near, far)103- `GridHelper` -- reference grid (size, divisions, color)104- `Text3D` -- SDF text (text, fontSize, color, anchorX, anchorY)105- `PerspectiveCamera` -- camera (position, fov, near, far, makeDefault)106- `OrbitControls` -- orbit controls (enableDamping, enableZoom, autoRotate)107108## Shared Schemas109110Reusable Zod schemas for custom 3D catalog definitions:111112```typescript113import { vector3Schema, materialSchema, transformProps, shadowProps } from "@json-render/react-three-fiber";114import { z } from "zod";115116// Custom 3D component117const myComponentDef = {118 props: z.object({119 ...transformProps,120 ...shadowProps,121 material: materialSchema.nullable(),122 myCustomProp: z.string(),123 }),124 description: "My custom 3D component",125};126```127128## Material Schema129130```typescript131materialSchema = z.object({132 color: z.string().nullable(), // default "#ffffff"133 metalness: z.number().nullable(), // default 0134 roughness: z.number().nullable(), // default 1135 emissive: z.string().nullable(), // default "#000000"136 emissiveIntensity: z.number().nullable(), // default 1137 opacity: z.number().nullable(), // default 1138 transparent: z.boolean().nullable(), // default false139 wireframe: z.boolean().nullable(), // default false140});141```142143## Spec Format1441453D specs use the standard json-render flat element format:146147```json148{149 "root": "scene",150 "elements": {151 "scene": {152 "type": "Group",153 "props": { "position": [0, 0, 0] },154 "children": ["light", "box"]155 },156 "light": {157 "type": "AmbientLight",158 "props": { "intensity": 0.5 },159 "children": []160 },161 "box": {162 "type": "Box",163 "props": {164 "position": [0, 0.5, 0],165 "material": { "color": "#4488ff", "metalness": 0.3, "roughness": 0.7 }166 },167 "children": []168 }169 }170}171```172173## Dependencies174175Peer dependencies required:176- `@react-three/fiber` >= 8.0.0177- `@react-three/drei` >= 9.0.0178- `three` >= 0.160.0179- `react` ^19.0.0180- `zod` ^4.0.0