首页 > 编程语言 >cesium源码分析-Worker&gltf

cesium源码分析-Worker&gltf

时间:2022-11-05 17:46:38浏览次数:68  
标签:positions Worker width colors 源码 线程 cesium new options

Worker:

cesium中使用线程的一个方面是进行几何数据计算,通常计算耗时,放到线程中计算也很合理,但是通常几何数据占用相当大的内存,虽然浏览器中主线程与子线程传递数据可以使用如下方式转移内存的所有权

myWorker. postMessage(aMessage, transferList);

参数
aMessage:The object to deliver to the worker; this will be in the data field in the event delivered to the DedicatedWorkerGlobalScope onmessage (en US) handler. This may.
transtierList(可选)-一个可选的Transferable对象的数组,用于传递所有权。如果一个对象的所有权被转移,在发送它的上下文中将变为不可用(中止),并且只有在它被发送到的worke
可转移对象是如ArrayBuffer MessagePort或ImageBitmap的实例对 象。transferlist数组中不可传入null.
Returns: Void.

但是针对javascript的对象类型,只支持像ArrayBuffer, MessagePort或lmageBitmap这- 类的内置对象, 不支持自定义对象,所 以在向子线程传递需要计算的数据,以及子线程向主线程传递数据时需要对数据进行打包处理,而cesium中将数据打包为ArrayBuffer格式,子线程解包,计算完成后子线程在打包,主线程解包数据。

按照下面的流程讲解一下具体的处理过程:

scene.primitives.add(new Cesium.Primitive({
  geometryInstances: new Cesium.GeometryInstance({
  geomety: new Cesium.olylineGeometry(t
  positions: positions,
  width: 5.0,
  vertexFormat: Cesium.PolylineColorAppearance.VERTEX FORMAT,
  colors: colors,
}).
}),
appearance: new Cesium.olylineColorAppearance(),
asynchronous : true
})
);

上面的这个过程创建一个polyline, 因为有参数"asynchronous: true"的存在,所以使用了异步的处理过程,在这个过程中会创建子线程。

首先看一下PolylineGeometry这个类的构造函数:

function PolylineGeometry(options){
//默认值
 options = defaultValue(options, defaultValue.EMPTY_OBJECT);
//位置
 var positions = options.positions;
 var colors = options.colors;
 var width=defaultValue(options.width,1.0);
//每个顶点是否包含颜色
var colorsPerVertex=defaultValue(options.colorsPerVertex, false);

if(!defined(positions)||positions.length<2){
throw new DeveloperError("At least two positions are required.")
}
if(typeof width !== "number"){
throw new DeveloperError("width must be a number");
}
//定义了颜色,但是顶点数量和颜色的数量不同
if(defined(colors)&&((colorsPerVertex&&colors.length<positions.length)||(!colorsPerVertex&&colors.length<positions.length-1))){
throw new DeveloperError("colors has an invalid length.")
}

 

参考:https://wenku.baidu.com/view/371e7af130d4b14e852458fb770bf78a65293aeb.html

标签:positions,Worker,width,colors,源码,线程,cesium,new,options
From: https://www.cnblogs.com/2008nmj/p/16860676.html

相关文章