其他分享
首页 > 其他分享> > 3dTiles 最后一块拼图:几何误差与屏幕空间误差

3dTiles 最后一块拼图:几何误差与屏幕空间误差

作者:互联网

// Cesium3DTile.js Cesium3DTile.prototype.getScreenSpaceError()
Cesium3DTile.prototype.getScreenSpaceError = function (
  frameState,
  useParentGeometricError,
  progressiveResolutionHeightFraction
) {
  var tileset = this._tileset;
  var heightFraction = defaultValue(progressiveResolutionHeightFraction, 1.0);
  var parentGeometricError = defined(this.parent)
    ? this.parent.geometricError
    : tileset._geometricError;
  var geometricError = useParentGeometricError
    ? parentGeometricError
    : this.geometricError;
  if (geometricError === 0.0) {
    // Leaf tiles do not have any error so save the computation
    return 0.0;
  }
  var camera = frameState.camera;
  var frustum = camera.frustum;
  var context = frameState.context;
  var width = context.drawingBufferWidth;
  var height = context.drawingBufferHeight * heightFraction;
  var error;
  if (
    frameState.mode === SceneMode.SCENE2D ||
    frustum instanceof OrthographicFrustum
  ) {
    if (defined(frustum._offCenterFrustum)) {
      frustum = frustum._offCenterFrustum;
    }
    var pixelSize =
      Math.max(frustum.top - frustum.bottom, frustum.right - frustum.left) /
      Math.max(width, height);
    error = geometricError / pixelSize;
  } else {
    // Avoid divide by zero when viewer is inside the tile
    var distance = Math.max(this._distanceToCamera, CesiumMath.EPSILON7);
    var sseDenominator = camera.frustum.sseDenominator;
    error = (geometricError * height) / (distance * sseDenominator);
    if (tileset.dynamicScreenSpaceError) {
      var density = tileset._dynamicScreenSpaceErrorComputedDensity;
      var factor = tileset.dynamicScreenSpaceErrorFactor;
      var dynamicError = CesiumMath.fog(distance, density) * factor;
      error -= dynamicError;
    }
  }

  error /= frameState.pixelRatio;

  return error;
};

上述源码是获取当前 Tile 的屏幕空间误差的,在这里,可以很直观看出 几何误差 与 屏幕空间误差 的关系。
屏幕空间误差是指当前摄像机状态下(如果是2D,那么就是当前高度的视角下),实时计算出来的一个值
而几何误差,则用于计算当前状态下的屏幕空间误差,见这两行:

error = geometricError / pixelSize;
error = (geometricError * height) / (distance * sseDenominator);

而具体的这个屏幕空间误差的含义,待后续研究。

标签:tileset,frustum,拼图,空间误差,error,geometricError,3dTiles,var
来源: https://www.cnblogs.com/onsummer/p/13357226.html