zyy-engine

图形引擎API


相机操作

<h2>BCore.Viewer.Viewer3D API</h2> <h3>构造函数</h3> <p><code>new BCore.Viewer.Viewer3D)</code></p> <ul> <li><strong>参数</strong> <ul> <li><code>config</code>: <code>BCore.Viewer.Viewer3DConfig</code> — 三维模型视图对象的配置</li> </ul></li> </ul> <h3>方法总览</h3> <p><code>getCameraType()</code> 获取相机类型 <code>setCameraType(cameraType)</code> 设置相机类型 <code>setCameraPosition(position,delay,isAnimation,callback)</code> 设置相机位置 <code>getCameraPosition():vector3</code> 获取相机位置 <code>setCameraLookAt(direction)</code> 设置相机朝向 <code>getCameraLookAt():vector3</code> 获取相机朝向 <code>getViewportInfo()</code> 获取视口状态 <code>setViewportInfo()</code> 恢复视口状态 <code>setCustomHomeViewportInfo()</code> 自定义Home视图 <code>getCustomHomeViewportInfo()</code> 获取自定义Home视图信息 <code>clearCustomHomeViewportInfo()</code> 清除自定义Home视图 <code>zoomToBoundingBox()</code> 缩放到指定的BoundingBox <code>setView()</code> 设置视图类型 <code>startAutoRotate(speed?, center?)</code> 开启相机自转 <code>stopAutoRotate()</code> 关闭相机自转 <code>setCameraControlType(controlType)</code> 设置相机控制器操作风格 <code>getCameraControlType():BCore.Static.CameraOperaType</code> 获取相机控制器操作风格 <code>setCameraPolarAngle(minPolarAngle, maxPolarAngle)</code> 设置相机俯仰角 <code>setMaximalRangeofCamera(distance)</code> 设置相机最远观测距离 <code>clearMaximalRangeofCamera()</code> 清除相机最远观测距离 <code>setViewerBoundingBox()</code> 设置视图的范围 <code>getViewerBoundingBox()</code> 获取视图的范围 <code>enableCameraRotate()</code> 相机旋转功能开启 <code>disableCameraRotate()</code> 相机旋转功能关闭 <code>setCameraRotateSpeed(speed)</code> 设置相机旋转速度 <code>clearCameraRotateSpeed()</code> 恢复相机旋转速度为默认 <code>getCameraRotateSpeed()</code> 返回相机的旋转速度 <code>enableCameraPan()</code> 相机平移功能开启 <code>disableCameraPan()</code> 相机平移功能关闭 <code>setCameraPanSpeed(speed)</code> 设置相机平移速度 <code>clearCameraPanSpeed()</code> 恢复相机平移速度为默认 <code>getCameraPanSpeed()</code> 返回相机的当前平移速度 <code>enableCameraZoom()</code> 相机缩放功能开启 <code>disableCameraZoom()</code> 相机缩放功能关闭 <code>setCameraZoomSpeed(speed)</code> 设置相机缩放速度 <code>clearCameraZoomSpeed()</code> 恢复相机缩放速度为默认 <code>getCameraZoomSpeed()</code> 返回相机的缩放速度</p> <h3>方法详细介绍</h3> <h4>1. 获取相机类型</h4> <ul> <li> <p><strong>接口</strong>: <code>getCameraType()</code></p> </li> <li><strong>返回值</strong>: <ul> <li><code>cameraType</code>: <code>string</code> — 相机类型(“OrthographicCamera” 或 “PerspectiveCamera”)</li> </ul></li> </ul> <h5>示例</h5> <pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig(); let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig); let cameraType; cameraType = viewer3D.getCameraType();</code></pre> <p>&lt;br&gt;</p> <h4>2. 设置相机类型</h4> <ul> <li> <p><strong>接口</strong>: <code>setCameraType(cameraType)</code></p> </li> <li> <p><strong>参数</strong>: </p> <ul> <li><code>cameraType</code>: <code>string</code> — 相机类型(“OrthographicCamera” 或 “PerspectiveCamera”)</li> </ul> <h5>示例</h5> <pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig(); let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig); let cameraType = BCore.Static.CameraType.PerspectiveCamera; viewer3D.setCameraType(cameraType );</code></pre> </li> </ul> <p>&lt;br&gt;</p> <h4>3. 设置相机位置</h4> <ul> <li> <p><strong>接口</strong>: <code>setCameraPosition(position, delay?, isAnimation?, callback?)</code></p> </li> <li> <p><strong>参数</strong>:</p> <ul> <li><code>position</code>: <code>vector3</code> 相机坐标</li> <li><code>delay</code>: <code>number</code> — 缓动时长(ms),0 为无延迟</li> <li><code>isAnimation</code>: <code>boolean</code> — 是否启用动画(默认启用)</li> <li><code>callback</code>: <code>Function</code> — 位置设置完成回调函数</li> </ul> <h5>示例</h5> <pre><code class="language-javascript">viewer3D.setCameraPosition({x:x,y:y,z:z},1000)</code></pre> </li> </ul> <p>&lt;br&gt;</p> <h4>4. 获取相机位置</h4> <ul> <li> <p><strong>接口</strong>: <code>getCameraPosition(): vector3</code></p> </li> <li> <p><strong>返回值</strong>: </p> <ul> <li><code>position</code>: <code>vector3</code> — 相机坐标</li> </ul> <h5>示例</h5> <pre><code class="language-javascript"> let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();  let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);  let position = viewer3D.getCameraPosition();</code></pre> </li> </ul> <p>&lt;br&gt;</p> <h4>5. 设置相机朝向</h4> <ul> <li> <p><strong>接口</strong>: <code>setCameraLookAt(direction)</code></p> </li> <li> <p><strong>参数</strong>:</p> <ul> <li><code>direction</code>: <code>vector3</code> — 相机坐标</li> </ul> <h5>示例</h5> <pre><code class="language-javascript"> let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();  let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);  viewer3D.setCameraLookAt({x:x,y:y,z:z});</code></pre> </li> </ul> <p>&lt;br&gt;</p> <h4>6. 获取相机朝向</h4> <ul> <li> <p><strong>接口</strong>: <code>getCameraLookAt(): vector3</code></p> </li> <li> <p><strong>返回值</strong>: </p> <ul> <li><code>direction</code>: <code>vector3</code> — 相机当前朝向</li> </ul> <h5>示例</h5> <pre><code class="language-javascript"> let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();  let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);  let lookat = viewer3D.getCameraLookAt();</code></pre> </li> </ul> <p>&lt;br&gt;</p> <h4>7. 获取视口状态</h4> <ul> <li> <p><strong>接口</strong>: <code>getViewportInfo ViewportInfo</code></p> </li> <li> <p><strong>返回值</strong>: </p> <ul> <li><code>ViewportInfo</code>: <code>ViewportInfo</code> — 返回视口状态</li> </ul> <h5>示例</h5> <pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig(); let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig); let lookat = viewer3D.getViewportInfo();</code></pre> </li> </ul> <p>&lt;br&gt;</p> <h4>8. 恢复视口状态</h4> <ul> <li> <p><strong>接口</strong>: <code>setViewportInfo(ViewportInfo): void</code></p> </li> <li> <p><strong>参数</strong>: </p> <ul> <li><code>ViewportInfo</code>: <code>ViewportInfo</code> — 自定义视口状态</li> </ul> <h5>示例</h5> <pre><code class="language-javascript">class ViewPortInfo{ public cameraViewPoint = new Vector3();     public cameraDirection = new Vector3();     public cameraUpVector = new Vector3();     public viewToWorldScale = 0;     public cameraType = BCore.Static.CameraType.PerspectiveCamera;     public fieldOfView = 45; }     let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();     let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);    let lookat = viewer3D.setViewportInfo(new ViewportInfo());</code></pre> </li> </ul> <p>&lt;br&gt;</p> <h4>9. 自定义Home视图</h4> <ul> <li> <p><strong>接口</strong>: <code>setCustomHomeViewportInfo(viewportInfo)</code></p> </li> <li> <p><strong>参数</strong>:</p> <ul> <li><code>viewportInfo</code>: <code>ViewportInfo</code> — 自定义视口状态</li> </ul> <h5>示例</h5> <pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig(); let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);  let viewInfo =  viewer3D.getViewportInfo();  viewer3D.setCustomHomeViewportInfo(viewInfo);</code></pre> </li> </ul> <p>&lt;br&gt;</p> <h4>10. 获取自定义Home视图</h4> <ul> <li> <p><strong>接口</strong>: <code>getCustomHomeViewportInfo(): viewportInfo</code></p> </li> <li> <p><strong>返回值</strong>: </p> <ul> <li><code>viewportInfo</code>: <code>ViewportInfo</code> — 自定义视口状态</li> </ul> <h5>示例</h5> <pre><code class="language-javascript"> let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();    let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);    let viewInfo = viewer3D.getCustomHomeViewportInfo();</code></pre> <p>&lt;br&gt;</p> <h4>11. 清除自定义Home视图信息</h4> </li> <li> <p><strong>接口</strong>: <code>clearCustomHomeViewportInfo()</code></p> </li> <li><strong>示例</strong>: <pre><code class="language-javascript">viewer3D.clearCustomHomeViewportInfo();</code></pre></li> </ul> <h4>12. 缩放到指定的BoundingBox</h4> <ul> <li> <p><strong>接口</strong> <code>zoomToBoundingBox(boundingBox, distance?, isAnimation?, delay?): void</code></p> </li> <li> <p><strong>参数</strong>:</p> <ul> <li><code>boundingBox</code>: `` — {min: {x: number,y: number,z: number}, max: {x: number,y: number,z: number}}</li> <li><code>distance</code>: <code>number</code> — 相机离Box3中心点的距离(-1为系统默认)</li> <li><code>isAnimation</code>: `` — 是否开启帧动画(默认为false)</li> <li> <p><code>delay</code>: <code>number</code> — 动画持续时间(默认1000ms)</p> </li> <li><strong>示例</strong>: <pre><code class="language-javascript">let box3 = mViewer3D.getModelBoundingBoxByFileId('fileId'); mViewer3D.zoomToBoundingBox(box3)</code></pre></li> </ul> </li> </ul> <h4>13. 设置相机视图类型</h4> <ul> <li> <p><strong>接口</strong>: <code>setView(viewType, delay): void</code></p> </li> <li><strong>参数</strong>: <ul> <li><code>viewType</code>: <code>BCore.Static.ViewType</code> — 上、下、左、右、前、后</li> <li><code>delay</code>: <code>number</code> — 动画持续时间,0表示不启用动画</li> </ul></li> </ul> <h4>14. 开启相机自转</h4> <ul> <li> <p><strong>接口</strong>: <code>startAutoRotate(speed?, center?)</code></p> </li> <li><strong>参数</strong>: <ul> <li><code>speed</code>: <code>number</code> — 自转速度(默认2.0)</li> <li><code>center</code>: <code>{x,y,z}</code> — 旋转中心(默认模型中心)</li> </ul></li> </ul> <h4>15. 关闭相机自转</h4> <ul> <li><strong>接口</strong>: <code>stopAutoRotate()</code></li> </ul> <h4>16. 设置相机控制器操作风格</h4> <ul> <li> <p><strong>接口</strong>: <code>setCameraControlType(controlType)</code></p> </li> <li><strong>参数</strong>: <ul> <li><code>controlType</code>: <code>BCore.Static.CameraOperaType</code> — DEFAULT 或 REVIT</li> </ul></li> </ul> <h4>17. 设置相机俯仰角</h4> <ul> <li> <p><strong>接口</strong>: <code>setCameraPolarAngle(minPolarAngle, maxPolarAngle)</code></p> </li> <li><strong>参数</strong>: <ul> <li><code>minPolarAngle</code>: <code>number</code> — 相机仰视最小值</li> <li><code>maxPolarAngle</code>: <code>number</code> — 相机俯视最大值</li> </ul></li> </ul> <h4>18. 设置相机最远观测距离</h4> <ul> <li> <p><strong>接口</strong>: <code>setMaximalRangeofCamera(distance)</code></p> </li> <li><strong>参数</strong>: <ul> <li><code>distance</code>: <code>number</code> — 相机与模型之间的最远观测距离</li> </ul></li> </ul> <h4>19. 清除相机最远观测距离的设置</h4> <ul> <li><strong>接口</strong>: <code>clearMaximalRangeofCamera()</code></li> </ul> <h4>20. 设置视图范围</h4> <ul> <li> <p><strong>接口</strong>: <code>setViewerBoundingBox(box3)</code></p> </li> <li> <p><strong>参数</strong>:</p> <ul> <li><code>box3</code>: <code>box3</code> — {min: {x: number,y: number,z: number}, max: {x: number,y: number,z: number}}</li> </ul> </li> <li><strong>说明</strong>: <ul> <li> <h2>修改该设置会影响引擎的视图相关操作,比如<code>viewer3D.setView(BCore.Static.ViewType.Home)</code></h2> </li> </ul></li> </ul> <p>以上是 BCore.Viewer.Viewer3D 的详细 API 文档,供开发者调用和使用。通过这些接口,可以灵活控制三维视图的各项参数。</p>

页面列表

ITEM_HTML