- 首先,使用Autodesk Forge的Model Derivative API将IFC 2x3文件转换为SVF格式。
// 引用Forge Node.js SDK
const ForgeSDK = require('forge-apis');
const { DerivativesApi } = ForgeSDK;
// 配置Forge应用程序
const { client_id, client_secret } = process.env;
const oauth2 = new ForgeSDK.AuthClientTwoLegged(client_id, client_secret, ['data:read', 'data:write']);
// 实例化Derivatives API客户端
const derivativesApi = new DerivativesApi();
// 定义要转换的文件URN
const urn = "dXJuOmFkc2sub...Li0wcjA2MA";
// 定义转换格式
const postJob = new ForgeSDK.JobPayload();
postJob.input = new ForgeSDK.JobPayloadInput().withUrn(urn).withRootFilename('model.ifc');
postJob.output = new ForgeSDK.JobPayloadOutput([
new ForgeSDK.JobSvfOutputPayload().withForce(true).withViews(['2d', '3d'])
]).withMisc(new ForgeSDK.JobPayloadItem().withKey('dbPath').withValue('model.db'));
// 创建转换作业并等待完成
const job = await derivativesApi.translate(postJob, {}, oauth2, null);
let manifest = null;
do {
manifest = await derivativesApi.getManifest(job.response.body.objectId, {}, oauth2, null);
await sleep(1000);
} while (manifest.status === 'inprogress');
// 获取SVF文件的URN
const svfUrn = manifest.derivatives.find(d => d.outputType === 'svf').urn;
- 接下来,使用Viewer API加载SVF文件。
// 引用Forge Viewer样式表和脚本