@3driseai/3drise-viewer

中文文档
0.1.47发布于 2026/11/03TypeScriptES Module近 30 天下载 2715

React components for embedding 3dRise scenes in your app.

原始使用文档
文档目录12 节
  1. Installation
  2. Peer dependencies
  3. Embed a whole project
  4. Reacting to the scene
  5. Controlling the scene ( SceneHandle )
  6. <ProjectLoader /> props
  7. Embed a single object
  8. <ObjectNodeApi /> props
  9. Getting at the three.js objects
  10. TypeScript
  11. Notes
  12. Links

@3driseai/3drise-viewer

React components for embedding 3dRise scenes in your app.

You build in the 3dRise studio — create objects, apply materials, set up animations, effects and interactions — then render the result in React with one component. Nothing about the scene is configured in code: geometry, materials, lighting, animations and interactions all come from what you published.

There are many components, these are the main ones:

ComponentEmbeds
<ProjectLoader />A whole project — scene, camera, lights, environment, animations, cursors. Renders its own canvas.
<ObjectNodeApi />A single object (and its children) from the studio, dropped into a canvas you control.

A ready to go react project with some examples: https://github.com/nadavtal/3drise-react

Installation

npm install @3driseai/3drise-viewer

The package ships as ESM only with bundled TypeScript declarations.

Peer dependencies

Peer dependencyVersion
react^18 or ^19
three^0.170
@react-three/fiber^9
@react-three/drei^10
@react-three/rapier^2
@gsap/react^2.1.2

npm 7+ and pnpm 8+ install these for you. On Yarn — classic or Berry — you'll need to add them yourself.

three must resolve to a single copy. Two versions of three.js in one app is the classic React Three Fiber failure — objects silently refuse to render, instanceof checks fail. If your app pins a different three than the ^0.170 declared here, dedupe it (npm ls three to check, overrides / resolutions to force one version) rather than letting both install.


Embed a whole project

ProjectLoader fetches a published project by id, renders its own <Canvas>, and shows a loading indicator until the scene is ready. This is the whole integration:

import { ProjectLoader } from '@3driseai/3drise-viewer';

export default function ProjectPage({ projectId }: { projectId: string }) {
  return (
    <div style={{ height: '100svh', position: 'relative' }}>
      <ProjectLoader projectId={projectId} />
    </div>
  );
}

ProjectLoader renders a <Canvas> internally, so it needs a sized parent — give the wrapper an explicit height (100svh, 100% of a sized container, a fixed pixel value) or nothing will be visible.

Reacting to the scene

Every callback is optional:

import { ProjectLoader } from '@3driseai/3drise-viewer';
import type { CreatedObjectSettings } from '@3driseai/3drise-core';
import type { Object3D } from 'three';

<ProjectLoader
  projectId={projectId}
  loadingIndicator={<MySpinner />}
  onSceneInitialized={() => setReady(true)}
  onObjectClick={(object: CreatedObjectSettings, ref: Object3D) => {
    openInspector(object.meshSettings.name, ref);
  }}
  onObjectHover={(object, ref) => setHovered(object.id)}
/>;

Controlling the scene (SceneHandle)

onSceneReady(scene) (or ref) hands you the project's handle — the same engine the studio and the project's own UI use:

scene.objects.list();                          // the scene tree: [{ id, name, type, parent, visible, … }]
scene.values.set('Lamp', 'config.intensity', 3); // one live property (not saved)
scene.values.get('shell', 'config.depth');       // as the scene shows it now
scene.actions.toggle('night-mode');
scene.clips.play('spin', { speed: 1.5 });
scene.sequences.setProgress('story', 0.4);       // drive a sequence from your own scroll / slider
scene.on('animationEnd', (e) => console.log(e.key));

Items are addressed by key (preferred), id, or exact name.

<ProjectLoader /> props

PropTypeDescription
projectIdstring (required)Id of the published 3dRise project to load.
loadingIndicatorReact.ReactNodeReplaces the built-in full-screen loader shown while the project is fetched.
onSceneInitialized() => voidFires once the scene has mounted.
onObjectClick(object: CreatedObjectSettings, ref: Object3D, event: ThreeEvent<MouseEvent>) => voidA scene object was clicked.
onObjectHover(object: CreatedObjectSettings, ref: Object3D) => voidPointer entered a scene object.
onElementClick(element: HtmlElement) => voidA 2D UI element in the project was clicked.
onElementHover(element: HtmlElement | null) => voidPointer entered/left a 2D UI element.
onObjectReady(object, ref: Object3D) => voidEvery object in the scene reports its Object3D here — see below.
onObjectDispose(object, ref: Object3D) => voidThe matching teardown event for onObjectReady.

Embed a single object

Sometimes you don't want a whole scene — you want one thing you built in the studio, placed in a canvas your app already owns.

Create the object in the 3dRise studio, give it its material, animations, effects and click interactions, publish it, and copy its object id. ObjectNodeApi fetches that object's tree and renders it — with everything you configured intact:

import { Canvas } from '@react-three/fiber';
import { OrbitControls } from '@react-three/drei';
import { ObjectNodeApi } from '@3driseai/3drise-viewer';
import type { CameraState } from '@3driseai/3drise-core';

const cameraSettings: CameraState = {
  position: [0, 2, 8],
  orientation: [0, 0, 0, 1],
  fov: 50,
  near: 0.1,
  far: 1000,
  animations: [],
  mouseMove: { enabled: false, properties: [] },
  controls: { enabled: true, target: [0, 0, 0] },
};

export function Hero({ objectId }: { objectId: string }) {
  return (
    <Canvas camera={{ position: [0, 2, 8], fov: 50 }} style={{ height: '60vh' }}>
      <ambientLight intensity={0.5} />
      <directionalLight position={[5, 10, 5]} intensity={1.5} />

      <ObjectNodeApi objectId={objectId} />

      <OrbitControls />
    </Canvas>
  );
}

Because you own the canvas here, you also own everything around the object — camera, lighting, controls and background are yours to provide. ObjectNodeApi contributes only the object itself, so an object with no emissive material in an unlit canvas will render black. It renders null until the fetch resolves, so it's safe to mount immediately.

Groups come through whole: if the object has children in the studio, they're rendered as a tree with their own materials and animations.

<ObjectNodeApi /> props

PropTypeDescription
objectIdstring (required)Id of the published scene object to load.
handleObjectClick(object: CreatedObjectSettings, ref: Object3D, event: ThreeEvent<MouseEvent>) => voidThe object was clicked. Note the name differs from ProjectLoader's onObjectClick.
onObjectReady(object, ref: Object3D) => voidThe object reports its Object3D here — see below.
onObjectDispose(object, ref: Object3D) => voidThe matching teardown event.

Getting at the three.js objects

Both components implement the same two props, so you can build a live registry of what's in the scene without reaching into refs yourself:

type OnObjectReady   = (object: ObjectReadySource, ref: Object3D) => void;
type OnObjectDispose = (object: ObjectReadySource, ref: Object3D) => void;
  • object is the settings the object was built with in the studio. It's a union: scene objects give you a CreatedObjectSettings (with its studio id and meshSettings), while effects and cursors give you their own config — narrow it before reading fields. Never null.
  • ref is the root Object3D that just mounted.
  • Every onObjectReady is eventually paired with an onObjectDispose for the same ref, on unmount or when the component swaps its root — so a Map built from these events stays accurate.
const objects = useRef(new Map<string, Object3D>());

<ProjectLoader
  projectId={projectId}
  onObjectReady={(object, ref) => objects.current.set(ref.uuid, ref)}
  onObjectDispose={(object, ref) => objects.current.delete(ref.uuid)}
/>;

To key by the studio id instead, narrow first — if ('meshSettings' in object) tells you it's a CreatedObjectSettings.

From there it's plain three.js — animate it, raycast against it, attach it to your own logic.


TypeScript

Types ship with the package:

import type {
  ObjectReadyProps,
  ObjectReadySource,
  OnObjectReady,
  OnObjectDispose,
} from '@3driseai/3drise-viewer';

Scene and object types come from the core package, which installs alongside this one:

import type { CameraState, CreatedObjectSettings } from '@3driseai/3drise-core';

Notes

  • ESM only. There is no CommonJS build. In Next.js or another SSR framework, render the viewer client-side ('use client', or a dynamic import with ssr: false) — it touches window and WebGL.
  • One entry point. Import everything from @3driseai/3drise-viewer; there are no deep subpath imports.

版本与发布记录

@3driseai/3drise-viewer 共发布 46 个版本,首次发布于 2026/07/23;过去 12 个月发布了 46 个版本。

版本发布日期距今
0.1.47latest2026/11/035 天前
0.1.462026/11/035 天前
0.1.452026/11/026 天前
0.1.442026/10/317 天前
0.1.432026/10/317 天前
0.1.422026/10/2514 天前

关于 @3driseai/3drise-viewer 的常见问题

@3driseai/3drise-viewer 是什么?

React components for embedding 3dRise scenes in your app.

如何安装 @3driseai/3drise-viewer?

在项目目录运行 npm install @3driseai/3drise-viewer,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18 || ^19)、three(^0.170)、@gsap/react(^2.1.2)、@react-three/drei(^10)、@react-three/fiber(^9)、@react-three/rapier(^2)、@react-three/postprocessing(^3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@3driseai/3drise-viewer 支持 TypeScript 吗?

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

@3driseai/3drise-viewer 支持 ESM 还是 CommonJS?

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

@3driseai/3drise-viewer 可以商用吗?

@3driseai/3drise-viewer 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@3driseai/3drise-viewer 的下载量有多少?

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

@3driseai/3drise-viewer 还在维护吗?

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