@loaders.gl/tiles
Advanced tools
Comparing version 3.0.0-alpha.7 to 3.0.0-alpha.8
"use strict"; | ||
const moduleExports = require('./index'); | ||
var moduleExports = require('./index'); | ||
const _global = typeof window === 'undefined' ? global : window; | ||
var _global = typeof window === 'undefined' ? global : window; | ||
@@ -7,0 +7,0 @@ _global.loaders = _global.loaders || {}; |
@@ -7,3 +7,3 @@ "use strict"; | ||
exports.TILE3D_OPTIMIZATION_HINT = exports.LOD_METRIC_TYPE = exports.TILESET_TYPE = exports.TILE_TYPE = exports.TILE_REFINEMENT = exports.TILE_CONTENT_STATE = void 0; | ||
const TILE_CONTENT_STATE = { | ||
var TILE_CONTENT_STATE = { | ||
UNLOADED: 0, | ||
@@ -17,3 +17,3 @@ LOADING: 1, | ||
exports.TILE_CONTENT_STATE = TILE_CONTENT_STATE; | ||
const TILE_REFINEMENT = { | ||
var TILE_REFINEMENT = { | ||
ADD: 1, | ||
@@ -23,3 +23,3 @@ REPLACE: 2 | ||
exports.TILE_REFINEMENT = TILE_REFINEMENT; | ||
const TILE_TYPE = { | ||
var TILE_TYPE = { | ||
EMPTY: 'empty', | ||
@@ -31,3 +31,3 @@ SCENEGRAPH: 'scenegraph', | ||
exports.TILE_TYPE = TILE_TYPE; | ||
const TILESET_TYPE = { | ||
var TILESET_TYPE = { | ||
I3S: 'I3S', | ||
@@ -37,3 +37,3 @@ TILES3D: 'TILES3D' | ||
exports.TILESET_TYPE = TILESET_TYPE; | ||
const LOD_METRIC_TYPE = { | ||
var LOD_METRIC_TYPE = { | ||
GEOMETRIC_ERROR: 'geometricError', | ||
@@ -43,3 +43,3 @@ MAX_SCREEN_THRESHOLD: 'maxScreenThreshold' | ||
exports.LOD_METRIC_TYPE = LOD_METRIC_TYPE; | ||
const TILE3D_OPTIMIZATION_HINT = { | ||
var TILE3D_OPTIMIZATION_HINT = { | ||
NOT_COMPUTED: -1, | ||
@@ -46,0 +46,0 @@ USE_OPTIMIZATION: 1, |
@@ -10,3 +10,3 @@ "use strict"; | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _tileset3d.default; | ||
@@ -17,3 +17,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _tile3d.default; | ||
@@ -24,3 +24,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _tilesetTraverser.default; | ||
@@ -31,3 +31,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _tilesetCache.default; | ||
@@ -38,3 +38,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _boundingVolume.createBoundingVolume; | ||
@@ -45,3 +45,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _transformUtils.calculateTransformProps; | ||
@@ -52,3 +52,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _frameState.getFrameState; | ||
@@ -59,3 +59,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _constants.TILE_CONTENT_STATE; | ||
@@ -66,3 +66,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _constants.TILE_REFINEMENT; | ||
@@ -73,3 +73,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _constants.TILE_TYPE; | ||
@@ -80,3 +80,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _constants.TILESET_TYPE; | ||
@@ -87,3 +87,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _constants.LOD_METRIC_TYPE; | ||
@@ -90,0 +90,0 @@ } |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,2 +10,4 @@ value: true | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _core = require("@math.gl/core"); | ||
@@ -21,6 +25,6 @@ | ||
const scratchScale = new _core.Vector3(); | ||
const scratchNorthWest = new _core.Vector3(); | ||
const scratchSouthEast = new _core.Vector3(); | ||
const scratchTransform = new _core.Matrix4(); | ||
var scratchScale = new _core.Vector3(); | ||
var scratchNorthWest = new _core.Vector3(); | ||
var scratchSouthEast = new _core.Vector3(); | ||
var scratchTransform = new _core.Matrix4(); | ||
@@ -35,10 +39,16 @@ function createBoundingVolume(boundingVolumeHeader, transform, result) { | ||
if (boundingVolumeHeader.region) { | ||
const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region; | ||
var _boundingVolumeHeader = (0, _slicedToArray2.default)(boundingVolumeHeader.region, 6), | ||
west = _boundingVolumeHeader[0], | ||
south = _boundingVolumeHeader[1], | ||
east = _boundingVolumeHeader[2], | ||
north = _boundingVolumeHeader[3], | ||
minHeight = _boundingVolumeHeader[4], | ||
maxHeight = _boundingVolumeHeader[5]; | ||
const northWest = _geospatial.Ellipsoid.WGS84.cartographicToCartesian([(0, _core.degrees)(west), (0, _core.degrees)(north), minHeight], scratchNorthWest); | ||
var northWest = _geospatial.Ellipsoid.WGS84.cartographicToCartesian([(0, _core.degrees)(west), (0, _core.degrees)(north), minHeight], scratchNorthWest); | ||
const southEast = _geospatial.Ellipsoid.WGS84.cartographicToCartesian([(0, _core.degrees)(east), (0, _core.degrees)(south), maxHeight], scratchSouthEast); | ||
var southEast = _geospatial.Ellipsoid.WGS84.cartographicToCartesian([(0, _core.degrees)(east), (0, _core.degrees)(south), maxHeight], scratchSouthEast); | ||
const centerInCartesian = new _core.Vector3().addVectors(northWest, southEast).multiplyScalar(0.5); | ||
const radius = new _core.Vector3().subVectors(northWest, southEast).len() / 2.0; | ||
var centerInCartesian = new _core.Vector3().addVectors(northWest, southEast).multiplyScalar(0.5); | ||
var radius = new _core.Vector3().subVectors(northWest, southEast).len() / 2.0; | ||
return createSphere([centerInCartesian[0], centerInCartesian[1], centerInCartesian[2], radius], new _core.Matrix4()); | ||
@@ -55,8 +65,8 @@ } | ||
function createBox(box, transform, result) { | ||
const center = new _core.Vector3(box[0], box[1], box[2]); | ||
var center = new _core.Vector3(box[0], box[1], box[2]); | ||
transform.transform(center, center); | ||
const xAxis = transform.transformAsVector(box.slice(3, 6)); | ||
const yAxis = transform.transformAsVector(box.slice(6, 9)); | ||
const zAxis = transform.transformAsVector(box.slice(9, 12)); | ||
const halfAxes = new _core.Matrix3([xAxis[0], xAxis[1], xAxis[2], yAxis[0], yAxis[1], yAxis[2], zAxis[0], zAxis[1], zAxis[2]]); | ||
var xAxis = transform.transformAsVector(box.slice(3, 6)); | ||
var yAxis = transform.transformAsVector(box.slice(6, 9)); | ||
var zAxis = transform.transformAsVector(box.slice(9, 12)); | ||
var halfAxes = new _core.Matrix3([xAxis[0], xAxis[1], xAxis[2], yAxis[0], yAxis[1], yAxis[2], zAxis[0], zAxis[1], zAxis[2]]); | ||
@@ -73,7 +83,7 @@ if (defined(result)) { | ||
function createSphere(sphere, transform, result) { | ||
const center = new _core.Vector3(sphere[0], sphere[1], sphere[2]); | ||
var center = new _core.Vector3(sphere[0], sphere[1], sphere[2]); | ||
transform.transform(center, center); | ||
const scale = transform.getScale(scratchScale); | ||
const uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]); | ||
const radius = sphere[3] * uniformScale; | ||
var scale = transform.getScale(scratchScale); | ||
var uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]); | ||
var radius = sphere[3] * uniformScale; | ||
@@ -80,0 +90,0 @@ if (defined(result)) { |
@@ -14,27 +14,23 @@ "use strict"; | ||
const scratchVector = new _core.Vector3(); | ||
const scratchPosition = new _core.Vector3(); | ||
const cullingVolume = new _culling.CullingVolume([new _culling.Plane(), new _culling.Plane(), new _culling.Plane(), new _culling.Plane(), new _culling.Plane(), new _culling.Plane()]); | ||
var scratchVector = new _core.Vector3(); | ||
var scratchPosition = new _core.Vector3(); | ||
var cullingVolume = new _culling.CullingVolume([new _culling.Plane(), new _culling.Plane(), new _culling.Plane(), new _culling.Plane(), new _culling.Plane(), new _culling.Plane()]); | ||
function getFrameState(viewport, frameNumber) { | ||
const { | ||
cameraDirection, | ||
cameraUp, | ||
height | ||
} = viewport; | ||
const { | ||
metersPerUnit | ||
} = viewport.distanceScales; | ||
const viewportCenterCartographic = [viewport.longitude, viewport.latitude, 0]; | ||
var cameraDirection = viewport.cameraDirection, | ||
cameraUp = viewport.cameraUp, | ||
height = viewport.height; | ||
var metersPerUnit = viewport.distanceScales.metersPerUnit; | ||
var viewportCenterCartographic = [viewport.longitude, viewport.latitude, 0]; | ||
const viewportCenterCartesian = _geospatial.Ellipsoid.WGS84.cartographicToCartesian(viewportCenterCartographic, new _core.Vector3()); | ||
var viewportCenterCartesian = _geospatial.Ellipsoid.WGS84.cartographicToCartesian(viewportCenterCartographic, new _core.Vector3()); | ||
const enuToFixedTransform = _geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian); | ||
var enuToFixedTransform = _geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian); | ||
const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition); | ||
var cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition); | ||
const cameraPositionCartesian = _geospatial.Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new _core.Vector3()); | ||
var cameraPositionCartesian = _geospatial.Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new _core.Vector3()); | ||
const cameraDirectionCartesian = new _core.Vector3(enuToFixedTransform.transformAsVector(new _core.Vector3(cameraDirection).scale(metersPerUnit))).normalize(); | ||
const cameraUpCartesian = new _core.Vector3(enuToFixedTransform.transformAsVector(new _core.Vector3(cameraUp).scale(metersPerUnit))).normalize(); | ||
var cameraDirectionCartesian = new _core.Vector3(enuToFixedTransform.transformAsVector(new _core.Vector3(cameraDirection).scale(metersPerUnit))).normalize(); | ||
var cameraUpCartesian = new _core.Vector3(enuToFixedTransform.transformAsVector(new _core.Vector3(cameraUp).scale(metersPerUnit))).normalize(); | ||
commonSpacePlanesToWGS84(viewport, viewportCenterCartesian); | ||
@@ -47,6 +43,6 @@ return { | ||
}, | ||
viewport, | ||
height, | ||
cullingVolume, | ||
frameNumber, | ||
viewport: viewport, | ||
height: height, | ||
cullingVolume: cullingVolume, | ||
frameNumber: frameNumber, | ||
sseDenominator: 1.15 | ||
@@ -57,12 +53,12 @@ }; | ||
function commonSpacePlanesToWGS84(viewport, viewportCenterCartesian) { | ||
const frustumPlanes = viewport.getFrustumPlanes(); | ||
let i = 0; | ||
var frustumPlanes = viewport.getFrustumPlanes(); | ||
var i = 0; | ||
for (const dir in frustumPlanes) { | ||
const plane = frustumPlanes[dir]; | ||
const distanceToCenter = plane.normal.dot(viewport.center); | ||
for (var dir in frustumPlanes) { | ||
var plane = frustumPlanes[dir]; | ||
var distanceToCenter = plane.normal.dot(viewport.center); | ||
scratchPosition.copy(plane.normal).scale(plane.distance - distanceToCenter).add(viewport.center); | ||
const cartographicPos = viewport.unprojectPosition(scratchPosition); | ||
var cartographicPos = viewport.unprojectPosition(scratchPosition); | ||
const cartesianPos = _geospatial.Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, new _core.Vector3()); | ||
var cartesianPos = _geospatial.Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, new _core.Vector3()); | ||
@@ -69,0 +65,0 @@ cullingVolume.planes[i++].fromPointNormal(cartesianPos, scratchVector.copy(viewportCenterCartesian).subtract(cartesianPos)); |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,28 +11,28 @@ value: true | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _core = require("@math.gl/core"); | ||
const WGS84_RADIUS_X = 6378137.0; | ||
const qualityFactor = Math.PI / 2; | ||
var WGS84_RADIUS_X = 6378137.0; | ||
var qualityFactor = Math.PI / 2; | ||
function lodJudge(tile, frameState) { | ||
const viewport = frameState.viewport; | ||
const metersPerPixel = viewport.metersPerPixel; | ||
const mbsLat = tile.header.mbs[1]; | ||
const mbsLon = tile.header.mbs[0]; | ||
const mbsZ = tile.header.mbs[2]; | ||
const mbsR = tile.header.mbs[3]; | ||
const { | ||
height, | ||
width, | ||
latitude, | ||
longitude | ||
} = viewport; | ||
const viewportCenter = [longitude, latitude]; | ||
const mbsCenter = [mbsLon, mbsLat, mbsZ]; | ||
const mbsLatProjected = [longitude, mbsLat]; | ||
const mbsLonProjected = [mbsLon, latitude]; | ||
const diagonalInMeters = Math.sqrt(height * height + width * width) * metersPerPixel[0]; | ||
const distanceInMeters = getDistanceFromLatLon(viewportCenter, mbsCenter); | ||
const visibleHeight = height * 0.5 + mbsR / WGS84_RADIUS_X; | ||
const visibleWidth = width * 0.5 + mbsR / WGS84_RADIUS_X; | ||
var viewport = frameState.viewport; | ||
var metersPerPixel = viewport.metersPerPixel; | ||
var mbsLat = tile.header.mbs[1]; | ||
var mbsLon = tile.header.mbs[0]; | ||
var mbsZ = tile.header.mbs[2]; | ||
var mbsR = tile.header.mbs[3]; | ||
var height = viewport.height, | ||
width = viewport.width, | ||
latitude = viewport.latitude, | ||
longitude = viewport.longitude; | ||
var viewportCenter = [longitude, latitude]; | ||
var mbsCenter = [mbsLon, mbsLat, mbsZ]; | ||
var mbsLatProjected = [longitude, mbsLat]; | ||
var mbsLonProjected = [mbsLon, latitude]; | ||
var diagonalInMeters = Math.sqrt(height * height + width * width) * metersPerPixel[0]; | ||
var distanceInMeters = getDistanceFromLatLon(viewportCenter, mbsCenter); | ||
var visibleHeight = height * 0.5 + mbsR / WGS84_RADIUS_X; | ||
var visibleWidth = width * 0.5 + mbsR / WGS84_RADIUS_X; | ||
@@ -53,3 +55,3 @@ if (distanceInMeters > diagonalInMeters + mbsR / WGS84_RADIUS_X) { | ||
let screenSize = getI3ScreenSize(tile, frameState); | ||
var screenSize = getI3ScreenSize(tile, frameState); | ||
screenSize *= qualityFactor; | ||
@@ -70,7 +72,12 @@ | ||
function projectVertexToSphere([x, y, z]) { | ||
const azim = (0, _core.toRadians)(x); | ||
const incl = (0, _core.toRadians)(y); | ||
const radius = 1.0 + z / WGS84_RADIUS_X; | ||
const radCosInc = radius * Math.cos(incl); | ||
function projectVertexToSphere(_ref) { | ||
var _ref2 = (0, _slicedToArray2.default)(_ref, 3), | ||
x = _ref2[0], | ||
y = _ref2[1], | ||
z = _ref2[2]; | ||
var azim = (0, _core.toRadians)(x); | ||
var incl = (0, _core.toRadians)(y); | ||
var radius = 1.0 + z / WGS84_RADIUS_X; | ||
var radCosInc = radius * Math.cos(incl); | ||
x = radCosInc * Math.cos(azim); | ||
@@ -82,8 +89,20 @@ y = radCosInc * Math.sin(azim); | ||
function getDistanceFromLatLon([observerLon, observerLat, observerZ = 0.0], [centerLon, centerLat, centerZ = 0.0]) { | ||
const projectedCenter = projectVertexToSphere([centerLon, centerLat, centerZ]); | ||
const projectedObserver = projectVertexToSphere([observerLon, observerLat, observerZ]); | ||
const dx = projectedObserver[0] - projectedCenter[0]; | ||
const dy = projectedObserver[1] - projectedCenter[1]; | ||
const dz = projectedObserver[2] - projectedCenter[2]; | ||
function getDistanceFromLatLon(_ref3, _ref4) { | ||
var _ref5 = (0, _slicedToArray2.default)(_ref3, 3), | ||
observerLon = _ref5[0], | ||
observerLat = _ref5[1], | ||
_ref5$ = _ref5[2], | ||
observerZ = _ref5$ === void 0 ? 0.0 : _ref5$; | ||
var _ref6 = (0, _slicedToArray2.default)(_ref4, 3), | ||
centerLon = _ref6[0], | ||
centerLat = _ref6[1], | ||
_ref6$ = _ref6[2], | ||
centerZ = _ref6$ === void 0 ? 0.0 : _ref6$; | ||
var projectedCenter = projectVertexToSphere([centerLon, centerLat, centerZ]); | ||
var projectedObserver = projectVertexToSphere([observerLon, observerLat, observerZ]); | ||
var dx = projectedObserver[0] - projectedCenter[0]; | ||
var dy = projectedObserver[1] - projectedCenter[1]; | ||
var dz = projectedObserver[2] - projectedCenter[2]; | ||
return dx * dx + dy * dy + dz * dz; | ||
@@ -93,13 +112,13 @@ } | ||
function getI3ScreenSize(tile, frameState) { | ||
const viewport = frameState.viewport; | ||
const mbsLat = tile.header.mbs[1]; | ||
const mbsLon = tile.header.mbs[0]; | ||
const mbsZ = tile.header.mbs[2]; | ||
const mbsR = tile.header.mbs[3]; | ||
const mbsCenter = [mbsLon, mbsLat, mbsZ]; | ||
const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition); | ||
const dSquared = getDistanceFromLatLon(cameraPositionCartographic, mbsCenter); | ||
const mbsRNormalized = mbsR / WGS84_RADIUS_X; | ||
const d = dSquared - mbsRNormalized * mbsRNormalized; | ||
const fltMax = 3.4028235e38; | ||
var viewport = frameState.viewport; | ||
var mbsLat = tile.header.mbs[1]; | ||
var mbsLon = tile.header.mbs[0]; | ||
var mbsZ = tile.header.mbs[2]; | ||
var mbsR = tile.header.mbs[3]; | ||
var mbsCenter = [mbsLon, mbsLat, mbsZ]; | ||
var cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition); | ||
var dSquared = getDistanceFromLatLon(cameraPositionCartographic, mbsCenter); | ||
var mbsRNormalized = mbsR / WGS84_RADIUS_X; | ||
var d = dSquared - mbsRNormalized * mbsRNormalized; | ||
var fltMax = 3.4028235e38; | ||
@@ -110,3 +129,3 @@ if (d <= 0.0) { | ||
let screenSizeFactor = calculateScreenSizeFactor(tile, frameState); | ||
var screenSizeFactor = calculateScreenSizeFactor(tile, frameState); | ||
screenSizeFactor *= mbsRNormalized / Math.sqrt(d) / viewport.scale; | ||
@@ -117,11 +136,10 @@ return screenSizeFactor; | ||
function calculateScreenSizeFactor(tile, frameState) { | ||
const { | ||
width, | ||
height, | ||
pixelProjectionMatrix | ||
} = frameState.viewport; | ||
const tanOfHalfVFAngle = Math.tan(Math.atan(Math.sqrt(1.0 / (pixelProjectionMatrix[0] * pixelProjectionMatrix[0]) + 1.0 / (pixelProjectionMatrix[5] * pixelProjectionMatrix[5])))); | ||
const screenCircleFactor = Math.sqrt(height * height + width * width) / tanOfHalfVFAngle; | ||
var _frameState$viewport = frameState.viewport, | ||
width = _frameState$viewport.width, | ||
height = _frameState$viewport.height, | ||
pixelProjectionMatrix = _frameState$viewport.pixelProjectionMatrix; | ||
var tanOfHalfVFAngle = Math.tan(Math.atan(Math.sqrt(1.0 / (pixelProjectionMatrix[0] * pixelProjectionMatrix[0]) + 1.0 / (pixelProjectionMatrix[5] * pixelProjectionMatrix[5])))); | ||
var screenCircleFactor = Math.sqrt(height * height + width * width) / tanOfHalfVFAngle; | ||
return screenCircleFactor; | ||
} | ||
//# sourceMappingURL=i3s-lod.js.map |
@@ -13,23 +13,23 @@ "use strict"; | ||
const scratchPositionNormal = new _core.Vector3(); | ||
const scratchCartographic = new _core.Vector3(); | ||
const scratchMatrix = new _core.Matrix4(); | ||
const scratchCenter = new _core.Vector3(); | ||
const scratchPosition = new _core.Vector3(); | ||
const scratchDirection = new _core.Vector3(); | ||
var scratchPositionNormal = new _core.Vector3(); | ||
var scratchCartographic = new _core.Vector3(); | ||
var scratchMatrix = new _core.Matrix4(); | ||
var scratchCenter = new _core.Vector3(); | ||
var scratchPosition = new _core.Vector3(); | ||
var scratchDirection = new _core.Vector3(); | ||
function calculateDynamicScreenSpaceError(root, { | ||
camera, | ||
mapProjection | ||
}, options = {}) { | ||
const { | ||
dynamicScreenSpaceErrorHeightFalloff = 0.25, | ||
dynamicScreenSpaceErrorDensity = 0.00278 | ||
} = options; | ||
let up; | ||
let direction; | ||
let height; | ||
let minimumHeight; | ||
let maximumHeight; | ||
const tileBoundingVolume = root.contentBoundingVolume; | ||
function calculateDynamicScreenSpaceError(root, _ref) { | ||
var camera = _ref.camera, | ||
mapProjection = _ref.mapProjection; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var _options$dynamicScree = options.dynamicScreenSpaceErrorHeightFalloff, | ||
dynamicScreenSpaceErrorHeightFalloff = _options$dynamicScree === void 0 ? 0.25 : _options$dynamicScree, | ||
_options$dynamicScree2 = options.dynamicScreenSpaceErrorDensity, | ||
dynamicScreenSpaceErrorDensity = _options$dynamicScree2 === void 0 ? 0.00278 : _options$dynamicScree2; | ||
var up; | ||
var direction; | ||
var height; | ||
var minimumHeight; | ||
var maximumHeight; | ||
var tileBoundingVolume = root.contentBoundingVolume; | ||
@@ -43,11 +43,11 @@ if (tileBoundingVolume instanceof TileBoundingRegion) { | ||
} else { | ||
const transformLocal = _core.Matrix4.inverseTransformation(root.computedTransform, scratchMatrix); | ||
var transformLocal = _core.Matrix4.inverseTransformation(root.computedTransform, scratchMatrix); | ||
const ellipsoid = mapProjection.ellipsoid; | ||
const boundingVolume = tileBoundingVolume.boundingVolume; | ||
var ellipsoid = mapProjection.ellipsoid; | ||
var boundingVolume = tileBoundingVolume.boundingVolume; | ||
const centerLocal = _core.Matrix4.multiplyByPoint(transformLocal, boundingVolume.center, scratchCenter); | ||
var centerLocal = _core.Matrix4.multiplyByPoint(transformLocal, boundingVolume.center, scratchCenter); | ||
if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) { | ||
const centerCartographic = Cartographic.fromCartesian(centerLocal, ellipsoid, scratchCartographic); | ||
var centerCartographic = Cartographic.fromCartesian(centerLocal, ellipsoid, scratchCartographic); | ||
up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal); | ||
@@ -59,3 +59,3 @@ direction = camera.directionWC; | ||
} else { | ||
const positionLocal = _core.Matrix4.multiplyByPoint(transformLocal, camera.positionWC, scratchPosition); | ||
var positionLocal = _core.Matrix4.multiplyByPoint(transformLocal, camera.positionWC, scratchPosition); | ||
@@ -68,7 +68,7 @@ up = Cartesian3.UNIT_Z; | ||
if (tileBoundingVolume instanceof TileOrientedBoundingBox) { | ||
const boxHeight = root._header.boundingVolume.box[11]; | ||
var boxHeight = root._header.boundingVolume.box[11]; | ||
minimumHeight = centerLocal.z - boxHeight; | ||
maximumHeight = centerLocal.z + boxHeight; | ||
} else if (tileBoundingVolume instanceof TileBoundingSphere) { | ||
const radius = boundingVolume.radius; | ||
var radius = boundingVolume.radius; | ||
minimumHeight = centerLocal.z - radius; | ||
@@ -80,8 +80,8 @@ maximumHeight = centerLocal.z + radius; | ||
const heightFalloff = dynamicScreenSpaceErrorHeightFalloff; | ||
const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff; | ||
const heightFar = maximumHeight; | ||
const t = (0, _core.clamp)((height - heightClose) / (heightFar - heightClose), 0.0, 1.0); | ||
const dot = Math.abs(Cartesian3.dot(direction, up)); | ||
let horizonFactor = 1.0 - dot; | ||
var heightFalloff = dynamicScreenSpaceErrorHeightFalloff; | ||
var heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff; | ||
var heightFar = maximumHeight; | ||
var t = (0, _core.clamp)((height - heightClose) / (heightFar - heightClose), 0.0, 1.0); | ||
var dot = Math.abs(Cartesian3.dot(direction, up)); | ||
var horizonFactor = 1.0 - dot; | ||
horizonFactor = horizonFactor * (1.0 - t); | ||
@@ -92,3 +92,3 @@ return dynamicScreenSpaceErrorDensity * horizonFactor; | ||
function fog(distanceToCamera, density) { | ||
const scalar = distanceToCamera * density; | ||
var scalar = distanceToCamera * density; | ||
return 1.0 - Math.exp(-(scalar * scalar)); | ||
@@ -99,5 +99,5 @@ } | ||
if (tileset.dynamicScreenSpaceError && tileset._dynamicScreenSpaceErrorComputedDensity) { | ||
const density = tileset._dynamicScreenSpaceErrorComputedDensity; | ||
const factor = tileset.dynamicScreenSpaceErrorFactor; | ||
const dynamicError = fog(distanceToCamera, density) * factor; | ||
var density = tileset._dynamicScreenSpaceErrorComputedDensity; | ||
var factor = tileset.dynamicScreenSpaceErrorFactor; | ||
var dynamicError = fog(distanceToCamera, density) * factor; | ||
return dynamicError; | ||
@@ -110,5 +110,5 @@ } | ||
function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) { | ||
const tileset = tile.tileset; | ||
const parentLodMetricValue = tile.parent && tile.parent.lodMetricValue || tile.lodMetricValue; | ||
const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue; | ||
var tileset = tile.tileset; | ||
var parentLodMetricValue = tile.parent && tile.parent.lodMetricValue || tile.lodMetricValue; | ||
var lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue; | ||
@@ -119,8 +119,6 @@ if (lodMetricValue === 0.0) { | ||
const distance = Math.max(tile._distanceToCamera, 1e-7); | ||
const { | ||
height, | ||
sseDenominator | ||
} = frameState; | ||
let error = lodMetricValue * height / (distance * sseDenominator); | ||
var distance = Math.max(tile._distanceToCamera, 1e-7); | ||
var height = frameState.height, | ||
sseDenominator = frameState.sseDenominator; | ||
var error = lodMetricValue * height / (distance * sseDenominator); | ||
error -= getDynamicScreenSpaceError(tileset, distance); | ||
@@ -127,0 +125,0 @@ return error; |
@@ -17,13 +17,7 @@ "use strict"; | ||
(0, _loaderUtils.assert)(tile); | ||
const { | ||
rtcCenter, | ||
gltfUpAxis | ||
} = tile; | ||
const { | ||
computedTransform, | ||
boundingVolume: { | ||
center | ||
} | ||
} = tileHeader; | ||
let modelMatrix = new _core.Matrix4(computedTransform); | ||
var rtcCenter = tile.rtcCenter, | ||
gltfUpAxis = tile.gltfUpAxis; | ||
var computedTransform = tileHeader.computedTransform, | ||
center = tileHeader.boundingVolume.center; | ||
var modelMatrix = new _core.Matrix4(computedTransform); | ||
@@ -39,3 +33,3 @@ if (rtcCenter) { | ||
case 'Y': | ||
const rotationY = new _core.Matrix4().rotateX(Math.PI / 2); | ||
var rotationY = new _core.Matrix4().rotateX(Math.PI / 2); | ||
modelMatrix = modelMatrix.multiplyRight(rotationY); | ||
@@ -45,3 +39,3 @@ break; | ||
case 'X': | ||
const rotationX = new _core.Matrix4().rotateY(-Math.PI / 2); | ||
var rotationX = new _core.Matrix4().rotateY(-Math.PI / 2); | ||
modelMatrix = modelMatrix.multiplyRight(rotationX); | ||
@@ -58,11 +52,11 @@ break; | ||
const cartesianOrigin = new _core.Vector3(center); | ||
var cartesianOrigin = new _core.Vector3(center); | ||
tile.cartesianModelMatrix = modelMatrix; | ||
tile.cartesianOrigin = cartesianOrigin; | ||
const cartographicOrigin = _geospatial.Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new _core.Vector3()); | ||
var cartographicOrigin = _geospatial.Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new _core.Vector3()); | ||
const fromFixedFrameMatrix = _geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin); | ||
var fromFixedFrameMatrix = _geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin); | ||
const toFixedFrameMatrix = fromFixedFrameMatrix.invert(); | ||
var toFixedFrameMatrix = fromFixedFrameMatrix.invert(); | ||
tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix); | ||
@@ -69,0 +63,0 @@ tile.cartographicOrigin = cartographicOrigin; |
@@ -10,28 +10,26 @@ "use strict"; | ||
const WGS84_RADIUS_X = 6378137.0; | ||
const WGS84_RADIUS_Y = 6378137.0; | ||
const WGS84_RADIUS_Z = 6356752.3142451793; | ||
const scratchVector = new _core.Vector3(); | ||
var WGS84_RADIUS_X = 6378137.0; | ||
var WGS84_RADIUS_Y = 6378137.0; | ||
var WGS84_RADIUS_Z = 6356752.3142451793; | ||
var scratchVector = new _core.Vector3(); | ||
function getZoomFromBoundingVolume(boundingVolume) { | ||
const { | ||
halfAxes, | ||
radius, | ||
width, | ||
height | ||
} = boundingVolume; | ||
var halfAxes = boundingVolume.halfAxes, | ||
radius = boundingVolume.radius, | ||
width = boundingVolume.width, | ||
height = boundingVolume.height; | ||
if (halfAxes) { | ||
halfAxes.getColumn(0, scratchVector); | ||
const x = scratchVector.len(); | ||
var x = scratchVector.len(); | ||
halfAxes.getColumn(1, scratchVector); | ||
const y = scratchVector.len(); | ||
var y = scratchVector.len(); | ||
halfAxes.getColumn(2, scratchVector); | ||
const z = scratchVector.len(); | ||
const halfX = x / 2; | ||
const halfY = y / 2; | ||
const halfZ = z / 2; | ||
const zoomX = Math.log2(WGS84_RADIUS_X / halfX); | ||
const zoomY = Math.log2(WGS84_RADIUS_Y / halfY); | ||
const zoomZ = Math.log2(WGS84_RADIUS_Z / halfZ); | ||
var z = scratchVector.len(); | ||
var halfX = x / 2; | ||
var halfY = y / 2; | ||
var halfZ = z / 2; | ||
var zoomX = Math.log2(WGS84_RADIUS_X / halfX); | ||
var zoomY = Math.log2(WGS84_RADIUS_Y / halfY); | ||
var zoomZ = Math.log2(WGS84_RADIUS_Z / halfZ); | ||
return (zoomX + zoomY + zoomZ) / 3; | ||
@@ -41,5 +39,7 @@ } else if (radius) { | ||
} else if (height && width) { | ||
const zoomX = Math.log2(WGS84_RADIUS_X / width); | ||
const zoomY = Math.log2(WGS84_RADIUS_Y / height); | ||
return (zoomX + zoomY) / 2; | ||
var _zoomX = Math.log2(WGS84_RADIUS_X / width); | ||
var _zoomY = Math.log2(WGS84_RADIUS_Y / height); | ||
return (_zoomX + _zoomY) / 2; | ||
} | ||
@@ -46,0 +46,0 @@ |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,2 +10,14 @@ value: true | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _core = require("@math.gl/core"); | ||
@@ -27,4 +41,8 @@ | ||
const scratchVector = new _core.Vector3(); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var scratchVector = new _core.Vector3(); | ||
function defined(x) { | ||
@@ -34,5 +52,6 @@ return x !== undefined && x !== null; | ||
class TileHeader { | ||
constructor(tileset, header, parentHeader) { | ||
(0, _loaderUtils.assert)(typeof header === 'object'); | ||
var TileHeader = function () { | ||
function TileHeader(tileset, header, parentHeader) { | ||
(0, _classCallCheck2.default)(this, TileHeader); | ||
(0, _loaderUtils.assert)((0, _typeof2.default)(header) === 'object'); | ||
this.header = header; | ||
@@ -76,354 +95,432 @@ this.tileset = tileset; | ||
destroy() { | ||
this.header = null; | ||
} | ||
isDestroyed() { | ||
return this.header === null; | ||
} | ||
get selected() { | ||
return this._selectedFrame === this.tileset._frameNumber; | ||
} | ||
get isVisible() { | ||
return this._visible; | ||
} | ||
get isVisibleAndInRequestVolume() { | ||
return this._visible && this._inRequestVolume; | ||
} | ||
get hasRenderContent() { | ||
return !this.hasEmptyContent && !this.hasTilesetContent; | ||
} | ||
get hasChildren() { | ||
return this.children.length > 0 || this.header.children && this.header.children.length > 0; | ||
} | ||
get contentReady() { | ||
return this.contentState === _constants.TILE_CONTENT_STATE.READY || this.hasEmptyContent; | ||
} | ||
get contentAvailable() { | ||
return Boolean(this.contentReady && this.hasRenderContent || this._expiredContent && !this.contentFailed); | ||
} | ||
get hasUnloadedContent() { | ||
return this.hasRenderContent && this.contentUnloaded; | ||
} | ||
get contentUnloaded() { | ||
return this.contentState === _constants.TILE_CONTENT_STATE.UNLOADED; | ||
} | ||
get contentExpired() { | ||
return this.contentState === _constants.TILE_CONTENT_STATE.EXPIRED; | ||
} | ||
get contentFailed() { | ||
return this.contentState === _constants.TILE_CONTENT_STATE.FAILED; | ||
} | ||
getScreenSpaceError(frameState, useParentLodMetric) { | ||
switch (this.tileset.type) { | ||
case _constants.TILESET_TYPE.I3S: | ||
return (0, _i3sLod.getI3ScreenSize)(this, frameState); | ||
case _constants.TILESET_TYPE.TILES3D: | ||
return (0, _tiles3dLod.getTiles3DScreenSpaceError)(this, frameState, useParentLodMetric); | ||
default: | ||
console.error('Unsupported tileset type'); | ||
return null; | ||
(0, _createClass2.default)(TileHeader, [{ | ||
key: "destroy", | ||
value: function destroy() { | ||
this.header = null; | ||
} | ||
} | ||
_getPriority() { | ||
if (!this.isVisible) { | ||
return -1; | ||
}, { | ||
key: "isDestroyed", | ||
value: function isDestroyed() { | ||
return this.header === null; | ||
} | ||
if (this.contentState === _constants.TILE_CONTENT_STATE.UNLOADED) { | ||
return -1; | ||
}, { | ||
key: "selected", | ||
get: function get() { | ||
return this._selectedFrame === this.tileset._frameNumber; | ||
} | ||
return Math.max(1e7 - this._priority, 0) || 0; | ||
} | ||
async loadContent() { | ||
if (this.hasEmptyContent) { | ||
return false; | ||
}, { | ||
key: "isVisible", | ||
get: function get() { | ||
return this._visible; | ||
} | ||
if (this.content) { | ||
return true; | ||
}, { | ||
key: "isVisibleAndInRequestVolume", | ||
get: function get() { | ||
return this._visible && this._inRequestVolume; | ||
} | ||
const expired = this.contentExpired; | ||
if (expired) { | ||
this._expireDate = null; | ||
}, { | ||
key: "hasRenderContent", | ||
get: function get() { | ||
return !this.hasEmptyContent && !this.hasTilesetContent; | ||
} | ||
}, { | ||
key: "hasChildren", | ||
get: function get() { | ||
return this.children.length > 0 || this.header.children && this.header.children.length > 0; | ||
} | ||
}, { | ||
key: "contentReady", | ||
get: function get() { | ||
return this.contentState === _constants.TILE_CONTENT_STATE.READY || this.hasEmptyContent; | ||
} | ||
}, { | ||
key: "contentAvailable", | ||
get: function get() { | ||
return Boolean(this.contentReady && this.hasRenderContent || this._expiredContent && !this.contentFailed); | ||
} | ||
}, { | ||
key: "hasUnloadedContent", | ||
get: function get() { | ||
return this.hasRenderContent && this.contentUnloaded; | ||
} | ||
}, { | ||
key: "contentUnloaded", | ||
get: function get() { | ||
return this.contentState === _constants.TILE_CONTENT_STATE.UNLOADED; | ||
} | ||
}, { | ||
key: "contentExpired", | ||
get: function get() { | ||
return this.contentState === _constants.TILE_CONTENT_STATE.EXPIRED; | ||
} | ||
}, { | ||
key: "contentFailed", | ||
get: function get() { | ||
return this.contentState === _constants.TILE_CONTENT_STATE.FAILED; | ||
} | ||
}, { | ||
key: "getScreenSpaceError", | ||
value: function getScreenSpaceError(frameState, useParentLodMetric) { | ||
switch (this.tileset.type) { | ||
case _constants.TILESET_TYPE.I3S: | ||
return (0, _i3sLod.getI3ScreenSize)(this, frameState); | ||
this.contentState = _constants.TILE_CONTENT_STATE.LOADING; | ||
const requestToken = await this.tileset._requestScheduler.scheduleRequest(this.id, this._getPriority); | ||
case _constants.TILESET_TYPE.TILES3D: | ||
return (0, _tiles3dLod.getTiles3DScreenSpaceError)(this, frameState, useParentLodMetric); | ||
if (!requestToken) { | ||
this.contentState = _constants.TILE_CONTENT_STATE.UNLOADED; | ||
return false; | ||
default: | ||
console.error('Unsupported tileset type'); | ||
return null; | ||
} | ||
} | ||
}, { | ||
key: "_getPriority", | ||
value: function _getPriority() { | ||
if (!this.isVisible) { | ||
return -1; | ||
} | ||
try { | ||
const contentUrl = this.tileset.getTileUrl(this.contentUrl); | ||
const fetchOptions = this.tileset.fetchOptions; | ||
const loader = this.tileset.loader; | ||
const options = { ...fetchOptions, | ||
[loader.id]: { | ||
isTileset: this.type === 'json', | ||
...this._getLoaderSpecificOptions(loader.id) | ||
} | ||
}; | ||
this.content = await (0, _core2.load)(contentUrl, loader, options); | ||
if (this._isTileset()) { | ||
this.tileset._initializeTileHeaders(this.content, this, _loaderUtils.path.dirname(this.contentUrl)); | ||
if (this.contentState === _constants.TILE_CONTENT_STATE.UNLOADED) { | ||
return -1; | ||
} | ||
this.contentState = _constants.TILE_CONTENT_STATE.READY; | ||
return Math.max(1e7 - this._priority, 0) || 0; | ||
} | ||
}, { | ||
key: "loadContent", | ||
value: function () { | ||
var _loadContent = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee() { | ||
var expired, requestToken, contentUrl, fetchOptions, loader, options; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!this.hasEmptyContent) { | ||
_context.next = 2; | ||
break; | ||
} | ||
this._onContentLoaded(); | ||
return _context.abrupt("return", false); | ||
return true; | ||
} catch (error) { | ||
this.contentState = _constants.TILE_CONTENT_STATE.FAILED; | ||
throw error; | ||
} finally { | ||
requestToken.done(); | ||
} | ||
} | ||
case 2: | ||
if (!this.content) { | ||
_context.next = 4; | ||
break; | ||
} | ||
unloadContent() { | ||
if (this.content && this.content.destroy) { | ||
this.content.destroy(); | ||
} | ||
return _context.abrupt("return", true); | ||
this.content = null; | ||
case 4: | ||
expired = this.contentExpired; | ||
if (this.header.content && this.header.content.destroy) { | ||
this.header.content.destroy(); | ||
} | ||
if (expired) { | ||
this._expireDate = null; | ||
} | ||
this.header.content = null; | ||
this.contentState = _constants.TILE_CONTENT_STATE.UNLOADED; | ||
return true; | ||
} | ||
this.contentState = _constants.TILE_CONTENT_STATE.LOADING; | ||
_context.next = 9; | ||
return this.tileset._requestScheduler.scheduleRequest(this.id, this._getPriority); | ||
updateVisibility(frameState) { | ||
if (this._frameNumber === frameState.frameNumber) { | ||
return; | ||
} | ||
case 9: | ||
requestToken = _context.sent; | ||
const parent = this.parent; | ||
const parentTransform = parent ? parent.computedTransform : this.tileset.modelMatrix; | ||
const parentVisibilityPlaneMask = parent ? parent._visibilityPlaneMask : _culling.CullingVolume.MASK_INDETERMINATE; | ||
if (requestToken) { | ||
_context.next = 13; | ||
break; | ||
} | ||
this._updateTransform(parentTransform); | ||
this.contentState = _constants.TILE_CONTENT_STATE.UNLOADED; | ||
return _context.abrupt("return", false); | ||
this._distanceToCamera = this.distanceToTile(frameState); | ||
this._screenSpaceError = this.getScreenSpaceError(frameState, false); | ||
this._visibilityPlaneMask = this.visibility(frameState, parentVisibilityPlaneMask); | ||
this._visible = this._visibilityPlaneMask !== _culling.CullingVolume.MASK_OUTSIDE; | ||
this._inRequestVolume = this.insideViewerRequestVolume(frameState); | ||
this._priority = this.lodMetricValue; | ||
this._frameNumber = frameState.frameNumber; | ||
} | ||
case 13: | ||
_context.prev = 13; | ||
contentUrl = this.tileset.getTileUrl(this.contentUrl); | ||
fetchOptions = this.tileset.fetchOptions; | ||
loader = this.tileset.loader; | ||
options = _objectSpread(_objectSpread({}, fetchOptions), {}, { | ||
[loader.id]: _objectSpread({ | ||
isTileset: this.type === 'json' | ||
}, this._getLoaderSpecificOptions(loader.id)) | ||
}); | ||
_context.next = 20; | ||
return (0, _core2.load)(contentUrl, loader, options); | ||
visibility(frameState, parentVisibilityPlaneMask) { | ||
const { | ||
cullingVolume | ||
} = frameState; | ||
const { | ||
boundingVolume | ||
} = this; | ||
return cullingVolume.computeVisibilityWithPlaneMask(boundingVolume, parentVisibilityPlaneMask); | ||
} | ||
case 20: | ||
this.content = _context.sent; | ||
contentVisibility(frameState) { | ||
return true; | ||
} | ||
if (this._isTileset()) { | ||
this.tileset._initializeTileHeaders(this.content, this, _loaderUtils.path.dirname(this.contentUrl)); | ||
} | ||
distanceToTile(frameState) { | ||
const boundingVolume = this.boundingVolume; | ||
return Math.sqrt(Math.max(boundingVolume.distanceSquaredTo(frameState.camera.position), 0)); | ||
} | ||
this.contentState = _constants.TILE_CONTENT_STATE.READY; | ||
cameraSpaceZDepth({ | ||
camera | ||
}) { | ||
const boundingVolume = this.boundingVolume; | ||
scratchVector.subVectors(boundingVolume.center, camera.position); | ||
return camera.direction.dot(scratchVector); | ||
} | ||
this._onContentLoaded(); | ||
insideViewerRequestVolume(frameState) { | ||
const viewerRequestVolume = this._viewerRequestVolume; | ||
return !viewerRequestVolume || viewerRequestVolume.distanceToCamera(frameState.camera.position) === 0.0; | ||
} | ||
return _context.abrupt("return", true); | ||
_initializeLodMetric(header) { | ||
if ('lodMetricType' in header) { | ||
this.lodMetricType = header.lodMetricType; | ||
} else { | ||
this.lodMetricType = this.parent && this.parent.lodMetricType || this.tileset.lodMetricType; | ||
console.warn("3D Tile: Required prop lodMetricType is undefined. Using parent lodMetricType"); | ||
} | ||
case 27: | ||
_context.prev = 27; | ||
_context.t0 = _context["catch"](13); | ||
this.contentState = _constants.TILE_CONTENT_STATE.FAILED; | ||
throw _context.t0; | ||
if ('lodMetricValue' in header) { | ||
this.lodMetricValue = header.lodMetricValue; | ||
} else { | ||
this.lodMetricValue = this.parent && this.parent.lodMetricValue || this.tileset.lodMetricValue; | ||
console.warn("3D Tile: Required prop lodMetricValue is undefined. Using parent lodMetricValue"); | ||
} | ||
} | ||
case 31: | ||
_context.prev = 31; | ||
requestToken.done(); | ||
return _context.finish(31); | ||
_initializeTransforms(tileHeader) { | ||
this.transform = tileHeader.transform ? new _core.Matrix4(tileHeader.transform) : new _core.Matrix4(); | ||
const parent = this.parent; | ||
const tileset = this.tileset; | ||
const parentTransform = parent && parent.computedTransform ? parent.computedTransform.clone() : tileset.modelMatrix.clone(); | ||
this.computedTransform = new _core.Matrix4(parentTransform).multiplyRight(this.transform); | ||
const parentInitialTransform = parent && parent._initialTransform ? parent._initialTransform.clone() : new _core.Matrix4(); | ||
this._initialTransform = new _core.Matrix4(parentInitialTransform).multiplyRight(this.transform); | ||
} | ||
case 34: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this, [[13, 27, 31, 34]]); | ||
})); | ||
_initializeBoundingVolumes(tileHeader) { | ||
this._contentBoundingVolume = null; | ||
this._viewerRequestVolume = null; | ||
function loadContent() { | ||
return _loadContent.apply(this, arguments); | ||
} | ||
this._updateBoundingVolume(tileHeader); | ||
} | ||
return loadContent; | ||
}() | ||
}, { | ||
key: "unloadContent", | ||
value: function unloadContent() { | ||
if (this.content && this.content.destroy) { | ||
this.content.destroy(); | ||
} | ||
_initializeContent(tileHeader) { | ||
this.content = { | ||
_tileset: this.tileset, | ||
_tile: this | ||
}; | ||
this.hasEmptyContent = true; | ||
this.contentState = _constants.TILE_CONTENT_STATE.UNLOADED; | ||
this.hasTilesetContent = false; | ||
if (tileHeader.contentUrl) { | ||
this.content = null; | ||
this.hasEmptyContent = false; | ||
} | ||
} | ||
_initializeRenderingState(header) { | ||
this.depth = header.level; | ||
this._shouldRefine = false; | ||
this._distanceToCamera = 0; | ||
this._centerZDepth = 0; | ||
this._screenSpaceError = 0; | ||
this._visibilityPlaneMask = _culling.CullingVolume.MASK_INDETERMINATE; | ||
this._visible = false; | ||
this._inRequestVolume = false; | ||
this._stackLength = 0; | ||
this._selectionDepth = 0; | ||
this._frameNumber = 0; | ||
this._touchedFrame = 0; | ||
this._visitedFrame = 0; | ||
this._selectedFrame = 0; | ||
this._requestedFrame = 0; | ||
this._priority = 0.0; | ||
} | ||
if (this.header.content && this.header.content.destroy) { | ||
this.header.content.destroy(); | ||
} | ||
_getRefine(refine) { | ||
return refine || this.parent && this.parent.refine || _constants.TILE_REFINEMENT.REPLACE; | ||
} | ||
this.header.content = null; | ||
this.contentState = _constants.TILE_CONTENT_STATE.UNLOADED; | ||
return true; | ||
} | ||
}, { | ||
key: "updateVisibility", | ||
value: function updateVisibility(frameState) { | ||
if (this._frameNumber === frameState.frameNumber) { | ||
return; | ||
} | ||
_isTileset() { | ||
return this.contentUrl.indexOf('.json') !== -1; | ||
} | ||
var parent = this.parent; | ||
var parentTransform = parent ? parent.computedTransform : this.tileset.modelMatrix; | ||
var parentVisibilityPlaneMask = parent ? parent._visibilityPlaneMask : _culling.CullingVolume.MASK_INDETERMINATE; | ||
_onContentLoaded() { | ||
switch (this.content && this.content.type) { | ||
case 'vctr': | ||
case 'geom': | ||
this.tileset.traverser.disableSkipLevelOfDetail = true; | ||
break; | ||
this._updateTransform(parentTransform); | ||
default: | ||
this._distanceToCamera = this.distanceToTile(frameState); | ||
this._screenSpaceError = this.getScreenSpaceError(frameState, false); | ||
this._visibilityPlaneMask = this.visibility(frameState, parentVisibilityPlaneMask); | ||
this._visible = this._visibilityPlaneMask !== _culling.CullingVolume.MASK_OUTSIDE; | ||
this._inRequestVolume = this.insideViewerRequestVolume(frameState); | ||
this._priority = this.lodMetricValue; | ||
this._frameNumber = frameState.frameNumber; | ||
} | ||
}, { | ||
key: "visibility", | ||
value: function visibility(frameState, parentVisibilityPlaneMask) { | ||
var cullingVolume = frameState.cullingVolume; | ||
var boundingVolume = this.boundingVolume; | ||
return cullingVolume.computeVisibilityWithPlaneMask(boundingVolume, parentVisibilityPlaneMask); | ||
} | ||
}, { | ||
key: "contentVisibility", | ||
value: function contentVisibility(frameState) { | ||
return true; | ||
} | ||
}, { | ||
key: "distanceToTile", | ||
value: function distanceToTile(frameState) { | ||
var boundingVolume = this.boundingVolume; | ||
return Math.sqrt(Math.max(boundingVolume.distanceSquaredTo(frameState.camera.position), 0)); | ||
} | ||
}, { | ||
key: "cameraSpaceZDepth", | ||
value: function cameraSpaceZDepth(_ref) { | ||
var camera = _ref.camera; | ||
var boundingVolume = this.boundingVolume; | ||
scratchVector.subVectors(boundingVolume.center, camera.position); | ||
return camera.direction.dot(scratchVector); | ||
} | ||
}, { | ||
key: "insideViewerRequestVolume", | ||
value: function insideViewerRequestVolume(frameState) { | ||
var viewerRequestVolume = this._viewerRequestVolume; | ||
return !viewerRequestVolume || viewerRequestVolume.distanceToCamera(frameState.camera.position) === 0.0; | ||
} | ||
}, { | ||
key: "_initializeLodMetric", | ||
value: function _initializeLodMetric(header) { | ||
if ('lodMetricType' in header) { | ||
this.lodMetricType = header.lodMetricType; | ||
} else { | ||
this.lodMetricType = this.parent && this.parent.lodMetricType || this.tileset.lodMetricType; | ||
console.warn("3D Tile: Required prop lodMetricType is undefined. Using parent lodMetricType"); | ||
} | ||
if (this._isTileset()) { | ||
this.hasTilesetContent = true; | ||
if ('lodMetricValue' in header) { | ||
this.lodMetricValue = header.lodMetricValue; | ||
} else { | ||
this.lodMetricValue = this.parent && this.parent.lodMetricValue || this.tileset.lodMetricValue; | ||
console.warn("3D Tile: Required prop lodMetricValue is undefined. Using parent lodMetricValue"); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "_initializeTransforms", | ||
value: function _initializeTransforms(tileHeader) { | ||
this.transform = tileHeader.transform ? new _core.Matrix4(tileHeader.transform) : new _core.Matrix4(); | ||
var parent = this.parent; | ||
var tileset = this.tileset; | ||
var parentTransform = parent && parent.computedTransform ? parent.computedTransform.clone() : tileset.modelMatrix.clone(); | ||
this.computedTransform = new _core.Matrix4(parentTransform).multiplyRight(this.transform); | ||
var parentInitialTransform = parent && parent._initialTransform ? parent._initialTransform.clone() : new _core.Matrix4(); | ||
this._initialTransform = new _core.Matrix4(parentInitialTransform).multiplyRight(this.transform); | ||
} | ||
}, { | ||
key: "_initializeBoundingVolumes", | ||
value: function _initializeBoundingVolumes(tileHeader) { | ||
this._contentBoundingVolume = null; | ||
this._viewerRequestVolume = null; | ||
_updateBoundingVolume(header) { | ||
this.boundingVolume = (0, _boundingVolume.createBoundingVolume)(header.boundingVolume, this.computedTransform, this.boundingVolume); | ||
const content = header.content; | ||
if (!content) { | ||
return; | ||
this._updateBoundingVolume(tileHeader); | ||
} | ||
}, { | ||
key: "_initializeContent", | ||
value: function _initializeContent(tileHeader) { | ||
this.content = { | ||
_tileset: this.tileset, | ||
_tile: this | ||
}; | ||
this.hasEmptyContent = true; | ||
this.contentState = _constants.TILE_CONTENT_STATE.UNLOADED; | ||
this.hasTilesetContent = false; | ||
if (content.boundingVolume) { | ||
this._contentBoundingVolume = (0, _boundingVolume.createBoundingVolume)(content.boundingVolume, this.computedTransform, this._contentBoundingVolume); | ||
if (tileHeader.contentUrl) { | ||
this.content = null; | ||
this.hasEmptyContent = false; | ||
} | ||
} | ||
}, { | ||
key: "_initializeRenderingState", | ||
value: function _initializeRenderingState(header) { | ||
this.depth = header.level; | ||
this._shouldRefine = false; | ||
this._distanceToCamera = 0; | ||
this._centerZDepth = 0; | ||
this._screenSpaceError = 0; | ||
this._visibilityPlaneMask = _culling.CullingVolume.MASK_INDETERMINATE; | ||
this._visible = false; | ||
this._inRequestVolume = false; | ||
this._stackLength = 0; | ||
this._selectionDepth = 0; | ||
this._frameNumber = 0; | ||
this._touchedFrame = 0; | ||
this._visitedFrame = 0; | ||
this._selectedFrame = 0; | ||
this._requestedFrame = 0; | ||
this._priority = 0.0; | ||
} | ||
}, { | ||
key: "_getRefine", | ||
value: function _getRefine(refine) { | ||
return refine || this.parent && this.parent.refine || _constants.TILE_REFINEMENT.REPLACE; | ||
} | ||
}, { | ||
key: "_isTileset", | ||
value: function _isTileset() { | ||
return this.contentUrl.indexOf('.json') !== -1; | ||
} | ||
}, { | ||
key: "_onContentLoaded", | ||
value: function _onContentLoaded() { | ||
switch (this.content && this.content.type) { | ||
case 'vctr': | ||
case 'geom': | ||
this.tileset.traverser.disableSkipLevelOfDetail = true; | ||
break; | ||
if (header.viewerRequestVolume) { | ||
this._viewerRequestVolume = (0, _boundingVolume.createBoundingVolume)(header.viewerRequestVolume, this.computedTransform, this._viewerRequestVolume); | ||
default: | ||
} | ||
if (this._isTileset()) { | ||
this.hasTilesetContent = true; | ||
} | ||
} | ||
} | ||
}, { | ||
key: "_updateBoundingVolume", | ||
value: function _updateBoundingVolume(header) { | ||
this.boundingVolume = (0, _boundingVolume.createBoundingVolume)(header.boundingVolume, this.computedTransform, this.boundingVolume); | ||
var content = header.content; | ||
_updateTransform(parentTransform = new _core.Matrix4()) { | ||
const computedTransform = parentTransform.clone().multiplyRight(this.transform); | ||
const didTransformChange = !computedTransform.equals(this.computedTransform); | ||
if (!content) { | ||
return; | ||
} | ||
if (!didTransformChange) { | ||
return; | ||
if (content.boundingVolume) { | ||
this._contentBoundingVolume = (0, _boundingVolume.createBoundingVolume)(content.boundingVolume, this.computedTransform, this._contentBoundingVolume); | ||
} | ||
if (header.viewerRequestVolume) { | ||
this._viewerRequestVolume = (0, _boundingVolume.createBoundingVolume)(header.viewerRequestVolume, this.computedTransform, this._viewerRequestVolume); | ||
} | ||
} | ||
}, { | ||
key: "_updateTransform", | ||
value: function _updateTransform() { | ||
var parentTransform = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new _core.Matrix4(); | ||
var computedTransform = parentTransform.clone().multiplyRight(this.transform); | ||
var didTransformChange = !computedTransform.equals(this.computedTransform); | ||
this.computedTransform = computedTransform; | ||
if (!didTransformChange) { | ||
return; | ||
} | ||
this._updateBoundingVolume(this.header); | ||
} | ||
this.computedTransform = computedTransform; | ||
_getLoaderSpecificOptions(loaderId) { | ||
switch (loaderId) { | ||
case 'i3s': | ||
return { ...this.tileset.options.i3s, | ||
tile: this.header, | ||
tileset: this.tileset.tileset, | ||
isTileHeader: false | ||
}; | ||
this._updateBoundingVolume(this.header); | ||
} | ||
}, { | ||
key: "_getLoaderSpecificOptions", | ||
value: function _getLoaderSpecificOptions(loaderId) { | ||
switch (loaderId) { | ||
case 'i3s': | ||
return _objectSpread(_objectSpread({}, this.tileset.options.i3s), {}, { | ||
tile: this.header, | ||
tileset: this.tileset.tileset, | ||
isTileHeader: false | ||
}); | ||
case '3d-tiles': | ||
case 'cesium-ion': | ||
default: | ||
return (0, _dTilesOptions.get3dTilesOptions)(this.tileset.tileset); | ||
case '3d-tiles': | ||
case 'cesium-ion': | ||
default: | ||
return (0, _dTilesOptions.get3dTilesOptions)(this.tileset.tileset); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "updateExpiration", | ||
value: function updateExpiration() { | ||
if (defined(this._expireDate) && this.contentReady && !this.hasEmptyContent) { | ||
var now = Date.now(); | ||
updateExpiration() { | ||
if (defined(this._expireDate) && this.contentReady && !this.hasEmptyContent) { | ||
const now = Date.now(); | ||
if (Date.lessThan(this._expireDate, now)) { | ||
this.contentState = _constants.TILE_CONTENT_STATE.EXPIRED; | ||
this._expiredContent = this.content; | ||
if (Date.lessThan(this._expireDate, now)) { | ||
this.contentState = _constants.TILE_CONTENT_STATE.EXPIRED; | ||
this._expiredContent = this.content; | ||
} | ||
} | ||
} | ||
} | ||
}, { | ||
key: "extras", | ||
get: function get() { | ||
return this.header.extras; | ||
} | ||
}]); | ||
return TileHeader; | ||
}(); | ||
get extras() { | ||
return this.header.extras; | ||
} | ||
} | ||
exports.default = TileHeader; | ||
//# sourceMappingURL=tile-3d.js.map |
@@ -10,2 +10,12 @@ "use strict"; | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _core = require("@math.gl/core"); | ||
@@ -37,17 +47,28 @@ | ||
const TILES_TOTAL = 'Tiles In Tileset(s)'; | ||
const TILES_IN_MEMORY = 'Tiles In Memory'; | ||
const TILES_IN_VIEW = 'Tiles In View'; | ||
const TILES_RENDERABLE = 'Tiles To Render'; | ||
const TILES_LOADED = 'Tiles Loaded'; | ||
const TILES_LOADING = 'Tiles Loading'; | ||
const TILES_UNLOADED = 'Tiles Unloaded'; | ||
const TILES_LOAD_FAILED = 'Failed Tile Loads'; | ||
const POINTS_COUNT = 'Points'; | ||
const TILES_GPU_MEMORY = 'Tile Memory Use'; | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var TILES_TOTAL = 'Tiles In Tileset(s)'; | ||
var TILES_IN_MEMORY = 'Tiles In Memory'; | ||
var TILES_IN_VIEW = 'Tiles In View'; | ||
var TILES_RENDERABLE = 'Tiles To Render'; | ||
var TILES_LOADED = 'Tiles Loaded'; | ||
var TILES_LOADING = 'Tiles Loading'; | ||
var TILES_UNLOADED = 'Tiles Unloaded'; | ||
var TILES_LOAD_FAILED = 'Failed Tile Loads'; | ||
var POINTS_COUNT = 'Points'; | ||
var TILES_GPU_MEMORY = 'Tile Memory Use'; | ||
function getQueryParamString(queryParams) { | ||
const queryParamStrings = []; | ||
var queryParamStrings = []; | ||
for (const key of Object.keys(queryParams)) { | ||
for (var _i = 0, _Object$keys = Object.keys(queryParams); _i < _Object$keys.length; _i++) { | ||
var key = _Object$keys[_i]; | ||
queryParamStrings.push("".concat(key, "=").concat(queryParams[key])); | ||
@@ -68,3 +89,3 @@ } | ||
const DEFAULT_OPTIONS = { | ||
var DEFAULT_OPTIONS = { | ||
ellipsoid: _geospatial.Ellipsoid.WGS84, | ||
@@ -74,14 +95,14 @@ modelMatrix: new _core.Matrix4(), | ||
maximumMemoryUsage: 32, | ||
onTileLoad: () => {}, | ||
onTileUnload: () => {}, | ||
onTileError: (tile, message, url) => {}, | ||
onTileLoad: function onTileLoad() {}, | ||
onTileUnload: function onTileUnload() {}, | ||
onTileError: function onTileError(tile, message, url) {}, | ||
maximumScreenSpaceError: 8 | ||
}; | ||
class Tileset3D { | ||
constructor(json, options = {}) { | ||
var Tileset3D = function () { | ||
function Tileset3D(json) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
(0, _classCallCheck2.default)(this, Tileset3D); | ||
(0, _loaderUtils.assert)(json); | ||
this.options = { ...DEFAULT_OPTIONS, | ||
...options | ||
}; | ||
this.options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options); | ||
this.tileset = json; | ||
@@ -150,366 +171,504 @@ this.loader = json.loader; | ||
isLoaded() { | ||
return this._pendingCount === 0; | ||
} | ||
(0, _createClass2.default)(Tileset3D, [{ | ||
key: "isLoaded", | ||
value: function isLoaded() { | ||
return this._pendingCount === 0; | ||
} | ||
}, { | ||
key: "destroy", | ||
value: function destroy() { | ||
this._destroy(); | ||
} | ||
}, { | ||
key: "tiles", | ||
get: function get() { | ||
return Object.values(this._tiles); | ||
} | ||
}, { | ||
key: "getTileUrl", | ||
value: function getTileUrl(tilePath) { | ||
var isDataUrl = tilePath.startsWith('data:'); | ||
destroy() { | ||
this._destroy(); | ||
} | ||
if (isDataUrl) { | ||
return tilePath; | ||
} | ||
get tiles() { | ||
return Object.values(this._tiles); | ||
} | ||
return "".concat(tilePath).concat(this.queryParams); | ||
} | ||
}, { | ||
key: "update", | ||
value: function update(viewport) { | ||
this._cache.reset(); | ||
getTileUrl(tilePath) { | ||
const isDataUrl = tilePath.startsWith('data:'); | ||
this._frameNumber++; | ||
this._frameState = (0, _frameState.getFrameState)(viewport, this._frameNumber); | ||
if (isDataUrl) { | ||
return tilePath; | ||
this._traverser.traverse(this.root, this._frameState, this.options); | ||
} | ||
}, { | ||
key: "_onTraversalEnd", | ||
value: function _onTraversalEnd() { | ||
var selectedTiles = Object.values(this._traverser.selectedTiles); | ||
return "".concat(tilePath).concat(this.queryParams); | ||
} | ||
if (this._tilesChanged(this.selectedTiles, selectedTiles)) { | ||
this._updateFrameNumber++; | ||
} | ||
update(viewport) { | ||
this._cache.reset(); | ||
this.selectedTiles = selectedTiles; | ||
this._frameNumber++; | ||
this._frameState = (0, _frameState.getFrameState)(viewport, this._frameNumber); | ||
var _iterator = _createForOfIteratorHelper(this.selectedTiles), | ||
_step; | ||
this._traverser.traverse(this.root, this._frameState, this.options); | ||
} | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var tile = _step.value; | ||
this._tiles[tile.id] = tile; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
_onTraversalEnd() { | ||
const selectedTiles = Object.values(this._traverser.selectedTiles); | ||
this._requestedTiles = Object.values(this._traverser.requestedTiles); | ||
this._emptyTiles = Object.values(this._traverser.emptyTiles); | ||
if (this._tilesChanged(this.selectedTiles, selectedTiles)) { | ||
this._updateFrameNumber++; | ||
} | ||
this._loadTiles(this._frameState); | ||
this.selectedTiles = selectedTiles; | ||
this._unloadTiles(); | ||
for (const tile of this.selectedTiles) { | ||
this._tiles[tile.id] = tile; | ||
this._updateStats(); | ||
return this._updateFrameNumber; | ||
} | ||
}, { | ||
key: "_tilesChanged", | ||
value: function _tilesChanged(oldSelectedTiles, selectedTiles) { | ||
if (oldSelectedTiles.length !== selectedTiles.length) { | ||
return true; | ||
} | ||
this._requestedTiles = Object.values(this._traverser.requestedTiles); | ||
this._emptyTiles = Object.values(this._traverser.emptyTiles); | ||
this._loadTiles(this._frameState); | ||
this._unloadTiles(); | ||
this._updateStats(); | ||
return this._updateFrameNumber; | ||
} | ||
_tilesChanged(oldSelectedTiles, selectedTiles) { | ||
if (oldSelectedTiles.length !== selectedTiles.length) { | ||
return true; | ||
var set1 = new Set(oldSelectedTiles.map(function (t) { | ||
return t.id; | ||
})); | ||
var set2 = new Set(selectedTiles.map(function (t) { | ||
return t.id; | ||
})); | ||
var changed = oldSelectedTiles.filter(function (x) { | ||
return !set2.has(x.id); | ||
}).length > 0; | ||
changed = changed || selectedTiles.filter(function (x) { | ||
return !set1.has(x.id); | ||
}).length > 0; | ||
return changed; | ||
} | ||
}, { | ||
key: "_loadTiles", | ||
value: function _loadTiles(frameState) { | ||
var _iterator2 = _createForOfIteratorHelper(this._requestedTiles), | ||
_step2; | ||
const set1 = new Set(oldSelectedTiles.map(t => t.id)); | ||
const set2 = new Set(selectedTiles.map(t => t.id)); | ||
let changed = oldSelectedTiles.filter(x => !set2.has(x.id)).length > 0; | ||
changed = changed || selectedTiles.filter(x => !set1.has(x.id)).length > 0; | ||
return changed; | ||
} | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var tile = _step2.value; | ||
_loadTiles(frameState) { | ||
for (const tile of this._requestedTiles) { | ||
if (tile.contentUnloaded) { | ||
this._loadTile(tile, frameState); | ||
if (tile.contentUnloaded) { | ||
this._loadTile(tile, frameState); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "_unloadTiles", | ||
value: function _unloadTiles() { | ||
this._cache.unloadTiles(this, function (tileset, tile) { | ||
return tileset._unloadTile(tile); | ||
}); | ||
} | ||
}, { | ||
key: "_updateStats", | ||
value: function _updateStats() { | ||
var tilesRenderable = 0; | ||
var pointsRenderable = 0; | ||
_unloadTiles() { | ||
this._cache.unloadTiles(this, (tileset, tile) => tileset._unloadTile(tile)); | ||
} | ||
var _iterator3 = _createForOfIteratorHelper(this.selectedTiles), | ||
_step3; | ||
_updateStats() { | ||
let tilesRenderable = 0; | ||
let pointsRenderable = 0; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var tile = _step3.value; | ||
for (const tile of this.selectedTiles) { | ||
if (tile.contentAvailable) { | ||
tilesRenderable++; | ||
if (tile.contentAvailable) { | ||
tilesRenderable++; | ||
if (tile.content.pointCount) { | ||
pointsRenderable += tile.content.pointCount; | ||
if (tile.content.pointCount) { | ||
pointsRenderable += tile.content.pointCount; | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
} | ||
this.stats.get(TILES_IN_VIEW).count = this.selectedTiles.length; | ||
this.stats.get(TILES_RENDERABLE).count = tilesRenderable; | ||
this.stats.get(POINTS_COUNT).count = pointsRenderable; | ||
} | ||
}, { | ||
key: "_initializeTileSet", | ||
value: function _initializeTileSet(tilesetJson) { | ||
this.root = this._initializeTileHeaders(tilesetJson, null, this.basePath); | ||
this.stats.get(TILES_IN_VIEW).count = this.selectedTiles.length; | ||
this.stats.get(TILES_RENDERABLE).count = tilesRenderable; | ||
this.stats.get(POINTS_COUNT).count = pointsRenderable; | ||
} | ||
if (this.type === _constants.TILESET_TYPE.TILES3D) { | ||
this._initializeCesiumTileset(tilesetJson); | ||
} | ||
_initializeTileSet(tilesetJson) { | ||
this.root = this._initializeTileHeaders(tilesetJson, null, this.basePath); | ||
if (this.type === _constants.TILESET_TYPE.I3S) { | ||
this._initializeI3STileset(tilesetJson); | ||
} | ||
if (this.type === _constants.TILESET_TYPE.TILES3D) { | ||
this._initializeCesiumTileset(tilesetJson); | ||
this._calculateViewProps(); | ||
} | ||
}, { | ||
key: "_calculateViewProps", | ||
value: function _calculateViewProps() { | ||
var root = this.root; | ||
var center = root.boundingVolume.center; | ||
if (this.type === _constants.TILESET_TYPE.I3S) { | ||
this._initializeI3STileset(tilesetJson); | ||
} | ||
if (!center) { | ||
console.warn('center was not pre-calculated for the root tile'); | ||
this.cartographicCenter = new _core.Vector3(); | ||
this.zoom = 1; | ||
return; | ||
} | ||
this._calculateViewProps(); | ||
} | ||
_calculateViewProps() { | ||
const root = this.root; | ||
const { | ||
center | ||
} = root.boundingVolume; | ||
if (!center) { | ||
console.warn('center was not pre-calculated for the root tile'); | ||
this.cartographicCenter = new _core.Vector3(); | ||
this.zoom = 1; | ||
return; | ||
this.cartographicCenter = _geospatial.Ellipsoid.WGS84.cartesianToCartographic(center, new _core.Vector3()); | ||
this.cartesianCenter = center; | ||
this.zoom = (0, _zoom.getZoomFromBoundingVolume)(root.boundingVolume); | ||
} | ||
}, { | ||
key: "_initializeStats", | ||
value: function _initializeStats() { | ||
this.stats.get(TILES_TOTAL); | ||
this.stats.get(TILES_LOADING); | ||
this.stats.get(TILES_IN_MEMORY); | ||
this.stats.get(TILES_IN_VIEW); | ||
this.stats.get(TILES_RENDERABLE); | ||
this.stats.get(TILES_LOADED); | ||
this.stats.get(TILES_UNLOADED); | ||
this.stats.get(TILES_LOAD_FAILED); | ||
this.stats.get(POINTS_COUNT, 'memory'); | ||
this.stats.get(TILES_GPU_MEMORY, 'memory'); | ||
} | ||
}, { | ||
key: "_initializeTileHeaders", | ||
value: function _initializeTileHeaders(tilesetJson, parentTileHeader, basePath) { | ||
var rootTile = new _tile3d.default(this, tilesetJson.root, parentTileHeader, basePath); | ||
this.cartographicCenter = _geospatial.Ellipsoid.WGS84.cartesianToCartographic(center, new _core.Vector3()); | ||
this.cartesianCenter = center; | ||
this.zoom = (0, _zoom.getZoomFromBoundingVolume)(root.boundingVolume); | ||
} | ||
if (parentTileHeader) { | ||
parentTileHeader.children.push(rootTile); | ||
rootTile.depth = parentTileHeader.depth + 1; | ||
} | ||
_initializeStats() { | ||
this.stats.get(TILES_TOTAL); | ||
this.stats.get(TILES_LOADING); | ||
this.stats.get(TILES_IN_MEMORY); | ||
this.stats.get(TILES_IN_VIEW); | ||
this.stats.get(TILES_RENDERABLE); | ||
this.stats.get(TILES_LOADED); | ||
this.stats.get(TILES_UNLOADED); | ||
this.stats.get(TILES_LOAD_FAILED); | ||
this.stats.get(POINTS_COUNT, 'memory'); | ||
this.stats.get(TILES_GPU_MEMORY, 'memory'); | ||
} | ||
if (this.type === _constants.TILESET_TYPE.TILES3D) { | ||
var stack = []; | ||
stack.push(rootTile); | ||
_initializeTileHeaders(tilesetJson, parentTileHeader, basePath) { | ||
const rootTile = new _tile3d.default(this, tilesetJson.root, parentTileHeader, basePath); | ||
while (stack.length > 0) { | ||
var tile = stack.pop(); | ||
this.stats.get(TILES_TOTAL).incrementCount(); | ||
var children = tile.header.children || []; | ||
if (parentTileHeader) { | ||
parentTileHeader.children.push(rootTile); | ||
rootTile.depth = parentTileHeader.depth + 1; | ||
} | ||
var _iterator4 = _createForOfIteratorHelper(children), | ||
_step4; | ||
if (this.type === _constants.TILESET_TYPE.TILES3D) { | ||
const stack = []; | ||
stack.push(rootTile); | ||
while (stack.length > 0) { | ||
const tile = stack.pop(); | ||
this.stats.get(TILES_TOTAL).incrementCount(); | ||
const children = tile.header.children || []; | ||
for (const childHeader of children) { | ||
const childTile = new _tile3d.default(this, childHeader, tile, basePath); | ||
tile.children.push(childTile); | ||
childTile.depth = tile.depth + 1; | ||
stack.push(childTile); | ||
try { | ||
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { | ||
var childHeader = _step4.value; | ||
var childTile = new _tile3d.default(this, childHeader, tile, basePath); | ||
tile.children.push(childTile); | ||
childTile.depth = tile.depth + 1; | ||
stack.push(childTile); | ||
} | ||
} catch (err) { | ||
_iterator4.e(err); | ||
} finally { | ||
_iterator4.f(); | ||
} | ||
} | ||
} | ||
return rootTile; | ||
} | ||
}, { | ||
key: "_initializeTraverser", | ||
value: function _initializeTraverser() { | ||
var TraverserClass; | ||
var type = this.type; | ||
return rootTile; | ||
} | ||
switch (type) { | ||
case _constants.TILESET_TYPE.TILES3D: | ||
TraverserClass = _tileset3dTraverser.default; | ||
break; | ||
_initializeTraverser() { | ||
let TraverserClass; | ||
const type = this.type; | ||
case _constants.TILESET_TYPE.I3S: | ||
TraverserClass = _i3sTilsetTraverser.default; | ||
break; | ||
switch (type) { | ||
case _constants.TILESET_TYPE.TILES3D: | ||
TraverserClass = _tileset3dTraverser.default; | ||
break; | ||
default: | ||
TraverserClass = _tilesetTraverser.default; | ||
} | ||
case _constants.TILESET_TYPE.I3S: | ||
TraverserClass = _i3sTilsetTraverser.default; | ||
break; | ||
default: | ||
TraverserClass = _tilesetTraverser.default; | ||
return new TraverserClass({ | ||
basePath: this.basePath, | ||
onTraversalEnd: this._onTraversalEnd.bind(this) | ||
}); | ||
} | ||
}, { | ||
key: "_destroyTileHeaders", | ||
value: function _destroyTileHeaders(parentTile) { | ||
this._destroySubtree(parentTile); | ||
} | ||
}, { | ||
key: "_loadTile", | ||
value: function () { | ||
var _loadTile2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(tile, frameState) { | ||
var loaded; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.prev = 0; | ||
return new TraverserClass({ | ||
basePath: this.basePath, | ||
onTraversalEnd: this._onTraversalEnd.bind(this) | ||
}); | ||
} | ||
this._onStartTileLoading(); | ||
_destroyTileHeaders(parentTile) { | ||
this._destroySubtree(parentTile); | ||
} | ||
_context.next = 4; | ||
return tile.loadContent(frameState); | ||
async _loadTile(tile, frameState) { | ||
let loaded; | ||
case 4: | ||
loaded = _context.sent; | ||
_context.next = 10; | ||
break; | ||
try { | ||
this._onStartTileLoading(); | ||
case 7: | ||
_context.prev = 7; | ||
_context.t0 = _context["catch"](0); | ||
loaded = await tile.loadContent(frameState); | ||
} catch (error) { | ||
this._onTileLoadError(tile, error); | ||
} finally { | ||
this._onEndTileLoading(); | ||
this._onTileLoadError(tile, _context.t0); | ||
this._onTileLoad(tile, loaded); | ||
} | ||
} | ||
case 10: | ||
_context.prev = 10; | ||
_onTileLoadError(tile, error) { | ||
this.stats.get(TILES_LOAD_FAILED).incrementCount(); | ||
const message = error.message || error.toString(); | ||
const url = tile.url; | ||
console.error("A 3D tile failed to load: ".concat(tile.url, " ").concat(message)); | ||
this.options.onTileError(tile, message, url); | ||
} | ||
this._onEndTileLoading(); | ||
_onTileLoad(tile, loaded) { | ||
if (!loaded) { | ||
return; | ||
} | ||
this._onTileLoad(tile, loaded); | ||
if (tile && tile.content) { | ||
(0, _transformUtils.calculateTransformProps)(tile, tile.content); | ||
} | ||
return _context.finish(10); | ||
this._addTileToCache(tile); | ||
case 14: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this, [[0, 7, 10, 14]]); | ||
})); | ||
this.options.onTileLoad(tile); | ||
} | ||
function _loadTile(_x, _x2) { | ||
return _loadTile2.apply(this, arguments); | ||
} | ||
_onStartTileLoading() { | ||
this._pendingCount++; | ||
this.stats.get(TILES_LOADING).incrementCount(); | ||
} | ||
return _loadTile; | ||
}() | ||
}, { | ||
key: "_onTileLoadError", | ||
value: function _onTileLoadError(tile, error) { | ||
this.stats.get(TILES_LOAD_FAILED).incrementCount(); | ||
var message = error.message || error.toString(); | ||
var url = tile.url; | ||
console.error("A 3D tile failed to load: ".concat(tile.url, " ").concat(message)); | ||
this.options.onTileError(tile, message, url); | ||
} | ||
}, { | ||
key: "_onTileLoad", | ||
value: function _onTileLoad(tile, loaded) { | ||
if (!loaded) { | ||
return; | ||
} | ||
_onEndTileLoading() { | ||
this._pendingCount--; | ||
this.stats.get(TILES_LOADING).decrementCount(); | ||
} | ||
if (tile && tile.content) { | ||
(0, _transformUtils.calculateTransformProps)(tile, tile.content); | ||
} | ||
_addTileToCache(tile) { | ||
this._cache.add(this, tile, tileset => tileset._updateCacheStats(tile)); | ||
} | ||
this._addTileToCache(tile); | ||
_updateCacheStats(tile) { | ||
this.stats.get(TILES_LOADED).incrementCount(); | ||
this.stats.get(TILES_IN_MEMORY).incrementCount(); | ||
this.gpuMemoryUsageInBytes += tile.content.byteLength || 0; | ||
this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes; | ||
} | ||
this.options.onTileLoad(tile); | ||
} | ||
}, { | ||
key: "_onStartTileLoading", | ||
value: function _onStartTileLoading() { | ||
this._pendingCount++; | ||
this.stats.get(TILES_LOADING).incrementCount(); | ||
} | ||
}, { | ||
key: "_onEndTileLoading", | ||
value: function _onEndTileLoading() { | ||
this._pendingCount--; | ||
this.stats.get(TILES_LOADING).decrementCount(); | ||
} | ||
}, { | ||
key: "_addTileToCache", | ||
value: function _addTileToCache(tile) { | ||
this._cache.add(this, tile, function (tileset) { | ||
return tileset._updateCacheStats(tile); | ||
}); | ||
} | ||
}, { | ||
key: "_updateCacheStats", | ||
value: function _updateCacheStats(tile) { | ||
this.stats.get(TILES_LOADED).incrementCount(); | ||
this.stats.get(TILES_IN_MEMORY).incrementCount(); | ||
this.gpuMemoryUsageInBytes += tile.content.byteLength || 0; | ||
this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes; | ||
} | ||
}, { | ||
key: "_unloadTile", | ||
value: function _unloadTile(tile) { | ||
this.gpuMemoryUsageInBytes -= tile.content.byteLength || 0; | ||
this.stats.get(TILES_IN_MEMORY).decrementCount(); | ||
this.stats.get(TILES_UNLOADED).incrementCount(); | ||
this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes; | ||
this.options.onTileUnload(tile); | ||
tile.unloadContent(); | ||
} | ||
}, { | ||
key: "_destroy", | ||
value: function _destroy() { | ||
var stack = []; | ||
_unloadTile(tile) { | ||
this.gpuMemoryUsageInBytes -= tile.content.byteLength || 0; | ||
this.stats.get(TILES_IN_MEMORY).decrementCount(); | ||
this.stats.get(TILES_UNLOADED).incrementCount(); | ||
this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes; | ||
this.options.onTileUnload(tile); | ||
tile.unloadContent(); | ||
} | ||
if (this.root) { | ||
stack.push(this.root); | ||
} | ||
_destroy() { | ||
const stack = []; | ||
while (stack.length > 0) { | ||
var tile = stack.pop(); | ||
if (this.root) { | ||
stack.push(this.root); | ||
} | ||
var _iterator5 = _createForOfIteratorHelper(tile.children), | ||
_step5; | ||
while (stack.length > 0) { | ||
const tile = stack.pop(); | ||
try { | ||
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { | ||
var child = _step5.value; | ||
stack.push(child); | ||
} | ||
} catch (err) { | ||
_iterator5.e(err); | ||
} finally { | ||
_iterator5.f(); | ||
} | ||
for (const child of tile.children) { | ||
stack.push(child); | ||
this._destroyTile(tile); | ||
} | ||
this._destroyTile(tile); | ||
this.root = null; | ||
} | ||
}, { | ||
key: "_destroySubtree", | ||
value: function _destroySubtree(tile) { | ||
var root = tile; | ||
var stack = []; | ||
stack.push(root); | ||
this.root = null; | ||
} | ||
while (stack.length > 0) { | ||
tile = stack.pop(); | ||
_destroySubtree(tile) { | ||
const root = tile; | ||
const stack = []; | ||
stack.push(root); | ||
var _iterator6 = _createForOfIteratorHelper(tile.children), | ||
_step6; | ||
while (stack.length > 0) { | ||
tile = stack.pop(); | ||
try { | ||
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { | ||
var child = _step6.value; | ||
stack.push(child); | ||
} | ||
} catch (err) { | ||
_iterator6.e(err); | ||
} finally { | ||
_iterator6.f(); | ||
} | ||
for (const child of tile.children) { | ||
stack.push(child); | ||
if (tile !== root) { | ||
this._destroyTile(tile); | ||
} | ||
} | ||
if (tile !== root) { | ||
this._destroyTile(tile); | ||
} | ||
root.children = []; | ||
} | ||
}, { | ||
key: "_destroyTile", | ||
value: function _destroyTile(tile) { | ||
this._cache.unloadTile(this, tile); | ||
root.children = []; | ||
} | ||
this._unloadTile(tile); | ||
_destroyTile(tile) { | ||
this._cache.unloadTile(this, tile); | ||
tile.destroy(); | ||
} | ||
}, { | ||
key: "_initializeCesiumTileset", | ||
value: function _initializeCesiumTileset(tilesetJson) { | ||
this.asset = tilesetJson.asset; | ||
this._unloadTile(tile); | ||
if (!this.asset) { | ||
throw new Error('Tileset must have an asset property.'); | ||
} | ||
tile.destroy(); | ||
} | ||
if (this.asset.version !== '0.0' && this.asset.version !== '1.0') { | ||
throw new Error('The tileset must be 3D Tiles version 0.0 or 1.0.'); | ||
} | ||
_initializeCesiumTileset(tilesetJson) { | ||
this.asset = tilesetJson.asset; | ||
if ('tilesetVersion' in this.asset) { | ||
this._queryParams.v = this.asset.tilesetVersion; | ||
} | ||
if (!this.asset) { | ||
throw new Error('Tileset must have an asset property.'); | ||
this.credits = { | ||
attributions: this.options.attributions || [] | ||
}; | ||
this.description = this.options.description; | ||
this.properties = tilesetJson.properties; | ||
this.geometricError = tilesetJson.geometricError; | ||
this._extensionsUsed = tilesetJson.extensionsUsed; | ||
this.extras = tilesetJson.extras; | ||
} | ||
}, { | ||
key: "_initializeI3STileset", | ||
value: function _initializeI3STileset(tilesetJson) { | ||
if ('token' in this.options) { | ||
this._queryParams.token = this.options.token; | ||
} | ||
if (this.asset.version !== '0.0' && this.asset.version !== '1.0') { | ||
throw new Error('The tileset must be 3D Tiles version 0.0 or 1.0.'); | ||
this._defaultGeometrySchema = tilesetJson.store.defaultGeometrySchema; | ||
} | ||
if ('tilesetVersion' in this.asset) { | ||
this._queryParams.v = this.asset.tilesetVersion; | ||
}, { | ||
key: "hasExtension", | ||
value: function hasExtension(extensionName) { | ||
return Boolean(this._extensionsUsed && this._extensionsUsed.indexOf(extensionName) > -1); | ||
} | ||
}, { | ||
key: "queryParams", | ||
get: function get() { | ||
if (!this._queryParamsString) { | ||
this._queryParamsString = getQueryParamString(this._queryParams); | ||
} | ||
this.credits = { | ||
attributions: this.options.attributions || [] | ||
}; | ||
this.description = this.options.description; | ||
this.properties = tilesetJson.properties; | ||
this.geometricError = tilesetJson.geometricError; | ||
this._extensionsUsed = tilesetJson.extensionsUsed; | ||
this.extras = tilesetJson.extras; | ||
} | ||
_initializeI3STileset(tilesetJson) { | ||
if ('token' in this.options) { | ||
this._queryParams.token = this.options.token; | ||
return this._queryParamsString; | ||
} | ||
}]); | ||
return Tileset3D; | ||
}(); | ||
this._defaultGeometrySchema = tilesetJson.store.defaultGeometrySchema; | ||
} | ||
hasExtension(extensionName) { | ||
return Boolean(this._extensionsUsed && this._extensionsUsed.indexOf(extensionName) > -1); | ||
} | ||
get queryParams() { | ||
if (!this._queryParamsString) { | ||
this._queryParamsString = getQueryParamString(this._queryParams); | ||
} | ||
return this._queryParamsString; | ||
} | ||
} | ||
exports.default = Tileset3D; | ||
//# sourceMappingURL=tileset-3d.js.map |
@@ -10,2 +10,6 @@ "use strict"; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _doublyLinkedList = _interopRequireDefault(require("../utils/doubly-linked-list")); | ||
@@ -17,4 +21,5 @@ | ||
class TilesetCache { | ||
constructor() { | ||
var TilesetCache = function () { | ||
function TilesetCache() { | ||
(0, _classCallCheck2.default)(this, TilesetCache); | ||
this._list = new _doublyLinkedList.default(); | ||
@@ -25,62 +30,70 @@ this._sentinel = this._list.add('sentinel'); | ||
reset() { | ||
this._list.splice(this._list.tail, this._sentinel); | ||
} | ||
(0, _createClass2.default)(TilesetCache, [{ | ||
key: "reset", | ||
value: function reset() { | ||
this._list.splice(this._list.tail, this._sentinel); | ||
} | ||
}, { | ||
key: "touch", | ||
value: function touch(tile) { | ||
var node = tile._cacheNode; | ||
touch(tile) { | ||
const node = tile._cacheNode; | ||
if (defined(node)) { | ||
this._list.splice(this._sentinel, node); | ||
if (defined(node)) { | ||
this._list.splice(this._sentinel, node); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "add", | ||
value: function add(tileset, tile, addCallback) { | ||
if (!defined(tile._cacheNode)) { | ||
tile._cacheNode = this._list.add(tile); | ||
add(tileset, tile, addCallback) { | ||
if (!defined(tile._cacheNode)) { | ||
tile._cacheNode = this._list.add(tile); | ||
if (addCallback) { | ||
addCallback(tileset, tile); | ||
if (addCallback) { | ||
addCallback(tileset, tile); | ||
} | ||
} | ||
} | ||
} | ||
}, { | ||
key: "unloadTile", | ||
value: function unloadTile(tileset, tile, unloadCallback) { | ||
var node = tile._cacheNode; | ||
unloadTile(tileset, tile, unloadCallback) { | ||
const node = tile._cacheNode; | ||
if (!defined(node)) { | ||
return; | ||
} | ||
if (!defined(node)) { | ||
return; | ||
} | ||
this._list.remove(node); | ||
this._list.remove(node); | ||
tile._cacheNode = undefined; | ||
tile._cacheNode = undefined; | ||
if (unloadCallback) { | ||
unloadCallback(tileset, tile); | ||
if (unloadCallback) { | ||
unloadCallback(tileset, tile); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "unloadTiles", | ||
value: function unloadTiles(tileset, unloadCallback) { | ||
var trimTiles = this._trimTiles; | ||
this._trimTiles = false; | ||
var list = this._list; | ||
var maximumMemoryUsageInBytes = tileset.maximumMemoryUsage * 1024 * 1024; | ||
var sentinel = this._sentinel; | ||
var node = list.head; | ||
unloadTiles(tileset, unloadCallback) { | ||
const trimTiles = this._trimTiles; | ||
this._trimTiles = false; | ||
const list = this._list; | ||
const maximumMemoryUsageInBytes = tileset.maximumMemoryUsage * 1024 * 1024; | ||
const sentinel = this._sentinel; | ||
let node = list.head; | ||
while (node !== sentinel && (tileset.gpuMemoryUsageInBytes > maximumMemoryUsageInBytes || trimTiles)) { | ||
const tile = node.item; | ||
node = node.next; | ||
this.unloadTile(tileset, tile, unloadCallback); | ||
while (node !== sentinel && (tileset.gpuMemoryUsageInBytes > maximumMemoryUsageInBytes || trimTiles)) { | ||
var tile = node.item; | ||
node = node.next; | ||
this.unloadTile(tileset, tile, unloadCallback); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "trim", | ||
value: function trim() { | ||
this._trimTiles = true; | ||
} | ||
}]); | ||
return TilesetCache; | ||
}(); | ||
trim() { | ||
this._trimTiles = true; | ||
} | ||
} | ||
exports.default = TilesetCache; | ||
//# sourceMappingURL=tileset-cache.js.map |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -7,3 +9,8 @@ value: true | ||
exports.default = void 0; | ||
const STATUS = { | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var STATUS = { | ||
REQUESTED: 'REQUESTED', | ||
@@ -14,40 +21,48 @@ COMPLETED: 'COMPLETED', | ||
class I3STileManager { | ||
constructor() { | ||
var I3STileManager = function () { | ||
function I3STileManager() { | ||
(0, _classCallCheck2.default)(this, I3STileManager); | ||
this._statusMap = {}; | ||
} | ||
add(request, key, callback, frameState) { | ||
if (!this._statusMap[key]) { | ||
this._statusMap[key] = { | ||
request, | ||
callback, | ||
key, | ||
frameState, | ||
status: STATUS.REQUESTED | ||
}; | ||
request().then(data => { | ||
this._statusMap[key].status = STATUS.COMPLETED; | ||
(0, _createClass2.default)(I3STileManager, [{ | ||
key: "add", | ||
value: function add(request, key, callback, frameState) { | ||
var _this = this; | ||
this._statusMap[key].callback(data, frameState); | ||
}).catch(error => { | ||
this._statusMap[key].status = STATUS.ERROR; | ||
callback(error); | ||
}); | ||
} | ||
} | ||
if (!this._statusMap[key]) { | ||
this._statusMap[key] = { | ||
request: request, | ||
callback: callback, | ||
key: key, | ||
frameState: frameState, | ||
status: STATUS.REQUESTED | ||
}; | ||
request().then(function (data) { | ||
_this._statusMap[key].status = STATUS.COMPLETED; | ||
update(key, frameState) { | ||
if (this._statusMap[key]) { | ||
this._statusMap[key].frameState = frameState; | ||
_this._statusMap[key].callback(data, frameState); | ||
}).catch(function (error) { | ||
_this._statusMap[key].status = STATUS.ERROR; | ||
callback(error); | ||
}); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "update", | ||
value: function update(key, frameState) { | ||
if (this._statusMap[key]) { | ||
this._statusMap[key].frameState = frameState; | ||
} | ||
} | ||
}, { | ||
key: "find", | ||
value: function find(key) { | ||
return this._statusMap[key]; | ||
} | ||
}]); | ||
return I3STileManager; | ||
}(); | ||
find(key) { | ||
return this._statusMap[key]; | ||
} | ||
} | ||
exports.default = I3STileManager; | ||
//# sourceMappingURL=i3s-tile-manager.js.map |
@@ -10,2 +10,18 @@ "use strict"; | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _core = require("@loaders.gl/core"); | ||
@@ -21,72 +37,146 @@ | ||
class I3STilesetTraverser extends _tilesetTraverser.default { | ||
constructor(options) { | ||
super(options); | ||
this._tileManager = new _i3sTileManager.default(); | ||
} | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
shouldRefine(tile, frameState) { | ||
tile._lodJudge = (0, _i3sLod.lodJudge)(tile, frameState); | ||
return tile._lodJudge === 'DIG'; | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
var I3STilesetTraverser = function (_TilesetTraverser) { | ||
(0, _inherits2.default)(I3STilesetTraverser, _TilesetTraverser); | ||
var _super = _createSuper(I3STilesetTraverser); | ||
function I3STilesetTraverser(options) { | ||
var _this; | ||
(0, _classCallCheck2.default)(this, I3STilesetTraverser); | ||
_this = _super.call(this, options); | ||
_this._tileManager = new _i3sTileManager.default(); | ||
return _this; | ||
} | ||
updateChildTiles(tile, frameState) { | ||
const children = tile.header.children || []; | ||
const childTiles = tile.children; | ||
const tileset = tile.tileset; | ||
(0, _createClass2.default)(I3STilesetTraverser, [{ | ||
key: "shouldRefine", | ||
value: function shouldRefine(tile, frameState) { | ||
tile._lodJudge = (0, _i3sLod.lodJudge)(tile, frameState); | ||
return tile._lodJudge === 'DIG'; | ||
} | ||
}, { | ||
key: "updateChildTiles", | ||
value: function updateChildTiles(tile, frameState) { | ||
var _this2 = this; | ||
for (const child of children) { | ||
const childTile = childTiles && childTiles.find(t => t.id === child.id); | ||
var children = tile.header.children || []; | ||
var childTiles = tile.children; | ||
var tileset = tile.tileset; | ||
if (!childTile) { | ||
let request = () => this._loadTile(child.id, tileset); | ||
var _iterator = _createForOfIteratorHelper(children), | ||
_step; | ||
const cachedRequest = this._tileManager.find(child.id); | ||
try { | ||
var _loop = function _loop() { | ||
var child = _step.value; | ||
var childTile = childTiles && childTiles.find(function (t) { | ||
return t.id === child.id; | ||
}); | ||
if (!cachedRequest) { | ||
if (tileset.tileset.nodePages) { | ||
request = () => tileset.tileset.nodePagesTile.formTileFromNodePages(child.id); | ||
if (!childTile) { | ||
var request = function request() { | ||
return _this2._loadTile(child.id, tileset); | ||
}; | ||
var cachedRequest = _this2._tileManager.find(child.id); | ||
if (!cachedRequest) { | ||
if (tileset.tileset.nodePages) { | ||
request = function request() { | ||
return tileset.tileset.nodePagesTile.formTileFromNodePages(child.id); | ||
}; | ||
} | ||
_this2._tileManager.add(request, child.id, function (header) { | ||
return _this2._onTileLoad(header, tile); | ||
}, frameState); | ||
} else { | ||
_this2._tileManager.update(child.id, frameState); | ||
} | ||
} else if (childTile) { | ||
_this2.updateTile(childTile, frameState); | ||
} | ||
}; | ||
this._tileManager.add(request, child.id, header => this._onTileLoad(header, tile), frameState); | ||
} else { | ||
this._tileManager.update(child.id, frameState); | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
_loop(); | ||
} | ||
} else if (childTile) { | ||
this.updateTile(childTile, frameState); | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "_loadTile", | ||
value: function () { | ||
var _loadTile2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(nodeId, tileset) { | ||
var loader, nodeUrl, options; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
loader = tileset.loader; | ||
nodeUrl = tileset.getTileUrl("".concat(tileset.url, "/nodes/").concat(nodeId)); | ||
options = { | ||
i3s: _objectSpread(_objectSpread({}, tileset.fetchOptions), {}, { | ||
isTileHeader: true, | ||
loadContent: false | ||
}) | ||
}; | ||
_context.next = 5; | ||
return (0, _core.load)(nodeUrl, loader, options); | ||
async _loadTile(nodeId, tileset) { | ||
const { | ||
loader | ||
} = tileset; | ||
const nodeUrl = tileset.getTileUrl("".concat(tileset.url, "/nodes/").concat(nodeId)); | ||
const options = { | ||
i3s: { ...tileset.fetchOptions, | ||
isTileHeader: true, | ||
loadContent: false | ||
case 5: | ||
return _context.abrupt("return", _context.sent); | ||
case 6: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
function _loadTile(_x, _x2) { | ||
return _loadTile2.apply(this, arguments); | ||
} | ||
}; | ||
return await (0, _core.load)(nodeUrl, loader, options); | ||
} | ||
_onTileLoad(header, tile) { | ||
const basePath = this.options.basePath; | ||
const childTile = new _tile3d.default(tile.tileset, header, tile, basePath); | ||
tile.children.push(childTile); | ||
return _loadTile; | ||
}() | ||
}, { | ||
key: "_onTileLoad", | ||
value: function _onTileLoad(header, tile) { | ||
var basePath = this.options.basePath; | ||
var childTile = new _tile3d.default(tile.tileset, header, tile, basePath); | ||
tile.children.push(childTile); | ||
const frameState = this._tileManager.find(childTile.id).frameState; | ||
var frameState = this._tileManager.find(childTile.id).frameState; | ||
this.updateTile(childTile, frameState); | ||
this.updateTile(childTile, frameState); | ||
if (this._frameNumber === frameState.frameNumber) { | ||
this.executeTraversal(childTile, frameState); | ||
if (this._frameNumber === frameState.frameNumber) { | ||
this.executeTraversal(childTile, frameState); | ||
} | ||
} | ||
} | ||
}]); | ||
return I3STilesetTraverser; | ||
}(_tilesetTraverser.default); | ||
} | ||
exports.default = I3STilesetTraverser; | ||
//# sourceMappingURL=i3s-tilset-traverser.js.map |
@@ -10,2 +10,12 @@ "use strict"; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _constants = require("../../constants"); | ||
@@ -15,54 +25,70 @@ | ||
class Tileset3DTraverser extends _tilesetTraverser.default { | ||
compareDistanceToCamera(a, b) { | ||
return b._distanceToCamera === 0 && a._distanceToCamera === 0 ? b._centerZDepth - a._centerZDepth : b._distanceToCamera - a._distanceToCamera; | ||
} | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; } | ||
updateTileVisibility(tile, frameState) { | ||
tile.updateVisibility(frameState); | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
if (!tile.isVisibleAndInRequestVolume) { | ||
return; | ||
} | ||
var Tileset3DTraverser = function (_TilesetTraverser) { | ||
(0, _inherits2.default)(Tileset3DTraverser, _TilesetTraverser); | ||
const hasChildren = tile.children.length > 0; | ||
var _super = _createSuper(Tileset3DTraverser); | ||
if (tile.hasTilesetContent && hasChildren) { | ||
const firstChild = tile.children[0]; | ||
this.updateTileVisibility(firstChild, frameState); | ||
tile._visible = firstChild._visible; | ||
return; | ||
} | ||
function Tileset3DTraverser() { | ||
(0, _classCallCheck2.default)(this, Tileset3DTraverser); | ||
return _super.apply(this, arguments); | ||
} | ||
if (this.meetsScreenSpaceErrorEarly(tile, frameState)) { | ||
tile._visible = false; | ||
return; | ||
(0, _createClass2.default)(Tileset3DTraverser, [{ | ||
key: "compareDistanceToCamera", | ||
value: function compareDistanceToCamera(a, b) { | ||
return b._distanceToCamera === 0 && a._distanceToCamera === 0 ? b._centerZDepth - a._centerZDepth : b._distanceToCamera - a._distanceToCamera; | ||
} | ||
}, { | ||
key: "updateTileVisibility", | ||
value: function updateTileVisibility(tile, frameState) { | ||
tile.updateVisibility(frameState); | ||
const replace = tile.refine === _constants.TILE_REFINEMENT.REPLACE; | ||
const useOptimization = tile._optimChildrenWithinParent === _constants.TILE3D_OPTIMIZATION_HINT.USE_OPTIMIZATION; | ||
if (!tile.isVisibleAndInRequestVolume) { | ||
return; | ||
} | ||
if (replace && useOptimization && hasChildren) { | ||
if (!this.anyChildrenVisible(tile, frameState)) { | ||
var hasChildren = tile.children.length > 0; | ||
if (tile.hasTilesetContent && hasChildren) { | ||
var firstChild = tile.children[0]; | ||
this.updateTileVisibility(firstChild, frameState); | ||
tile._visible = firstChild._visible; | ||
return; | ||
} | ||
if (this.meetsScreenSpaceErrorEarly(tile, frameState)) { | ||
tile._visible = false; | ||
return; | ||
} | ||
} | ||
} | ||
meetsScreenSpaceErrorEarly(tile, frameState) { | ||
const { | ||
parent | ||
} = tile; | ||
var replace = tile.refine === _constants.TILE_REFINEMENT.REPLACE; | ||
var useOptimization = tile._optimChildrenWithinParent === _constants.TILE3D_OPTIMIZATION_HINT.USE_OPTIMIZATION; | ||
if (!parent || parent.hasTilesetContent || parent.refine !== _constants.TILE_REFINEMENT.ADD) { | ||
return false; | ||
if (replace && useOptimization && hasChildren) { | ||
if (!this.anyChildrenVisible(tile, frameState)) { | ||
tile._visible = false; | ||
return; | ||
} | ||
} | ||
} | ||
}, { | ||
key: "meetsScreenSpaceErrorEarly", | ||
value: function meetsScreenSpaceErrorEarly(tile, frameState) { | ||
var parent = tile.parent; | ||
return !this.shouldRefine(tile, frameState, true); | ||
} | ||
if (!parent || parent.hasTilesetContent || parent.refine !== _constants.TILE_REFINEMENT.ADD) { | ||
return false; | ||
} | ||
} | ||
return !this.shouldRefine(tile, frameState, true); | ||
} | ||
}]); | ||
return Tileset3DTraverser; | ||
}(_tilesetTraverser.default); | ||
exports.default = Tileset3DTraverser; | ||
//# sourceMappingURL=tileset-3d-traverser.js.map |
@@ -10,2 +10,8 @@ "use strict"; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _managedArray = _interopRequireDefault(require("../../utils/managed-array")); | ||
@@ -17,3 +23,13 @@ | ||
const DEFAULT_OPTIONS = { | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var DEFAULT_OPTIONS = { | ||
loadSiblings: false, | ||
@@ -25,7 +41,6 @@ skipLevelOfDetail: false, | ||
class TilesetTraverser { | ||
constructor(options) { | ||
this.options = { ...DEFAULT_OPTIONS, | ||
...options | ||
}; | ||
var TilesetTraverser = function () { | ||
function TilesetTraverser(options) { | ||
(0, _classCallCheck2.default)(this, TilesetTraverser); | ||
this.options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options); | ||
this._traversalStack = new _managedArray.default(); | ||
@@ -40,259 +55,319 @@ this._emptyTraversalStack = new _managedArray.default(); | ||
traverse(root, frameState, options) { | ||
this.root = root; | ||
this.options = { ...this.options, | ||
...options | ||
}; | ||
this.reset(); | ||
this.updateTile(root, frameState); | ||
this._frameNumber = frameState.frameNumber; | ||
this.executeTraversal(root, frameState); | ||
} | ||
(0, _createClass2.default)(TilesetTraverser, [{ | ||
key: "traverse", | ||
value: function traverse(root, frameState, options) { | ||
this.root = root; | ||
this.options = _objectSpread(_objectSpread({}, this.options), options); | ||
this.reset(); | ||
this.updateTile(root, frameState); | ||
this._frameNumber = frameState.frameNumber; | ||
this.executeTraversal(root, frameState); | ||
} | ||
}, { | ||
key: "reset", | ||
value: function reset() { | ||
this.requestedTiles = {}; | ||
this.selectedTiles = {}; | ||
this.emptyTiles = {}; | ||
reset() { | ||
this.requestedTiles = {}; | ||
this.selectedTiles = {}; | ||
this.emptyTiles = {}; | ||
this._traversalStack.reset(); | ||
this._traversalStack.reset(); | ||
this._emptyTraversalStack.reset(); | ||
} | ||
}, { | ||
key: "executeTraversal", | ||
value: function executeTraversal(root, frameState) { | ||
var stack = this._traversalStack; | ||
stack.push(root); | ||
this._emptyTraversalStack.reset(); | ||
} | ||
while (stack.length > 0) { | ||
var tile = stack.pop(); | ||
var shouldRefine = false; | ||
executeTraversal(root, frameState) { | ||
const stack = this._traversalStack; | ||
stack.push(root); | ||
if (this.canTraverse(tile, frameState)) { | ||
this.updateChildTiles(tile, frameState); | ||
shouldRefine = this.updateAndPushChildren(tile, frameState, stack); | ||
} | ||
while (stack.length > 0) { | ||
const tile = stack.pop(); | ||
let shouldRefine = false; | ||
var parent = tile.parent; | ||
var parentRefines = Boolean(!parent || parent._shouldRefine); | ||
var stoppedRefining = !shouldRefine; | ||
if (this.canTraverse(tile, frameState)) { | ||
this.updateChildTiles(tile, frameState); | ||
shouldRefine = this.updateAndPushChildren(tile, frameState, stack); | ||
} | ||
if (!tile.hasRenderContent) { | ||
this.emptyTiles[tile.id] = tile; | ||
this.loadTile(tile, frameState); | ||
const parent = tile.parent; | ||
const parentRefines = Boolean(!parent || parent._shouldRefine); | ||
const stoppedRefining = !shouldRefine; | ||
if (stoppedRefining) { | ||
this.selectTile(tile, frameState); | ||
} | ||
} else if (tile.refine === _constants.TILE_REFINEMENT.ADD) { | ||
this.loadTile(tile, frameState); | ||
this.selectTile(tile, frameState); | ||
} else if (tile.refine === _constants.TILE_REFINEMENT.REPLACE) { | ||
this.loadTile(tile, frameState); | ||
if (!tile.hasRenderContent) { | ||
this.emptyTiles[tile.id] = tile; | ||
this.loadTile(tile, frameState); | ||
if (stoppedRefining) { | ||
this.selectTile(tile, frameState); | ||
if (stoppedRefining) { | ||
this.selectTile(tile, frameState); | ||
} | ||
} | ||
} else if (tile.refine === _constants.TILE_REFINEMENT.ADD) { | ||
this.loadTile(tile, frameState); | ||
this.selectTile(tile, frameState); | ||
} else if (tile.refine === _constants.TILE_REFINEMENT.REPLACE) { | ||
this.loadTile(tile, frameState); | ||
if (stoppedRefining) { | ||
this.selectTile(tile, frameState); | ||
} | ||
this.touchTile(tile, frameState); | ||
tile._shouldRefine = shouldRefine && parentRefines; | ||
} | ||
this.touchTile(tile, frameState); | ||
tile._shouldRefine = shouldRefine && parentRefines; | ||
if (this.options.onTraversalEnd) { | ||
this.options.onTraversalEnd(frameState); | ||
} | ||
} | ||
}, { | ||
key: "updateChildTiles", | ||
value: function updateChildTiles(tile, frameState) { | ||
var children = tile.children; | ||
if (this.options.onTraversalEnd) { | ||
this.options.onTraversalEnd(frameState); | ||
} | ||
} | ||
var _iterator = _createForOfIteratorHelper(children), | ||
_step; | ||
updateChildTiles(tile, frameState) { | ||
const children = tile.children; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var child = _step.value; | ||
this.updateTile(child, frameState); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
for (const child of children) { | ||
this.updateTile(child, frameState); | ||
return true; | ||
} | ||
}, { | ||
key: "updateAndPushChildren", | ||
value: function updateAndPushChildren(tile, frameState, stack) { | ||
var _this$options = this.options, | ||
loadSiblings = _this$options.loadSiblings, | ||
skipLevelOfDetail = _this$options.skipLevelOfDetail; | ||
var children = tile.children; | ||
children.sort(this.compareDistanceToCamera); | ||
var checkRefines = !skipLevelOfDetail && tile.refine === _constants.TILE_REFINEMENT.REPLACE && tile.hasRenderContent; | ||
var hasVisibleChild = false; | ||
return true; | ||
} | ||
var _iterator2 = _createForOfIteratorHelper(children), | ||
_step2; | ||
updateAndPushChildren(tile, frameState, stack) { | ||
const { | ||
loadSiblings, | ||
skipLevelOfDetail | ||
} = this.options; | ||
const children = tile.children; | ||
children.sort(this.compareDistanceToCamera); | ||
const checkRefines = !skipLevelOfDetail && tile.refine === _constants.TILE_REFINEMENT.REPLACE && tile.hasRenderContent; | ||
let hasVisibleChild = false; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var child = _step2.value; | ||
for (const child of children) { | ||
if (child.isVisibleAndInRequestVolume) { | ||
if (stack.find(child)) { | ||
stack.delete(child); | ||
} | ||
if (child.isVisibleAndInRequestVolume) { | ||
if (stack.find(child)) { | ||
stack.delete(child); | ||
} | ||
stack.push(child); | ||
hasVisibleChild = true; | ||
} else if (checkRefines || loadSiblings) { | ||
this.loadTile(child, frameState); | ||
this.touchTile(child, frameState); | ||
} | ||
stack.push(child); | ||
hasVisibleChild = true; | ||
} else if (checkRefines || loadSiblings) { | ||
this.loadTile(child, frameState); | ||
this.touchTile(child, frameState); | ||
} | ||
if (checkRefines) { | ||
let childRefines; | ||
if (checkRefines) { | ||
var childRefines = void 0; | ||
if (!child._inRequestVolume) { | ||
childRefines = false; | ||
} else if (!child.hasRenderContent) { | ||
childRefines = this.executeEmptyTraversal(child, frameState); | ||
} else { | ||
childRefines = child.contentAvailable; | ||
} | ||
if (!child._inRequestVolume) { | ||
childRefines = false; | ||
} else if (!child.hasRenderContent) { | ||
childRefines = this.executeEmptyTraversal(child, frameState); | ||
} else { | ||
childRefines = child.contentAvailable; | ||
} | ||
if (!childRefines) { | ||
return childRefines; | ||
if (!childRefines) { | ||
return childRefines; | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
} | ||
return hasVisibleChild; | ||
} | ||
updateTile(tile, frameState) { | ||
this.updateTileVisibility(tile, frameState); | ||
} | ||
selectTile(tile, frameState) { | ||
if (this.shouldSelectTile(tile, frameState)) { | ||
tile._selectedFrame = frameState.frameNumber; | ||
this.selectedTiles[tile.id] = tile; | ||
return hasVisibleChild; | ||
} | ||
} | ||
}, { | ||
key: "updateTile", | ||
value: function updateTile(tile, frameState) { | ||
this.updateTileVisibility(tile, frameState); | ||
} | ||
}, { | ||
key: "selectTile", | ||
value: function selectTile(tile, frameState) { | ||
if (this.shouldSelectTile(tile, frameState)) { | ||
tile._selectedFrame = frameState.frameNumber; | ||
this.selectedTiles[tile.id] = tile; | ||
} | ||
} | ||
}, { | ||
key: "loadTile", | ||
value: function loadTile(tile, frameState) { | ||
if (this.shouldLoadTile(tile, frameState)) { | ||
tile._requestedFrame = frameState.frameNumber; | ||
tile._priority = this.getPriority(tile); | ||
this.requestedTiles[tile.id] = tile; | ||
} | ||
} | ||
}, { | ||
key: "touchTile", | ||
value: function touchTile(tile, frameState) { | ||
tile.tileset._cache.touch(tile); | ||
loadTile(tile, frameState) { | ||
if (this.shouldLoadTile(tile, frameState)) { | ||
tile._requestedFrame = frameState.frameNumber; | ||
tile._priority = this.getPriority(tile); | ||
this.requestedTiles[tile.id] = tile; | ||
tile._touchedFrame = frameState.frameNumber; | ||
} | ||
} | ||
}, { | ||
key: "canTraverse", | ||
value: function canTraverse(tile, frameState) { | ||
var useParentMetric = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var ignoreVisibility = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
touchTile(tile, frameState) { | ||
tile.tileset._cache.touch(tile); | ||
if (!ignoreVisibility && !tile.isVisibleAndInRequestVolume) { | ||
return false; | ||
} | ||
tile._touchedFrame = frameState.frameNumber; | ||
} | ||
if (!tile.hasChildren) { | ||
return false; | ||
} | ||
canTraverse(tile, frameState, useParentMetric = false, ignoreVisibility = false) { | ||
if (!ignoreVisibility && !tile.isVisibleAndInRequestVolume) { | ||
return false; | ||
} | ||
if (tile.hasTilesetContent) { | ||
return !tile.contentExpired; | ||
} | ||
if (!tile.hasChildren) { | ||
return false; | ||
return this.shouldRefine(tile, frameState, useParentMetric); | ||
} | ||
if (tile.hasTilesetContent) { | ||
return !tile.contentExpired; | ||
}, { | ||
key: "shouldLoadTile", | ||
value: function shouldLoadTile(tile, frameState) { | ||
return tile.hasUnloadedContent || tile.contentExpired; | ||
} | ||
}, { | ||
key: "shouldSelectTile", | ||
value: function shouldSelectTile(tile, frameState) { | ||
return tile.contentAvailable && !this.options.skipLevelOfDetail; | ||
} | ||
}, { | ||
key: "shouldRefine", | ||
value: function shouldRefine(tile, frameState, useParentMetric) { | ||
var screenSpaceError = tile._screenSpaceError; | ||
return this.shouldRefine(tile, frameState, useParentMetric); | ||
} | ||
if (useParentMetric) { | ||
screenSpaceError = tile.getScreenSpaceError(frameState, true); | ||
} | ||
shouldLoadTile(tile, frameState) { | ||
return tile.hasUnloadedContent || tile.contentExpired; | ||
} | ||
return screenSpaceError > this.options.maximumScreenSpaceError; | ||
} | ||
}, { | ||
key: "updateTileVisibility", | ||
value: function updateTileVisibility(tile, frameState) { | ||
tile.updateVisibility(frameState); | ||
} | ||
}, { | ||
key: "compareDistanceToCamera", | ||
value: function compareDistanceToCamera(b, a) { | ||
return b._distanceToCamera - a._distanceToCamera; | ||
} | ||
}, { | ||
key: "getPriority", | ||
value: function getPriority(tile) { | ||
var options = this.options; | ||
shouldSelectTile(tile, frameState) { | ||
return tile.contentAvailable && !this.options.skipLevelOfDetail; | ||
} | ||
switch (tile.refine) { | ||
case _constants.TILE_REFINEMENT.ADD: | ||
return tile._distanceToCamera; | ||
shouldRefine(tile, frameState, useParentMetric) { | ||
let screenSpaceError = tile._screenSpaceError; | ||
case _constants.TILE_REFINEMENT.REPLACE: | ||
var parent = tile.parent; | ||
var useParentScreenSpaceError = parent && (!options.skipLevelOfDetail || tile._screenSpaceError === 0.0 || parent.hasTilesetContent); | ||
var screenSpaceError = useParentScreenSpaceError ? parent._screenSpaceError : tile._screenSpaceError; | ||
var rootScreenSpaceError = this.root._screenSpaceError; | ||
return rootScreenSpaceError - screenSpaceError; | ||
if (useParentMetric) { | ||
screenSpaceError = tile.getScreenSpaceError(frameState, true); | ||
default: | ||
return (0, _loaderUtils.assert)(false); | ||
} | ||
} | ||
}, { | ||
key: "anyChildrenVisible", | ||
value: function anyChildrenVisible(tile, frameState) { | ||
var anyVisible = false; | ||
return screenSpaceError > this.options.maximumScreenSpaceError; | ||
} | ||
var _iterator3 = _createForOfIteratorHelper(tile.children), | ||
_step3; | ||
updateTileVisibility(tile, frameState) { | ||
tile.updateVisibility(frameState); | ||
} | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var child = _step3.value; | ||
child.updateVisibility(frameState); | ||
anyVisible = anyVisible || child.isVisibleAndInRequestVolume; | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
} | ||
compareDistanceToCamera(b, a) { | ||
return b._distanceToCamera - a._distanceToCamera; | ||
} | ||
getPriority(tile) { | ||
const { | ||
options | ||
} = this; | ||
switch (tile.refine) { | ||
case _constants.TILE_REFINEMENT.ADD: | ||
return tile._distanceToCamera; | ||
case _constants.TILE_REFINEMENT.REPLACE: | ||
const { | ||
parent | ||
} = tile; | ||
const useParentScreenSpaceError = parent && (!options.skipLevelOfDetail || tile._screenSpaceError === 0.0 || parent.hasTilesetContent); | ||
const screenSpaceError = useParentScreenSpaceError ? parent._screenSpaceError : tile._screenSpaceError; | ||
const rootScreenSpaceError = this.root._screenSpaceError; | ||
return rootScreenSpaceError - screenSpaceError; | ||
default: | ||
return (0, _loaderUtils.assert)(false); | ||
return anyVisible; | ||
} | ||
} | ||
}, { | ||
key: "executeEmptyTraversal", | ||
value: function executeEmptyTraversal(root, frameState) { | ||
var allDescendantsLoaded = true; | ||
var stack = this._emptyTraversalStack; | ||
anyChildrenVisible(tile, frameState) { | ||
let anyVisible = false; | ||
while (stack.length > 0) { | ||
var tile = stack.pop(); | ||
this.updateTile(tile, frameState); | ||
for (const child of tile.children) { | ||
child.updateVisibility(frameState); | ||
anyVisible = anyVisible || child.isVisibleAndInRequestVolume; | ||
} | ||
if (!tile.isVisibleAndInRequestVolume) { | ||
this.loadTile(tile, frameState); | ||
this.touchTile(tile, frameState); | ||
} | ||
return anyVisible; | ||
} | ||
var traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, true); | ||
executeEmptyTraversal(root, frameState) { | ||
let allDescendantsLoaded = true; | ||
const stack = this._emptyTraversalStack; | ||
if (!traverse && !tile.contentAvailable) { | ||
allDescendantsLoaded = false; | ||
} | ||
while (stack.length > 0) { | ||
const tile = stack.pop(); | ||
this.updateTile(tile, frameState); | ||
if (traverse) { | ||
var children = tile.children.filter(function (c) { | ||
return c; | ||
}); | ||
if (!tile.isVisibleAndInRequestVolume) { | ||
this.loadTile(tile, frameState); | ||
this.touchTile(tile, frameState); | ||
} | ||
var _iterator4 = _createForOfIteratorHelper(children), | ||
_step4; | ||
const traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, true); | ||
try { | ||
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { | ||
var child = _step4.value; | ||
if (!traverse && !tile.contentAvailable) { | ||
allDescendantsLoaded = false; | ||
} | ||
if (stack.find(child)) { | ||
stack.delete(child); | ||
} | ||
if (traverse) { | ||
const children = tile.children.filter(c => c); | ||
for (const child of children) { | ||
if (stack.find(child)) { | ||
stack.delete(child); | ||
stack.push(child); | ||
} | ||
} catch (err) { | ||
_iterator4.e(err); | ||
} finally { | ||
_iterator4.f(); | ||
} | ||
stack.push(child); | ||
} | ||
} | ||
return allDescendantsLoaded; | ||
} | ||
}]); | ||
return TilesetTraverser; | ||
}(); | ||
return allDescendantsLoaded; | ||
} | ||
} | ||
exports.default = TilesetTraverser; | ||
//# sourceMappingURL=tileset-traverser.js.map |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,12 +10,12 @@ value: true | ||
class DoublyLinkedListNode { | ||
constructor(item, previous, next) { | ||
this.item = item; | ||
this.previous = previous; | ||
this.next = next; | ||
} | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
} | ||
var DoublyLinkedListNode = function DoublyLinkedListNode(item, previous, next) { | ||
(0, _classCallCheck2.default)(this, DoublyLinkedListNode); | ||
this.item = item; | ||
this.previous = previous; | ||
this.next = next; | ||
}; | ||
exports.default = DoublyLinkedListNode; | ||
//# sourceMappingURL=doubly-linked-list-node.js.map |
@@ -10,6 +10,11 @@ "use strict"; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _doublyLinkedListNode = _interopRequireDefault(require("../utils/doubly-linked-list-node")); | ||
class DoublyLinkedList { | ||
constructor() { | ||
var DoublyLinkedList = function () { | ||
function DoublyLinkedList() { | ||
(0, _classCallCheck2.default)(this, DoublyLinkedList); | ||
this.head = null; | ||
@@ -20,73 +25,80 @@ this.tail = null; | ||
get length() { | ||
return this._length; | ||
} | ||
(0, _createClass2.default)(DoublyLinkedList, [{ | ||
key: "length", | ||
get: function get() { | ||
return this._length; | ||
} | ||
}, { | ||
key: "add", | ||
value: function add(item) { | ||
var node = new _doublyLinkedListNode.default(item, this.tail, null); | ||
add(item) { | ||
const node = new _doublyLinkedListNode.default(item, this.tail, null); | ||
if (this.tail) { | ||
this.tail.next = node; | ||
this.tail = node; | ||
} else { | ||
this.head = node; | ||
this.tail = node; | ||
} | ||
if (this.tail) { | ||
this.tail.next = node; | ||
this.tail = node; | ||
} else { | ||
this.head = node; | ||
this.tail = node; | ||
++this._length; | ||
return node; | ||
} | ||
}, { | ||
key: "remove", | ||
value: function remove(node) { | ||
if (!node) { | ||
return; | ||
} | ||
++this._length; | ||
return node; | ||
} | ||
if (node.previous && node.next) { | ||
node.previous.next = node.next; | ||
node.next.previous = node.previous; | ||
} else if (node.previous) { | ||
node.previous.next = null; | ||
this.tail = node.previous; | ||
} else if (node.next) { | ||
node.next.previous = null; | ||
this.head = node.next; | ||
} else { | ||
this.head = null; | ||
this.tail = null; | ||
} | ||
remove(node) { | ||
if (!node) { | ||
return; | ||
node.next = null; | ||
node.previous = null; | ||
--this._length; | ||
} | ||
}, { | ||
key: "splice", | ||
value: function splice(node, nextNode) { | ||
if (node === nextNode) { | ||
return; | ||
} | ||
if (node.previous && node.next) { | ||
node.previous.next = node.next; | ||
node.next.previous = node.previous; | ||
} else if (node.previous) { | ||
node.previous.next = null; | ||
this.tail = node.previous; | ||
} else if (node.next) { | ||
node.next.previous = null; | ||
this.head = node.next; | ||
} else { | ||
this.head = null; | ||
this.tail = null; | ||
} | ||
this.remove(nextNode); | ||
node.next = null; | ||
node.previous = null; | ||
--this._length; | ||
} | ||
splice(node, nextNode) { | ||
if (node === nextNode) { | ||
return; | ||
this._insert(node, nextNode); | ||
} | ||
}, { | ||
key: "_insert", | ||
value: function _insert(node, nextNode) { | ||
var oldNodeNext = node.next; | ||
node.next = nextNode; | ||
this.remove(nextNode); | ||
if (this.tail === node) { | ||
this.tail = nextNode; | ||
} else { | ||
oldNodeNext.previous = nextNode; | ||
} | ||
this._insert(node, nextNode); | ||
} | ||
_insert(node, nextNode) { | ||
const oldNodeNext = node.next; | ||
node.next = nextNode; | ||
if (this.tail === node) { | ||
this.tail = nextNode; | ||
} else { | ||
oldNodeNext.previous = nextNode; | ||
nextNode.next = oldNodeNext; | ||
nextNode.previous = node; | ||
++this._length; | ||
} | ||
}]); | ||
return DoublyLinkedList; | ||
}(); | ||
nextNode.next = oldNodeNext; | ||
nextNode.previous = node; | ||
++this._length; | ||
} | ||
} | ||
exports.default = DoublyLinkedList; | ||
//# sourceMappingURL=doubly-linked-list.js.map |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,6 +10,12 @@ value: true | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _loaderUtils = require("@loaders.gl/loader-utils"); | ||
class ManagedArray { | ||
constructor(length = 0) { | ||
var ManagedArray = function () { | ||
function ManagedArray() { | ||
var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
(0, _classCallCheck2.default)(this, ManagedArray); | ||
this._array = new Array(length); | ||
@@ -18,106 +26,120 @@ this._map = new Map(); | ||
get length() { | ||
return this._length; | ||
} | ||
(0, _createClass2.default)(ManagedArray, [{ | ||
key: "length", | ||
get: function get() { | ||
return this._length; | ||
}, | ||
set: function set(length) { | ||
this._length = length; | ||
set length(length) { | ||
this._length = length; | ||
if (length > this._array.length) { | ||
this._array.length = length; | ||
if (length > this._array.length) { | ||
this._array.length = length; | ||
} | ||
} | ||
} | ||
}, { | ||
key: "values", | ||
get: function get() { | ||
return this._array; | ||
} | ||
}, { | ||
key: "get", | ||
value: function get(index) { | ||
(0, _loaderUtils.assert)(index < this._array.length); | ||
return this._array[index]; | ||
} | ||
}, { | ||
key: "set", | ||
value: function set(index, element) { | ||
(0, _loaderUtils.assert)(index >= 0); | ||
get values() { | ||
return this._array; | ||
} | ||
if (index >= this.length) { | ||
this.length = index + 1; | ||
} | ||
get(index) { | ||
(0, _loaderUtils.assert)(index < this._array.length); | ||
return this._array[index]; | ||
} | ||
if (this._map.has(this._array[index])) { | ||
this._map.delete(this._array[index]); | ||
} | ||
set(index, element) { | ||
(0, _loaderUtils.assert)(index >= 0); | ||
this._array[index] = element; | ||
if (index >= this.length) { | ||
this.length = index + 1; | ||
this._map.set(element, index); | ||
} | ||
}, { | ||
key: "delete", | ||
value: function _delete(element) { | ||
var index = this._map.get(element); | ||
if (this._map.has(this._array[index])) { | ||
this._map.delete(this._array[index]); | ||
} | ||
if (index >= 0) { | ||
this._array.splice(index, 1); | ||
this._array[index] = element; | ||
this._map.delete(element); | ||
this._map.set(element, index); | ||
} | ||
this.length--; | ||
} | ||
} | ||
}, { | ||
key: "peek", | ||
value: function peek() { | ||
return this._array[this._length - 1]; | ||
} | ||
}, { | ||
key: "push", | ||
value: function push(element) { | ||
if (!this._map.has(element)) { | ||
var index = this.length++; | ||
this._array[index] = element; | ||
delete(element) { | ||
const index = this._map.get(element); | ||
this._map.set(element, index); | ||
} | ||
} | ||
}, { | ||
key: "pop", | ||
value: function pop() { | ||
var element = this._array[--this.length]; | ||
if (index >= 0) { | ||
this._array.splice(index, 1); | ||
this._map.delete(element); | ||
this.length--; | ||
return element; | ||
} | ||
} | ||
}, { | ||
key: "reserve", | ||
value: function reserve(length) { | ||
(0, _loaderUtils.assert)(length >= 0); | ||
peek() { | ||
return this._array[this._length - 1]; | ||
} | ||
push(element) { | ||
if (!this._map.has(element)) { | ||
const index = this.length++; | ||
this._array[index] = element; | ||
this._map.set(element, index); | ||
if (length > this._array.length) { | ||
this._array.length = length; | ||
} | ||
} | ||
} | ||
}, { | ||
key: "resize", | ||
value: function resize(length) { | ||
(0, _loaderUtils.assert)(length >= 0); | ||
this.length = length; | ||
} | ||
}, { | ||
key: "trim", | ||
value: function trim(length) { | ||
if (length === null || length === undefined) { | ||
length = this.length; | ||
} | ||
pop() { | ||
const element = this._array[--this.length]; | ||
this._map.delete(element); | ||
return element; | ||
} | ||
reserve(length) { | ||
(0, _loaderUtils.assert)(length >= 0); | ||
if (length > this._array.length) { | ||
this._array.length = length; | ||
} | ||
} | ||
resize(length) { | ||
(0, _loaderUtils.assert)(length >= 0); | ||
this.length = length; | ||
} | ||
trim(length) { | ||
if (length === null || length === undefined) { | ||
length = this.length; | ||
}, { | ||
key: "reset", | ||
value: function reset() { | ||
this._array = []; | ||
this._map = new Map(); | ||
this._length = 0; | ||
} | ||
}, { | ||
key: "find", | ||
value: function find(target) { | ||
return this._map.has(target); | ||
} | ||
}]); | ||
return ManagedArray; | ||
}(); | ||
this._array.length = length; | ||
} | ||
reset() { | ||
this._array = []; | ||
this._map = new Map(); | ||
this._length = 0; | ||
} | ||
find(target) { | ||
return this._map.has(target); | ||
} | ||
} | ||
exports.default = ManagedArray; | ||
//# sourceMappingURL=managed-array.js.map |
@@ -1,4 +0,4 @@ | ||
const moduleExports = require('./index'); | ||
var moduleExports = require('./index'); | ||
const _global = typeof window === 'undefined' ? global : window; | ||
var _global = typeof window === 'undefined' ? global : window; | ||
@@ -5,0 +5,0 @@ _global.loaders = _global.loaders || {}; |
@@ -1,2 +0,2 @@ | ||
export const TILE_CONTENT_STATE = { | ||
export var TILE_CONTENT_STATE = { | ||
UNLOADED: 0, | ||
@@ -9,7 +9,7 @@ LOADING: 1, | ||
}; | ||
export const TILE_REFINEMENT = { | ||
export var TILE_REFINEMENT = { | ||
ADD: 1, | ||
REPLACE: 2 | ||
}; | ||
export const TILE_TYPE = { | ||
export var TILE_TYPE = { | ||
EMPTY: 'empty', | ||
@@ -20,11 +20,11 @@ SCENEGRAPH: 'scenegraph', | ||
}; | ||
export const TILESET_TYPE = { | ||
export var TILESET_TYPE = { | ||
I3S: 'I3S', | ||
TILES3D: 'TILES3D' | ||
}; | ||
export const LOD_METRIC_TYPE = { | ||
export var LOD_METRIC_TYPE = { | ||
GEOMETRIC_ERROR: 'geometricError', | ||
MAX_SCREEN_THRESHOLD: 'maxScreenThreshold' | ||
}; | ||
export const TILE3D_OPTIMIZATION_HINT = { | ||
export var TILE3D_OPTIMIZATION_HINT = { | ||
NOT_COMPUTED: -1, | ||
@@ -31,0 +31,0 @@ USE_OPTIMIZATION: 1, |
@@ -0,1 +1,2 @@ | ||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
import { Vector3, Matrix3, Matrix4, degrees } from '@math.gl/core'; | ||
@@ -10,6 +11,6 @@ import { BoundingSphere, OrientedBoundingBox } from '@math.gl/culling'; | ||
const scratchScale = new Vector3(); | ||
const scratchNorthWest = new Vector3(); | ||
const scratchSouthEast = new Vector3(); | ||
const scratchTransform = new Matrix4(); | ||
var scratchScale = new Vector3(); | ||
var scratchNorthWest = new Vector3(); | ||
var scratchSouthEast = new Vector3(); | ||
var scratchTransform = new Matrix4(); | ||
export function createBoundingVolume(boundingVolumeHeader, transform, result) { | ||
@@ -23,7 +24,14 @@ assert(boundingVolumeHeader, '3D Tile: boundingVolume must be defined'); | ||
if (boundingVolumeHeader.region) { | ||
const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region; | ||
const northWest = Ellipsoid.WGS84.cartographicToCartesian([degrees(west), degrees(north), minHeight], scratchNorthWest); | ||
const southEast = Ellipsoid.WGS84.cartographicToCartesian([degrees(east), degrees(south), maxHeight], scratchSouthEast); | ||
const centerInCartesian = new Vector3().addVectors(northWest, southEast).multiplyScalar(0.5); | ||
const radius = new Vector3().subVectors(northWest, southEast).len() / 2.0; | ||
var _boundingVolumeHeader = _slicedToArray(boundingVolumeHeader.region, 6), | ||
west = _boundingVolumeHeader[0], | ||
south = _boundingVolumeHeader[1], | ||
east = _boundingVolumeHeader[2], | ||
north = _boundingVolumeHeader[3], | ||
minHeight = _boundingVolumeHeader[4], | ||
maxHeight = _boundingVolumeHeader[5]; | ||
var northWest = Ellipsoid.WGS84.cartographicToCartesian([degrees(west), degrees(north), minHeight], scratchNorthWest); | ||
var southEast = Ellipsoid.WGS84.cartographicToCartesian([degrees(east), degrees(south), maxHeight], scratchSouthEast); | ||
var centerInCartesian = new Vector3().addVectors(northWest, southEast).multiplyScalar(0.5); | ||
var radius = new Vector3().subVectors(northWest, southEast).len() / 2.0; | ||
return createSphere([centerInCartesian[0], centerInCartesian[1], centerInCartesian[2], radius], new Matrix4()); | ||
@@ -40,8 +48,8 @@ } | ||
function createBox(box, transform, result) { | ||
const center = new Vector3(box[0], box[1], box[2]); | ||
var center = new Vector3(box[0], box[1], box[2]); | ||
transform.transform(center, center); | ||
const xAxis = transform.transformAsVector(box.slice(3, 6)); | ||
const yAxis = transform.transformAsVector(box.slice(6, 9)); | ||
const zAxis = transform.transformAsVector(box.slice(9, 12)); | ||
const halfAxes = new Matrix3([xAxis[0], xAxis[1], xAxis[2], yAxis[0], yAxis[1], yAxis[2], zAxis[0], zAxis[1], zAxis[2]]); | ||
var xAxis = transform.transformAsVector(box.slice(3, 6)); | ||
var yAxis = transform.transformAsVector(box.slice(6, 9)); | ||
var zAxis = transform.transformAsVector(box.slice(9, 12)); | ||
var halfAxes = new Matrix3([xAxis[0], xAxis[1], xAxis[2], yAxis[0], yAxis[1], yAxis[2], zAxis[0], zAxis[1], zAxis[2]]); | ||
@@ -58,7 +66,7 @@ if (defined(result)) { | ||
function createSphere(sphere, transform, result) { | ||
const center = new Vector3(sphere[0], sphere[1], sphere[2]); | ||
var center = new Vector3(sphere[0], sphere[1], sphere[2]); | ||
transform.transform(center, center); | ||
const scale = transform.getScale(scratchScale); | ||
const uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]); | ||
const radius = sphere[3] * uniformScale; | ||
var scale = transform.getScale(scratchScale); | ||
var uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]); | ||
var radius = sphere[3] * uniformScale; | ||
@@ -65,0 +73,0 @@ if (defined(result)) { |
import { Vector3 } from '@math.gl/core'; | ||
import { CullingVolume, Plane } from '@math.gl/culling'; | ||
import { Ellipsoid } from '@math.gl/geospatial'; | ||
const scratchVector = new Vector3(); | ||
const scratchPosition = new Vector3(); | ||
const cullingVolume = new CullingVolume([new Plane(), new Plane(), new Plane(), new Plane(), new Plane(), new Plane()]); | ||
var scratchVector = new Vector3(); | ||
var scratchPosition = new Vector3(); | ||
var cullingVolume = new CullingVolume([new Plane(), new Plane(), new Plane(), new Plane(), new Plane(), new Plane()]); | ||
export function getFrameState(viewport, frameNumber) { | ||
const { | ||
cameraDirection, | ||
cameraUp, | ||
height | ||
} = viewport; | ||
const { | ||
metersPerUnit | ||
} = viewport.distanceScales; | ||
const viewportCenterCartographic = [viewport.longitude, viewport.latitude, 0]; | ||
const viewportCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(viewportCenterCartographic, new Vector3()); | ||
const enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian); | ||
const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition); | ||
const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3()); | ||
const cameraDirectionCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))).normalize(); | ||
const cameraUpCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))).normalize(); | ||
var cameraDirection = viewport.cameraDirection, | ||
cameraUp = viewport.cameraUp, | ||
height = viewport.height; | ||
var metersPerUnit = viewport.distanceScales.metersPerUnit; | ||
var viewportCenterCartographic = [viewport.longitude, viewport.latitude, 0]; | ||
var viewportCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(viewportCenterCartographic, new Vector3()); | ||
var enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian); | ||
var cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition); | ||
var cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3()); | ||
var cameraDirectionCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))).normalize(); | ||
var cameraUpCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))).normalize(); | ||
commonSpacePlanesToWGS84(viewport, viewportCenterCartesian); | ||
@@ -30,6 +26,6 @@ return { | ||
}, | ||
viewport, | ||
height, | ||
cullingVolume, | ||
frameNumber, | ||
viewport: viewport, | ||
height: height, | ||
cullingVolume: cullingVolume, | ||
frameNumber: frameNumber, | ||
sseDenominator: 1.15 | ||
@@ -40,11 +36,11 @@ }; | ||
function commonSpacePlanesToWGS84(viewport, viewportCenterCartesian) { | ||
const frustumPlanes = viewport.getFrustumPlanes(); | ||
let i = 0; | ||
var frustumPlanes = viewport.getFrustumPlanes(); | ||
var i = 0; | ||
for (const dir in frustumPlanes) { | ||
const plane = frustumPlanes[dir]; | ||
const distanceToCenter = plane.normal.dot(viewport.center); | ||
for (var dir in frustumPlanes) { | ||
var plane = frustumPlanes[dir]; | ||
var distanceToCenter = plane.normal.dot(viewport.center); | ||
scratchPosition.copy(plane.normal).scale(plane.distance - distanceToCenter).add(viewport.center); | ||
const cartographicPos = viewport.unprojectPosition(scratchPosition); | ||
const cartesianPos = Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, new Vector3()); | ||
var cartographicPos = viewport.unprojectPosition(scratchPosition); | ||
var cartesianPos = Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, new Vector3()); | ||
cullingVolume.planes[i++].fromPointNormal(cartesianPos, scratchVector.copy(viewportCenterCartesian).subtract(cartesianPos)); | ||
@@ -51,0 +47,0 @@ } |
@@ -0,25 +1,24 @@ | ||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
import { toRadians } from '@math.gl/core'; | ||
const WGS84_RADIUS_X = 6378137.0; | ||
const qualityFactor = Math.PI / 2; | ||
var WGS84_RADIUS_X = 6378137.0; | ||
var qualityFactor = Math.PI / 2; | ||
export function lodJudge(tile, frameState) { | ||
const viewport = frameState.viewport; | ||
const metersPerPixel = viewport.metersPerPixel; | ||
const mbsLat = tile.header.mbs[1]; | ||
const mbsLon = tile.header.mbs[0]; | ||
const mbsZ = tile.header.mbs[2]; | ||
const mbsR = tile.header.mbs[3]; | ||
const { | ||
height, | ||
width, | ||
latitude, | ||
longitude | ||
} = viewport; | ||
const viewportCenter = [longitude, latitude]; | ||
const mbsCenter = [mbsLon, mbsLat, mbsZ]; | ||
const mbsLatProjected = [longitude, mbsLat]; | ||
const mbsLonProjected = [mbsLon, latitude]; | ||
const diagonalInMeters = Math.sqrt(height * height + width * width) * metersPerPixel[0]; | ||
const distanceInMeters = getDistanceFromLatLon(viewportCenter, mbsCenter); | ||
const visibleHeight = height * 0.5 + mbsR / WGS84_RADIUS_X; | ||
const visibleWidth = width * 0.5 + mbsR / WGS84_RADIUS_X; | ||
var viewport = frameState.viewport; | ||
var metersPerPixel = viewport.metersPerPixel; | ||
var mbsLat = tile.header.mbs[1]; | ||
var mbsLon = tile.header.mbs[0]; | ||
var mbsZ = tile.header.mbs[2]; | ||
var mbsR = tile.header.mbs[3]; | ||
var height = viewport.height, | ||
width = viewport.width, | ||
latitude = viewport.latitude, | ||
longitude = viewport.longitude; | ||
var viewportCenter = [longitude, latitude]; | ||
var mbsCenter = [mbsLon, mbsLat, mbsZ]; | ||
var mbsLatProjected = [longitude, mbsLat]; | ||
var mbsLonProjected = [mbsLon, latitude]; | ||
var diagonalInMeters = Math.sqrt(height * height + width * width) * metersPerPixel[0]; | ||
var distanceInMeters = getDistanceFromLatLon(viewportCenter, mbsCenter); | ||
var visibleHeight = height * 0.5 + mbsR / WGS84_RADIUS_X; | ||
var visibleWidth = width * 0.5 + mbsR / WGS84_RADIUS_X; | ||
@@ -42,3 +41,3 @@ if (distanceInMeters > diagonalInMeters + mbsR / WGS84_RADIUS_X) { | ||
let screenSize = getI3ScreenSize(tile, frameState); | ||
var screenSize = getI3ScreenSize(tile, frameState); | ||
screenSize *= qualityFactor; | ||
@@ -59,7 +58,12 @@ | ||
function projectVertexToSphere([x, y, z]) { | ||
const azim = toRadians(x); | ||
const incl = toRadians(y); | ||
const radius = 1.0 + z / WGS84_RADIUS_X; | ||
const radCosInc = radius * Math.cos(incl); | ||
function projectVertexToSphere(_ref) { | ||
var _ref2 = _slicedToArray(_ref, 3), | ||
x = _ref2[0], | ||
y = _ref2[1], | ||
z = _ref2[2]; | ||
var azim = toRadians(x); | ||
var incl = toRadians(y); | ||
var radius = 1.0 + z / WGS84_RADIUS_X; | ||
var radCosInc = radius * Math.cos(incl); | ||
x = radCosInc * Math.cos(azim); | ||
@@ -71,8 +75,20 @@ y = radCosInc * Math.sin(azim); | ||
function getDistanceFromLatLon([observerLon, observerLat, observerZ = 0.0], [centerLon, centerLat, centerZ = 0.0]) { | ||
const projectedCenter = projectVertexToSphere([centerLon, centerLat, centerZ]); | ||
const projectedObserver = projectVertexToSphere([observerLon, observerLat, observerZ]); | ||
const dx = projectedObserver[0] - projectedCenter[0]; | ||
const dy = projectedObserver[1] - projectedCenter[1]; | ||
const dz = projectedObserver[2] - projectedCenter[2]; | ||
function getDistanceFromLatLon(_ref3, _ref4) { | ||
var _ref5 = _slicedToArray(_ref3, 3), | ||
observerLon = _ref5[0], | ||
observerLat = _ref5[1], | ||
_ref5$ = _ref5[2], | ||
observerZ = _ref5$ === void 0 ? 0.0 : _ref5$; | ||
var _ref6 = _slicedToArray(_ref4, 3), | ||
centerLon = _ref6[0], | ||
centerLat = _ref6[1], | ||
_ref6$ = _ref6[2], | ||
centerZ = _ref6$ === void 0 ? 0.0 : _ref6$; | ||
var projectedCenter = projectVertexToSphere([centerLon, centerLat, centerZ]); | ||
var projectedObserver = projectVertexToSphere([observerLon, observerLat, observerZ]); | ||
var dx = projectedObserver[0] - projectedCenter[0]; | ||
var dy = projectedObserver[1] - projectedCenter[1]; | ||
var dz = projectedObserver[2] - projectedCenter[2]; | ||
return dx * dx + dy * dy + dz * dz; | ||
@@ -82,13 +98,13 @@ } | ||
export function getI3ScreenSize(tile, frameState) { | ||
const viewport = frameState.viewport; | ||
const mbsLat = tile.header.mbs[1]; | ||
const mbsLon = tile.header.mbs[0]; | ||
const mbsZ = tile.header.mbs[2]; | ||
const mbsR = tile.header.mbs[3]; | ||
const mbsCenter = [mbsLon, mbsLat, mbsZ]; | ||
const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition); | ||
const dSquared = getDistanceFromLatLon(cameraPositionCartographic, mbsCenter); | ||
const mbsRNormalized = mbsR / WGS84_RADIUS_X; | ||
const d = dSquared - mbsRNormalized * mbsRNormalized; | ||
const fltMax = 3.4028235e38; | ||
var viewport = frameState.viewport; | ||
var mbsLat = tile.header.mbs[1]; | ||
var mbsLon = tile.header.mbs[0]; | ||
var mbsZ = tile.header.mbs[2]; | ||
var mbsR = tile.header.mbs[3]; | ||
var mbsCenter = [mbsLon, mbsLat, mbsZ]; | ||
var cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition); | ||
var dSquared = getDistanceFromLatLon(cameraPositionCartographic, mbsCenter); | ||
var mbsRNormalized = mbsR / WGS84_RADIUS_X; | ||
var d = dSquared - mbsRNormalized * mbsRNormalized; | ||
var fltMax = 3.4028235e38; | ||
@@ -99,3 +115,3 @@ if (d <= 0.0) { | ||
let screenSizeFactor = calculateScreenSizeFactor(tile, frameState); | ||
var screenSizeFactor = calculateScreenSizeFactor(tile, frameState); | ||
screenSizeFactor *= mbsRNormalized / Math.sqrt(d) / viewport.scale; | ||
@@ -106,11 +122,10 @@ return screenSizeFactor; | ||
function calculateScreenSizeFactor(tile, frameState) { | ||
const { | ||
width, | ||
height, | ||
pixelProjectionMatrix | ||
} = frameState.viewport; | ||
const tanOfHalfVFAngle = Math.tan(Math.atan(Math.sqrt(1.0 / (pixelProjectionMatrix[0] * pixelProjectionMatrix[0]) + 1.0 / (pixelProjectionMatrix[5] * pixelProjectionMatrix[5])))); | ||
const screenCircleFactor = Math.sqrt(height * height + width * width) / tanOfHalfVFAngle; | ||
var _frameState$viewport = frameState.viewport, | ||
width = _frameState$viewport.width, | ||
height = _frameState$viewport.height, | ||
pixelProjectionMatrix = _frameState$viewport.pixelProjectionMatrix; | ||
var tanOfHalfVFAngle = Math.tan(Math.atan(Math.sqrt(1.0 / (pixelProjectionMatrix[0] * pixelProjectionMatrix[0]) + 1.0 / (pixelProjectionMatrix[5] * pixelProjectionMatrix[5])))); | ||
var screenCircleFactor = Math.sqrt(height * height + width * width) / tanOfHalfVFAngle; | ||
return screenCircleFactor; | ||
} | ||
//# sourceMappingURL=i3s-lod.js.map |
import { Matrix4, Vector3, clamp } from '@math.gl/core'; | ||
const scratchPositionNormal = new Vector3(); | ||
const scratchCartographic = new Vector3(); | ||
const scratchMatrix = new Matrix4(); | ||
const scratchCenter = new Vector3(); | ||
const scratchPosition = new Vector3(); | ||
const scratchDirection = new Vector3(); | ||
export function calculateDynamicScreenSpaceError(root, { | ||
camera, | ||
mapProjection | ||
}, options = {}) { | ||
const { | ||
dynamicScreenSpaceErrorHeightFalloff = 0.25, | ||
dynamicScreenSpaceErrorDensity = 0.00278 | ||
} = options; | ||
let up; | ||
let direction; | ||
let height; | ||
let minimumHeight; | ||
let maximumHeight; | ||
const tileBoundingVolume = root.contentBoundingVolume; | ||
var scratchPositionNormal = new Vector3(); | ||
var scratchCartographic = new Vector3(); | ||
var scratchMatrix = new Matrix4(); | ||
var scratchCenter = new Vector3(); | ||
var scratchPosition = new Vector3(); | ||
var scratchDirection = new Vector3(); | ||
export function calculateDynamicScreenSpaceError(root, _ref) { | ||
var camera = _ref.camera, | ||
mapProjection = _ref.mapProjection; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var _options$dynamicScree = options.dynamicScreenSpaceErrorHeightFalloff, | ||
dynamicScreenSpaceErrorHeightFalloff = _options$dynamicScree === void 0 ? 0.25 : _options$dynamicScree, | ||
_options$dynamicScree2 = options.dynamicScreenSpaceErrorDensity, | ||
dynamicScreenSpaceErrorDensity = _options$dynamicScree2 === void 0 ? 0.00278 : _options$dynamicScree2; | ||
var up; | ||
var direction; | ||
var height; | ||
var minimumHeight; | ||
var maximumHeight; | ||
var tileBoundingVolume = root.contentBoundingVolume; | ||
@@ -30,9 +30,9 @@ if (tileBoundingVolume instanceof TileBoundingRegion) { | ||
} else { | ||
const transformLocal = Matrix4.inverseTransformation(root.computedTransform, scratchMatrix); | ||
const ellipsoid = mapProjection.ellipsoid; | ||
const boundingVolume = tileBoundingVolume.boundingVolume; | ||
const centerLocal = Matrix4.multiplyByPoint(transformLocal, boundingVolume.center, scratchCenter); | ||
var transformLocal = Matrix4.inverseTransformation(root.computedTransform, scratchMatrix); | ||
var ellipsoid = mapProjection.ellipsoid; | ||
var boundingVolume = tileBoundingVolume.boundingVolume; | ||
var centerLocal = Matrix4.multiplyByPoint(transformLocal, boundingVolume.center, scratchCenter); | ||
if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) { | ||
const centerCartographic = Cartographic.fromCartesian(centerLocal, ellipsoid, scratchCartographic); | ||
var centerCartographic = Cartographic.fromCartesian(centerLocal, ellipsoid, scratchCartographic); | ||
up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal); | ||
@@ -44,3 +44,3 @@ direction = camera.directionWC; | ||
} else { | ||
const positionLocal = Matrix4.multiplyByPoint(transformLocal, camera.positionWC, scratchPosition); | ||
var positionLocal = Matrix4.multiplyByPoint(transformLocal, camera.positionWC, scratchPosition); | ||
up = Cartesian3.UNIT_Z; | ||
@@ -52,7 +52,7 @@ direction = Matrix4.multiplyByPointAsVector(transformLocal, camera.directionWC, scratchDirection); | ||
if (tileBoundingVolume instanceof TileOrientedBoundingBox) { | ||
const boxHeight = root._header.boundingVolume.box[11]; | ||
var boxHeight = root._header.boundingVolume.box[11]; | ||
minimumHeight = centerLocal.z - boxHeight; | ||
maximumHeight = centerLocal.z + boxHeight; | ||
} else if (tileBoundingVolume instanceof TileBoundingSphere) { | ||
const radius = boundingVolume.radius; | ||
var radius = boundingVolume.radius; | ||
minimumHeight = centerLocal.z - radius; | ||
@@ -64,8 +64,8 @@ maximumHeight = centerLocal.z + radius; | ||
const heightFalloff = dynamicScreenSpaceErrorHeightFalloff; | ||
const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff; | ||
const heightFar = maximumHeight; | ||
const t = clamp((height - heightClose) / (heightFar - heightClose), 0.0, 1.0); | ||
const dot = Math.abs(Cartesian3.dot(direction, up)); | ||
let horizonFactor = 1.0 - dot; | ||
var heightFalloff = dynamicScreenSpaceErrorHeightFalloff; | ||
var heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff; | ||
var heightFar = maximumHeight; | ||
var t = clamp((height - heightClose) / (heightFar - heightClose), 0.0, 1.0); | ||
var dot = Math.abs(Cartesian3.dot(direction, up)); | ||
var horizonFactor = 1.0 - dot; | ||
horizonFactor = horizonFactor * (1.0 - t); | ||
@@ -75,3 +75,3 @@ return dynamicScreenSpaceErrorDensity * horizonFactor; | ||
export function fog(distanceToCamera, density) { | ||
const scalar = distanceToCamera * density; | ||
var scalar = distanceToCamera * density; | ||
return 1.0 - Math.exp(-(scalar * scalar)); | ||
@@ -81,5 +81,5 @@ } | ||
if (tileset.dynamicScreenSpaceError && tileset._dynamicScreenSpaceErrorComputedDensity) { | ||
const density = tileset._dynamicScreenSpaceErrorComputedDensity; | ||
const factor = tileset.dynamicScreenSpaceErrorFactor; | ||
const dynamicError = fog(distanceToCamera, density) * factor; | ||
var density = tileset._dynamicScreenSpaceErrorComputedDensity; | ||
var factor = tileset.dynamicScreenSpaceErrorFactor; | ||
var dynamicError = fog(distanceToCamera, density) * factor; | ||
return dynamicError; | ||
@@ -91,5 +91,5 @@ } | ||
export function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) { | ||
const tileset = tile.tileset; | ||
const parentLodMetricValue = tile.parent && tile.parent.lodMetricValue || tile.lodMetricValue; | ||
const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue; | ||
var tileset = tile.tileset; | ||
var parentLodMetricValue = tile.parent && tile.parent.lodMetricValue || tile.lodMetricValue; | ||
var lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue; | ||
@@ -100,8 +100,6 @@ if (lodMetricValue === 0.0) { | ||
const distance = Math.max(tile._distanceToCamera, 1e-7); | ||
const { | ||
height, | ||
sseDenominator | ||
} = frameState; | ||
let error = lodMetricValue * height / (distance * sseDenominator); | ||
var distance = Math.max(tile._distanceToCamera, 1e-7); | ||
var height = frameState.height, | ||
sseDenominator = frameState.sseDenominator; | ||
var error = lodMetricValue * height / (distance * sseDenominator); | ||
error -= getDynamicScreenSpaceError(tileset, distance); | ||
@@ -108,0 +106,0 @@ return error; |
@@ -7,13 +7,7 @@ import { Ellipsoid } from '@math.gl/geospatial'; | ||
assert(tile); | ||
const { | ||
rtcCenter, | ||
gltfUpAxis | ||
} = tile; | ||
const { | ||
computedTransform, | ||
boundingVolume: { | ||
center | ||
} | ||
} = tileHeader; | ||
let modelMatrix = new Matrix4(computedTransform); | ||
var rtcCenter = tile.rtcCenter, | ||
gltfUpAxis = tile.gltfUpAxis; | ||
var computedTransform = tileHeader.computedTransform, | ||
center = tileHeader.boundingVolume.center; | ||
var modelMatrix = new Matrix4(computedTransform); | ||
@@ -29,3 +23,3 @@ if (rtcCenter) { | ||
case 'Y': | ||
const rotationY = new Matrix4().rotateX(Math.PI / 2); | ||
var rotationY = new Matrix4().rotateX(Math.PI / 2); | ||
modelMatrix = modelMatrix.multiplyRight(rotationY); | ||
@@ -35,3 +29,3 @@ break; | ||
case 'X': | ||
const rotationX = new Matrix4().rotateY(-Math.PI / 2); | ||
var rotationX = new Matrix4().rotateY(-Math.PI / 2); | ||
modelMatrix = modelMatrix.multiplyRight(rotationX); | ||
@@ -48,8 +42,8 @@ break; | ||
const cartesianOrigin = new Vector3(center); | ||
var cartesianOrigin = new Vector3(center); | ||
tile.cartesianModelMatrix = modelMatrix; | ||
tile.cartesianOrigin = cartesianOrigin; | ||
const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new Vector3()); | ||
const fromFixedFrameMatrix = Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin); | ||
const toFixedFrameMatrix = fromFixedFrameMatrix.invert(); | ||
var cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new Vector3()); | ||
var fromFixedFrameMatrix = Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin); | ||
var toFixedFrameMatrix = fromFixedFrameMatrix.invert(); | ||
tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix); | ||
@@ -56,0 +50,0 @@ tile.cartographicOrigin = cartographicOrigin; |
import { Vector3 } from '@math.gl/core'; | ||
const WGS84_RADIUS_X = 6378137.0; | ||
const WGS84_RADIUS_Y = 6378137.0; | ||
const WGS84_RADIUS_Z = 6356752.3142451793; | ||
const scratchVector = new Vector3(); | ||
var WGS84_RADIUS_X = 6378137.0; | ||
var WGS84_RADIUS_Y = 6378137.0; | ||
var WGS84_RADIUS_Z = 6356752.3142451793; | ||
var scratchVector = new Vector3(); | ||
export function getZoomFromBoundingVolume(boundingVolume) { | ||
const { | ||
halfAxes, | ||
radius, | ||
width, | ||
height | ||
} = boundingVolume; | ||
var halfAxes = boundingVolume.halfAxes, | ||
radius = boundingVolume.radius, | ||
width = boundingVolume.width, | ||
height = boundingVolume.height; | ||
if (halfAxes) { | ||
halfAxes.getColumn(0, scratchVector); | ||
const x = scratchVector.len(); | ||
var x = scratchVector.len(); | ||
halfAxes.getColumn(1, scratchVector); | ||
const y = scratchVector.len(); | ||
var y = scratchVector.len(); | ||
halfAxes.getColumn(2, scratchVector); | ||
const z = scratchVector.len(); | ||
const halfX = x / 2; | ||
const halfY = y / 2; | ||
const halfZ = z / 2; | ||
const zoomX = Math.log2(WGS84_RADIUS_X / halfX); | ||
const zoomY = Math.log2(WGS84_RADIUS_Y / halfY); | ||
const zoomZ = Math.log2(WGS84_RADIUS_Z / halfZ); | ||
var z = scratchVector.len(); | ||
var halfX = x / 2; | ||
var halfY = y / 2; | ||
var halfZ = z / 2; | ||
var zoomX = Math.log2(WGS84_RADIUS_X / halfX); | ||
var zoomY = Math.log2(WGS84_RADIUS_Y / halfY); | ||
var zoomZ = Math.log2(WGS84_RADIUS_Z / halfZ); | ||
return (zoomX + zoomY + zoomZ) / 3; | ||
@@ -31,5 +29,7 @@ } else if (radius) { | ||
} else if (height && width) { | ||
const zoomX = Math.log2(WGS84_RADIUS_X / width); | ||
const zoomY = Math.log2(WGS84_RADIUS_Y / height); | ||
return (zoomX + zoomY) / 2; | ||
var _zoomX = Math.log2(WGS84_RADIUS_X / width); | ||
var _zoomY = Math.log2(WGS84_RADIUS_Y / height); | ||
return (_zoomX + _zoomY) / 2; | ||
} | ||
@@ -36,0 +36,0 @@ |
@@ -0,1 +1,12 @@ | ||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
import _typeof from "@babel/runtime/helpers/esm/typeof"; | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
import { Vector3, Matrix4 } from '@math.gl/core'; | ||
@@ -10,3 +21,3 @@ import { CullingVolume } from '@math.gl/culling'; | ||
import { get3dTilesOptions } from './helpers/3d-tiles-options'; | ||
const scratchVector = new Vector3(); | ||
var scratchVector = new Vector3(); | ||
@@ -17,5 +28,7 @@ function defined(x) { | ||
export default class TileHeader { | ||
constructor(tileset, header, parentHeader) { | ||
assert(typeof header === 'object'); | ||
var TileHeader = function () { | ||
function TileHeader(tileset, header, parentHeader) { | ||
_classCallCheck(this, TileHeader); | ||
assert(_typeof(header) === 'object'); | ||
this.header = header; | ||
@@ -59,352 +72,433 @@ this.tileset = tileset; | ||
destroy() { | ||
this.header = null; | ||
} | ||
isDestroyed() { | ||
return this.header === null; | ||
} | ||
get selected() { | ||
return this._selectedFrame === this.tileset._frameNumber; | ||
} | ||
get isVisible() { | ||
return this._visible; | ||
} | ||
get isVisibleAndInRequestVolume() { | ||
return this._visible && this._inRequestVolume; | ||
} | ||
get hasRenderContent() { | ||
return !this.hasEmptyContent && !this.hasTilesetContent; | ||
} | ||
get hasChildren() { | ||
return this.children.length > 0 || this.header.children && this.header.children.length > 0; | ||
} | ||
get contentReady() { | ||
return this.contentState === TILE_CONTENT_STATE.READY || this.hasEmptyContent; | ||
} | ||
get contentAvailable() { | ||
return Boolean(this.contentReady && this.hasRenderContent || this._expiredContent && !this.contentFailed); | ||
} | ||
get hasUnloadedContent() { | ||
return this.hasRenderContent && this.contentUnloaded; | ||
} | ||
get contentUnloaded() { | ||
return this.contentState === TILE_CONTENT_STATE.UNLOADED; | ||
} | ||
get contentExpired() { | ||
return this.contentState === TILE_CONTENT_STATE.EXPIRED; | ||
} | ||
get contentFailed() { | ||
return this.contentState === TILE_CONTENT_STATE.FAILED; | ||
} | ||
getScreenSpaceError(frameState, useParentLodMetric) { | ||
switch (this.tileset.type) { | ||
case TILESET_TYPE.I3S: | ||
return getI3ScreenSize(this, frameState); | ||
case TILESET_TYPE.TILES3D: | ||
return getTiles3DScreenSpaceError(this, frameState, useParentLodMetric); | ||
default: | ||
console.error('Unsupported tileset type'); | ||
return null; | ||
_createClass(TileHeader, [{ | ||
key: "destroy", | ||
value: function destroy() { | ||
this.header = null; | ||
} | ||
} | ||
_getPriority() { | ||
if (!this.isVisible) { | ||
return -1; | ||
}, { | ||
key: "isDestroyed", | ||
value: function isDestroyed() { | ||
return this.header === null; | ||
} | ||
if (this.contentState === TILE_CONTENT_STATE.UNLOADED) { | ||
return -1; | ||
}, { | ||
key: "selected", | ||
get: function get() { | ||
return this._selectedFrame === this.tileset._frameNumber; | ||
} | ||
return Math.max(1e7 - this._priority, 0) || 0; | ||
} | ||
async loadContent() { | ||
if (this.hasEmptyContent) { | ||
return false; | ||
}, { | ||
key: "isVisible", | ||
get: function get() { | ||
return this._visible; | ||
} | ||
if (this.content) { | ||
return true; | ||
}, { | ||
key: "isVisibleAndInRequestVolume", | ||
get: function get() { | ||
return this._visible && this._inRequestVolume; | ||
} | ||
const expired = this.contentExpired; | ||
if (expired) { | ||
this._expireDate = null; | ||
}, { | ||
key: "hasRenderContent", | ||
get: function get() { | ||
return !this.hasEmptyContent && !this.hasTilesetContent; | ||
} | ||
}, { | ||
key: "hasChildren", | ||
get: function get() { | ||
return this.children.length > 0 || this.header.children && this.header.children.length > 0; | ||
} | ||
}, { | ||
key: "contentReady", | ||
get: function get() { | ||
return this.contentState === TILE_CONTENT_STATE.READY || this.hasEmptyContent; | ||
} | ||
}, { | ||
key: "contentAvailable", | ||
get: function get() { | ||
return Boolean(this.contentReady && this.hasRenderContent || this._expiredContent && !this.contentFailed); | ||
} | ||
}, { | ||
key: "hasUnloadedContent", | ||
get: function get() { | ||
return this.hasRenderContent && this.contentUnloaded; | ||
} | ||
}, { | ||
key: "contentUnloaded", | ||
get: function get() { | ||
return this.contentState === TILE_CONTENT_STATE.UNLOADED; | ||
} | ||
}, { | ||
key: "contentExpired", | ||
get: function get() { | ||
return this.contentState === TILE_CONTENT_STATE.EXPIRED; | ||
} | ||
}, { | ||
key: "contentFailed", | ||
get: function get() { | ||
return this.contentState === TILE_CONTENT_STATE.FAILED; | ||
} | ||
}, { | ||
key: "getScreenSpaceError", | ||
value: function getScreenSpaceError(frameState, useParentLodMetric) { | ||
switch (this.tileset.type) { | ||
case TILESET_TYPE.I3S: | ||
return getI3ScreenSize(this, frameState); | ||
this.contentState = TILE_CONTENT_STATE.LOADING; | ||
const requestToken = await this.tileset._requestScheduler.scheduleRequest(this.id, this._getPriority); | ||
case TILESET_TYPE.TILES3D: | ||
return getTiles3DScreenSpaceError(this, frameState, useParentLodMetric); | ||
if (!requestToken) { | ||
this.contentState = TILE_CONTENT_STATE.UNLOADED; | ||
return false; | ||
default: | ||
console.error('Unsupported tileset type'); | ||
return null; | ||
} | ||
} | ||
}, { | ||
key: "_getPriority", | ||
value: function _getPriority() { | ||
if (!this.isVisible) { | ||
return -1; | ||
} | ||
try { | ||
const contentUrl = this.tileset.getTileUrl(this.contentUrl); | ||
const fetchOptions = this.tileset.fetchOptions; | ||
const loader = this.tileset.loader; | ||
const options = { ...fetchOptions, | ||
[loader.id]: { | ||
isTileset: this.type === 'json', | ||
...this._getLoaderSpecificOptions(loader.id) | ||
} | ||
}; | ||
this.content = await load(contentUrl, loader, options); | ||
if (this._isTileset()) { | ||
this.tileset._initializeTileHeaders(this.content, this, path.dirname(this.contentUrl)); | ||
if (this.contentState === TILE_CONTENT_STATE.UNLOADED) { | ||
return -1; | ||
} | ||
this.contentState = TILE_CONTENT_STATE.READY; | ||
return Math.max(1e7 - this._priority, 0) || 0; | ||
} | ||
}, { | ||
key: "loadContent", | ||
value: function () { | ||
var _loadContent = _asyncToGenerator(_regeneratorRuntime.mark(function _callee() { | ||
var expired, requestToken, contentUrl, fetchOptions, loader, options; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!this.hasEmptyContent) { | ||
_context.next = 2; | ||
break; | ||
} | ||
this._onContentLoaded(); | ||
return _context.abrupt("return", false); | ||
return true; | ||
} catch (error) { | ||
this.contentState = TILE_CONTENT_STATE.FAILED; | ||
throw error; | ||
} finally { | ||
requestToken.done(); | ||
} | ||
} | ||
case 2: | ||
if (!this.content) { | ||
_context.next = 4; | ||
break; | ||
} | ||
unloadContent() { | ||
if (this.content && this.content.destroy) { | ||
this.content.destroy(); | ||
} | ||
return _context.abrupt("return", true); | ||
this.content = null; | ||
case 4: | ||
expired = this.contentExpired; | ||
if (this.header.content && this.header.content.destroy) { | ||
this.header.content.destroy(); | ||
} | ||
if (expired) { | ||
this._expireDate = null; | ||
} | ||
this.header.content = null; | ||
this.contentState = TILE_CONTENT_STATE.UNLOADED; | ||
return true; | ||
} | ||
this.contentState = TILE_CONTENT_STATE.LOADING; | ||
_context.next = 9; | ||
return this.tileset._requestScheduler.scheduleRequest(this.id, this._getPriority); | ||
updateVisibility(frameState) { | ||
if (this._frameNumber === frameState.frameNumber) { | ||
return; | ||
} | ||
case 9: | ||
requestToken = _context.sent; | ||
const parent = this.parent; | ||
const parentTransform = parent ? parent.computedTransform : this.tileset.modelMatrix; | ||
const parentVisibilityPlaneMask = parent ? parent._visibilityPlaneMask : CullingVolume.MASK_INDETERMINATE; | ||
if (requestToken) { | ||
_context.next = 13; | ||
break; | ||
} | ||
this._updateTransform(parentTransform); | ||
this.contentState = TILE_CONTENT_STATE.UNLOADED; | ||
return _context.abrupt("return", false); | ||
this._distanceToCamera = this.distanceToTile(frameState); | ||
this._screenSpaceError = this.getScreenSpaceError(frameState, false); | ||
this._visibilityPlaneMask = this.visibility(frameState, parentVisibilityPlaneMask); | ||
this._visible = this._visibilityPlaneMask !== CullingVolume.MASK_OUTSIDE; | ||
this._inRequestVolume = this.insideViewerRequestVolume(frameState); | ||
this._priority = this.lodMetricValue; | ||
this._frameNumber = frameState.frameNumber; | ||
} | ||
case 13: | ||
_context.prev = 13; | ||
contentUrl = this.tileset.getTileUrl(this.contentUrl); | ||
fetchOptions = this.tileset.fetchOptions; | ||
loader = this.tileset.loader; | ||
options = _objectSpread(_objectSpread({}, fetchOptions), {}, { | ||
[loader.id]: _objectSpread({ | ||
isTileset: this.type === 'json' | ||
}, this._getLoaderSpecificOptions(loader.id)) | ||
}); | ||
_context.next = 20; | ||
return load(contentUrl, loader, options); | ||
visibility(frameState, parentVisibilityPlaneMask) { | ||
const { | ||
cullingVolume | ||
} = frameState; | ||
const { | ||
boundingVolume | ||
} = this; | ||
return cullingVolume.computeVisibilityWithPlaneMask(boundingVolume, parentVisibilityPlaneMask); | ||
} | ||
case 20: | ||
this.content = _context.sent; | ||
contentVisibility(frameState) { | ||
return true; | ||
} | ||
if (this._isTileset()) { | ||
this.tileset._initializeTileHeaders(this.content, this, path.dirname(this.contentUrl)); | ||
} | ||
distanceToTile(frameState) { | ||
const boundingVolume = this.boundingVolume; | ||
return Math.sqrt(Math.max(boundingVolume.distanceSquaredTo(frameState.camera.position), 0)); | ||
} | ||
this.contentState = TILE_CONTENT_STATE.READY; | ||
cameraSpaceZDepth({ | ||
camera | ||
}) { | ||
const boundingVolume = this.boundingVolume; | ||
scratchVector.subVectors(boundingVolume.center, camera.position); | ||
return camera.direction.dot(scratchVector); | ||
} | ||
this._onContentLoaded(); | ||
insideViewerRequestVolume(frameState) { | ||
const viewerRequestVolume = this._viewerRequestVolume; | ||
return !viewerRequestVolume || viewerRequestVolume.distanceToCamera(frameState.camera.position) === 0.0; | ||
} | ||
return _context.abrupt("return", true); | ||
_initializeLodMetric(header) { | ||
if ('lodMetricType' in header) { | ||
this.lodMetricType = header.lodMetricType; | ||
} else { | ||
this.lodMetricType = this.parent && this.parent.lodMetricType || this.tileset.lodMetricType; | ||
console.warn("3D Tile: Required prop lodMetricType is undefined. Using parent lodMetricType"); | ||
} | ||
case 27: | ||
_context.prev = 27; | ||
_context.t0 = _context["catch"](13); | ||
this.contentState = TILE_CONTENT_STATE.FAILED; | ||
throw _context.t0; | ||
if ('lodMetricValue' in header) { | ||
this.lodMetricValue = header.lodMetricValue; | ||
} else { | ||
this.lodMetricValue = this.parent && this.parent.lodMetricValue || this.tileset.lodMetricValue; | ||
console.warn("3D Tile: Required prop lodMetricValue is undefined. Using parent lodMetricValue"); | ||
} | ||
} | ||
case 31: | ||
_context.prev = 31; | ||
requestToken.done(); | ||
return _context.finish(31); | ||
_initializeTransforms(tileHeader) { | ||
this.transform = tileHeader.transform ? new Matrix4(tileHeader.transform) : new Matrix4(); | ||
const parent = this.parent; | ||
const tileset = this.tileset; | ||
const parentTransform = parent && parent.computedTransform ? parent.computedTransform.clone() : tileset.modelMatrix.clone(); | ||
this.computedTransform = new Matrix4(parentTransform).multiplyRight(this.transform); | ||
const parentInitialTransform = parent && parent._initialTransform ? parent._initialTransform.clone() : new Matrix4(); | ||
this._initialTransform = new Matrix4(parentInitialTransform).multiplyRight(this.transform); | ||
} | ||
case 34: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this, [[13, 27, 31, 34]]); | ||
})); | ||
_initializeBoundingVolumes(tileHeader) { | ||
this._contentBoundingVolume = null; | ||
this._viewerRequestVolume = null; | ||
function loadContent() { | ||
return _loadContent.apply(this, arguments); | ||
} | ||
this._updateBoundingVolume(tileHeader); | ||
} | ||
return loadContent; | ||
}() | ||
}, { | ||
key: "unloadContent", | ||
value: function unloadContent() { | ||
if (this.content && this.content.destroy) { | ||
this.content.destroy(); | ||
} | ||
_initializeContent(tileHeader) { | ||
this.content = { | ||
_tileset: this.tileset, | ||
_tile: this | ||
}; | ||
this.hasEmptyContent = true; | ||
this.contentState = TILE_CONTENT_STATE.UNLOADED; | ||
this.hasTilesetContent = false; | ||
if (tileHeader.contentUrl) { | ||
this.content = null; | ||
this.hasEmptyContent = false; | ||
} | ||
} | ||
_initializeRenderingState(header) { | ||
this.depth = header.level; | ||
this._shouldRefine = false; | ||
this._distanceToCamera = 0; | ||
this._centerZDepth = 0; | ||
this._screenSpaceError = 0; | ||
this._visibilityPlaneMask = CullingVolume.MASK_INDETERMINATE; | ||
this._visible = false; | ||
this._inRequestVolume = false; | ||
this._stackLength = 0; | ||
this._selectionDepth = 0; | ||
this._frameNumber = 0; | ||
this._touchedFrame = 0; | ||
this._visitedFrame = 0; | ||
this._selectedFrame = 0; | ||
this._requestedFrame = 0; | ||
this._priority = 0.0; | ||
} | ||
if (this.header.content && this.header.content.destroy) { | ||
this.header.content.destroy(); | ||
} | ||
_getRefine(refine) { | ||
return refine || this.parent && this.parent.refine || TILE_REFINEMENT.REPLACE; | ||
} | ||
this.header.content = null; | ||
this.contentState = TILE_CONTENT_STATE.UNLOADED; | ||
return true; | ||
} | ||
}, { | ||
key: "updateVisibility", | ||
value: function updateVisibility(frameState) { | ||
if (this._frameNumber === frameState.frameNumber) { | ||
return; | ||
} | ||
_isTileset() { | ||
return this.contentUrl.indexOf('.json') !== -1; | ||
} | ||
var parent = this.parent; | ||
var parentTransform = parent ? parent.computedTransform : this.tileset.modelMatrix; | ||
var parentVisibilityPlaneMask = parent ? parent._visibilityPlaneMask : CullingVolume.MASK_INDETERMINATE; | ||
_onContentLoaded() { | ||
switch (this.content && this.content.type) { | ||
case 'vctr': | ||
case 'geom': | ||
this.tileset.traverser.disableSkipLevelOfDetail = true; | ||
break; | ||
this._updateTransform(parentTransform); | ||
default: | ||
this._distanceToCamera = this.distanceToTile(frameState); | ||
this._screenSpaceError = this.getScreenSpaceError(frameState, false); | ||
this._visibilityPlaneMask = this.visibility(frameState, parentVisibilityPlaneMask); | ||
this._visible = this._visibilityPlaneMask !== CullingVolume.MASK_OUTSIDE; | ||
this._inRequestVolume = this.insideViewerRequestVolume(frameState); | ||
this._priority = this.lodMetricValue; | ||
this._frameNumber = frameState.frameNumber; | ||
} | ||
}, { | ||
key: "visibility", | ||
value: function visibility(frameState, parentVisibilityPlaneMask) { | ||
var cullingVolume = frameState.cullingVolume; | ||
var boundingVolume = this.boundingVolume; | ||
return cullingVolume.computeVisibilityWithPlaneMask(boundingVolume, parentVisibilityPlaneMask); | ||
} | ||
}, { | ||
key: "contentVisibility", | ||
value: function contentVisibility(frameState) { | ||
return true; | ||
} | ||
}, { | ||
key: "distanceToTile", | ||
value: function distanceToTile(frameState) { | ||
var boundingVolume = this.boundingVolume; | ||
return Math.sqrt(Math.max(boundingVolume.distanceSquaredTo(frameState.camera.position), 0)); | ||
} | ||
}, { | ||
key: "cameraSpaceZDepth", | ||
value: function cameraSpaceZDepth(_ref) { | ||
var camera = _ref.camera; | ||
var boundingVolume = this.boundingVolume; | ||
scratchVector.subVectors(boundingVolume.center, camera.position); | ||
return camera.direction.dot(scratchVector); | ||
} | ||
}, { | ||
key: "insideViewerRequestVolume", | ||
value: function insideViewerRequestVolume(frameState) { | ||
var viewerRequestVolume = this._viewerRequestVolume; | ||
return !viewerRequestVolume || viewerRequestVolume.distanceToCamera(frameState.camera.position) === 0.0; | ||
} | ||
}, { | ||
key: "_initializeLodMetric", | ||
value: function _initializeLodMetric(header) { | ||
if ('lodMetricType' in header) { | ||
this.lodMetricType = header.lodMetricType; | ||
} else { | ||
this.lodMetricType = this.parent && this.parent.lodMetricType || this.tileset.lodMetricType; | ||
console.warn("3D Tile: Required prop lodMetricType is undefined. Using parent lodMetricType"); | ||
} | ||
if (this._isTileset()) { | ||
this.hasTilesetContent = true; | ||
if ('lodMetricValue' in header) { | ||
this.lodMetricValue = header.lodMetricValue; | ||
} else { | ||
this.lodMetricValue = this.parent && this.parent.lodMetricValue || this.tileset.lodMetricValue; | ||
console.warn("3D Tile: Required prop lodMetricValue is undefined. Using parent lodMetricValue"); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "_initializeTransforms", | ||
value: function _initializeTransforms(tileHeader) { | ||
this.transform = tileHeader.transform ? new Matrix4(tileHeader.transform) : new Matrix4(); | ||
var parent = this.parent; | ||
var tileset = this.tileset; | ||
var parentTransform = parent && parent.computedTransform ? parent.computedTransform.clone() : tileset.modelMatrix.clone(); | ||
this.computedTransform = new Matrix4(parentTransform).multiplyRight(this.transform); | ||
var parentInitialTransform = parent && parent._initialTransform ? parent._initialTransform.clone() : new Matrix4(); | ||
this._initialTransform = new Matrix4(parentInitialTransform).multiplyRight(this.transform); | ||
} | ||
}, { | ||
key: "_initializeBoundingVolumes", | ||
value: function _initializeBoundingVolumes(tileHeader) { | ||
this._contentBoundingVolume = null; | ||
this._viewerRequestVolume = null; | ||
_updateBoundingVolume(header) { | ||
this.boundingVolume = createBoundingVolume(header.boundingVolume, this.computedTransform, this.boundingVolume); | ||
const content = header.content; | ||
if (!content) { | ||
return; | ||
this._updateBoundingVolume(tileHeader); | ||
} | ||
}, { | ||
key: "_initializeContent", | ||
value: function _initializeContent(tileHeader) { | ||
this.content = { | ||
_tileset: this.tileset, | ||
_tile: this | ||
}; | ||
this.hasEmptyContent = true; | ||
this.contentState = TILE_CONTENT_STATE.UNLOADED; | ||
this.hasTilesetContent = false; | ||
if (content.boundingVolume) { | ||
this._contentBoundingVolume = createBoundingVolume(content.boundingVolume, this.computedTransform, this._contentBoundingVolume); | ||
if (tileHeader.contentUrl) { | ||
this.content = null; | ||
this.hasEmptyContent = false; | ||
} | ||
} | ||
}, { | ||
key: "_initializeRenderingState", | ||
value: function _initializeRenderingState(header) { | ||
this.depth = header.level; | ||
this._shouldRefine = false; | ||
this._distanceToCamera = 0; | ||
this._centerZDepth = 0; | ||
this._screenSpaceError = 0; | ||
this._visibilityPlaneMask = CullingVolume.MASK_INDETERMINATE; | ||
this._visible = false; | ||
this._inRequestVolume = false; | ||
this._stackLength = 0; | ||
this._selectionDepth = 0; | ||
this._frameNumber = 0; | ||
this._touchedFrame = 0; | ||
this._visitedFrame = 0; | ||
this._selectedFrame = 0; | ||
this._requestedFrame = 0; | ||
this._priority = 0.0; | ||
} | ||
}, { | ||
key: "_getRefine", | ||
value: function _getRefine(refine) { | ||
return refine || this.parent && this.parent.refine || TILE_REFINEMENT.REPLACE; | ||
} | ||
}, { | ||
key: "_isTileset", | ||
value: function _isTileset() { | ||
return this.contentUrl.indexOf('.json') !== -1; | ||
} | ||
}, { | ||
key: "_onContentLoaded", | ||
value: function _onContentLoaded() { | ||
switch (this.content && this.content.type) { | ||
case 'vctr': | ||
case 'geom': | ||
this.tileset.traverser.disableSkipLevelOfDetail = true; | ||
break; | ||
if (header.viewerRequestVolume) { | ||
this._viewerRequestVolume = createBoundingVolume(header.viewerRequestVolume, this.computedTransform, this._viewerRequestVolume); | ||
default: | ||
} | ||
if (this._isTileset()) { | ||
this.hasTilesetContent = true; | ||
} | ||
} | ||
} | ||
}, { | ||
key: "_updateBoundingVolume", | ||
value: function _updateBoundingVolume(header) { | ||
this.boundingVolume = createBoundingVolume(header.boundingVolume, this.computedTransform, this.boundingVolume); | ||
var content = header.content; | ||
_updateTransform(parentTransform = new Matrix4()) { | ||
const computedTransform = parentTransform.clone().multiplyRight(this.transform); | ||
const didTransformChange = !computedTransform.equals(this.computedTransform); | ||
if (!content) { | ||
return; | ||
} | ||
if (!didTransformChange) { | ||
return; | ||
if (content.boundingVolume) { | ||
this._contentBoundingVolume = createBoundingVolume(content.boundingVolume, this.computedTransform, this._contentBoundingVolume); | ||
} | ||
if (header.viewerRequestVolume) { | ||
this._viewerRequestVolume = createBoundingVolume(header.viewerRequestVolume, this.computedTransform, this._viewerRequestVolume); | ||
} | ||
} | ||
}, { | ||
key: "_updateTransform", | ||
value: function _updateTransform() { | ||
var parentTransform = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Matrix4(); | ||
var computedTransform = parentTransform.clone().multiplyRight(this.transform); | ||
var didTransformChange = !computedTransform.equals(this.computedTransform); | ||
this.computedTransform = computedTransform; | ||
if (!didTransformChange) { | ||
return; | ||
} | ||
this._updateBoundingVolume(this.header); | ||
} | ||
this.computedTransform = computedTransform; | ||
_getLoaderSpecificOptions(loaderId) { | ||
switch (loaderId) { | ||
case 'i3s': | ||
return { ...this.tileset.options.i3s, | ||
tile: this.header, | ||
tileset: this.tileset.tileset, | ||
isTileHeader: false | ||
}; | ||
this._updateBoundingVolume(this.header); | ||
} | ||
}, { | ||
key: "_getLoaderSpecificOptions", | ||
value: function _getLoaderSpecificOptions(loaderId) { | ||
switch (loaderId) { | ||
case 'i3s': | ||
return _objectSpread(_objectSpread({}, this.tileset.options.i3s), {}, { | ||
tile: this.header, | ||
tileset: this.tileset.tileset, | ||
isTileHeader: false | ||
}); | ||
case '3d-tiles': | ||
case 'cesium-ion': | ||
default: | ||
return get3dTilesOptions(this.tileset.tileset); | ||
case '3d-tiles': | ||
case 'cesium-ion': | ||
default: | ||
return get3dTilesOptions(this.tileset.tileset); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "updateExpiration", | ||
value: function updateExpiration() { | ||
if (defined(this._expireDate) && this.contentReady && !this.hasEmptyContent) { | ||
var now = Date.now(); | ||
updateExpiration() { | ||
if (defined(this._expireDate) && this.contentReady && !this.hasEmptyContent) { | ||
const now = Date.now(); | ||
if (Date.lessThan(this._expireDate, now)) { | ||
this.contentState = TILE_CONTENT_STATE.EXPIRED; | ||
this._expiredContent = this.content; | ||
if (Date.lessThan(this._expireDate, now)) { | ||
this.contentState = TILE_CONTENT_STATE.EXPIRED; | ||
this._expiredContent = this.content; | ||
} | ||
} | ||
} | ||
} | ||
}, { | ||
key: "extras", | ||
get: function get() { | ||
return this.header.extras; | ||
} | ||
}]); | ||
get extras() { | ||
return this.header.extras; | ||
} | ||
return TileHeader; | ||
}(); | ||
} | ||
export { TileHeader as default }; | ||
//# sourceMappingURL=tile-3d.js.map |
@@ -0,1 +1,17 @@ | ||
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
import { Matrix4, Vector3 } from '@math.gl/core'; | ||
@@ -14,17 +30,18 @@ import { Ellipsoid } from '@math.gl/geospatial'; | ||
import { TILESET_TYPE } from '../constants'; | ||
const TILES_TOTAL = 'Tiles In Tileset(s)'; | ||
const TILES_IN_MEMORY = 'Tiles In Memory'; | ||
const TILES_IN_VIEW = 'Tiles In View'; | ||
const TILES_RENDERABLE = 'Tiles To Render'; | ||
const TILES_LOADED = 'Tiles Loaded'; | ||
const TILES_LOADING = 'Tiles Loading'; | ||
const TILES_UNLOADED = 'Tiles Unloaded'; | ||
const TILES_LOAD_FAILED = 'Failed Tile Loads'; | ||
const POINTS_COUNT = 'Points'; | ||
const TILES_GPU_MEMORY = 'Tile Memory Use'; | ||
var TILES_TOTAL = 'Tiles In Tileset(s)'; | ||
var TILES_IN_MEMORY = 'Tiles In Memory'; | ||
var TILES_IN_VIEW = 'Tiles In View'; | ||
var TILES_RENDERABLE = 'Tiles To Render'; | ||
var TILES_LOADED = 'Tiles Loaded'; | ||
var TILES_LOADING = 'Tiles Loading'; | ||
var TILES_UNLOADED = 'Tiles Unloaded'; | ||
var TILES_LOAD_FAILED = 'Failed Tile Loads'; | ||
var POINTS_COUNT = 'Points'; | ||
var TILES_GPU_MEMORY = 'Tile Memory Use'; | ||
function getQueryParamString(queryParams) { | ||
const queryParamStrings = []; | ||
var queryParamStrings = []; | ||
for (const key of Object.keys(queryParams)) { | ||
for (var _i = 0, _Object$keys = Object.keys(queryParams); _i < _Object$keys.length; _i++) { | ||
var key = _Object$keys[_i]; | ||
queryParamStrings.push("".concat(key, "=").concat(queryParams[key])); | ||
@@ -45,3 +62,3 @@ } | ||
const DEFAULT_OPTIONS = { | ||
var DEFAULT_OPTIONS = { | ||
ellipsoid: Ellipsoid.WGS84, | ||
@@ -51,13 +68,16 @@ modelMatrix: new Matrix4(), | ||
maximumMemoryUsage: 32, | ||
onTileLoad: () => {}, | ||
onTileUnload: () => {}, | ||
onTileError: (tile, message, url) => {}, | ||
onTileLoad: function onTileLoad() {}, | ||
onTileUnload: function onTileUnload() {}, | ||
onTileError: function onTileError(tile, message, url) {}, | ||
maximumScreenSpaceError: 8 | ||
}; | ||
export default class Tileset3D { | ||
constructor(json, options = {}) { | ||
var Tileset3D = function () { | ||
function Tileset3D(json) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
_classCallCheck(this, Tileset3D); | ||
assert(json); | ||
this.options = { ...DEFAULT_OPTIONS, | ||
...options | ||
}; | ||
this.options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options); | ||
this.tileset = json; | ||
@@ -126,364 +146,505 @@ this.loader = json.loader; | ||
isLoaded() { | ||
return this._pendingCount === 0; | ||
} | ||
_createClass(Tileset3D, [{ | ||
key: "isLoaded", | ||
value: function isLoaded() { | ||
return this._pendingCount === 0; | ||
} | ||
}, { | ||
key: "destroy", | ||
value: function destroy() { | ||
this._destroy(); | ||
} | ||
}, { | ||
key: "tiles", | ||
get: function get() { | ||
return Object.values(this._tiles); | ||
} | ||
}, { | ||
key: "getTileUrl", | ||
value: function getTileUrl(tilePath) { | ||
var isDataUrl = tilePath.startsWith('data:'); | ||
destroy() { | ||
this._destroy(); | ||
} | ||
if (isDataUrl) { | ||
return tilePath; | ||
} | ||
get tiles() { | ||
return Object.values(this._tiles); | ||
} | ||
return "".concat(tilePath).concat(this.queryParams); | ||
} | ||
}, { | ||
key: "update", | ||
value: function update(viewport) { | ||
this._cache.reset(); | ||
getTileUrl(tilePath) { | ||
const isDataUrl = tilePath.startsWith('data:'); | ||
this._frameNumber++; | ||
this._frameState = getFrameState(viewport, this._frameNumber); | ||
if (isDataUrl) { | ||
return tilePath; | ||
this._traverser.traverse(this.root, this._frameState, this.options); | ||
} | ||
}, { | ||
key: "_onTraversalEnd", | ||
value: function _onTraversalEnd() { | ||
var selectedTiles = Object.values(this._traverser.selectedTiles); | ||
return "".concat(tilePath).concat(this.queryParams); | ||
} | ||
if (this._tilesChanged(this.selectedTiles, selectedTiles)) { | ||
this._updateFrameNumber++; | ||
} | ||
update(viewport) { | ||
this._cache.reset(); | ||
this.selectedTiles = selectedTiles; | ||
this._frameNumber++; | ||
this._frameState = getFrameState(viewport, this._frameNumber); | ||
var _iterator = _createForOfIteratorHelper(this.selectedTiles), | ||
_step; | ||
this._traverser.traverse(this.root, this._frameState, this.options); | ||
} | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var tile = _step.value; | ||
this._tiles[tile.id] = tile; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
_onTraversalEnd() { | ||
const selectedTiles = Object.values(this._traverser.selectedTiles); | ||
this._requestedTiles = Object.values(this._traverser.requestedTiles); | ||
this._emptyTiles = Object.values(this._traverser.emptyTiles); | ||
if (this._tilesChanged(this.selectedTiles, selectedTiles)) { | ||
this._updateFrameNumber++; | ||
} | ||
this._loadTiles(this._frameState); | ||
this.selectedTiles = selectedTiles; | ||
this._unloadTiles(); | ||
for (const tile of this.selectedTiles) { | ||
this._tiles[tile.id] = tile; | ||
this._updateStats(); | ||
return this._updateFrameNumber; | ||
} | ||
}, { | ||
key: "_tilesChanged", | ||
value: function _tilesChanged(oldSelectedTiles, selectedTiles) { | ||
if (oldSelectedTiles.length !== selectedTiles.length) { | ||
return true; | ||
} | ||
this._requestedTiles = Object.values(this._traverser.requestedTiles); | ||
this._emptyTiles = Object.values(this._traverser.emptyTiles); | ||
this._loadTiles(this._frameState); | ||
this._unloadTiles(); | ||
this._updateStats(); | ||
return this._updateFrameNumber; | ||
} | ||
_tilesChanged(oldSelectedTiles, selectedTiles) { | ||
if (oldSelectedTiles.length !== selectedTiles.length) { | ||
return true; | ||
var set1 = new Set(oldSelectedTiles.map(function (t) { | ||
return t.id; | ||
})); | ||
var set2 = new Set(selectedTiles.map(function (t) { | ||
return t.id; | ||
})); | ||
var changed = oldSelectedTiles.filter(function (x) { | ||
return !set2.has(x.id); | ||
}).length > 0; | ||
changed = changed || selectedTiles.filter(function (x) { | ||
return !set1.has(x.id); | ||
}).length > 0; | ||
return changed; | ||
} | ||
}, { | ||
key: "_loadTiles", | ||
value: function _loadTiles(frameState) { | ||
var _iterator2 = _createForOfIteratorHelper(this._requestedTiles), | ||
_step2; | ||
const set1 = new Set(oldSelectedTiles.map(t => t.id)); | ||
const set2 = new Set(selectedTiles.map(t => t.id)); | ||
let changed = oldSelectedTiles.filter(x => !set2.has(x.id)).length > 0; | ||
changed = changed || selectedTiles.filter(x => !set1.has(x.id)).length > 0; | ||
return changed; | ||
} | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var tile = _step2.value; | ||
_loadTiles(frameState) { | ||
for (const tile of this._requestedTiles) { | ||
if (tile.contentUnloaded) { | ||
this._loadTile(tile, frameState); | ||
if (tile.contentUnloaded) { | ||
this._loadTile(tile, frameState); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "_unloadTiles", | ||
value: function _unloadTiles() { | ||
this._cache.unloadTiles(this, function (tileset, tile) { | ||
return tileset._unloadTile(tile); | ||
}); | ||
} | ||
}, { | ||
key: "_updateStats", | ||
value: function _updateStats() { | ||
var tilesRenderable = 0; | ||
var pointsRenderable = 0; | ||
_unloadTiles() { | ||
this._cache.unloadTiles(this, (tileset, tile) => tileset._unloadTile(tile)); | ||
} | ||
var _iterator3 = _createForOfIteratorHelper(this.selectedTiles), | ||
_step3; | ||
_updateStats() { | ||
let tilesRenderable = 0; | ||
let pointsRenderable = 0; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var tile = _step3.value; | ||
for (const tile of this.selectedTiles) { | ||
if (tile.contentAvailable) { | ||
tilesRenderable++; | ||
if (tile.contentAvailable) { | ||
tilesRenderable++; | ||
if (tile.content.pointCount) { | ||
pointsRenderable += tile.content.pointCount; | ||
if (tile.content.pointCount) { | ||
pointsRenderable += tile.content.pointCount; | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
} | ||
this.stats.get(TILES_IN_VIEW).count = this.selectedTiles.length; | ||
this.stats.get(TILES_RENDERABLE).count = tilesRenderable; | ||
this.stats.get(POINTS_COUNT).count = pointsRenderable; | ||
} | ||
}, { | ||
key: "_initializeTileSet", | ||
value: function _initializeTileSet(tilesetJson) { | ||
this.root = this._initializeTileHeaders(tilesetJson, null, this.basePath); | ||
this.stats.get(TILES_IN_VIEW).count = this.selectedTiles.length; | ||
this.stats.get(TILES_RENDERABLE).count = tilesRenderable; | ||
this.stats.get(POINTS_COUNT).count = pointsRenderable; | ||
} | ||
if (this.type === TILESET_TYPE.TILES3D) { | ||
this._initializeCesiumTileset(tilesetJson); | ||
} | ||
_initializeTileSet(tilesetJson) { | ||
this.root = this._initializeTileHeaders(tilesetJson, null, this.basePath); | ||
if (this.type === TILESET_TYPE.I3S) { | ||
this._initializeI3STileset(tilesetJson); | ||
} | ||
if (this.type === TILESET_TYPE.TILES3D) { | ||
this._initializeCesiumTileset(tilesetJson); | ||
this._calculateViewProps(); | ||
} | ||
}, { | ||
key: "_calculateViewProps", | ||
value: function _calculateViewProps() { | ||
var root = this.root; | ||
var center = root.boundingVolume.center; | ||
if (this.type === TILESET_TYPE.I3S) { | ||
this._initializeI3STileset(tilesetJson); | ||
} | ||
if (!center) { | ||
console.warn('center was not pre-calculated for the root tile'); | ||
this.cartographicCenter = new Vector3(); | ||
this.zoom = 1; | ||
return; | ||
} | ||
this._calculateViewProps(); | ||
} | ||
_calculateViewProps() { | ||
const root = this.root; | ||
const { | ||
center | ||
} = root.boundingVolume; | ||
if (!center) { | ||
console.warn('center was not pre-calculated for the root tile'); | ||
this.cartographicCenter = new Vector3(); | ||
this.zoom = 1; | ||
return; | ||
this.cartographicCenter = Ellipsoid.WGS84.cartesianToCartographic(center, new Vector3()); | ||
this.cartesianCenter = center; | ||
this.zoom = getZoomFromBoundingVolume(root.boundingVolume); | ||
} | ||
}, { | ||
key: "_initializeStats", | ||
value: function _initializeStats() { | ||
this.stats.get(TILES_TOTAL); | ||
this.stats.get(TILES_LOADING); | ||
this.stats.get(TILES_IN_MEMORY); | ||
this.stats.get(TILES_IN_VIEW); | ||
this.stats.get(TILES_RENDERABLE); | ||
this.stats.get(TILES_LOADED); | ||
this.stats.get(TILES_UNLOADED); | ||
this.stats.get(TILES_LOAD_FAILED); | ||
this.stats.get(POINTS_COUNT, 'memory'); | ||
this.stats.get(TILES_GPU_MEMORY, 'memory'); | ||
} | ||
}, { | ||
key: "_initializeTileHeaders", | ||
value: function _initializeTileHeaders(tilesetJson, parentTileHeader, basePath) { | ||
var rootTile = new Tile3D(this, tilesetJson.root, parentTileHeader, basePath); | ||
this.cartographicCenter = Ellipsoid.WGS84.cartesianToCartographic(center, new Vector3()); | ||
this.cartesianCenter = center; | ||
this.zoom = getZoomFromBoundingVolume(root.boundingVolume); | ||
} | ||
if (parentTileHeader) { | ||
parentTileHeader.children.push(rootTile); | ||
rootTile.depth = parentTileHeader.depth + 1; | ||
} | ||
_initializeStats() { | ||
this.stats.get(TILES_TOTAL); | ||
this.stats.get(TILES_LOADING); | ||
this.stats.get(TILES_IN_MEMORY); | ||
this.stats.get(TILES_IN_VIEW); | ||
this.stats.get(TILES_RENDERABLE); | ||
this.stats.get(TILES_LOADED); | ||
this.stats.get(TILES_UNLOADED); | ||
this.stats.get(TILES_LOAD_FAILED); | ||
this.stats.get(POINTS_COUNT, 'memory'); | ||
this.stats.get(TILES_GPU_MEMORY, 'memory'); | ||
} | ||
if (this.type === TILESET_TYPE.TILES3D) { | ||
var stack = []; | ||
stack.push(rootTile); | ||
_initializeTileHeaders(tilesetJson, parentTileHeader, basePath) { | ||
const rootTile = new Tile3D(this, tilesetJson.root, parentTileHeader, basePath); | ||
while (stack.length > 0) { | ||
var tile = stack.pop(); | ||
this.stats.get(TILES_TOTAL).incrementCount(); | ||
var children = tile.header.children || []; | ||
if (parentTileHeader) { | ||
parentTileHeader.children.push(rootTile); | ||
rootTile.depth = parentTileHeader.depth + 1; | ||
} | ||
var _iterator4 = _createForOfIteratorHelper(children), | ||
_step4; | ||
if (this.type === TILESET_TYPE.TILES3D) { | ||
const stack = []; | ||
stack.push(rootTile); | ||
while (stack.length > 0) { | ||
const tile = stack.pop(); | ||
this.stats.get(TILES_TOTAL).incrementCount(); | ||
const children = tile.header.children || []; | ||
for (const childHeader of children) { | ||
const childTile = new Tile3D(this, childHeader, tile, basePath); | ||
tile.children.push(childTile); | ||
childTile.depth = tile.depth + 1; | ||
stack.push(childTile); | ||
try { | ||
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { | ||
var childHeader = _step4.value; | ||
var childTile = new Tile3D(this, childHeader, tile, basePath); | ||
tile.children.push(childTile); | ||
childTile.depth = tile.depth + 1; | ||
stack.push(childTile); | ||
} | ||
} catch (err) { | ||
_iterator4.e(err); | ||
} finally { | ||
_iterator4.f(); | ||
} | ||
} | ||
} | ||
return rootTile; | ||
} | ||
}, { | ||
key: "_initializeTraverser", | ||
value: function _initializeTraverser() { | ||
var TraverserClass; | ||
var type = this.type; | ||
return rootTile; | ||
} | ||
switch (type) { | ||
case TILESET_TYPE.TILES3D: | ||
TraverserClass = Tileset3DTraverser; | ||
break; | ||
_initializeTraverser() { | ||
let TraverserClass; | ||
const type = this.type; | ||
case TILESET_TYPE.I3S: | ||
TraverserClass = I3SetTraverser; | ||
break; | ||
switch (type) { | ||
case TILESET_TYPE.TILES3D: | ||
TraverserClass = Tileset3DTraverser; | ||
break; | ||
default: | ||
TraverserClass = TilesetTraverser; | ||
} | ||
case TILESET_TYPE.I3S: | ||
TraverserClass = I3SetTraverser; | ||
break; | ||
default: | ||
TraverserClass = TilesetTraverser; | ||
return new TraverserClass({ | ||
basePath: this.basePath, | ||
onTraversalEnd: this._onTraversalEnd.bind(this) | ||
}); | ||
} | ||
}, { | ||
key: "_destroyTileHeaders", | ||
value: function _destroyTileHeaders(parentTile) { | ||
this._destroySubtree(parentTile); | ||
} | ||
}, { | ||
key: "_loadTile", | ||
value: function () { | ||
var _loadTile2 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(tile, frameState) { | ||
var loaded; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.prev = 0; | ||
return new TraverserClass({ | ||
basePath: this.basePath, | ||
onTraversalEnd: this._onTraversalEnd.bind(this) | ||
}); | ||
} | ||
this._onStartTileLoading(); | ||
_destroyTileHeaders(parentTile) { | ||
this._destroySubtree(parentTile); | ||
} | ||
_context.next = 4; | ||
return tile.loadContent(frameState); | ||
async _loadTile(tile, frameState) { | ||
let loaded; | ||
case 4: | ||
loaded = _context.sent; | ||
_context.next = 10; | ||
break; | ||
try { | ||
this._onStartTileLoading(); | ||
case 7: | ||
_context.prev = 7; | ||
_context.t0 = _context["catch"](0); | ||
loaded = await tile.loadContent(frameState); | ||
} catch (error) { | ||
this._onTileLoadError(tile, error); | ||
} finally { | ||
this._onEndTileLoading(); | ||
this._onTileLoadError(tile, _context.t0); | ||
this._onTileLoad(tile, loaded); | ||
} | ||
} | ||
case 10: | ||
_context.prev = 10; | ||
_onTileLoadError(tile, error) { | ||
this.stats.get(TILES_LOAD_FAILED).incrementCount(); | ||
const message = error.message || error.toString(); | ||
const url = tile.url; | ||
console.error("A 3D tile failed to load: ".concat(tile.url, " ").concat(message)); | ||
this.options.onTileError(tile, message, url); | ||
} | ||
this._onEndTileLoading(); | ||
_onTileLoad(tile, loaded) { | ||
if (!loaded) { | ||
return; | ||
} | ||
this._onTileLoad(tile, loaded); | ||
if (tile && tile.content) { | ||
calculateTransformProps(tile, tile.content); | ||
} | ||
return _context.finish(10); | ||
this._addTileToCache(tile); | ||
case 14: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this, [[0, 7, 10, 14]]); | ||
})); | ||
this.options.onTileLoad(tile); | ||
} | ||
function _loadTile(_x, _x2) { | ||
return _loadTile2.apply(this, arguments); | ||
} | ||
_onStartTileLoading() { | ||
this._pendingCount++; | ||
this.stats.get(TILES_LOADING).incrementCount(); | ||
} | ||
return _loadTile; | ||
}() | ||
}, { | ||
key: "_onTileLoadError", | ||
value: function _onTileLoadError(tile, error) { | ||
this.stats.get(TILES_LOAD_FAILED).incrementCount(); | ||
var message = error.message || error.toString(); | ||
var url = tile.url; | ||
console.error("A 3D tile failed to load: ".concat(tile.url, " ").concat(message)); | ||
this.options.onTileError(tile, message, url); | ||
} | ||
}, { | ||
key: "_onTileLoad", | ||
value: function _onTileLoad(tile, loaded) { | ||
if (!loaded) { | ||
return; | ||
} | ||
_onEndTileLoading() { | ||
this._pendingCount--; | ||
this.stats.get(TILES_LOADING).decrementCount(); | ||
} | ||
if (tile && tile.content) { | ||
calculateTransformProps(tile, tile.content); | ||
} | ||
_addTileToCache(tile) { | ||
this._cache.add(this, tile, tileset => tileset._updateCacheStats(tile)); | ||
} | ||
this._addTileToCache(tile); | ||
_updateCacheStats(tile) { | ||
this.stats.get(TILES_LOADED).incrementCount(); | ||
this.stats.get(TILES_IN_MEMORY).incrementCount(); | ||
this.gpuMemoryUsageInBytes += tile.content.byteLength || 0; | ||
this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes; | ||
} | ||
this.options.onTileLoad(tile); | ||
} | ||
}, { | ||
key: "_onStartTileLoading", | ||
value: function _onStartTileLoading() { | ||
this._pendingCount++; | ||
this.stats.get(TILES_LOADING).incrementCount(); | ||
} | ||
}, { | ||
key: "_onEndTileLoading", | ||
value: function _onEndTileLoading() { | ||
this._pendingCount--; | ||
this.stats.get(TILES_LOADING).decrementCount(); | ||
} | ||
}, { | ||
key: "_addTileToCache", | ||
value: function _addTileToCache(tile) { | ||
this._cache.add(this, tile, function (tileset) { | ||
return tileset._updateCacheStats(tile); | ||
}); | ||
} | ||
}, { | ||
key: "_updateCacheStats", | ||
value: function _updateCacheStats(tile) { | ||
this.stats.get(TILES_LOADED).incrementCount(); | ||
this.stats.get(TILES_IN_MEMORY).incrementCount(); | ||
this.gpuMemoryUsageInBytes += tile.content.byteLength || 0; | ||
this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes; | ||
} | ||
}, { | ||
key: "_unloadTile", | ||
value: function _unloadTile(tile) { | ||
this.gpuMemoryUsageInBytes -= tile.content.byteLength || 0; | ||
this.stats.get(TILES_IN_MEMORY).decrementCount(); | ||
this.stats.get(TILES_UNLOADED).incrementCount(); | ||
this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes; | ||
this.options.onTileUnload(tile); | ||
tile.unloadContent(); | ||
} | ||
}, { | ||
key: "_destroy", | ||
value: function _destroy() { | ||
var stack = []; | ||
_unloadTile(tile) { | ||
this.gpuMemoryUsageInBytes -= tile.content.byteLength || 0; | ||
this.stats.get(TILES_IN_MEMORY).decrementCount(); | ||
this.stats.get(TILES_UNLOADED).incrementCount(); | ||
this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes; | ||
this.options.onTileUnload(tile); | ||
tile.unloadContent(); | ||
} | ||
if (this.root) { | ||
stack.push(this.root); | ||
} | ||
_destroy() { | ||
const stack = []; | ||
while (stack.length > 0) { | ||
var tile = stack.pop(); | ||
if (this.root) { | ||
stack.push(this.root); | ||
} | ||
var _iterator5 = _createForOfIteratorHelper(tile.children), | ||
_step5; | ||
while (stack.length > 0) { | ||
const tile = stack.pop(); | ||
try { | ||
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { | ||
var child = _step5.value; | ||
stack.push(child); | ||
} | ||
} catch (err) { | ||
_iterator5.e(err); | ||
} finally { | ||
_iterator5.f(); | ||
} | ||
for (const child of tile.children) { | ||
stack.push(child); | ||
this._destroyTile(tile); | ||
} | ||
this._destroyTile(tile); | ||
this.root = null; | ||
} | ||
}, { | ||
key: "_destroySubtree", | ||
value: function _destroySubtree(tile) { | ||
var root = tile; | ||
var stack = []; | ||
stack.push(root); | ||
this.root = null; | ||
} | ||
while (stack.length > 0) { | ||
tile = stack.pop(); | ||
_destroySubtree(tile) { | ||
const root = tile; | ||
const stack = []; | ||
stack.push(root); | ||
var _iterator6 = _createForOfIteratorHelper(tile.children), | ||
_step6; | ||
while (stack.length > 0) { | ||
tile = stack.pop(); | ||
try { | ||
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { | ||
var child = _step6.value; | ||
stack.push(child); | ||
} | ||
} catch (err) { | ||
_iterator6.e(err); | ||
} finally { | ||
_iterator6.f(); | ||
} | ||
for (const child of tile.children) { | ||
stack.push(child); | ||
if (tile !== root) { | ||
this._destroyTile(tile); | ||
} | ||
} | ||
if (tile !== root) { | ||
this._destroyTile(tile); | ||
} | ||
root.children = []; | ||
} | ||
}, { | ||
key: "_destroyTile", | ||
value: function _destroyTile(tile) { | ||
this._cache.unloadTile(this, tile); | ||
root.children = []; | ||
} | ||
this._unloadTile(tile); | ||
_destroyTile(tile) { | ||
this._cache.unloadTile(this, tile); | ||
tile.destroy(); | ||
} | ||
}, { | ||
key: "_initializeCesiumTileset", | ||
value: function _initializeCesiumTileset(tilesetJson) { | ||
this.asset = tilesetJson.asset; | ||
this._unloadTile(tile); | ||
if (!this.asset) { | ||
throw new Error('Tileset must have an asset property.'); | ||
} | ||
tile.destroy(); | ||
} | ||
if (this.asset.version !== '0.0' && this.asset.version !== '1.0') { | ||
throw new Error('The tileset must be 3D Tiles version 0.0 or 1.0.'); | ||
} | ||
_initializeCesiumTileset(tilesetJson) { | ||
this.asset = tilesetJson.asset; | ||
if ('tilesetVersion' in this.asset) { | ||
this._queryParams.v = this.asset.tilesetVersion; | ||
} | ||
if (!this.asset) { | ||
throw new Error('Tileset must have an asset property.'); | ||
this.credits = { | ||
attributions: this.options.attributions || [] | ||
}; | ||
this.description = this.options.description; | ||
this.properties = tilesetJson.properties; | ||
this.geometricError = tilesetJson.geometricError; | ||
this._extensionsUsed = tilesetJson.extensionsUsed; | ||
this.extras = tilesetJson.extras; | ||
} | ||
}, { | ||
key: "_initializeI3STileset", | ||
value: function _initializeI3STileset(tilesetJson) { | ||
if ('token' in this.options) { | ||
this._queryParams.token = this.options.token; | ||
} | ||
if (this.asset.version !== '0.0' && this.asset.version !== '1.0') { | ||
throw new Error('The tileset must be 3D Tiles version 0.0 or 1.0.'); | ||
this._defaultGeometrySchema = tilesetJson.store.defaultGeometrySchema; | ||
} | ||
if ('tilesetVersion' in this.asset) { | ||
this._queryParams.v = this.asset.tilesetVersion; | ||
}, { | ||
key: "hasExtension", | ||
value: function hasExtension(extensionName) { | ||
return Boolean(this._extensionsUsed && this._extensionsUsed.indexOf(extensionName) > -1); | ||
} | ||
}, { | ||
key: "queryParams", | ||
get: function get() { | ||
if (!this._queryParamsString) { | ||
this._queryParamsString = getQueryParamString(this._queryParams); | ||
} | ||
this.credits = { | ||
attributions: this.options.attributions || [] | ||
}; | ||
this.description = this.options.description; | ||
this.properties = tilesetJson.properties; | ||
this.geometricError = tilesetJson.geometricError; | ||
this._extensionsUsed = tilesetJson.extensionsUsed; | ||
this.extras = tilesetJson.extras; | ||
} | ||
_initializeI3STileset(tilesetJson) { | ||
if ('token' in this.options) { | ||
this._queryParams.token = this.options.token; | ||
return this._queryParamsString; | ||
} | ||
}]); | ||
this._defaultGeometrySchema = tilesetJson.store.defaultGeometrySchema; | ||
} | ||
return Tileset3D; | ||
}(); | ||
hasExtension(extensionName) { | ||
return Boolean(this._extensionsUsed && this._extensionsUsed.indexOf(extensionName) > -1); | ||
} | ||
get queryParams() { | ||
if (!this._queryParamsString) { | ||
this._queryParamsString = getQueryParamString(this._queryParams); | ||
} | ||
return this._queryParamsString; | ||
} | ||
} | ||
export { Tileset3D as default }; | ||
//# sourceMappingURL=tileset-3d.js.map |
@@ -0,1 +1,3 @@ | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import DoublyLinkedList from '../utils/doubly-linked-list'; | ||
@@ -7,4 +9,6 @@ | ||
export default class TilesetCache { | ||
constructor() { | ||
var TilesetCache = function () { | ||
function TilesetCache() { | ||
_classCallCheck(this, TilesetCache); | ||
this._list = new DoublyLinkedList(); | ||
@@ -15,60 +19,71 @@ this._sentinel = this._list.add('sentinel'); | ||
reset() { | ||
this._list.splice(this._list.tail, this._sentinel); | ||
} | ||
_createClass(TilesetCache, [{ | ||
key: "reset", | ||
value: function reset() { | ||
this._list.splice(this._list.tail, this._sentinel); | ||
} | ||
}, { | ||
key: "touch", | ||
value: function touch(tile) { | ||
var node = tile._cacheNode; | ||
touch(tile) { | ||
const node = tile._cacheNode; | ||
if (defined(node)) { | ||
this._list.splice(this._sentinel, node); | ||
if (defined(node)) { | ||
this._list.splice(this._sentinel, node); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "add", | ||
value: function add(tileset, tile, addCallback) { | ||
if (!defined(tile._cacheNode)) { | ||
tile._cacheNode = this._list.add(tile); | ||
add(tileset, tile, addCallback) { | ||
if (!defined(tile._cacheNode)) { | ||
tile._cacheNode = this._list.add(tile); | ||
if (addCallback) { | ||
addCallback(tileset, tile); | ||
if (addCallback) { | ||
addCallback(tileset, tile); | ||
} | ||
} | ||
} | ||
} | ||
}, { | ||
key: "unloadTile", | ||
value: function unloadTile(tileset, tile, unloadCallback) { | ||
var node = tile._cacheNode; | ||
unloadTile(tileset, tile, unloadCallback) { | ||
const node = tile._cacheNode; | ||
if (!defined(node)) { | ||
return; | ||
} | ||
if (!defined(node)) { | ||
return; | ||
} | ||
this._list.remove(node); | ||
this._list.remove(node); | ||
tile._cacheNode = undefined; | ||
tile._cacheNode = undefined; | ||
if (unloadCallback) { | ||
unloadCallback(tileset, tile); | ||
if (unloadCallback) { | ||
unloadCallback(tileset, tile); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "unloadTiles", | ||
value: function unloadTiles(tileset, unloadCallback) { | ||
var trimTiles = this._trimTiles; | ||
this._trimTiles = false; | ||
var list = this._list; | ||
var maximumMemoryUsageInBytes = tileset.maximumMemoryUsage * 1024 * 1024; | ||
var sentinel = this._sentinel; | ||
var node = list.head; | ||
unloadTiles(tileset, unloadCallback) { | ||
const trimTiles = this._trimTiles; | ||
this._trimTiles = false; | ||
const list = this._list; | ||
const maximumMemoryUsageInBytes = tileset.maximumMemoryUsage * 1024 * 1024; | ||
const sentinel = this._sentinel; | ||
let node = list.head; | ||
while (node !== sentinel && (tileset.gpuMemoryUsageInBytes > maximumMemoryUsageInBytes || trimTiles)) { | ||
const tile = node.item; | ||
node = node.next; | ||
this.unloadTile(tileset, tile, unloadCallback); | ||
while (node !== sentinel && (tileset.gpuMemoryUsageInBytes > maximumMemoryUsageInBytes || trimTiles)) { | ||
var tile = node.item; | ||
node = node.next; | ||
this.unloadTile(tileset, tile, unloadCallback); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "trim", | ||
value: function trim() { | ||
this._trimTiles = true; | ||
} | ||
}]); | ||
trim() { | ||
this._trimTiles = true; | ||
} | ||
return TilesetCache; | ||
}(); | ||
} | ||
export { TilesetCache as default }; | ||
//# sourceMappingURL=tileset-cache.js.map |
@@ -1,2 +0,4 @@ | ||
const STATUS = { | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
var STATUS = { | ||
REQUESTED: 'REQUESTED', | ||
@@ -6,38 +8,51 @@ COMPLETED: 'COMPLETED', | ||
}; | ||
export default class I3STileManager { | ||
constructor() { | ||
var I3STileManager = function () { | ||
function I3STileManager() { | ||
_classCallCheck(this, I3STileManager); | ||
this._statusMap = {}; | ||
} | ||
add(request, key, callback, frameState) { | ||
if (!this._statusMap[key]) { | ||
this._statusMap[key] = { | ||
request, | ||
callback, | ||
key, | ||
frameState, | ||
status: STATUS.REQUESTED | ||
}; | ||
request().then(data => { | ||
this._statusMap[key].status = STATUS.COMPLETED; | ||
_createClass(I3STileManager, [{ | ||
key: "add", | ||
value: function add(request, key, callback, frameState) { | ||
var _this = this; | ||
this._statusMap[key].callback(data, frameState); | ||
}).catch(error => { | ||
this._statusMap[key].status = STATUS.ERROR; | ||
callback(error); | ||
}); | ||
} | ||
} | ||
if (!this._statusMap[key]) { | ||
this._statusMap[key] = { | ||
request: request, | ||
callback: callback, | ||
key: key, | ||
frameState: frameState, | ||
status: STATUS.REQUESTED | ||
}; | ||
request().then(function (data) { | ||
_this._statusMap[key].status = STATUS.COMPLETED; | ||
update(key, frameState) { | ||
if (this._statusMap[key]) { | ||
this._statusMap[key].frameState = frameState; | ||
_this._statusMap[key].callback(data, frameState); | ||
}).catch(function (error) { | ||
_this._statusMap[key].status = STATUS.ERROR; | ||
callback(error); | ||
}); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "update", | ||
value: function update(key, frameState) { | ||
if (this._statusMap[key]) { | ||
this._statusMap[key].frameState = frameState; | ||
} | ||
} | ||
}, { | ||
key: "find", | ||
value: function find(key) { | ||
return this._statusMap[key]; | ||
} | ||
}]); | ||
find(key) { | ||
return this._statusMap[key]; | ||
} | ||
return I3STileManager; | ||
}(); | ||
} | ||
export { I3STileManager as default }; | ||
//# sourceMappingURL=i3s-tile-manager.js.map |
@@ -0,1 +1,24 @@ | ||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import _inherits from "@babel/runtime/helpers/esm/inherits"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
import { load } from '@loaders.gl/core'; | ||
@@ -6,70 +29,135 @@ import TilesetTraverser from './tileset-traverser'; | ||
import I3STileManager from './i3s-tile-manager'; | ||
export default class I3STilesetTraverser extends TilesetTraverser { | ||
constructor(options) { | ||
super(options); | ||
this._tileManager = new I3STileManager(); | ||
} | ||
shouldRefine(tile, frameState) { | ||
tile._lodJudge = lodJudge(tile, frameState); | ||
return tile._lodJudge === 'DIG'; | ||
var I3STilesetTraverser = function (_TilesetTraverser) { | ||
_inherits(I3STilesetTraverser, _TilesetTraverser); | ||
var _super = _createSuper(I3STilesetTraverser); | ||
function I3STilesetTraverser(options) { | ||
var _this; | ||
_classCallCheck(this, I3STilesetTraverser); | ||
_this = _super.call(this, options); | ||
_this._tileManager = new I3STileManager(); | ||
return _this; | ||
} | ||
updateChildTiles(tile, frameState) { | ||
const children = tile.header.children || []; | ||
const childTiles = tile.children; | ||
const tileset = tile.tileset; | ||
_createClass(I3STilesetTraverser, [{ | ||
key: "shouldRefine", | ||
value: function shouldRefine(tile, frameState) { | ||
tile._lodJudge = lodJudge(tile, frameState); | ||
return tile._lodJudge === 'DIG'; | ||
} | ||
}, { | ||
key: "updateChildTiles", | ||
value: function updateChildTiles(tile, frameState) { | ||
var _this2 = this; | ||
for (const child of children) { | ||
const childTile = childTiles && childTiles.find(t => t.id === child.id); | ||
var children = tile.header.children || []; | ||
var childTiles = tile.children; | ||
var tileset = tile.tileset; | ||
if (!childTile) { | ||
let request = () => this._loadTile(child.id, tileset); | ||
var _iterator = _createForOfIteratorHelper(children), | ||
_step; | ||
const cachedRequest = this._tileManager.find(child.id); | ||
try { | ||
var _loop = function _loop() { | ||
var child = _step.value; | ||
var childTile = childTiles && childTiles.find(function (t) { | ||
return t.id === child.id; | ||
}); | ||
if (!cachedRequest) { | ||
if (tileset.tileset.nodePages) { | ||
request = () => tileset.tileset.nodePagesTile.formTileFromNodePages(child.id); | ||
if (!childTile) { | ||
var request = function request() { | ||
return _this2._loadTile(child.id, tileset); | ||
}; | ||
var cachedRequest = _this2._tileManager.find(child.id); | ||
if (!cachedRequest) { | ||
if (tileset.tileset.nodePages) { | ||
request = function request() { | ||
return tileset.tileset.nodePagesTile.formTileFromNodePages(child.id); | ||
}; | ||
} | ||
_this2._tileManager.add(request, child.id, function (header) { | ||
return _this2._onTileLoad(header, tile); | ||
}, frameState); | ||
} else { | ||
_this2._tileManager.update(child.id, frameState); | ||
} | ||
} else if (childTile) { | ||
_this2.updateTile(childTile, frameState); | ||
} | ||
}; | ||
this._tileManager.add(request, child.id, header => this._onTileLoad(header, tile), frameState); | ||
} else { | ||
this._tileManager.update(child.id, frameState); | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
_loop(); | ||
} | ||
} else if (childTile) { | ||
this.updateTile(childTile, frameState); | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "_loadTile", | ||
value: function () { | ||
var _loadTile2 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(nodeId, tileset) { | ||
var loader, nodeUrl, options; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
loader = tileset.loader; | ||
nodeUrl = tileset.getTileUrl("".concat(tileset.url, "/nodes/").concat(nodeId)); | ||
options = { | ||
i3s: _objectSpread(_objectSpread({}, tileset.fetchOptions), {}, { | ||
isTileHeader: true, | ||
loadContent: false | ||
}) | ||
}; | ||
_context.next = 5; | ||
return load(nodeUrl, loader, options); | ||
async _loadTile(nodeId, tileset) { | ||
const { | ||
loader | ||
} = tileset; | ||
const nodeUrl = tileset.getTileUrl("".concat(tileset.url, "/nodes/").concat(nodeId)); | ||
const options = { | ||
i3s: { ...tileset.fetchOptions, | ||
isTileHeader: true, | ||
loadContent: false | ||
case 5: | ||
return _context.abrupt("return", _context.sent); | ||
case 6: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
function _loadTile(_x, _x2) { | ||
return _loadTile2.apply(this, arguments); | ||
} | ||
}; | ||
return await load(nodeUrl, loader, options); | ||
} | ||
_onTileLoad(header, tile) { | ||
const basePath = this.options.basePath; | ||
const childTile = new TileHeader(tile.tileset, header, tile, basePath); | ||
tile.children.push(childTile); | ||
return _loadTile; | ||
}() | ||
}, { | ||
key: "_onTileLoad", | ||
value: function _onTileLoad(header, tile) { | ||
var basePath = this.options.basePath; | ||
var childTile = new TileHeader(tile.tileset, header, tile, basePath); | ||
tile.children.push(childTile); | ||
const frameState = this._tileManager.find(childTile.id).frameState; | ||
var frameState = this._tileManager.find(childTile.id).frameState; | ||
this.updateTile(childTile, frameState); | ||
this.updateTile(childTile, frameState); | ||
if (this._frameNumber === frameState.frameNumber) { | ||
this.executeTraversal(childTile, frameState); | ||
if (this._frameNumber === frameState.frameNumber) { | ||
this.executeTraversal(childTile, frameState); | ||
} | ||
} | ||
} | ||
}]); | ||
} | ||
return I3STilesetTraverser; | ||
}(TilesetTraverser); | ||
export { I3STilesetTraverser as default }; | ||
//# sourceMappingURL=i3s-tilset-traverser.js.map |
@@ -0,53 +1,80 @@ | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import _inherits from "@babel/runtime/helpers/esm/inherits"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
import { TILE3D_OPTIMIZATION_HINT, TILE_REFINEMENT } from '../../constants'; | ||
import TilesetTraverser from './tileset-traverser'; | ||
export default class Tileset3DTraverser extends TilesetTraverser { | ||
compareDistanceToCamera(a, b) { | ||
return b._distanceToCamera === 0 && a._distanceToCamera === 0 ? b._centerZDepth - a._centerZDepth : b._distanceToCamera - a._distanceToCamera; | ||
} | ||
updateTileVisibility(tile, frameState) { | ||
tile.updateVisibility(frameState); | ||
var Tileset3DTraverser = function (_TilesetTraverser) { | ||
_inherits(Tileset3DTraverser, _TilesetTraverser); | ||
if (!tile.isVisibleAndInRequestVolume) { | ||
return; | ||
} | ||
var _super = _createSuper(Tileset3DTraverser); | ||
const hasChildren = tile.children.length > 0; | ||
function Tileset3DTraverser() { | ||
_classCallCheck(this, Tileset3DTraverser); | ||
if (tile.hasTilesetContent && hasChildren) { | ||
const firstChild = tile.children[0]; | ||
this.updateTileVisibility(firstChild, frameState); | ||
tile._visible = firstChild._visible; | ||
return; | ||
} | ||
return _super.apply(this, arguments); | ||
} | ||
if (this.meetsScreenSpaceErrorEarly(tile, frameState)) { | ||
tile._visible = false; | ||
return; | ||
_createClass(Tileset3DTraverser, [{ | ||
key: "compareDistanceToCamera", | ||
value: function compareDistanceToCamera(a, b) { | ||
return b._distanceToCamera === 0 && a._distanceToCamera === 0 ? b._centerZDepth - a._centerZDepth : b._distanceToCamera - a._distanceToCamera; | ||
} | ||
}, { | ||
key: "updateTileVisibility", | ||
value: function updateTileVisibility(tile, frameState) { | ||
tile.updateVisibility(frameState); | ||
const replace = tile.refine === TILE_REFINEMENT.REPLACE; | ||
const useOptimization = tile._optimChildrenWithinParent === TILE3D_OPTIMIZATION_HINT.USE_OPTIMIZATION; | ||
if (!tile.isVisibleAndInRequestVolume) { | ||
return; | ||
} | ||
if (replace && useOptimization && hasChildren) { | ||
if (!this.anyChildrenVisible(tile, frameState)) { | ||
var hasChildren = tile.children.length > 0; | ||
if (tile.hasTilesetContent && hasChildren) { | ||
var firstChild = tile.children[0]; | ||
this.updateTileVisibility(firstChild, frameState); | ||
tile._visible = firstChild._visible; | ||
return; | ||
} | ||
if (this.meetsScreenSpaceErrorEarly(tile, frameState)) { | ||
tile._visible = false; | ||
return; | ||
} | ||
var replace = tile.refine === TILE_REFINEMENT.REPLACE; | ||
var useOptimization = tile._optimChildrenWithinParent === TILE3D_OPTIMIZATION_HINT.USE_OPTIMIZATION; | ||
if (replace && useOptimization && hasChildren) { | ||
if (!this.anyChildrenVisible(tile, frameState)) { | ||
tile._visible = false; | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
}, { | ||
key: "meetsScreenSpaceErrorEarly", | ||
value: function meetsScreenSpaceErrorEarly(tile, frameState) { | ||
var parent = tile.parent; | ||
meetsScreenSpaceErrorEarly(tile, frameState) { | ||
const { | ||
parent | ||
} = tile; | ||
if (!parent || parent.hasTilesetContent || parent.refine !== TILE_REFINEMENT.ADD) { | ||
return false; | ||
} | ||
if (!parent || parent.hasTilesetContent || parent.refine !== TILE_REFINEMENT.ADD) { | ||
return false; | ||
return !this.shouldRefine(tile, frameState, true); | ||
} | ||
}]); | ||
return !this.shouldRefine(tile, frameState, true); | ||
} | ||
return Tileset3DTraverser; | ||
}(TilesetTraverser); | ||
} | ||
export { Tileset3DTraverser as default }; | ||
//# sourceMappingURL=tileset-3d-traverser.js.map |
@@ -0,5 +1,19 @@ | ||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
import ManagedArray from '../../utils/managed-array'; | ||
import { TILE_REFINEMENT } from '../../constants'; | ||
import { assert } from '@loaders.gl/loader-utils'; | ||
export const DEFAULT_OPTIONS = { | ||
export var DEFAULT_OPTIONS = { | ||
loadSiblings: false, | ||
@@ -9,7 +23,8 @@ skipLevelOfDetail: false, | ||
}; | ||
export default class TilesetTraverser { | ||
constructor(options) { | ||
this.options = { ...DEFAULT_OPTIONS, | ||
...options | ||
}; | ||
var TilesetTraverser = function () { | ||
function TilesetTraverser(options) { | ||
_classCallCheck(this, TilesetTraverser); | ||
this.options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options); | ||
this._traversalStack = new ManagedArray(); | ||
@@ -24,257 +39,320 @@ this._emptyTraversalStack = new ManagedArray(); | ||
traverse(root, frameState, options) { | ||
this.root = root; | ||
this.options = { ...this.options, | ||
...options | ||
}; | ||
this.reset(); | ||
this.updateTile(root, frameState); | ||
this._frameNumber = frameState.frameNumber; | ||
this.executeTraversal(root, frameState); | ||
} | ||
_createClass(TilesetTraverser, [{ | ||
key: "traverse", | ||
value: function traverse(root, frameState, options) { | ||
this.root = root; | ||
this.options = _objectSpread(_objectSpread({}, this.options), options); | ||
this.reset(); | ||
this.updateTile(root, frameState); | ||
this._frameNumber = frameState.frameNumber; | ||
this.executeTraversal(root, frameState); | ||
} | ||
}, { | ||
key: "reset", | ||
value: function reset() { | ||
this.requestedTiles = {}; | ||
this.selectedTiles = {}; | ||
this.emptyTiles = {}; | ||
reset() { | ||
this.requestedTiles = {}; | ||
this.selectedTiles = {}; | ||
this.emptyTiles = {}; | ||
this._traversalStack.reset(); | ||
this._traversalStack.reset(); | ||
this._emptyTraversalStack.reset(); | ||
} | ||
}, { | ||
key: "executeTraversal", | ||
value: function executeTraversal(root, frameState) { | ||
var stack = this._traversalStack; | ||
stack.push(root); | ||
this._emptyTraversalStack.reset(); | ||
} | ||
while (stack.length > 0) { | ||
var tile = stack.pop(); | ||
var shouldRefine = false; | ||
executeTraversal(root, frameState) { | ||
const stack = this._traversalStack; | ||
stack.push(root); | ||
if (this.canTraverse(tile, frameState)) { | ||
this.updateChildTiles(tile, frameState); | ||
shouldRefine = this.updateAndPushChildren(tile, frameState, stack); | ||
} | ||
while (stack.length > 0) { | ||
const tile = stack.pop(); | ||
let shouldRefine = false; | ||
var parent = tile.parent; | ||
var parentRefines = Boolean(!parent || parent._shouldRefine); | ||
var stoppedRefining = !shouldRefine; | ||
if (this.canTraverse(tile, frameState)) { | ||
this.updateChildTiles(tile, frameState); | ||
shouldRefine = this.updateAndPushChildren(tile, frameState, stack); | ||
} | ||
if (!tile.hasRenderContent) { | ||
this.emptyTiles[tile.id] = tile; | ||
this.loadTile(tile, frameState); | ||
const parent = tile.parent; | ||
const parentRefines = Boolean(!parent || parent._shouldRefine); | ||
const stoppedRefining = !shouldRefine; | ||
if (stoppedRefining) { | ||
this.selectTile(tile, frameState); | ||
} | ||
} else if (tile.refine === TILE_REFINEMENT.ADD) { | ||
this.loadTile(tile, frameState); | ||
this.selectTile(tile, frameState); | ||
} else if (tile.refine === TILE_REFINEMENT.REPLACE) { | ||
this.loadTile(tile, frameState); | ||
if (!tile.hasRenderContent) { | ||
this.emptyTiles[tile.id] = tile; | ||
this.loadTile(tile, frameState); | ||
if (stoppedRefining) { | ||
this.selectTile(tile, frameState); | ||
if (stoppedRefining) { | ||
this.selectTile(tile, frameState); | ||
} | ||
} | ||
} else if (tile.refine === TILE_REFINEMENT.ADD) { | ||
this.loadTile(tile, frameState); | ||
this.selectTile(tile, frameState); | ||
} else if (tile.refine === TILE_REFINEMENT.REPLACE) { | ||
this.loadTile(tile, frameState); | ||
if (stoppedRefining) { | ||
this.selectTile(tile, frameState); | ||
} | ||
this.touchTile(tile, frameState); | ||
tile._shouldRefine = shouldRefine && parentRefines; | ||
} | ||
this.touchTile(tile, frameState); | ||
tile._shouldRefine = shouldRefine && parentRefines; | ||
if (this.options.onTraversalEnd) { | ||
this.options.onTraversalEnd(frameState); | ||
} | ||
} | ||
}, { | ||
key: "updateChildTiles", | ||
value: function updateChildTiles(tile, frameState) { | ||
var children = tile.children; | ||
if (this.options.onTraversalEnd) { | ||
this.options.onTraversalEnd(frameState); | ||
} | ||
} | ||
var _iterator = _createForOfIteratorHelper(children), | ||
_step; | ||
updateChildTiles(tile, frameState) { | ||
const children = tile.children; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var child = _step.value; | ||
this.updateTile(child, frameState); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
for (const child of children) { | ||
this.updateTile(child, frameState); | ||
return true; | ||
} | ||
}, { | ||
key: "updateAndPushChildren", | ||
value: function updateAndPushChildren(tile, frameState, stack) { | ||
var _this$options = this.options, | ||
loadSiblings = _this$options.loadSiblings, | ||
skipLevelOfDetail = _this$options.skipLevelOfDetail; | ||
var children = tile.children; | ||
children.sort(this.compareDistanceToCamera); | ||
var checkRefines = !skipLevelOfDetail && tile.refine === TILE_REFINEMENT.REPLACE && tile.hasRenderContent; | ||
var hasVisibleChild = false; | ||
return true; | ||
} | ||
var _iterator2 = _createForOfIteratorHelper(children), | ||
_step2; | ||
updateAndPushChildren(tile, frameState, stack) { | ||
const { | ||
loadSiblings, | ||
skipLevelOfDetail | ||
} = this.options; | ||
const children = tile.children; | ||
children.sort(this.compareDistanceToCamera); | ||
const checkRefines = !skipLevelOfDetail && tile.refine === TILE_REFINEMENT.REPLACE && tile.hasRenderContent; | ||
let hasVisibleChild = false; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var child = _step2.value; | ||
for (const child of children) { | ||
if (child.isVisibleAndInRequestVolume) { | ||
if (stack.find(child)) { | ||
stack.delete(child); | ||
} | ||
if (child.isVisibleAndInRequestVolume) { | ||
if (stack.find(child)) { | ||
stack.delete(child); | ||
} | ||
stack.push(child); | ||
hasVisibleChild = true; | ||
} else if (checkRefines || loadSiblings) { | ||
this.loadTile(child, frameState); | ||
this.touchTile(child, frameState); | ||
} | ||
stack.push(child); | ||
hasVisibleChild = true; | ||
} else if (checkRefines || loadSiblings) { | ||
this.loadTile(child, frameState); | ||
this.touchTile(child, frameState); | ||
} | ||
if (checkRefines) { | ||
let childRefines; | ||
if (checkRefines) { | ||
var childRefines = void 0; | ||
if (!child._inRequestVolume) { | ||
childRefines = false; | ||
} else if (!child.hasRenderContent) { | ||
childRefines = this.executeEmptyTraversal(child, frameState); | ||
} else { | ||
childRefines = child.contentAvailable; | ||
} | ||
if (!child._inRequestVolume) { | ||
childRefines = false; | ||
} else if (!child.hasRenderContent) { | ||
childRefines = this.executeEmptyTraversal(child, frameState); | ||
} else { | ||
childRefines = child.contentAvailable; | ||
} | ||
if (!childRefines) { | ||
return childRefines; | ||
if (!childRefines) { | ||
return childRefines; | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
} | ||
return hasVisibleChild; | ||
} | ||
updateTile(tile, frameState) { | ||
this.updateTileVisibility(tile, frameState); | ||
} | ||
selectTile(tile, frameState) { | ||
if (this.shouldSelectTile(tile, frameState)) { | ||
tile._selectedFrame = frameState.frameNumber; | ||
this.selectedTiles[tile.id] = tile; | ||
return hasVisibleChild; | ||
} | ||
} | ||
}, { | ||
key: "updateTile", | ||
value: function updateTile(tile, frameState) { | ||
this.updateTileVisibility(tile, frameState); | ||
} | ||
}, { | ||
key: "selectTile", | ||
value: function selectTile(tile, frameState) { | ||
if (this.shouldSelectTile(tile, frameState)) { | ||
tile._selectedFrame = frameState.frameNumber; | ||
this.selectedTiles[tile.id] = tile; | ||
} | ||
} | ||
}, { | ||
key: "loadTile", | ||
value: function loadTile(tile, frameState) { | ||
if (this.shouldLoadTile(tile, frameState)) { | ||
tile._requestedFrame = frameState.frameNumber; | ||
tile._priority = this.getPriority(tile); | ||
this.requestedTiles[tile.id] = tile; | ||
} | ||
} | ||
}, { | ||
key: "touchTile", | ||
value: function touchTile(tile, frameState) { | ||
tile.tileset._cache.touch(tile); | ||
loadTile(tile, frameState) { | ||
if (this.shouldLoadTile(tile, frameState)) { | ||
tile._requestedFrame = frameState.frameNumber; | ||
tile._priority = this.getPriority(tile); | ||
this.requestedTiles[tile.id] = tile; | ||
tile._touchedFrame = frameState.frameNumber; | ||
} | ||
} | ||
}, { | ||
key: "canTraverse", | ||
value: function canTraverse(tile, frameState) { | ||
var useParentMetric = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var ignoreVisibility = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
touchTile(tile, frameState) { | ||
tile.tileset._cache.touch(tile); | ||
if (!ignoreVisibility && !tile.isVisibleAndInRequestVolume) { | ||
return false; | ||
} | ||
tile._touchedFrame = frameState.frameNumber; | ||
} | ||
if (!tile.hasChildren) { | ||
return false; | ||
} | ||
canTraverse(tile, frameState, useParentMetric = false, ignoreVisibility = false) { | ||
if (!ignoreVisibility && !tile.isVisibleAndInRequestVolume) { | ||
return false; | ||
} | ||
if (tile.hasTilesetContent) { | ||
return !tile.contentExpired; | ||
} | ||
if (!tile.hasChildren) { | ||
return false; | ||
return this.shouldRefine(tile, frameState, useParentMetric); | ||
} | ||
if (tile.hasTilesetContent) { | ||
return !tile.contentExpired; | ||
}, { | ||
key: "shouldLoadTile", | ||
value: function shouldLoadTile(tile, frameState) { | ||
return tile.hasUnloadedContent || tile.contentExpired; | ||
} | ||
}, { | ||
key: "shouldSelectTile", | ||
value: function shouldSelectTile(tile, frameState) { | ||
return tile.contentAvailable && !this.options.skipLevelOfDetail; | ||
} | ||
}, { | ||
key: "shouldRefine", | ||
value: function shouldRefine(tile, frameState, useParentMetric) { | ||
var screenSpaceError = tile._screenSpaceError; | ||
return this.shouldRefine(tile, frameState, useParentMetric); | ||
} | ||
if (useParentMetric) { | ||
screenSpaceError = tile.getScreenSpaceError(frameState, true); | ||
} | ||
shouldLoadTile(tile, frameState) { | ||
return tile.hasUnloadedContent || tile.contentExpired; | ||
} | ||
return screenSpaceError > this.options.maximumScreenSpaceError; | ||
} | ||
}, { | ||
key: "updateTileVisibility", | ||
value: function updateTileVisibility(tile, frameState) { | ||
tile.updateVisibility(frameState); | ||
} | ||
}, { | ||
key: "compareDistanceToCamera", | ||
value: function compareDistanceToCamera(b, a) { | ||
return b._distanceToCamera - a._distanceToCamera; | ||
} | ||
}, { | ||
key: "getPriority", | ||
value: function getPriority(tile) { | ||
var options = this.options; | ||
shouldSelectTile(tile, frameState) { | ||
return tile.contentAvailable && !this.options.skipLevelOfDetail; | ||
} | ||
switch (tile.refine) { | ||
case TILE_REFINEMENT.ADD: | ||
return tile._distanceToCamera; | ||
shouldRefine(tile, frameState, useParentMetric) { | ||
let screenSpaceError = tile._screenSpaceError; | ||
case TILE_REFINEMENT.REPLACE: | ||
var parent = tile.parent; | ||
var useParentScreenSpaceError = parent && (!options.skipLevelOfDetail || tile._screenSpaceError === 0.0 || parent.hasTilesetContent); | ||
var screenSpaceError = useParentScreenSpaceError ? parent._screenSpaceError : tile._screenSpaceError; | ||
var rootScreenSpaceError = this.root._screenSpaceError; | ||
return rootScreenSpaceError - screenSpaceError; | ||
if (useParentMetric) { | ||
screenSpaceError = tile.getScreenSpaceError(frameState, true); | ||
default: | ||
return assert(false); | ||
} | ||
} | ||
}, { | ||
key: "anyChildrenVisible", | ||
value: function anyChildrenVisible(tile, frameState) { | ||
var anyVisible = false; | ||
return screenSpaceError > this.options.maximumScreenSpaceError; | ||
} | ||
var _iterator3 = _createForOfIteratorHelper(tile.children), | ||
_step3; | ||
updateTileVisibility(tile, frameState) { | ||
tile.updateVisibility(frameState); | ||
} | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var child = _step3.value; | ||
child.updateVisibility(frameState); | ||
anyVisible = anyVisible || child.isVisibleAndInRequestVolume; | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
} | ||
compareDistanceToCamera(b, a) { | ||
return b._distanceToCamera - a._distanceToCamera; | ||
} | ||
getPriority(tile) { | ||
const { | ||
options | ||
} = this; | ||
switch (tile.refine) { | ||
case TILE_REFINEMENT.ADD: | ||
return tile._distanceToCamera; | ||
case TILE_REFINEMENT.REPLACE: | ||
const { | ||
parent | ||
} = tile; | ||
const useParentScreenSpaceError = parent && (!options.skipLevelOfDetail || tile._screenSpaceError === 0.0 || parent.hasTilesetContent); | ||
const screenSpaceError = useParentScreenSpaceError ? parent._screenSpaceError : tile._screenSpaceError; | ||
const rootScreenSpaceError = this.root._screenSpaceError; | ||
return rootScreenSpaceError - screenSpaceError; | ||
default: | ||
return assert(false); | ||
return anyVisible; | ||
} | ||
} | ||
}, { | ||
key: "executeEmptyTraversal", | ||
value: function executeEmptyTraversal(root, frameState) { | ||
var allDescendantsLoaded = true; | ||
var stack = this._emptyTraversalStack; | ||
anyChildrenVisible(tile, frameState) { | ||
let anyVisible = false; | ||
while (stack.length > 0) { | ||
var tile = stack.pop(); | ||
this.updateTile(tile, frameState); | ||
for (const child of tile.children) { | ||
child.updateVisibility(frameState); | ||
anyVisible = anyVisible || child.isVisibleAndInRequestVolume; | ||
} | ||
if (!tile.isVisibleAndInRequestVolume) { | ||
this.loadTile(tile, frameState); | ||
this.touchTile(tile, frameState); | ||
} | ||
return anyVisible; | ||
} | ||
var traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, true); | ||
executeEmptyTraversal(root, frameState) { | ||
let allDescendantsLoaded = true; | ||
const stack = this._emptyTraversalStack; | ||
if (!traverse && !tile.contentAvailable) { | ||
allDescendantsLoaded = false; | ||
} | ||
while (stack.length > 0) { | ||
const tile = stack.pop(); | ||
this.updateTile(tile, frameState); | ||
if (traverse) { | ||
var children = tile.children.filter(function (c) { | ||
return c; | ||
}); | ||
if (!tile.isVisibleAndInRequestVolume) { | ||
this.loadTile(tile, frameState); | ||
this.touchTile(tile, frameState); | ||
} | ||
var _iterator4 = _createForOfIteratorHelper(children), | ||
_step4; | ||
const traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, true); | ||
try { | ||
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { | ||
var child = _step4.value; | ||
if (!traverse && !tile.contentAvailable) { | ||
allDescendantsLoaded = false; | ||
} | ||
if (stack.find(child)) { | ||
stack.delete(child); | ||
} | ||
if (traverse) { | ||
const children = tile.children.filter(c => c); | ||
for (const child of children) { | ||
if (stack.find(child)) { | ||
stack.delete(child); | ||
stack.push(child); | ||
} | ||
} catch (err) { | ||
_iterator4.e(err); | ||
} finally { | ||
_iterator4.f(); | ||
} | ||
stack.push(child); | ||
} | ||
} | ||
return allDescendantsLoaded; | ||
} | ||
}]); | ||
return allDescendantsLoaded; | ||
} | ||
return TilesetTraverser; | ||
}(); | ||
} | ||
export { TilesetTraverser as default }; | ||
//# sourceMappingURL=tileset-traverser.js.map |
@@ -1,9 +0,12 @@ | ||
export default class DoublyLinkedListNode { | ||
constructor(item, previous, next) { | ||
this.item = item; | ||
this.previous = previous; | ||
this.next = next; | ||
} | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
} | ||
var DoublyLinkedListNode = function DoublyLinkedListNode(item, previous, next) { | ||
_classCallCheck(this, DoublyLinkedListNode); | ||
this.item = item; | ||
this.previous = previous; | ||
this.next = next; | ||
}; | ||
export { DoublyLinkedListNode as default }; | ||
//# sourceMappingURL=doubly-linked-list-node.js.map |
@@ -0,4 +1,9 @@ | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import DoublyLinkedListNode from '../utils/doubly-linked-list-node'; | ||
export default class DoublyLinkedList { | ||
constructor() { | ||
var DoublyLinkedList = function () { | ||
function DoublyLinkedList() { | ||
_classCallCheck(this, DoublyLinkedList); | ||
this.head = null; | ||
@@ -9,71 +14,81 @@ this.tail = null; | ||
get length() { | ||
return this._length; | ||
} | ||
_createClass(DoublyLinkedList, [{ | ||
key: "length", | ||
get: function get() { | ||
return this._length; | ||
} | ||
}, { | ||
key: "add", | ||
value: function add(item) { | ||
var node = new DoublyLinkedListNode(item, this.tail, null); | ||
add(item) { | ||
const node = new DoublyLinkedListNode(item, this.tail, null); | ||
if (this.tail) { | ||
this.tail.next = node; | ||
this.tail = node; | ||
} else { | ||
this.head = node; | ||
this.tail = node; | ||
} | ||
if (this.tail) { | ||
this.tail.next = node; | ||
this.tail = node; | ||
} else { | ||
this.head = node; | ||
this.tail = node; | ||
++this._length; | ||
return node; | ||
} | ||
}, { | ||
key: "remove", | ||
value: function remove(node) { | ||
if (!node) { | ||
return; | ||
} | ||
++this._length; | ||
return node; | ||
} | ||
if (node.previous && node.next) { | ||
node.previous.next = node.next; | ||
node.next.previous = node.previous; | ||
} else if (node.previous) { | ||
node.previous.next = null; | ||
this.tail = node.previous; | ||
} else if (node.next) { | ||
node.next.previous = null; | ||
this.head = node.next; | ||
} else { | ||
this.head = null; | ||
this.tail = null; | ||
} | ||
remove(node) { | ||
if (!node) { | ||
return; | ||
node.next = null; | ||
node.previous = null; | ||
--this._length; | ||
} | ||
}, { | ||
key: "splice", | ||
value: function splice(node, nextNode) { | ||
if (node === nextNode) { | ||
return; | ||
} | ||
if (node.previous && node.next) { | ||
node.previous.next = node.next; | ||
node.next.previous = node.previous; | ||
} else if (node.previous) { | ||
node.previous.next = null; | ||
this.tail = node.previous; | ||
} else if (node.next) { | ||
node.next.previous = null; | ||
this.head = node.next; | ||
} else { | ||
this.head = null; | ||
this.tail = null; | ||
} | ||
this.remove(nextNode); | ||
node.next = null; | ||
node.previous = null; | ||
--this._length; | ||
} | ||
splice(node, nextNode) { | ||
if (node === nextNode) { | ||
return; | ||
this._insert(node, nextNode); | ||
} | ||
}, { | ||
key: "_insert", | ||
value: function _insert(node, nextNode) { | ||
var oldNodeNext = node.next; | ||
node.next = nextNode; | ||
this.remove(nextNode); | ||
if (this.tail === node) { | ||
this.tail = nextNode; | ||
} else { | ||
oldNodeNext.previous = nextNode; | ||
} | ||
this._insert(node, nextNode); | ||
} | ||
_insert(node, nextNode) { | ||
const oldNodeNext = node.next; | ||
node.next = nextNode; | ||
if (this.tail === node) { | ||
this.tail = nextNode; | ||
} else { | ||
oldNodeNext.previous = nextNode; | ||
nextNode.next = oldNodeNext; | ||
nextNode.previous = node; | ||
++this._length; | ||
} | ||
}]); | ||
nextNode.next = oldNodeNext; | ||
nextNode.previous = node; | ||
++this._length; | ||
} | ||
return DoublyLinkedList; | ||
}(); | ||
} | ||
export { DoublyLinkedList as default }; | ||
//# sourceMappingURL=doubly-linked-list.js.map |
@@ -0,4 +1,11 @@ | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import { assert } from '@loaders.gl/loader-utils'; | ||
export default class ManagedArray { | ||
constructor(length = 0) { | ||
var ManagedArray = function () { | ||
function ManagedArray() { | ||
var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
_classCallCheck(this, ManagedArray); | ||
this._array = new Array(length); | ||
@@ -9,104 +16,121 @@ this._map = new Map(); | ||
get length() { | ||
return this._length; | ||
} | ||
_createClass(ManagedArray, [{ | ||
key: "length", | ||
get: function get() { | ||
return this._length; | ||
}, | ||
set: function set(length) { | ||
this._length = length; | ||
set length(length) { | ||
this._length = length; | ||
if (length > this._array.length) { | ||
this._array.length = length; | ||
if (length > this._array.length) { | ||
this._array.length = length; | ||
} | ||
} | ||
} | ||
}, { | ||
key: "values", | ||
get: function get() { | ||
return this._array; | ||
} | ||
}, { | ||
key: "get", | ||
value: function get(index) { | ||
assert(index < this._array.length); | ||
return this._array[index]; | ||
} | ||
}, { | ||
key: "set", | ||
value: function set(index, element) { | ||
assert(index >= 0); | ||
get values() { | ||
return this._array; | ||
} | ||
if (index >= this.length) { | ||
this.length = index + 1; | ||
} | ||
get(index) { | ||
assert(index < this._array.length); | ||
return this._array[index]; | ||
} | ||
if (this._map.has(this._array[index])) { | ||
this._map.delete(this._array[index]); | ||
} | ||
set(index, element) { | ||
assert(index >= 0); | ||
this._array[index] = element; | ||
if (index >= this.length) { | ||
this.length = index + 1; | ||
this._map.set(element, index); | ||
} | ||
}, { | ||
key: "delete", | ||
value: function _delete(element) { | ||
var index = this._map.get(element); | ||
if (this._map.has(this._array[index])) { | ||
this._map.delete(this._array[index]); | ||
} | ||
if (index >= 0) { | ||
this._array.splice(index, 1); | ||
this._array[index] = element; | ||
this._map.delete(element); | ||
this._map.set(element, index); | ||
} | ||
this.length--; | ||
} | ||
} | ||
}, { | ||
key: "peek", | ||
value: function peek() { | ||
return this._array[this._length - 1]; | ||
} | ||
}, { | ||
key: "push", | ||
value: function push(element) { | ||
if (!this._map.has(element)) { | ||
var index = this.length++; | ||
this._array[index] = element; | ||
delete(element) { | ||
const index = this._map.get(element); | ||
this._map.set(element, index); | ||
} | ||
} | ||
}, { | ||
key: "pop", | ||
value: function pop() { | ||
var element = this._array[--this.length]; | ||
if (index >= 0) { | ||
this._array.splice(index, 1); | ||
this._map.delete(element); | ||
this.length--; | ||
return element; | ||
} | ||
} | ||
}, { | ||
key: "reserve", | ||
value: function reserve(length) { | ||
assert(length >= 0); | ||
peek() { | ||
return this._array[this._length - 1]; | ||
} | ||
push(element) { | ||
if (!this._map.has(element)) { | ||
const index = this.length++; | ||
this._array[index] = element; | ||
this._map.set(element, index); | ||
if (length > this._array.length) { | ||
this._array.length = length; | ||
} | ||
} | ||
} | ||
}, { | ||
key: "resize", | ||
value: function resize(length) { | ||
assert(length >= 0); | ||
this.length = length; | ||
} | ||
}, { | ||
key: "trim", | ||
value: function trim(length) { | ||
if (length === null || length === undefined) { | ||
length = this.length; | ||
} | ||
pop() { | ||
const element = this._array[--this.length]; | ||
this._map.delete(element); | ||
return element; | ||
} | ||
reserve(length) { | ||
assert(length >= 0); | ||
if (length > this._array.length) { | ||
this._array.length = length; | ||
} | ||
} | ||
resize(length) { | ||
assert(length >= 0); | ||
this.length = length; | ||
} | ||
trim(length) { | ||
if (length === null || length === undefined) { | ||
length = this.length; | ||
}, { | ||
key: "reset", | ||
value: function reset() { | ||
this._array = []; | ||
this._map = new Map(); | ||
this._length = 0; | ||
} | ||
}, { | ||
key: "find", | ||
value: function find(target) { | ||
return this._map.has(target); | ||
} | ||
}]); | ||
this._array.length = length; | ||
} | ||
return ManagedArray; | ||
}(); | ||
reset() { | ||
this._array = []; | ||
this._map = new Map(); | ||
this._length = 0; | ||
} | ||
find(target) { | ||
return this._map.has(target); | ||
} | ||
} | ||
export { ManagedArray as default }; | ||
//# sourceMappingURL=managed-array.js.map |
{ | ||
"name": "@loaders.gl/tiles", | ||
"version": "3.0.0-alpha.7", | ||
"version": "3.0.0-alpha.8", | ||
"description": "Common components for different tiles loaders.", | ||
@@ -35,5 +35,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"@loaders.gl/core": "3.0.0-alpha.7", | ||
"@loaders.gl/loader-utils": "3.0.0-alpha.7", | ||
"@loaders.gl/math": "3.0.0-alpha.7", | ||
"@loaders.gl/core": "3.0.0-alpha.8", | ||
"@loaders.gl/loader-utils": "3.0.0-alpha.8", | ||
"@loaders.gl/math": "3.0.0-alpha.8", | ||
"@math.gl/core": "^3.3.0", | ||
@@ -48,3 +48,3 @@ "@math.gl/culling": "^3.3.0", | ||
}, | ||
"gitHead": "42832866753e5b62ff1a07112e6f6466f26365b0" | ||
"gitHead": "057c51eb80062656da9c3e7d4bdb1254aab6cbfc" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2637826
26946
+ Added@loaders.gl/core@3.0.0-alpha.8(transitive)
+ Added@loaders.gl/images@3.0.0-alpha.8(transitive)
+ Added@loaders.gl/loader-utils@3.0.0-alpha.8(transitive)
+ Added@loaders.gl/math@3.0.0-alpha.8(transitive)
+ Added@loaders.gl/worker-utils@3.0.0-alpha.8(transitive)
- Removed@loaders.gl/core@3.0.0-alpha.7(transitive)
- Removed@loaders.gl/images@3.0.0-alpha.7(transitive)
- Removed@loaders.gl/loader-utils@3.0.0-alpha.7(transitive)
- Removed@loaders.gl/math@3.0.0-alpha.7(transitive)
- Removed@loaders.gl/worker-utils@3.0.0-alpha.7(transitive)