如何从 BIM BCF Topic Viewpoint 正确初始化 Autodesk Forge 3D 查看器?
How to initialize Autodesk Forge 3D viewer correctly from BIM BCF Topic Viewpoint?
我正在尝试根据 BCF 文件中的 BIM 主题可视化数据正确初始化 Autodesk Forge 3D 查看器。
我已将 3D 模型 (IFC) 上传到 Autodesk API,它已被处理,我可以 visualize/navigate 使用 Autodesk Forge 3D 查看器成功制作模型。
我在 Nemetschek SOLIBRI 中使用相同的 3D 模型 (IFC) 创建主题并使用 BIM BCF 2.1 标准导出它(参见 https://github.com/buildingSMART/BCF-XML)。
XML-来自VisualizationInfo的数据:
<PerspectiveCamera>
<CameraViewPoint>
<X>2.803843040759871</X>
<Y>14.568845808384443</Y>
<Z>0.8249055320631105</Z>
</CameraViewPoint>
<CameraDirection>
<X>0.4898262677194313</X>
<Y>-0.8652456579090667</Y>
<Z>0.1068652371988122</Z>
</CameraDirection>
<CameraUpVector>
<X>-0.05264688190667085</X>
<Y>0.09299722978166312</Y>
<Z>0.9942735142195238</Z>
</CameraUpVector>
<FieldOfView>60.0</FieldOfView>
</PerspectiveCamera>
我尝试在 Autodesk Forge 3D 查看器上设置相同的 camera/view:
viewer.restoreState(JSON.parse(`{
"viewport": {
"eye": [2.803843040759871, 14.568845808384443, 0.8249055320631105],
"target": [0.4898262677194313, -0.8652456579090667, 0.1068652371988122],
"up": [-0.05264688190667085, 0.09299722978166312, 0.9942735142195238],
"projection": "perspective",
"isOrthographic": false,
"fieldOfView": 60.0
}
}`));
结果:
一个 Forge 3D 查看器相机视图,它与在 SOLIBRI 中看到的不匹配,也不与在 BCF 文件中保存为 snapshot-png 的那个相匹配。
也许 SOLIBRI 中的 IFC 模型和 Autodesk 处理的 IFC 模型具有不同的坐标系或者可能是什么错误?
CameraDirection
值不是 Forge 查看器的目标参数。你得用下面的公式自己计算。
{Target} = {CameraViewPoint} + {CameraDirection} * {CurrentFocalLength}
您的问题视图的完整相机映射将是:
var lengthScale = 1000; //! Use viwer.model.getUnitString(), the model I loaded is in `mm`, and BCF camera definition is in `m`
var eye = new THREE.Vector3( 2.803843040759871 * lengthScale, 14.568845808384443 * lengthScale, 0.8249055320631105 * lengthScale );
var sightVec = new THREE.Vector3( 0.4898262677194313, -0.8652456579090667, 0.1068652371988122 ).multiplyScalar( viewer.navigation.getFocalLength() );
var target = eye.clone().add( sightVec )
var up = new THREE.Vector3( -0.05264688190667085, 0.09299722978166312, 0.9942735142195238 );
//Since Forge Viewer will apply a global offset to the whole model
var offsetMatrix = viewer.model.getData().placementWithOffset;
var offsetEye = eye.applyMatrix4(offsetMatrix);
var offsetTarget = target.applyMatrix4(offsetMatrix);
var fov = 60;
var cameraView = {
aspect: viewer.getCamera().aspect,
isPerspective: true,
fov: fov,
position: offsetEye,
target: offsetTarget,
up: up,
orthoScale: 1
};
viwer.impl.setViewFromCamera( cameraView );
尽情享受吧!
我正在尝试根据 BCF 文件中的 BIM 主题可视化数据正确初始化 Autodesk Forge 3D 查看器。
我已将 3D 模型 (IFC) 上传到 Autodesk API,它已被处理,我可以 visualize/navigate 使用 Autodesk Forge 3D 查看器成功制作模型。
我在 Nemetschek SOLIBRI 中使用相同的 3D 模型 (IFC) 创建主题并使用 BIM BCF 2.1 标准导出它(参见 https://github.com/buildingSMART/BCF-XML)。
XML-来自VisualizationInfo的数据:
<PerspectiveCamera>
<CameraViewPoint>
<X>2.803843040759871</X>
<Y>14.568845808384443</Y>
<Z>0.8249055320631105</Z>
</CameraViewPoint>
<CameraDirection>
<X>0.4898262677194313</X>
<Y>-0.8652456579090667</Y>
<Z>0.1068652371988122</Z>
</CameraDirection>
<CameraUpVector>
<X>-0.05264688190667085</X>
<Y>0.09299722978166312</Y>
<Z>0.9942735142195238</Z>
</CameraUpVector>
<FieldOfView>60.0</FieldOfView>
</PerspectiveCamera>
我尝试在 Autodesk Forge 3D 查看器上设置相同的 camera/view:
viewer.restoreState(JSON.parse(`{
"viewport": {
"eye": [2.803843040759871, 14.568845808384443, 0.8249055320631105],
"target": [0.4898262677194313, -0.8652456579090667, 0.1068652371988122],
"up": [-0.05264688190667085, 0.09299722978166312, 0.9942735142195238],
"projection": "perspective",
"isOrthographic": false,
"fieldOfView": 60.0
}
}`));
结果: 一个 Forge 3D 查看器相机视图,它与在 SOLIBRI 中看到的不匹配,也不与在 BCF 文件中保存为 snapshot-png 的那个相匹配。
也许 SOLIBRI 中的 IFC 模型和 Autodesk 处理的 IFC 模型具有不同的坐标系或者可能是什么错误?
CameraDirection
值不是 Forge 查看器的目标参数。你得用下面的公式自己计算。
{Target} = {CameraViewPoint} + {CameraDirection} * {CurrentFocalLength}
您的问题视图的完整相机映射将是:
var lengthScale = 1000; //! Use viwer.model.getUnitString(), the model I loaded is in `mm`, and BCF camera definition is in `m`
var eye = new THREE.Vector3( 2.803843040759871 * lengthScale, 14.568845808384443 * lengthScale, 0.8249055320631105 * lengthScale );
var sightVec = new THREE.Vector3( 0.4898262677194313, -0.8652456579090667, 0.1068652371988122 ).multiplyScalar( viewer.navigation.getFocalLength() );
var target = eye.clone().add( sightVec )
var up = new THREE.Vector3( -0.05264688190667085, 0.09299722978166312, 0.9942735142195238 );
//Since Forge Viewer will apply a global offset to the whole model
var offsetMatrix = viewer.model.getData().placementWithOffset;
var offsetEye = eye.applyMatrix4(offsetMatrix);
var offsetTarget = target.applyMatrix4(offsetMatrix);
var fov = 60;
var cameraView = {
aspect: viewer.getCamera().aspect,
isPerspective: true,
fov: fov,
position: offsetEye,
target: offsetTarget,
up: up,
orthoScale: 1
};
viwer.impl.setViewFromCamera( cameraView );
尽情享受吧!