首页 > 其他分享 >primitive动态修改

primitive动态修改

时间:2023-12-29 11:59:30浏览次数:26  
标签:primitive geometryInstances appearance 修改 ._ var attributes 动态

以贴底线 GroundPolylinePrimitive 为例

我们知道,primitive的更新机制主要是通过update函数,所以通过源码我们可以很容易找到如何对针对性的更新属性。

可以看到,update 每次都会判断 _primitive 这个属性,如果他未定义,则重新构建geometry相关的属性,所以我们只需要将_primitive清空,然后让他自己重构即可。

注:记的设置 asynchronous 为 false,默认异步抖动严重。

primitive._primitive = undefined;
primitive.geometryInstances = [geometryInstances];

源码中update如下:

GroundPolylinePrimitive.prototype.update = function (frameState) {
  ...省略
var that = this; var primitiveOptions = this._primitiveOptions; if (!defined(this._primitive)) { var geometryInstances = Array.isArray(this.geometryInstances) ? this.geometryInstances : [this.geometryInstances]; var geometryInstancesLength = geometryInstances.length; var groundInstances = new Array(geometryInstancesLength); var attributes; // Check if each instance has a color attribute. for (i = 0; i < geometryInstancesLength; ++i) { attributes = geometryInstances[i].attributes; if (!defined(attributes) || !defined(attributes.color)) { this._hasPerInstanceColors = false; break; } } for (i = 0; i < geometryInstancesLength; ++i) { var geometryInstance = geometryInstances[i]; attributes = {}; var instanceAttributes = geometryInstance.attributes; for (var attributeKey in instanceAttributes) { if (instanceAttributes.hasOwnProperty(attributeKey)) { attributes[attributeKey] = instanceAttributes[attributeKey]; } } // Automatically create line width attribute if not already given if (!defined(attributes.width)) { attributes.width = new GeometryInstanceAttribute({ componentDatatype: ComponentDatatype.UNSIGNED_BYTE, componentsPerAttribute: 1.0, value: [geometryInstance.geometry.width], }); } // Update each geometry for framestate.scene3DOnly = true and projection geometryInstance.geometry._scene3DOnly = frameState.scene3DOnly; GroundPolylineGeometry.setProjectionAndEllipsoid( geometryInstance.geometry, frameState.mapProjection ); groundInstances[i] = new GeometryInstance({ geometry: geometryInstance.geometry, attributes: attributes, id: geometryInstance.id, pickPrimitive: that, }); } primitiveOptions.geometryInstances = groundInstances; primitiveOptions.appearance = this.appearance; primitiveOptions._createShaderProgramFunction = function ( primitive, frameState, appearance ) { createShaderProgram(that, frameState, appearance); }; primitiveOptions._createCommandsFunction = function ( primitive, appearance, material, translucent, twoPasses, colorCommands, pickCommands ) { createCommands( that, appearance, material, translucent, colorCommands, pickCommands ); }; primitiveOptions._updateAndQueueCommandsFunction = function ( primitive, frameState, colorCommands, pickCommands, modelMatrix, cull, debugShowBoundingVolume, twoPasses ) { updateAndQueueCommands( that, frameState, colorCommands, pickCommands, modelMatrix, cull, debugShowBoundingVolume ); }; this._primitive = new Primitive(primitiveOptions); this._primitive.readyPromise.then(function (primitive) { that._ready = true; if (that.releaseGeometryInstances) { that.geometryInstances = undefined; } var error = primitive._error; if (!defined(error)) { that._readyPromise.resolve(that); } else { that._readyPromise.reject(error); } }); } if ( this.appearance instanceof PolylineColorAppearance && !this._hasPerInstanceColors ) { throw new DeveloperError( "All GeometryInstances must have color attributes to use PolylineColorAppearance with GroundPolylinePrimitive." ); } this._primitive.appearance = this.appearance; this._primitive.show = this.show; this._primitive.debugShowBoundingVolume = this.debugShowBoundingVolume; this._primitive.update(frameState); };

 

标签:primitive,geometryInstances,appearance,修改,._,var,attributes,动态
From: https://www.cnblogs.com/xt112233/p/17934547.html

相关文章

  • MacOS - QT动态库打包嵌入问题处理
    Crash信息TerminationReason:NamespaceDYLD,Code1LibrarymissingLibrarynotloaded:@rpath/QtCore.framework/Versions/5/QtCoreReferencedfrom:/Applications/AppName.app/Contents/MacOS/AppNameReason:tried:'/Applications/AppName.app/Contents/MacOS/......
  • Unreal入门,Timeline动画02,动态材质
    这里动态材质效果主要是利用Timeline生成随时间变化的颜色插值来实现1.创建动态材质实例变量,用于控制材质动态效果将返回值提升为变量MI_Frame注意这里都是在ConstructionScript中完成的回到事件图表,添加颜色插值以实现动态材质变化注意这里的变化参数来自于门框材质......
  • 动态加载JS文件
    在某些特殊场景下,特别是在库和框架的开发过程中,需要动态加载JS文件并执行它们。下面是使用Promise的简单封装。functionloadJS(files,done){//Gettheheadtagconsthead=document.getElementsByTagName('head')[0];Promise.all(files.map(file=>{returnnewProm......
  • 12.28数组遍历以及动态初始化,数组求最值,基础方法1
    fori用法:数组名.fori直接依次遍历数组中所有元素数组的动态初始化:定义没有元素的数组(静态初始化即已知元素)   方法调用:方法名(); ......
  • elf与动态库大小裁剪
    老板最近看拼多多的包挺小的,扔了一篇文章过来让我们优化优化各自的动态库,美团这篇关于动态库大小缩减的文章,说的极好哈哈:https://tech.meituan.com/2022/06/02/meituans-technical-exploration-and-practice-of-android-so-volume-optimization.html#按需导出符号对库大小影响大......
  • JQuery 修改用户信息
    JQuery修改用户信息,多项选择,赋值,框架:https://www.h-ui.net/v3.shtml$(data.data.roleList).each(function(i,val){$('input[type="checkbox"][name="doctorRole"]').each(function(){if(this.value==val.roleCode){......
  • phantomjs selenium 如何动态修改代理?
    在使用PhantomJS和Selenium进行网页爬取时,动态修改代理可以通过使用Selenium的WebDriver的service_args参数来实现。以下是一个基本的示例,演示了如何在PhantomJS中动态修改代理:fromseleniumimportwebdriver#设置PhantomJS的可执行文件路径phantomjs_path='/......
  • (打标修改)读取每个文件夹内的txt,加入逗号后加入数据前
    importosdefrename_images_in_folder(folder_path,txt_prefix):"""在指定文件夹中重命名所有图片文件,将给定的txt_prefix添加到每个文件名的开头。"""forfilenameinos.listdir(folder_path):#检查文件是否为图片(简单地通过文件扩展名判断)......
  • 接口自动化测试第三天,利用类的动态方法设置全局变量
    今天的注意知识点是学会使用jsonpath,利用类的动态方法设置全局变量我们大多数情况下,接口都需要使用到登录时获取的token,为了方便使用,我们需要将登录后的token使用jsonpath表达式提取出来然后设置为全局变量首先提前下载好第三方库,jsonpath,这里给一个jsonpath官方地址和在线练习......
  • VMware vCenter Server 7.0、vSphere Client 7.0 修改会话超时时间(session timeout pe
    vCenterServer7.0(仅有vCenterServerAppliance和H5vSphereClien)使用SSH登录vCenterServerAppliance执行shell命令修改如下配置文件:vi/etc/vmware/vsphere-ui/webclient.properties修改如下内容:session.timeout=*value(默认120,单位分钟,例如修改为10080,7天)重启服......