Skip to content
Projects

nnrj/threejson has 39 GitHub stars and 3 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-15 04:37 UTC. Last push 2026-10-27.

How these counts are measured

Measured star growth

in 24h
0
in 7 days
Collecting history
in 15 days
Collecting history
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

About

ThreeJSON is a JSON-driven declarative scene runtime for Three.js, designed for persistent, mutable and extensible 3D worlds — from human-authored scenes to AI and Agent-driven generation and control.

Creative & Media

docs/en/README.md

Original

中文 | English

ThreeJSON Caller Guide

ThreeJSON is a Web3D JSON runtime built on top of Three.js. Instead of hand-writing large amounts of scene setup, render-loop, controls, lights, and mesh creation code, callers describe scenes and objects as configuration data. The ThreeJSON core then parses that configuration, creates the corresponding Three.js objects, starts the render loop, and updates declarative animations.

This handbook is written for library callers. It focuses on the scene pipeline under core/handler/ and general-purpose object builders under core/builder/ such as core/builder/modelBuilder.js. An ideal, non-mandatory view of builder / handler / runtime is in Design principles. The repository still contains some business-specific machine-room and cabinet code, but those parts are not the main focus of this handbook.

Contents

The default entry page at the repo root is ../index.html, which redirects to website/index.html. The tutorial index demo.html lets you switch between the examples/html-demo/ samples and integrated pages such as room-show.html, the scene editor, the scene player, and port-show.html.

npm Install (Optional)

The repository already provides a root ../package.json and the package name is threejson. When installing it into your own application, also install the peer dependencies so your bundler can resolve imports such as three from node_modules:

npm install threejson three @tweenjs/tween.js

Install html2canvas-pro, gifuct-js, fflate, three-bvh-csg + three-mesh-bvh, or troika-three-text only for the corresponding HTML-panel, GIF, archive, CSG, or SDF-text capability.

Prefer importing from the package root:

import { createSceneRuntime, deployMesh } from "threejson";

Before publishing to npm, you can still import directly from the cloned source path ../core/index.js. See the root ../package.json for the current package version and peer dependency range.

Recommended Usage

  1. Use createSceneRuntime() to create the scene, camera, renderer, controls, lights, and the shared render loop.
  2. Prepare object JSON descriptions.
  3. Convert JSON objects into Three.js objects with deployMesh(), createGroup(), createLine2(), createHeatmap(), and similar helpers.
  4. Call sceneRuntime.start() to start the shared render loop.

Minimal example:

import { createSceneRuntime, deployMesh } from "../core/index.js";

const sceneRuntime = createSceneRuntime({
  canvas: document.getElementById("canvasContainer"),
  config: {
    canvasWidth: window.innerWidth,
    canvasHeight: window.innerHeight,
    scene: { background: "#222222" },
    camera: { fov: 60, near: 0.1, far: 2500, position: { x: 220, y: 180, z: 280 } },
    renderer: { antialias: true, ratioRate: 1 },
    controls: { enableDamping: true, target: { x: 0, y: 40, z: 0 } },
    lights: [
      { type: "ambient", color: "#ffffff", intensity: 0.45 },
      { type: "directional", color: "#ffffff", intensity: 0.9, position: { x: 300, y: 400, z: 300 } }
    ],
    renderLoop: { autoResize: true, firstAutoResize: true }
  }
});

const boxJson = {
  name: "demo-box",
  objType: "box",
  geometry: { width: 100, height: 80, depth: 60 },
  position: { x: 0, y: 40, z: 0 },
  rotation: { rotationX: 0, rotationY: 0, rotationZ: 0 },
  scale: { scaleX: 1, scaleY: 1, scaleZ: 1 },
  material: {
    type: "standard",
    color: "#409eff"
  }
};

deployMesh(boxJson, sceneRuntime.scene);
sceneRuntime.start();

Running Notes

Running HTML in VS Code / Cursor

  1. Open the project root in VS Code or Cursor.
  2. Install the Live Server extension.
  3. In the file explorer, right-click the .html file you want to preview and choose Open with Live Server.
  4. Your browser will open the page over a local HTTP server.

Running HTML in WebStorm

  1. Open the project in WebStorm.
  2. In the project view, right-click the .html file you want to run and choose Run.

Other Notes

  • Serve pages over a local static server instead of opening them with file://. ES modules, textures, and OBJ / GLTF loading usually require HTTP.
  • The minimal runtime uses bare module specifiers such as three and @tweenjs/tween.js. Optional capability modules such as html2canvas-pro need an import-map entry only when that capability is used. With Vite or Webpack, installed packages are resolved from node_modules.
  • Texture paths can use project-root paths such as /assets/textures/.... Pages inside examples/html-demo/ usually import engine modules from ../../core/....
  • With npm install threejson: built-in domains and /assets/... paths in JSON try the active base first and fall back to jsDelivr @threejson/assets (see Static assets in api.md). Cloned-repo demos can still use assetsBase: "/assets" or setAssetsBaseUrl("/assets") for the local mount.
  • rotationX, rotationY, and rotationZ use radians, not degrees.
  • The engine stores the original JSON on userData.objJson, which is useful for later type checks, hiding, deletion, or business extensions.
  • Start with examples/html-demo/track-00-runtime/00-03-friendly-full-scene.html and assets/json/sceneRuntimeBasic.json for a modern example.