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
import Color from "../Core/Color.js";
import defined from "../Core/defined.js";
import destroyObject from "../Core/destroyObject.js";
import RequestType from "../Core/RequestType.js";
import Pass from "../Renderer/Pass.js";
import Axis from "./Axis.js";
import Model from "./Model.js";
import ModelAnimationLoop from "./ModelAnimationLoop.js";
 
/**
 * Represents the contents of a glTF or glb tile in a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles} tileset using the {@link https://github.com/CesiumGS/3d-tiles/tree/3d-tiles-next/extensions/3DTILES_content_gltf/|3DTILES_content_gltf} extension.
 * <p>
 * Implements the {@link Cesium3DTileContent} interface.
 * </p>
 *
 * @alias Gltf3DTileContent
 * @constructor
 *
 * @private
 * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
 */
function Gltf3DTileContent(tileset, tile, resource, gltf) {
  this._tileset = tileset;
  this._tile = tile;
  this._resource = resource;
  this._model = undefined;
 
  this.featurePropertiesDirty = false;
  this._groupMetadata = undefined;
 
  initialize(this, gltf);
}
 
Object.defineProperties(Gltf3DTileContent.prototype, {
  featuresLength: {
    get: function () {
      return 0;
    },
  },
 
  pointsLength: {
    get: function () {
      return this._model.pointsLength;
    },
  },
 
  trianglesLength: {
    get: function () {
      return this._model.trianglesLength;
    },
  },
 
  geometryByteLength: {
    get: function () {
      return this._model.geometryByteLength;
    },
  },
 
  texturesByteLength: {
    get: function () {
      return this._model.texturesByteLength;
    },
  },
 
  batchTableByteLength: {
    get: function () {
      return 0;
    },
  },
 
  innerContents: {
    get: function () {
      return undefined;
    },
  },
 
  readyPromise: {
    get: function () {
      return this._model.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 undefined;
    },
  },
 
  groupMetadata: {
    get: function () {
      return this._groupMetadata;
    },
    set: function (value) {
      this._groupMetadata = value;
    },
  },
});
 
function initialize(content, gltf) {
  var tileset = content._tileset;
  var tile = content._tile;
  var resource = content._resource;
 
  var pickObject = {
    content: content,
    primitive: tileset,
  };
 
  content._model = new Model({
    gltf: gltf,
    cull: false, // The model is already culled by 3D Tiles
    releaseGltfJson: true, // Models are unique and will not benefit from caching so save memory
    opaquePass: Pass.CESIUM_3D_TILE, // Draw opaque portions of the model during the 3D Tiles pass
    basePath: resource,
    requestType: RequestType.TILES3D,
    modelMatrix: tile.computedTransform,
    upAxis: tileset._gltfUpAxis,
    forwardAxis: Axis.X,
    shadows: tileset.shadows,
    debugWireframe: tileset.debugWireframe,
    incrementallyLoadTextures: false,
    addBatchIdToGeneratedShaders: false,
    pickObject: pickObject,
    imageBasedLightingFactor: tileset.imageBasedLightingFactor,
    lightColor: tileset.lightColor,
    luminanceAtZenith: tileset.luminanceAtZenith,
    sphericalHarmonicCoefficients: tileset.sphericalHarmonicCoefficients,
    specularEnvironmentMaps: tileset.specularEnvironmentMaps,
    backFaceCulling: tileset.backFaceCulling,
    showOutline: tileset.showOutline,
  });
  content._model.readyPromise.then(function (model) {
    model.activeAnimations.addAll({
      loop: ModelAnimationLoop.REPEAT,
    });
  });
}
 
Gltf3DTileContent.prototype.hasProperty = function (batchId, name) {
  return false;
};
 
Gltf3DTileContent.prototype.getFeature = function (batchId) {
  return undefined;
};
 
Gltf3DTileContent.prototype.applyDebugSettings = function (enabled, color) {
  color = enabled ? color : Color.WHITE;
  this._model.color = color;
};
 
Gltf3DTileContent.prototype.applyStyle = function (style) {
  var hasColorStyle = defined(style) && defined(style.color);
  var hasShowStyle = defined(style) && defined(style.show);
  this._model.color = hasColorStyle
    ? style.color.evaluateColor(undefined, this._model.color)
    : Color.clone(Color.WHITE, this._model.color);
  this._model.show = hasShowStyle ? style.show.evaluate(undefined) : true;
};
 
Gltf3DTileContent.prototype.update = function (tileset, frameState) {
  var model = this._model;
  var tile = this._tile;
 
  model.modelMatrix = tile.computedTransform;
  model.shadows = tileset.shadows;
  model.imageBasedLightingFactor = tileset.imageBasedLightingFactor;
  model.lightColor = tileset.lightColor;
  model.luminanceAtZenith = tileset.luminanceAtZenith;
  model.sphericalHarmonicCoefficients = tileset.sphericalHarmonicCoefficients;
  model.specularEnvironmentMaps = tileset.specularEnvironmentMaps;
  model.backFaceCulling = tileset.backFaceCulling;
  model.debugWireframe = tileset.debugWireframe;
 
  // Update clipping planes
  var tilesetClippingPlanes = tileset.clippingPlanes;
  model.referenceMatrix = tileset.clippingPlanesOriginMatrix;
  if (defined(tilesetClippingPlanes) && tile.clippingPlanesDirty) {
    // Dereference the clipping planes from the model if they are irrelevant.
    // Link/Dereference directly to avoid ownership checks.
    // This will also trigger synchronous shader regeneration to remove or add the clipping plane and color blending code.
    model._clippingPlanes =
      tilesetClippingPlanes.enabled && tile._isClipped
        ? tilesetClippingPlanes
        : undefined;
  }
 
  // If the model references a different ClippingPlaneCollection due to the tileset's collection being replaced with a
  // ClippingPlaneCollection that gives this tile the same clipping status, update the model to use the new ClippingPlaneCollection.
  if (
    defined(tilesetClippingPlanes) &&
    defined(model._clippingPlanes) &&
    model._clippingPlanes !== tilesetClippingPlanes
  ) {
    model._clippingPlanes = tilesetClippingPlanes;
  }
 
  model.update(frameState);
};
 
Gltf3DTileContent.prototype.isDestroyed = function () {
  return false;
};
 
Gltf3DTileContent.prototype.destroy = function () {
  this._model = this._model && this._model.destroy();
  return destroyObject(this);
};
 
export default Gltf3DTileContent;