聚光灯
<h1>聚光灯</h1>
<h2>聚光灯配置类 - BCore.Viewer.Light.SpotLightConfig</h2>
<h3>构造函数</h3>
<pre><code class="language-javascript">new BCore.Viewer.Light.SpotLightConfig();</code></pre>
<h3>属性</h3>
<table>
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>color</td>
<td>string</td>
<td><code>&quot;#FF0000&quot;</code></td>
<td>光源颜色</td>
</tr>
<tr>
<td>intensity</td>
<td>number</td>
<td><code>3</code></td>
<td>光源强度</td>
</tr>
<tr>
<td>distance</td>
<td>number</td>
<td><code>100</code></td>
<td>照射距离</td>
</tr>
<tr>
<td>decay</td>
<td>number</td>
<td><code>2</code></td>
<td>衰减</td>
</tr>
<tr>
<td>angle</td>
<td>number</td>
<td><code>0.6</code></td>
<td>光源角度</td>
</tr>
<tr>
<td>penumbra</td>
<td>number</td>
<td><code>0</code></td>
<td>半影</td>
</tr>
<tr>
<td>position</td>
<td>{ x: number, y: number, z: number }</td>
<td><code>{ x: 0, y: 0, z: 50 }</code></td>
<td>光源位置</td>
</tr>
<tr>
<td>target</td>
<td>{ x: number, y: number, z: number }</td>
<td><code>{ x: 0, y: 0, z: 0 }</code></td>
<td>光源照射方向</td>
</tr>
<tr>
<td>castShadow</td>
<td>boolean</td>
<td><code>false</code></td>
<td>是否投射阴影</td>
</tr>
<tr>
<td>mapSize</td>
<td>number</td>
<td><code>1024 * 2</code></td>
<td>不宜过大</td>
</tr>
<tr>
<td>radius</td>
<td>number</td>
<td><code>1.5</code></td>
<td>光源半径</td>
</tr>
<tr>
<td>bias</td>
<td>number</td>
<td><code>0.0001</code></td>
<td>偏差</td>
</tr>
<tr>
<td>normalBias</td>
<td>number</td>
<td><code>2</code></td>
<td>法线偏差</td>
</tr>
<tr>
<td>isShowHelper</td>
<td>boolean</td>
<td><code>true</code></td>
<td>是否显示光源辅助</td>
</tr>
<tr>
<td>helpercolor</td>
<td>string</td>
<td><code>&quot;#FFFFFF&quot;</code></td>
<td>光源辅助线条颜色</td>
</tr>
</tbody>
</table>
<ul>
<li>聚光灯详情参考:<a href="https://threejs.org/docs/index.html?q=sp#api/en/lights/SpotLight">Three.js SpotLight</a></li>
</ul>
<hr />
<h2>方法总览</h2>
<ul>
<li><code>addSpotLight(id: string, lightConfig: SpotLightConfig)</code> 添加聚光光源</li>
<li><code>deleteSpotLight(id: string)</code> 删除聚光光源</li>
<li><code>getSpotLightConfig(id: string)</code> 获取聚光光源参数</li>
<li><code>setSpotLightConfig(id: string, config: SpotLightConfig)</code> 设置聚光光源参数</li>
<li><code>clearSpotLights()</code> 清空所有聚光光源</li>
</ul>
<h2>方法示例</h2>
<h3>1.添加聚光光源</h3>
<ul>
<li><strong>简要描述</strong>: 添加聚光光源</li>
<li><strong>接口</strong>: <code>addSpotLight(id: string, lightConfig: SpotLightConfig)</code></li>
<li>
<table>
<thead>
<tr>
<th><strong>参数</strong>:</th>
<th>参数名</th>
<th>必选</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>是</td>
<td>string</td>
<td>光源Id</td>
</tr>
<tr>
<td>lightConfig</td>
<td>是</td>
<td>BCore.Viewer.Light.SpotLightConfig</td>
<td>光源参数</td>
</tr>
</tbody>
</table>
</li>
</ul>
<h4>示例</h4>
<pre><code class="language-javascript">// 关闭环境光
mViewer3D.closeAmbientLight();
// 关闭平行光
mViewer3D.closeDirectionalLight();
let mSpotLightConfig = new BCore.Viewer.Light.SpotLightConfig();
mViewer3D.addSpotLight('mSpotLightConfig', mLightConfig);</code></pre>
<p><br></p>
<h3>2.删除聚光光源</h3>
<ul>
<li><strong>简要描述</strong>: 删除聚光光源</li>
<li><strong>接口</strong>: <code>deleteSpotLight(id: string)</code></li>
<li>
<table>
<thead>
<tr>
<th><strong>参数</strong>:</th>
<th>参数名</th>
<th>必选</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>是</td>
<td>string</td>
<td>光源Id</td>
</tr>
</tbody>
</table>
</li>
</ul>
<h4>示例</h4>
<pre><code class="language-javascript">let mSpotLightConfig = new BCore.Viewer.Light.SpotLightConfig();
mViewer3D.addSpotLight('mSpotLightConfig', mSpotLightConfig);
mViewer3D.deleteSpotLight('mSpotLightConfig');</code></pre>
<p><br></p>
<h3>3.获取聚光光源参数</h3>
<ul>
<li><strong>简要描述</strong>: 获取聚光光源参数</li>
<li><strong>接口</strong>: <code>getSpotLightConfig(id: string)</code></li>
<li>
<table>
<thead>
<tr>
<th><strong>参数</strong>:</th>
<th>参数名</th>
<th>必选</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>是</td>
<td>string</td>
<td>光源Id</td>
</tr>
</tbody>
</table>
</li>
</ul>
<h4>示例</h4>
<pre><code class="language-javascript">let mSpotLightConfig = new BCore.Viewer.Light.SpotLightConfig();
mViewer3D.addSpotLight('mSpotLightConfig', mSpotLightConfig);
let config = mViewer3D.getSpotLightConfig('mSpotLightConfig');</code></pre>
<p><br></p>
<h3>4.设置聚光光源参数</h3>
<ul>
<li><strong>简要描述</strong>: 设置聚光光源参数</li>
<li><strong>接口</strong>: <code>setSpotLightConfig(id: string, config: SpotLightConfig)</code></li>
<li>
<table>
<thead>
<tr>
<th><strong>参数</strong>:</th>
<th>参数名</th>
<th>必选</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>是</td>
<td>string</td>
<td>光源Id</td>
</tr>
<tr>
<td>config</td>
<td>是</td>
<td>SpotLightConfig</td>
<td>光源配置</td>
</tr>
</tbody>
</table>
</li>
</ul>
<h4>示例</h4>
<pre><code class="language-javascript">let mSpotLightConfig = new BCore.Viewer.Light.SpotLightConfig();
mViewer3D.addSpotLight('mSpotLightConfig', mSpotLightConfig);
let config = mViewer3D.getSpotLightConfig('mSpotLightConfig');
config.castShadow = true;
config.color = '#FF00FF';
mViewer3D.setSpotLightConfig('mSpotLightConfig', config);</code></pre>
<p><br></p>
<h3>5.清空所有聚光光源</h3>
<ul>
<li><strong>简要描述</strong>: 清空所有聚光光源</li>
<li><strong>接口</strong>: <code>clearSpotLights()</code></li>
<li><strong>参数</strong>: 无</li>
</ul>
<h4>示例</h4>
<pre><code class="language-javascript">let mSpotLightConfig = new BCore.Viewer.Light.SpotLightConfig();
mViewer3D.addSpotLight('mSpotLightConfig', mSpotLightConfig);
mViewer3D.clearSpotLights();</code></pre>
<hr />
<p>这个文档为您提供了 <code>聚光灯</code> 的用法说明,帮助您在开发中更好地使用这些功能。如有问题,请随时联系我们~</p>