构件操作
<h3>BCore.Viewer.Viewer3D</h3>
<h4>构造函数</h4>
<p><code>new BCore.Viewer.Viewer3D(config)</code></p>
<h5>参数:</h5>
<ul>
<li><strong>config</strong>: <code>BCore.Viewer.Viewer3DConfig</code> 三维模型视图对象的配置。</li>
</ul>
<hr />
<h3>方法总览</h3>
<p><code>getSelectedObjectsGuids()</code> 获取选中构件的GUID
<code>setObjectsSelectedByGuids(guids)</code> 通过GUID选中构件
<code>addSelectedObjectsByGuids(guids)</code> 继续添加构件到选中构件的集合
<code>deleteSelectedObjectsByGuids(guids)</code> 删除选中集合中的构件
<code>selectAllObjects()</code> 选中所有构件
<code>clearAllSelectedObjects()</code> 清除所有选中构件
<code>focusObjectByGuid(guid,distance)</code> 通过GUID聚焦单个构件 (构件聚焦 = 适配相机位置 + 触发构件选中)
<code>focusObjectsByGuids(guids,distance,)</code> 通过GUID聚焦构件集合 (构件聚焦 = 适配相机位置 + 触发构件选中)
<code>getObjectBox3ByGuid(guid)</code> 通过GUID获取构件Box3
<code>getObjectsBox3ByGuids(guids)</code> 通过GUID列表获取多个构件Box3
<code>getObjectElementIdByGuid(guid)</code> 通过GUID获取构件ElementID
<code>getObjectGuidByElementId(elementId)</code> 通过ElementId获取构件GUID
<code>setObjectsColorByGuids(guids, color)</code> 设置构件颜色
<code>setObjectsColorByGuidMap(colorMap: Map)</code> 批量设置构件颜色
<code>clearObjectsColorByGuids(guids)</code> 恢复构件颜色
<code>clearAllObjectsColor()</code> 清空所有自定义构件颜色
<code>getAllObjectsColorMap()</code> 返回所有自定义构件颜色信息
<code>setBloomComponent(guid)</code> 设置构件发光
<code>deleteBloomComponents(guids)</code> 批量删除发光构件
<code>clearBloomComponents()</code> 清空发光构件
<code>setBloomOptions(options)</code> 设置发光属性
<code>getBloomOptions()</code> 获取发光属性
<code>getContainsObjectsGuidsByBoundingBox(box)</code> 获得所有被boundingBox包围的构件GUID
<code>getIntersectsObjectsGuidsByBoundingBox(box)</code> 获得所有与boundingBox相交的构件GUID
<code>setComponentsPositionByGuidMap(positionMap: Map)</code> 设置构件坐标
<code>clearComponentsPosition()</code> 清除构件坐标
<br></p>
<h3>方法示例</h3>
<h4>1. 获取选中构件的GUID</h4>
<ul>
<li><strong>接口</strong>: <code>getSelectedObjectsGuids()</code></li>
<li><strong>返回值</strong>: 选中构件的GUID数组。
<strong>示例</strong>:
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let guids = viewer3D.getSelectedObjectsGuids();</code></pre></li>
</ul>
<p><br></p>
<h4>2. 通过GUID选中构件</h4>
<ul>
<li><strong>接口</strong>: <code>setObjectsSelectedByGuids(guids)</code></li>
<li><strong>参数</strong>:
guids: <code>array</code> — GUID数组
isDispatchEvent: <code>boolean</code> 是否触发相关事件</li>
</ul>
<p>示例**:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let guids = [&quot;37cU2nGL100xirW00wMfaL&quot;, &quot;37cU2nGL100xirY08wMfms&quot;];
viewer3D.setSelectedByGuids(guids);</code></pre>
<p><br></p>
<h4>3. 继续添加构件到选中集合</h4>
<ul>
<li><strong>接口</strong>: <code>addSelectedObjectsByGuids(guids)</code></li>
<li><strong>参数</strong>:
guids: <code>array</code> — GUID数组</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let guids = [&quot;37cU2nGL100xirW00wMfaL&quot;, &quot;37cU2nGL100xirY08wMfms&quot;];
viewer3D.addSelectedObjectsByGuids(guids);</code></pre>
<p><br></p>
<h4>4. 根据构件GUID从选中集合中移除</h4>
<ul>
<li><strong>接口</strong>: <code>deleteSelectedObjectsByGuids(guids)</code></li>
<li><strong>参数</strong>:
guids: <code>array</code> — GUID数组</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let guids = [&quot;37cU2nGL100xirW00wMfaL&quot;, &quot;37cU2nGL100xirY08wMfms&quot;];
viewer3SelectedObjectsByGuids(guids);</code></pre>
<p><br></p>
<h4>5. 选中所有构件</h4>
<ul>
<li><strong>接口</strong>: <code>selectAllObjects()</code></li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
viewer3D.selectAllObjects();</code></pre>
<p><br></p>
<h4>6. 清除所有构件的选中状态</h4>
<ul>
<li><strong>接口</strong>: <code>clearAllSelectedObjects()</code></li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
viewer3D.clearAllSelectedObjects();</code></pre>
<p><br></p>
<h4>7. 通过GUID聚焦单个构件</h4>
<ul>
<li><strong>接口</strong>: <code>focusObjectByGuid(guid, distance)</code></li>
<li><strong>参数</strong>:
guid: <code>string</code> — GUID
distance: <code>number</code> — 聚焦相机到构件的距离(可选)</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let guid = &quot;37cU2nGL100xirW00wMfaL&quot;;
viewer3D.focusObjectByGuid(&quot;37cU2nGL100xirW00wMfaL&quot;, 15);</code></pre>
<p><br></p>
<h4>8. 通过GUID聚焦构件集合</h4>
<ul>
<li><strong>接口</strong>: <code>focusObjectsByGuids(guids, distance)</code></li>
<li><strong>参数</strong>:
guid: <code>string</code> — GUID
distance: <code>number</code> — 聚焦相机到构件的距离(可选)</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">//聚焦构件集合不易过多
let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let guids = [&quot;37cU2nGL100xirW00wMfaL&quot;,&quot;37cU2nGL100xirY08wMfms&quot;];
viewer3D.focusObjectsByGuids(guids, 15);</code></pre>
<p><br></p>
<h4>9. 获取构件Box3</h4>
<ul>
<li><strong>接口</strong>: <code>getObjectBox3ByGuid(guid)</code></li>
<li><strong>参数</strong>:
guid: <code>string</code> — RVT\IFC模型构件guid、体量模型name、外部构件name</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let guid = &quot;37cU2nGL100xirW00wMfaL&quot;;
let bbox3 = viewer3D.getObjectBox3ByGuid(&quot;37cU2nGL100xirW00wMfaL&quot;);</code></pre>
<p><br></p>
<h4>10. 获取多个构件Box3</h4>
<ul>
<li><strong>接口</strong>: <code>getObjectsBox3ByGuids(guids)</code></li>
<li><strong>参数</strong>:
guids: <code>string</code> — guid集合</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let guids = [&quot;37cU2nGL100xirW00wMfaL&quot;,&quot;37cU2nGL100xirY08wMfms&quot;];
let bbox3 = viewer3D.getObjectsBox3ByGuids(guids);</code></pre>
<p><br></p>
<h4>11. 设置构件颜色</h4>
<ul>
<li><strong>接口</strong>: <code>setObjectsColorByGuids(guids, color)</code></li>
<li><strong>参数</strong>:
guids: <code>string</code> — guid集合
color: <code>string</code> — 颜色值,如:"#FFFFFF"</li>
</ul>
<p>示例**:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let guids = [&quot;37cU2nGL100xirW00wMfaL&quot;,&quot;37cU2nGL100xirY08wMfms&quot;];
viewer3D.setObjectsColorByGuidsguids, &quot;#FF0000&quot;);</code></pre>
<p><br></p>
<h4>12.批量设置构件颜色</h4>
<ul>
<li><strong>接口</strong>: <code>setObjectsColorGuidMap(colorMap)</code></li>
<li><strong>参数</strong>:
colorMap: <code>Map</code> — key:colorString; value:guids</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
//设置的构件颜色种类越多,性能越低
let guids1 = [&quot;37cU2nGL100xirW00wMfaL&quot;,&quot;37cU2nGL100xirY08wMfms&quot;];
let guids2 = [&quot;37cU2nGL100xirW00wMfas&quot;,&quot;37cU2nGL100xirY08wMfxx&quot;];
let colorMap = new Map();
colorMap.set('#FF0000', guids1);
colorMap.set('#00FF00', guids2);
viewer3D.setObjectsColorByGuidMap(colorMap);</code></pre>
<p><br></p>
<h4>13. 恢复构件颜色</h4>
<ul>
<li><strong>接口</strong>: <code>clearObjectsColorByGuids(guids)</code></li>
<li><strong>参数</strong>:
guids: <code>string</code> — guid集合</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let guids = [&quot;37cU2nGL100xirW00wMfaL&quot;,&quot;37cU2nGL100xirY08wMfms&quot;];
viewer3D.setObjectsColorByUuids(guids,&quot;#FF0000&quot;);
viewer3D.clearObjectsColorByGuids(guids);</code></pre>
<p><br></p>
<h4>14. 恢复所有自定义构件颜色</h4>
<ul>
<li><strong>接口</strong>: <code>clearAllObjectsColor()</code></li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let guids = [&quot;37cU2nGL100xirW00wMfaL&quot;,&quot;37cU2nGL100xirY08wMfms&quot;];
viewer3D.setObjectsColorByUuids(guids,&quot;#FF0000&quot;);
viewer3D.clearAllObjectsColor();</code></pre>
<p><br></p>
<h4>15. 返回所有自定义构件颜色信息</h4>
<ul>
<li><strong>接口</strong>: <code>getAllObjectsColorMap()</code></li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let guids = [&quot;37cU2nGL100xirW00wMfaL&quot;,&quot;37cU2nGL100xirY08wMfms&quot;];
viewer3D.setObjectsColorByUuids(guids,&quot;#FF0000&quot;);
let colorMap = viewer3D.getAllObjectsColorMap();</code></pre>
<p><br></p>
<h4>16. 设置构件发光</h4>
<ul>
<li><strong>接口</strong>: <code>setBloomComponent(guid)</code></li>
<li><strong>参数</strong>:
guids: <code>string</code> - RVT\IFC模型构件guid、FBX模型fileId、体量模型name、外部构件name</li>
<li><strong>说明</strong>:
<ul>
<li>设置构件发光,支持RVT\IFC模型构件,FBX模型,外部构件,体量模型</li>
<li>线框发光调用 viewer3D.setBloomWireframeLine(fileId,color)</li>
</ul></li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let guid = &quot;37cU2nGL100xirW00wMfaL&quot;;
viewer3D.setBloomComponent(guid);
viewer3D.render();</code></pre>
<p><br></p>
<h4>17. 清空发光构件</h4>
<ul>
<li><strong>接口</strong>: <code>clearBloomComponents()</code></li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
viewer3D.clearBloomComponents();</code></pre>
<p><br></p>
<h4>18. 设置发光属性</h4>
<ul>
<li><strong>接口</strong>: <code>setBloomOptions(options)</code></li>
<li><strong>参数</strong>:
options: <code>{threshold: number, strength: number, radius: number}</code> - 值域、强度、半径</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
viewer3D.setBloomOptions({threshold: 0, strength: 1.7, radius: 0.5});
viewer3D.render();</code></pre>
<p><br></p>
<h4>19. 获取发光属性</h4>
<ul>
<li><strong>接口</strong>: <code>getBloomOptions()</code></li>
<li><strong>返回值说明</strong>:
options: <code>{threshold: number, strength: number, radius: number}</code> - 值域、强度、半径</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let viewer3dConfig = new BCore.Viewer.Viewer3DConfig();
let viewer3D = new BCore.Viewer.Viewer3D(viewer3dConfig);
let bloomOptions = viewer3D.getBloomOptions();</code></pre>
<p><br></p>
<h4>20. 根据bounding box获取构件GUID</h4>
<ul>
<li><strong>接口</strong>: <code>getContainsObjectsGuidsByBoundingBox(box)</code></li>
<li><strong>参数</strong>:
box: <code>Box3</code> - threejs支持的boundingbox类型</li>
<li><strong>返回值说明</strong>:
GUIDs: <code>Array</code> - 构件Guids数组</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let mApplication3D = new BCore.Application.Application3D(new BCore.Application.Application3DConfig());
let mViewer3D = new BCore.Viewer.Viewer3D('bcorecontanier', new BCore.Viewer.Viewer3DConfig());
let box = mViewer3D.getObjectsBox3ByGuids(['2UD3D7uxP8kecbbBCRtzEl','2E3cuzY0LCc9ztHo7GNGl4']);
mViewer3D.getContainsObjectsGuidsByBoundingBox(box);</code></pre>
<p><br></p>
<h3>21. 根据bounding box获取交集构件GUID</h3>
<ul>
<li><strong>接口</strong>: <code>getIntersectsObjectsGuidsByBoundingBox(box)</code></li>
<li><strong>参数</strong>:
box: <code>Box3</code> - threejs支持的boundingbox类型</li>
<li><strong>说明</strong>:
用户提供boundingbox,调用方法可返回场景中与该boundingbox相交的构件GUID(该相交方法返回结果包含被boundingbox完全包含的构件)</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let mApplication3D = new BCore.Application.Application3D(new BCore.Application.Application3DConfig());
let mViewer3D = new BCore.Viewer.Viewer3D('bcorecontanier', new BCore.Viewer.Viewer3DConfig());
let box = mViewer3D.getObjectsBox3ByGuids(['2UD3D7uxP8kecbbBCRtzEl','2E3cuzY0LCc9ztHo7GNGl4']);
mViewer3D.getIntersectsObjectsGuidsByBoundingBox(box);</code></pre>
<p><br></p>
<h3>22. 设置构件坐标</h3>
<ul>
<li><strong>接口</strong>: <code>setComponentsPositionByGuidMap(positionMap)</code></li>
<li><strong>参数</strong>:
positionMap: <code>Map</code> - 位置坐标及要设置的构件id集合</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let mViewer3D = new BCore.Viewer.Viewer3D('bcorecontanier', new BCore.Viewer.Viewer3DConfig());
const map = new Map();
map.set({x:25,y:25,z:0},[uuid])
mViewer3D.setComponentsPositionByGuidMap(map);</code></pre>
<p><br></p>
<h3>23. 清除构件坐标</h3>
<ul>
<li><strong>接口</strong>: <code>clearComponentsPosition()</code>
<strong>示例</strong>:
<pre><code class="language-javascript">let mViewer3D = new BCore.Viewer.Viewer3D('bcorecontanier', new BCore.Viewer.Viewer3DConfig());
const map = new Map();
map.set({x:25,y:25,z:0},[uuid])
mViewer3D.setComponentsPositionByGuidMap(map);
mViewer3D.clearComponentsPosition()</code></pre>
<hr /></li>
</ul>
<p>以上是 <code>BCore.Viewer.Viewer3D</code> 类的详细文档及其方法的使用示例。如需进一步的信息或示例,请联系我们~</p>