当前位置: 首页 > news >正文

CesiumInstancedMesh 实例

CesiumInstancedMesh 实例

import * as Cesium from 'cesium';// Three.js 风格的 InstancedMesh 类, https://threejs.org/docs/#api/en/objects/InstancedMesh
export class CesiumInstancedMesh {/*** Creates an instance of InstancedMesh.** @param {Cesium.Geometry} geometry - Cesium geometry instance* @param {Cesium.MaterialAppearance} material - Cesium material appearance* @param {number} count - Number of instances*/constructor(geometry, material, count) {this._instances = Array.from({ length: count }, () => ({modelMatrix: null,geometry: null}));this._geometry = geometry;this._material = material;this._primitive = null;}/*** Gets the Cesium Primitive for rendering.* @returns {Cesium.Primitive}*/get primitive() {if (this._primitive) return this._primitive;// 验证所有实例是否有效for (let i = 0; i < this._instances.length; i++) {if (!this._instances[i].modelMatrix || !this._instances[i].geometry) {throw new Error(`Instance at index ${i} is not fully initialized`);}}this._primitive = new Cesium.Primitive({geometryInstances: this._instances.map(instance => new Cesium.GeometryInstance({geometry: instance.geometry,modelMatrix: instance.modelMatrix})),appearance: this._material,asynchronous: false});return this._primitive;}/*** Sets the model matrix for an instance at the specified index.* @param {number} index - Instance index* @param {Cesium.Matrix4} matrix - Model matrix*/setMatrixAt(index, matrix) {if (index < 0 || index >= this._instances.length) {throw new Error(`Index ${index} is out of bounds (0 to ${this._instances.length - 1})`);}this._instances[index].modelMatrix = Cesium.Matrix4.clone(matrix, new Cesium.Matrix4());this._instances[index].geometry = this._geometry;if (this._primitive) {this._primitive.geometryInstances = this._instances.map(instance => new Cesium.GeometryInstance({geometry: instance.geometry,modelMatrix: instance.modelMatrix}));}}/*** Destroys the instance and releases resources.*/destroy() {this._primitive = null;this._instances = null;this._geometry = null;this._material = null;}
}

相关文章:

  • 数据库主键与索引详解
  • Nature:多模态大模型LLMs如何驱动多组学与生命科学研究新范式?
  • Hash 的工程优势: port range 匹配
  • embbeding 视频截图
  • 循序渐进PersistentVolumes与PersistentVolumeClaim
  • AI感知与行动:考拉悠然发布空间智能世界模型,让AI走进物理世界
  • 如何解决MySQL Workbench中的错误Error Code: 1175
  • ToolsSet之:十六进制及二进制编辑运算工具
  • SFINAE(替换并不是错误)机制详解详解
  • 【Java基础-环境搭建-创建项目】IntelliJ IDEA创建Java项目的详细步骤
  • C++ 之多线程和互斥锁原理和使用详解
  • TestHubo V1.1.0版本发布,新增用例评审功能,确保测试用例质量,提升测试用例覆盖率
  • shell管道笔记
  • 统计C盘各种扩展名文件大小总和及数量的PowerShell脚本
  • 集成测试 maestro-我的第一个flow以及第一次云端测试
  • 【递归、搜索与回溯算法】综合练习(二)
  • 免费高清多功能录屏软件推荐
  • Bootstrap:精通级教程(VIP10万字版)
  • (24)多租户 SaaS 平台设计
  • Microsoft.Extensions.AI 技术深度解析与实践指南
  • 网站域名注册商标/凡科建站的优势
  • 有没有卖设计的网站/中国国际新闻
  • 怎么利用网站做淘宝客/aso优化服务平台
  • 手机微网站开发/cpa游戏推广联盟
  • 谷歌风格wordpress/seo产品优化推广
  • 做动画相册在哪个网站好/郑州最新通告