通过 npm 或 yarn 安装:
npm install three@^0.117.1 @realsee/five
# or
yarn add three@^0.117.1 @realsee/five
注意: Five 依赖
three,请确保安装了兼容的版本。
初始化 Five 实例并加载 Work 数据:
import { Five, parseWork } from "@realsee/five";
// 1. 创建 Five 实例
const five = new Five();
// 2. 挂载到 DOM
const app = document.getElementById('app');
if (app) {
// 设置容器全屏
app.style.width = '100vw';
app.style.height = '100vh';
five.appendTo(app);
// 监听窗口大小变化
window.addEventListener('resize', () => five.refresh());
}
// 3. 加载数据 (Work)
// 这是一个公开测试数据
const workURL = 'https://raw.githubusercontent.com/realsee-developer/dnalogel/main/open-works/real/80o024DE2xyva3j5BE/work.json';
fetch(workURL)
.then(res => res.json())
.then(json => {
// 解析并加载
const work = parseWork(json);
return five.load(work);
})
.then(() => {
console.log("模型加载完成");
})
.catch(err => console.error(err));
掌握基础用法后,您可以探索更多核心功能: