@json-render/react-three-fiber

React Three Fiber renderer for json-render. 19 built-in 3D components for meshes, lights, models, environments, text, cameras, and controls.

Installation

npm install @json-render/react-three-fiber @json-render/core @json-render/react @react-three/fiber @react-three/drei three zod

Entry Points

Entry PointExportsUse For
@json-render/react-three-fiberthreeComponents, ThreeRenderer, ThreeCanvas, schemasReact Three Fiber implementations and renderer
@json-render/react-three-fiber/catalogthreeComponentDefinitionsCatalog schemas (no R3F dependency, safe for server)

Usage

import {'{ defineCatalog }'} from "@json-render/core";
import {'{ schema, defineRegistry }'} from "@json-render/react";
import {'{'}
  threeComponentDefinitions,
  threeComponents,
  ThreeCanvas,
{'}'} from "@json-render/react-three-fiber";

const catalog = defineCatalog(schema, {'{'}
  components: {'{'}
    Box: threeComponentDefinitions.Box,
    Sphere: threeComponentDefinitions.Sphere,
    AmbientLight: threeComponentDefinitions.AmbientLight,
    DirectionalLight: threeComponentDefinitions.DirectionalLight,
    OrbitControls: threeComponentDefinitions.OrbitControls,
  {'}'},
  actions: {'{}'},
{'}'});

const {'{ registry }'} = defineRegistry(catalog, {'{'}
  components: {'{'}
    Box: threeComponents.Box,
    Sphere: threeComponents.Sphere,
    AmbientLight: threeComponents.AmbientLight,
    DirectionalLight: threeComponents.DirectionalLight,
    OrbitControls: threeComponents.OrbitControls,
  {'}'},
{'}'});

ThreeCanvas (convenience)

<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}'} />
</Canvas>

Components

Primitives

ComponentDescriptionKey Props
BoxBox mesh (default 1x1x1)width, height, depth, material
SphereSphere meshradius, widthSegments, heightSegments, material
CylinderCylinder meshradiusTop, radiusBottom, height, material
ConeCone meshradius, height, material
TorusTorus (donut) meshradius, tube, material
PlaneFlat plane meshwidth, height, material
CapsuleCapsule meshradius, length, material

All primitives share: position, rotation, scale, castShadow, receiveShadow, material.

Material Schema

PropertyTypeDefault
colorstring"#ffffff"
metalnessnumber0
roughnessnumber1
emissivestring"#000000"
emissiveIntensitynumber1
opacitynumber1
transparentbooleanfalse
wireframebooleanfalse

Lights

ComponentDescriptionKey Props
AmbientLightUniform illuminationcolor, intensity
DirectionalLightSunlight-styleposition, color, intensity, castShadow
PointLightRadiates from a pointposition, color, intensity, distance, decay
SpotLightCone of lightposition, color, intensity, angle, penumbra

Other Components

ComponentDescriptionKey Props
GroupContainer for childrenposition, rotation, scale
ModelGLTF/GLB model loaderurl, position, rotation, scale
EnvironmentHDRI environment mappreset, background, blur, intensity
FogLinear fog effectcolor, near, far
GridHelperReference gridsize, divisions, color
Text3D3D text (SDF)text, fontSize, color, anchorX, anchorY
PerspectiveCameraCameraposition, fov, near, far, makeDefault
OrbitControlsCamera controlsenableDamping, enableZoom, autoRotate

Shared Schemas

Reusable Zod schemas for custom 3D components:

import {'{ vector3Schema, materialSchema, transformProps, shadowProps }'} from "@json-render/react-three-fiber";
ExportDescription
vector3Schemaz.tuple([z.number(), z.number(), z.number()])
materialSchemaStandard material props (color, metalness, roughness, etc.)
transformProps{ position, rotation, scale } schema fields
shadowProps{ castShadow, receiveShadow } schema fields

ThreeRenderer

PropTypeDescription
specSpec | nullThe spec to render as a 3D scene
registryComponentRegistryComponent registry from defineRegistry
storeStateStoreExternal state store (controlled mode)
initialStateRecord<string, unknown>Initial state (uncontrolled mode)
handlersRecord<string, Function>Action handlers
loadingbooleanWhether the spec is streaming
childrenReactNodeAdditional R3F elements alongside the spec

ThreeCanvas

Extends ThreeRendererProps with Canvas options:

PropTypeDescription
shadowsbooleanEnable shadow maps
cameraobjectDefault camera config (position, fov, etc.)
classNamestringCSS class for the canvas container
styleCSSPropertiesInline styles for the canvas container

Type Helpers

import type {'{ ThreeProps }'} from "@json-render/react-three-fiber";

type BoxProps = ThreeProps<"Box">;
type SphereProps = ThreeProps<"Sphere">;