reveal-3d
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReveal 3D Viewer
Reveal 3D查看器
Add a Cognite Reveal 3D viewer to a Flows app by copying the bundled source into the target app. Renders CAD models from CDF, with support for model browsing, direct model/revision IDs, or FDM-linked assets.
FDM instance to visualize: $ARGUMENTS
通过将打包后的源代码复制到目标应用中,为Flows应用添加Cognite Reveal 3D查看器。可渲染来自CDF的CAD模型,支持模型浏览、直接模型/版本ID或FDM关联资产。
要可视化的FDM实例:$ARGUMENTS
Use This When
适用场景
The user wants to embed an interactive Cognite Reveal viewer for CDF 3D/CAD content in a Flows app.
Do not use this skill for static diagrams, graph visualizations, or unrelated custom Three.js scenes.
用户希望在Flows应用中嵌入用于CDF 3D/CAD内容的交互式Cognite Reveal查看器时。
请勿将此技能用于静态图表、图形可视化或无关的自定义Three.js场景。
Prerequisites
前提条件
- The app uses React + TypeScript and is wrapped in auth (Flows auth).
@cognite/dune - The app has a from
QueryClientProvider.@tanstack/react-query - The CDF project has 3D models, or the user has supplied direct model/revision IDs.
- For FDM-linked 3D, the instance must be linked through Core DM (->
CogniteVisualizable.object3D).CogniteCADNode
- 应用使用React + TypeScript,并通过认证(Flows认证)。
@cognite/dune - 应用包含来自的
@tanstack/react-query。QueryClientProvider - CDF项目拥有3D模型,或用户已提供直接的模型/版本ID。
- 对于FDM关联的3D模型,实例必须通过Core DM(->
CogniteVisualizable.object3D)建立关联。CogniteCADNode
Integration Workflow
集成流程
Follow these steps in order. Adapt paths to the target app's conventions instead of inventing new ones.
-
Inspect the target app. Read,
package.json,vite.config.ts, and the app's folder/alias conventions.src/main.tsx -
Install missing dependencies with the app's package manager. See Dependencies. Reuse existing pinned React, Flows, SDK, and React Query versions.
-
Copy the bundle into the app. Copy every file frominto an app-local feature folder, typically:
skills/reveal-3d/code/reveal/textsrc/features/reveal-3d/ -
Import from the local folder, never from the skill directory or the old external package. With a typicalalias:
@/*tsximport { CacheProvider, RevealKeepAlive, RevealProvider } from '@/features/reveal-3d'; -
Configure Vite and. Read vite-config.md and apply the process polyfill, manual
main.tsx/process/utilaliases,assertalias, dedupe settings, andthree.worker.format: 'es' -
Choose the implementation pattern. Use Pattern B (model browser or direct model ID) unless you already have aand confirmed Core DM 3D linkage. For full examples, read implementation.md.
DMInstanceRef -
Keep provider placement stable.and
CacheProviderare always mounted at page/app level.RevealKeepAliveis conditional, only when a model is selected or linked.RevealProvider -
Run typecheck and build (,
tsc --noEmit, etc.) and fix any copied-import or dependency issues.pnpm build
按以下顺序执行步骤。根据目标应用的约定调整路径,而非创建新路径。
-
检查目标应用。阅读、
package.json、vite.config.ts以及应用的文件夹/别名约定。src/main.tsx -
使用应用的包管理器安装缺失的依赖。参见依赖项。复用已有的固定版本React、Flows、SDK和React Query。
-
将包复制到应用中。将中的所有文件复制到应用本地的功能文件夹中,通常为:
skills/reveal-3d/code/reveal/textsrc/features/reveal-3d/ -
从本地文件夹导入,绝不要从技能目录或旧的外部包导入。使用典型的别名:
@/*tsximport { CacheProvider, RevealKeepAlive, RevealProvider } from '@/features/reveal-3d'; -
配置Vite和。阅读vite-config.md并应用process polyfill、手动的
main.tsx/process/util别名、assert别名、去重设置以及three。worker.format: 'es' -
选择实现模式。除非您已经拥有并确认Core DM 3D关联,否则使用模式B(模型浏览器或直接模型ID)。完整示例请阅读implementation.md。
DMInstanceRef -
保持Provider位置稳定。和
CacheProvider始终挂载在页面/应用级别。RevealKeepAlive是条件性的,仅在选择或关联模型时挂载。RevealProvider -
运行类型检查和构建(、
tsc --noEmit等)并修复任何复制导入或依赖问题。pnpm build
Minimal Example
最简示例
tsx
import { useCallback, useMemo } from 'react';
import type { CogniteClient } from '@cognite/sdk';
import {
CacheProvider,
Reveal3DResources,
RevealCanvas,
RevealKeepAlive,
RevealProvider,
type AddCadResourceOptions,
} from '@/features/reveal-3d';
type SelectedModel = { modelId: number; revisionId: number };
function ViewerContent({ modelId, revisionId }: SelectedModel) {
const resources = useMemo<AddCadResourceOptions[]>(
() => [{ modelId, revisionId }],
[modelId, revisionId]
);
const onLoaded = useCallback(() => {}, []);
return (
<RevealCanvas>
<Reveal3DResources resources={resources} onModelsLoaded={onLoaded} />
</RevealCanvas>
);
}
export function ViewerPage({
sdk,
selected,
}: {
sdk: CogniteClient;
selected: SelectedModel | null;
}) {
const memoizedSdk = useMemo(() => sdk, [sdk.project]);
return (
<CacheProvider>
<RevealKeepAlive>
<div style={{ width: '100%', height: '70vh', position: 'relative' }}>
{selected && (
<RevealProvider sdk={memoizedSdk}>
<ViewerContent
modelId={selected.modelId}
revisionId={selected.revisionId}
/>
</RevealProvider>
)}
</div>
</RevealKeepAlive>
</CacheProvider>
);
}tsx
import { useCallback, useMemo } from 'react';
import type { CogniteClient } from '@cognite/sdk';
import {
CacheProvider,
Reveal3DResources,
RevealCanvas,
RevealKeepAlive,
RevealProvider,
type AddCadResourceOptions,
} from '@/features/reveal-3d';
type SelectedModel = { modelId: number; revisionId: number };
function ViewerContent({ modelId, revisionId }: SelectedModel) {
const resources = useMemo<AddCadResourceOptions[]>(
() => [{ modelId, revisionId }],
[modelId, revisionId]
);
const onLoaded = useCallback(() => {}, []);
return (
<RevealCanvas>
<Reveal3DResources resources={resources} onModelsLoaded={onLoaded} />
</RevealCanvas>
);
}
export function ViewerPage({
sdk,
selected,
}: {
sdk: CogniteClient;
selected: SelectedModel | null;
}) {
const memoizedSdk = useMemo(() => sdk, [sdk.project]);
return (
<CacheProvider>
<RevealKeepAlive>
<div style={{ width: '100%', height: '70vh', position: 'relative' }}>
{selected && (
<RevealProvider sdk={memoizedSdk}>
<ViewerContent
modelId={selected.modelId}
revisionId={selected.revisionId}
/>
</RevealProvider>
)}
</div>
</RevealKeepAlive>
</CacheProvider>
);
}Dependencies
依赖项
Suggested versions are starting points. If the target app already pins compatible versions, defer to the app.
| Package | Suggested version | Purpose |
|---|---|---|
| app version | UI framework |
| app version | Authenticated SDK via |
| | Reveal viewer runtime |
| | CDF API client |
| | Reveal/FDM data fetching hooks |
| | Three.js singleton used by Reveal |
| latest | Browser polyfills for Reveal dependencies |
| | Avoids older transitive AJV resolution in monorepos |
| latest dev dep | TypeScript types |
Example install (pnpm; adapt to the app's package manager):
bash
pnpm add @cognite/reveal @cognite/sdk @tanstack/react-query three process util assert ajv
pnpm add -D @types/threeAfter install, check 's peer requirement and align if needed.
@cognite/revealthreethreeDo not install ; use the explicit Vite aliases in vite-config.md.
vite-plugin-node-polyfills建议版本为起始参考值。如果目标应用已固定兼容版本,请以应用为准。
| 包 | 建议版本 | 用途 |
|---|---|---|
| 应用版本 | UI框架 |
| 应用版本 | 通过 |
| | Reveal查看器运行时 |
| | CDF API客户端 |
| | Reveal/FDM数据获取钩子 |
| | Reveal使用的Three.js单例 |
| 最新版本 | Reveal依赖的浏览器polyfill |
| | 避免单体仓库中旧版本的传递性AJV解析 |
| 最新开发依赖 | TypeScript类型定义 |
示例安装(使用pnpm;根据应用的包管理器调整):
bash
pnpm add @cognite/reveal @cognite/sdk @tanstack/react-query three process util assert ajv
pnpm add -D @types/three安装后,检查的 peer依赖要求,必要时调整版本。
@cognite/revealthreethree请勿安装;使用vite-config.md中的显式Vite别名。
vite-plugin-node-polyfillsCritical Rules
关键规则
- contains only
ViewerContentandRevealCanvas; no providers.Reveal3DResources - passed to
resourcesmust be memoized withReveal3DResources.useMemo - ,
onModelsLoaded, and similar callbacks must be memoized withonSelect.useCallback - The SDK passed to must be memoized with
RevealProviderkeyed onuseMemo.client.project - fills its parent; the parent must have an explicit height.
RevealCanvas - Lazy-load canvas-heavy viewer content with +
React.lazywhen adding a route/page.Suspense
- 仅包含
ViewerContent和RevealCanvas;不包含Provider。Reveal3DResources - 传递给的
Reveal3DResources必须使用resources进行记忆化。useMemo - 、
onModelsLoaded及类似回调必须使用onSelect进行记忆化。useCallback - 传递给的SDK必须使用
RevealProvider并以useMemo为键进行记忆化。client.project - 填充其父容器;父容器必须有明确的高度。
RevealCanvas - 添加路由/页面时,使用+
React.lazy懒加载占用大量画布资源的查看器内容。Suspense
Advanced Reference
进阶参考
For the copied bundle API and exports, read .
code/README.mdFor model browser and FDM-linked implementations, read .
references/implementation.mdFor Vite, worker, polyfill, and troubleshooting details, read .
references/vite-config.md关于复制包的API和导出,请阅读。
code/README.md关于模型浏览器和FDM关联实现,请阅读。
references/implementation.md关于Vite、worker、polyfill和故障排除细节,请阅读。
references/vite-config.mdVerification Checklist
验证清单
- All files from were copied into an app-local feature folder.
skills/reveal-3d/code/reveal/ - Imports point to the app-local folder (e.g. ).
@/features/reveal-3d - The app does not import Reveal helpers from the old external package.
- Required dependencies are present in .
package.json - starts with the
main.tsxpolyfill before other imports.process - uses manual aliases, dedupe,
vite.config.tssingleton alias, andthree.worker.format: 'es' - and
CacheProviderare always mounted;RevealKeepAliveis conditional when model selection is conditional.RevealProvider - The viewer container has an explicit height.
- Typecheck and build pass.
- 已将中的所有文件复制到应用本地的功能文件夹中。
skills/reveal-3d/code/reveal/ - 导入指向应用本地文件夹(例如)。
@/features/reveal-3d - 应用未从旧的外部包导入Reveal工具。
- 中包含所需的依赖项。
package.json - 在其他导入之前启动process polyfill。
main.tsx - 使用手动别名、去重、
vite.config.ts单例别名以及three。worker.format: 'es' - 和
CacheProvider始终挂载;当模型选择为条件性时,RevealKeepAlive为条件性挂载。RevealProvider - 查看器容器有明确的高度。
- 类型检查和构建通过。