15832144755
2022-01-06 7b4c8991dca9cf2a809a95e239d144697d3afb56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
import Color from "../Core/Color.js";
import combine from "../Core/combine.js";
import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import destroyObject from "../Core/destroyObject.js";
import DeveloperError from "../Core/DeveloperError.js";
import CesiumMath from "../Core/Math.js";
import Pass from "../Renderer/Pass.js";
import Cesium3DTileBatchTable from "./Cesium3DTileBatchTable.js";
import Cesium3DTileFeature from "./Cesium3DTileFeature.js";
import Cesium3DTileRefine from "./Cesium3DTileRefine.js";
import PointCloud from "./PointCloud.js";
import PointCloudShading from "./PointCloudShading.js";
import SceneMode from "./SceneMode.js";
 
/**
 * Represents the contents of a
 * {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/PointCloud|Point Cloud}
 * tile in a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles} tileset.
 * <p>
 * Implements the {@link Cesium3DTileContent} interface.
 * </p>
 *
 * @alias PointCloud3DTileContent
 * @constructor
 *
 * @private
 */
function PointCloud3DTileContent(
  tileset,
  tile,
  resource,
  arrayBuffer,
  byteOffset
) {
  this._tileset = tileset;
  this._tile = tile;
  this._resource = resource;
  this._pickId = undefined; // Only defined when batchTable is undefined
  this._batchTable = undefined; // Used when feature table contains BATCH_ID semantic
  this._styleDirty = false;
  this._features = undefined;
  this.featurePropertiesDirty = false;
  this._groupMetadata = undefined;
 
  this._pointCloud = new PointCloud({
    arrayBuffer: arrayBuffer,
    byteOffset: byteOffset,
    cull: false,
    opaquePass: Pass.CESIUM_3D_TILE,
    vertexShaderLoaded: getVertexShaderLoaded(this),
    fragmentShaderLoaded: getFragmentShaderLoaded(this),
    uniformMapLoaded: getUniformMapLoaded(this),
    batchTableLoaded: getBatchTableLoaded(this),
    pickIdLoaded: getPickIdLoaded(this),
  });
}
 
Object.defineProperties(PointCloud3DTileContent.prototype, {
  featuresLength: {
    get: function () {
      if (defined(this._batchTable)) {
        return this._batchTable.featuresLength;
      }
      return 0;
    },
  },
 
  pointsLength: {
    get: function () {
      return this._pointCloud.pointsLength;
    },
  },
 
  trianglesLength: {
    get: function () {
      return 0;
    },
  },
 
  geometryByteLength: {
    get: function () {
      return this._pointCloud.geometryByteLength;
    },
  },
 
  texturesByteLength: {
    get: function () {
      return 0;
    },
  },
 
  batchTableByteLength: {
    get: function () {
      if (defined(this._batchTable)) {
        return this._batchTable.memorySizeInBytes;
      }
      return 0;
    },
  },
 
  innerContents: {
    get: function () {
      return undefined;
    },
  },
 
  readyPromise: {
    get: function () {
      return this._pointCloud.readyPromise;
    },
  },
 
  tileset: {
    get: function () {
      return this._tileset;
    },
  },
 
  tile: {
    get: function () {
      return this._tile;
    },
  },
 
  url: {
    get: function () {
      return this._resource.getUrlComponent(true);
    },
  },
 
  batchTable: {
    get: function () {
      return this._batchTable;
    },
  },
 
  groupMetadata: {
    get: function () {
      return this._groupMetadata;
    },
    set: function (value) {
      this._groupMetadata = value;
    },
  },
});
 
function getVertexShaderLoaded(content) {
  return function (vs) {
    if (defined(content._batchTable)) {
      return content._batchTable.getVertexShaderCallback(
        false,
        "a_batchId",
        undefined
      )(vs);
    }
    return vs;
  };
}
 
function getFragmentShaderLoaded(content) {
  return function (fs) {
    if (defined(content._batchTable)) {
      return content._batchTable.getFragmentShaderCallback(
        false,
        undefined,
        false
      )(fs);
    }
    return "uniform vec4 czm_pickColor;\n" + fs;
  };
}
 
function getUniformMapLoaded(content) {
  return function (uniformMap) {
    if (defined(content._batchTable)) {
      return content._batchTable.getUniformMapCallback()(uniformMap);
    }
    return combine(uniformMap, {
      czm_pickColor: function () {
        return content._pickId.color;
      },
    });
  };
}
 
function getBatchTableLoaded(content) {
  return function (batchLength, batchTableJson, batchTableBinary) {
    content._batchTable = new Cesium3DTileBatchTable(
      content,
      batchLength,
      batchTableJson,
      batchTableBinary
    );
  };
}
 
function getPickIdLoaded(content) {
  return function () {
    return defined(content._batchTable)
      ? content._batchTable.getPickId()
      : "czm_pickColor";
  };
}
 
function getGeometricError(content) {
  var pointCloudShading = content._tileset.pointCloudShading;
  var sphereVolume = content._tile.contentBoundingVolume.boundingSphere.volume();
  var baseResolutionApproximation = CesiumMath.cbrt(
    sphereVolume / content.pointsLength
  );
 
  var geometricError = content._tile.geometricError;
  if (geometricError === 0) {
    if (
      defined(pointCloudShading) &&
      defined(pointCloudShading.baseResolution)
    ) {
      geometricError = pointCloudShading.baseResolution;
    } else {
      geometricError = baseResolutionApproximation;
    }
  }
  return geometricError;
}
 
function createFeatures(content) {
  var featuresLength = content.featuresLength;
  if (!defined(content._features) && featuresLength > 0) {
    var features = new Array(featuresLength);
    for (var i = 0; i < featuresLength; ++i) {
      features[i] = new Cesium3DTileFeature(content, i);
    }
    content._features = features;
  }
}
 
PointCloud3DTileContent.prototype.hasProperty = function (batchId, name) {
  if (defined(this._batchTable)) {
    return this._batchTable.hasProperty(batchId, name);
  }
  return false;
};
 
/**
 * Part of the {@link Cesium3DTileContent} interface.
 *
 * In this context a feature refers to a group of points that share the same BATCH_ID.
 * For example all the points that represent a door in a house point cloud would be a feature.
 *
 * Features are backed by a batch table and can be colored, shown/hidden, picked, etc like features
 * in b3dm and i3dm.
 *
 * When the BATCH_ID semantic is omitted and the point cloud stores per-point properties, they
 * are not accessible by getFeature. They are only used for dynamic styling.
 */
PointCloud3DTileContent.prototype.getFeature = function (batchId) {
  if (!defined(this._batchTable)) {
    return undefined;
  }
  var featuresLength = this.featuresLength;
  //>>includeStart('debug', pragmas.debug);
  if (!defined(batchId) || batchId < 0 || batchId >= featuresLength) {
    throw new DeveloperError(
      "batchId is required and between zero and featuresLength - 1 (" +
        (featuresLength - 1) +
        ")."
    );
  }
  //>>includeEnd('debug');
  createFeatures(this);
  return this._features[batchId];
};
 
PointCloud3DTileContent.prototype.applyDebugSettings = function (
  enabled,
  color
) {
  this._pointCloud.color = enabled ? color : Color.WHITE;
};
 
PointCloud3DTileContent.prototype.applyStyle = function (style) {
  if (defined(this._batchTable)) {
    this._batchTable.applyStyle(style);
  } else {
    this._styleDirty = true;
  }
};
 
var defaultShading = new PointCloudShading();
 
PointCloud3DTileContent.prototype.update = function (tileset, frameState) {
  var pointCloud = this._pointCloud;
  var pointCloudShading = defaultValue(
    tileset.pointCloudShading,
    defaultShading
  );
  var tile = this._tile;
  var batchTable = this._batchTable;
  var mode = frameState.mode;
  var clippingPlanes = tileset.clippingPlanes;
 
  if (!defined(this._pickId) && !defined(batchTable)) {
    this._pickId = frameState.context.createPickId({
      primitive: tileset,
      content: this,
    });
  }
 
  if (defined(batchTable)) {
    batchTable.update(tileset, frameState);
  }
 
  var boundingSphere;
  if (defined(tile._contentBoundingVolume)) {
    boundingSphere =
      mode === SceneMode.SCENE3D
        ? tile._contentBoundingVolume.boundingSphere
        : tile._contentBoundingVolume2D.boundingSphere;
  } else {
    boundingSphere =
      mode === SceneMode.SCENE3D
        ? tile._boundingVolume.boundingSphere
        : tile._boundingVolume2D.boundingSphere;
  }
 
  var styleDirty = this._styleDirty;
  this._styleDirty = false;
 
  pointCloud.clippingPlanesOriginMatrix = tileset.clippingPlanesOriginMatrix;
  pointCloud.style = defined(batchTable) ? undefined : tileset.style;
  pointCloud.styleDirty = styleDirty;
  pointCloud.modelMatrix = tile.computedTransform;
  pointCloud.time = tileset.timeSinceLoad;
  pointCloud.shadows = tileset.shadows;
  pointCloud.boundingSphere = boundingSphere;
  pointCloud.clippingPlanes = clippingPlanes;
  pointCloud.isClipped =
    defined(clippingPlanes) && clippingPlanes.enabled && tile._isClipped;
  pointCloud.clippingPlanesDirty = tile.clippingPlanesDirty;
  pointCloud.attenuation = pointCloudShading.attenuation;
  pointCloud.backFaceCulling = pointCloudShading.backFaceCulling;
  pointCloud.normalShading = pointCloudShading.normalShading;
  pointCloud.geometricError = getGeometricError(this);
  pointCloud.geometricErrorScale = pointCloudShading.geometricErrorScale;
  if (
    defined(pointCloudShading) &&
    defined(pointCloudShading.maximumAttenuation)
  ) {
    pointCloud.maximumAttenuation = pointCloudShading.maximumAttenuation;
  } else if (tile.refine === Cesium3DTileRefine.ADD) {
    pointCloud.maximumAttenuation = 5.0;
  } else {
    pointCloud.maximumAttenuation = tileset.maximumScreenSpaceError;
  }
 
  pointCloud.update(frameState);
};
 
PointCloud3DTileContent.prototype.isDestroyed = function () {
  return false;
};
 
PointCloud3DTileContent.prototype.destroy = function () {
  this._pickId = this._pickId && this._pickId.destroy();
  this._pointCloud = this._pointCloud && this._pointCloud.destroy();
  this._batchTable = this._batchTable && this._batchTable.destroy();
  return destroyObject(this);
};
export default PointCloud3DTileContent;