zyy-engine

图形引擎API


屏幕坐标

<h1>屏幕坐标</h1> <p><code>H5Position</code> :5坐标对象 <code>H5PositionManagerConfig</code> : H5坐标对象管理容器配置 <code>H5PositionManager</code> : H5坐标对象管理容器</p> <h2>类说明</h2> <h3>H5Position</h3> <ul> <li><strong>构造</strong>: <code>new BCore.Extension.H5Position(id, position)</code></li> <li><strong>参数</strong>: <ul> <li><strong>id</strong>: <code>string</code> - H5坐标对象的唯一标识符</li> <li><strong>position</strong>: <code>{x, y, z}</code> - 世界坐标,如 <code>{ x: 0, y: 0, z: 0 }</code></li> </ul></li> </ul> <h4>属性</h4> <ul> <li><strong>id</strong>: <code>string</code></li> <li><strong>worldPosition</strong>: <code>Vector3</code> - 世界坐标</li> <li><strong>screenPosition</strong>Vector2` - 屏幕坐标</li> <li><strong>onChange?</strong>: <code>Function</code> - 在 viewer3D 渲染时触发的回调,返回 <code>this</code></li> </ul> <h3>H5PositionManagerConfig</h3> <ul> <li><strong>构造</strong>: <code>new BCore.Extension.H5PositionManagerConfig(viewer3D)</code></li> <li><strong>成员变量</strong>: <ul> <li><strong>viewer3D</strong>: <code>BCore.Viewer.Viewer3D</code> - 3D查看器实例</li> </ul></li> </ul> <h3>H5PositionManager</h3> <ul> <li><strong>构造</strong>: <code>BCore.Extension.H5PositionManager(config)</code></li> <li><strong>成员变量</strong>: <ul> <li><strong>config</strong>: <code>BCore.Extension.H5PositionManagerConfig</code></li> </ul></li> </ul> <h3>方法</h3> <ul> <li><strong>addPosition(position: H5Position)</strong> - 添加一个 H5 屏幕坐标</li> <li><strong>getPosition(id: string)</strong> - <code>H5Position | undefined</code> - 根据 ID 获取 H5Position(v2.8)</li> <li><strong>deletePosition(id: string)</strong> - 移除指定 ID 的 H5Position</li> <li><strong>clearAllPosition()</strong> - 清空所有 H5 屏幕坐标(v2.8)</li> <li><strong>getAllPosition(): H5Position[]</strong> - 获取所有 H5Position(v2.8)</li> </ul> <h2>示例</h2> <h3>1.添加 H5 屏幕坐标</h3> <pre><code class="language-javascript">let mydiv = document.createElement(&amp;quot;div&amp;quot;); let root = document.getElementById('bcorecontainer'); mydiv.style.width = &amp;quot;50px&amp;quot;; mydiv.style.height = &amp;quot;50px&amp;quot;; mydiv.style.position = &amp;quot;absolute&amp;quot;; mydiv.style.top = '0px'; mydiv.style.left = '0px'; mydiv.style.marginLeft = '-25px'; mydiv.style.marginTop = '-25px'; mydiv.style.backgroundColor = &amp;quot;#FF0000&amp;quot;; mydiv.innerHTML = &amp;quot;Hello BCore&amp;quot;; root.appendChild(mydiv); let h5Position = new BCore.Extension.H5Position('LKJxhiohADd', {x: 0, y: 0, z: 0}); h5Position.onChange = (val) =&amp;gt; { mydiv.style.left = val.screenPosition.x + 'px'; mydiv.style.top = val.screenPosition.y + 'px'; }; let h5PositionManagerConfig = new BCore.Extension.H5PositionManagerConfig(mViewer3D); let h5PositionManager = new BCore.Extension.H5PositionManager(h5PositionManagerConfig); h5PositionManager.addPosition(h5Position);</code></pre> <h3>2.移除 H5 屏幕坐标</h3> <pre><code class="language-javascript">var h5Position = new BCore.Extension.H5Position('1', {x: 0, y: , z: 0}); h5Position.onChange = (val) =&amp;gt; { console.log(val); }; var h5PositionManagerConfig = new BCore.Extension.H5PositionManagerConfig(viewer3D); var h5PositionManager = new BCore.Extension.H5PositionManager(h5PositionManagerConfig); h5PositionManager.addPosition(h5Position); h5PositionManager.deletePosition(h5Position.id);</code></pre> <h3>3.清空所有 H5 屏幕坐标</h3> <pre><code class="language-javascript">var h5Position = new BCore.Extension.H5Position('name', {x: 0, y: 0, z: 0}); h5Position.onChange = (val) =&amp;gt; { console.log(val); }; var h5PositionManagerConfig = new BCore.Extension.H5PositionManagerConfig(viewer3D); var h5PositionManager = new BCore.Extension.H5PositionManager(h5PositionManagerConfig); h5PositionManager.addPosition(h5Position); h5PositionManager.clearAllPosition();</code></pre>

页面列表

ITEM_HTML