外部模型
<h1>外部模型处理</h1>
<h2>说明</h2>
<p><code>ExternalObjectManager</code> 外部模型工具类,用于管理三维场景中的外部模型。
<code>ExternalObjectManagerConfig</code> 外部模型的配置类。</p>
<p><strong>注意</strong>:在使用外部构建一类功能时,建议使用 Three.js r120 以上版本及其兼容功能。</p>
<h2>BCore.Extension.ExternalObjectManagerConfig</h2>
<h3>构造</h3>
<pre><code class="language-javascript">new BCore.Extension.ExternalObjectManagerConfig(viewer3D)</code></pre>
<h3>成员变量</h3>
<table>
<thead>
<tr>
<th>成员变量</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>viewer3D</td>
<td>BCore.Viewer.Viewer3D</td>
<td>三维查看器实例</td>
</tr>
</tbody>
</table>
<h2>BCore.Extension.ExternalObjectManager</h2>
<h3>构造</h3>
<pre><code class="language-javascript">new BCore.Extension.ExternalObjectManager(config)</code></pre>
<h4>参数</h4>
<table>
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>config</td>
<td>BCore.Extension.ExternalObjectManagerConfig</td>
<td>外部模型的配置类</td>
</tr>
</tbody>
</table>
<h3>方法总览</h3>
<p><code>addExternalObject()</code> 添加外部模型
<code>getExternalObject()</code> 获取外部模型
<code>removeExternalObject()</code> 移除外部模型
<code>clearExternalObject()</code> 清除所有外部模型
<code>adjustModelWorldPosition(name,{ x: number, y: number, z: number })</code> 设置模型世界坐标增量
<code>adjustModelWorldRotation(name,{ x: number, y: number, z: number })</code> 设置模型自身三轴旋转增量
<code>adjustModelScale(name,{ x: number, y: number, z: number })</code> 设置模型自身缩放
<code>onClick()</code> 鼠标单击事件
<code>onDbClick()</code> 鼠标双击事件</p>
<h3>方法示例</h3>
<h4>1. 添加和外部模型</h4>
<p><strong>接口</strong>:</p>
<pre><code class="language-javascript">addExternalObject(name, object3D)</code></pre>
<h4>参数</h4>
<table>
<thead>
<tr>
<th>参数名</th>
<th>必选</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>是</td>
<td>string</td>
<td>模型名称</td>
</tr>
<tr>
<td>object3D</td>
<td>是</td>
<td>THREE.Object3D</td>
<td>外部模型对象</td>
</tr>
</tbody>
</table>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">var geometry = new THREE.BoxGeometry(1, 1, 1);
var material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
var cube = new THREE.Mesh(geometry, material);
var externalObjectManagerConfig = new BCore.Extension.ExternalObjectManagerConfig(mViewer3D);
var externalObjectManager = new BCore.Extension.ExternalObjectManager(externalObjectManagerConfig);
externalObjectManager.addExternalObject('name', cube);</code></pre>
<h4>2.获取外部模型</h4>
<p><strong>接口</strong>:</p>
<pre><code class="language-javascript">getExternalObject(name)</code></pre>
<h4>参数</h4>
<table>
<thead>
<tr>
<th>参数名</th>
<th>必选</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>是</td>
<td>string</td>
<td>模型名称</td>
</tr>
</tbody>
</table>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let obj = externalObjectManager.getExternalObject('name');</code></pre>
<h4>返回值说明</h4>
<table>
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>obj</td>
<td>Object3D</td>
<td>获取的外部模型对象</td>
</tr>
</tbody>
</table>
<h4>3. 移除外部模型</h4>
<p><strong>接口</strong>:</p>
<pre><code class="language-javascript">removeExternalObject(name)</code></pre>
<h4>参数</h4>
<table>
<thead>
<tr>
<th>参数名</th>
<th>必选</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>是</td>
<td>string</td>
<td>模型名称</td>
</tr>
</tbody>
</table>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">externalObjectManager.removeExternalObject('name');</code></pre>
<h4>4. 清除所有外部模型</h4>
<p><strong>接口</strong>:</p>
<pre><code class="language-javascript">clearExternalObject()</code></pre>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">externalObjectManager.clearExternalObject();</code></pre>
<h4>5. 设置模型世界坐标增量</h4>
<p><strong>接口</strong>:</p>
<pre><code class="language-javascript">adjustModelWorldPosition(name, { x: number, y: number, z: number })</code></pre>
<h4>6. 设置模型自身三轴旋转增量</h4>
<p><strong>接口</strong>:</p>
<pre><code class="language-javascript">adjustModelWorldRotation(name, { x: number, y: number, z: number })</code></pre>
<h4>7. 设置模型自身缩放</h4>
<p><strong>接口</strong>:</p>
<pre><code class="language-javascript">adjustModelScale(name, { x: number, y: number, z: number })</code></pre>
<h4>8. 鼠标单击事件</h4>
<p><strong>接口</strong>:</p>
<pre><code class="language-javascript">onClick(callback: Function)</code></pre>
<ul>
<li><strong>参数</strong>:
<strong>callback</strong> : <code>Function</code>- 回调函数</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let geometry = new THREE.BoxGeometry( 1, 1, 1 );
let material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
let cube = new THREE.Mesh( geometry, material );
let externalObjectManagerConfig = new BCore.Extension.ExternalObjectManagerConfig(mViewer3D);
let externalObjectManager = new BCore.Extension.ExternalObjectManager(externalObjectManagerConfig);
externalObjectManager.addExternalObject('name',cube);
//鼠标单击事件
externalObjectManager.onClick((e)=&gt;{console.log(e)});</code></pre>
<h4>9. 鼠标双击事件</h4>
<p><strong>接口</strong>:</p>
<pre><code class="language-javascript">onDbClick(callback: Function)</code></pre>
<ul>
<li><strong>参数</strong>:
<strong>callback</strong> : <code>Function</code>- 回调函数</li>
</ul>
<p><strong>示例</strong>:</p>
<pre><code class="language-javascript">let geometry = new THREE.BoxGeometry( 1, 1, 1 );
let material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
let cube = new THREE.Mesh( geometry, material );
let externalObjectManagerConfig = new BCore.Extension.ExternalObjectManagerConfig(mViewer3D);
let externalObjectManager = new BCore.Extension.ExternalObjectManager(externalObjectManagerConfig);
externalObjectManager.addExternalObject('name',cube);
// 鼠标双击事件
externalObjectManager.onDbClick((e)=&gt;{console.log(e)});</code></pre>