yzt
2023-05-26 2f70f6727314edd84d8ec2bfe3ce832803f1ea77
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
import Axis from "../Axis.js";
import defined from "../../Core/defined.js";
import destroyObject from "../../Core/destroyObject.js";
import ModelExperimental from "./ModelExperimental.js";
import Pass from "../../Renderer/Pass.js";
 
/**
 * Represents the contents of a glTF, glb or
 * {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/Batched3DModel|Batched 3D Model}
 * tile in a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles} tileset.
 * <p>
 * Implements the {@link Cesium3DTileContent} interface.
 * </p>
 * @alias ModelExperimental3DTileContent
 * @constructor
 * @private
 */
export default function ModelExperimental3DTileContent(
  tileset,
  tile,
  resource
) {
  this._tileset = tileset;
  this._tile = tile;
  this._resource = resource;
 
  this._model = undefined;
  this._groupMetadata = undefined;
}
 
Object.defineProperties(ModelExperimental3DTileContent.prototype, {
  featuresLength: {
    get: function () {
      var model = this._model;
      var featureTables = model.featureTables;
      var featureTableId = model.featureTableId;
 
      if (defined(featureTables) && defined(featureTables[featureTableId])) {
        return featureTables[featureTableId].featuresLength;
      }
 
      return 0;
    },
  },
 
  pointsLength: {
    get: function () {
      return 0;
    },
  },
 
  trianglesLength: {
    get: function () {
      return 0;
    },
  },
 
  geometryByteLength: {
    get: function () {
      return 0;
    },
  },
 
  texturesByteLength: {
    get: function () {
      return 0;
    },
  },
 
  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 () {
      var model = this._model;
      var featureTables = model.featureTables;
      var featureTableId = model.featureTableId;
 
      if (defined(featureTables) && defined(featureTables[featureTableId])) {
        return featureTables[featureTableId];
      }
 
      return undefined;
    },
  },
 
  groupMetadata: {
    get: function () {
      return this._groupMetadata;
    },
    set: function (value) {
      this._groupMetadata = value;
    },
  },
});
 
ModelExperimental3DTileContent.prototype.getFeature = function (featureId) {
  var model = this._model;
  var featureTableId = model.featureTableId;
  if (!defined(featureTableId)) {
    return undefined;
  }
 
  var featureTable = model.featureTables[featureTableId];
  return featureTable.getFeature(featureId);
};
 
ModelExperimental3DTileContent.prototype.hasProperty = function (
  featureId,
  name
) {
  var model = this._model;
  var featureTableId = model.featureTableId;
  if (!defined(featureTableId)) {
    return false;
  }
 
  var featureTable = model.featureTables[featureTableId];
  return featureTable.hasProperty(featureId, name);
};
 
ModelExperimental3DTileContent.prototype.applyDebugSettings = function (
  enabled,
  color
) {
  return;
};
 
ModelExperimental3DTileContent.prototype.applyStyle = function (style) {
  this._model.applyStyle(style);
};
 
ModelExperimental3DTileContent.prototype.update = function (
  tileset,
  frameState
) {
  var model = this._model;
  var tile = this._tile;
 
  model.colorBlendAmount = tileset.colorBlendAmount;
  model.colorBlendMode = tileset.colorBlendMode;
  model.modelMatrix = tile.computedTransform;
  model.customShader = tileset.customShader;
 
  model.update(frameState);
};
 
ModelExperimental3DTileContent.prototype.isDestroyed = function () {
  return false;
};
 
ModelExperimental3DTileContent.prototype.destroy = function () {
  this._model = this._model && this._model.destroy();
  return destroyObject(this);
};
 
ModelExperimental3DTileContent.fromGltf = function (
  tileset,
  tile,
  resource,
  gltf
) {
  var content = new ModelExperimental3DTileContent(tileset, tile, resource);
 
  var modelOptions = {
    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,
    modelMatrix: tile.computedTransform,
    upAxis: tileset._gltfUpAxis,
    forwardAxis: Axis.X,
    incrementallyLoadTextures: false,
    customShader: tileset.customShader,
    content: content,
    colorBlendMode: tileset.colorBlendMode,
    colorBlendAmount: tileset.colorBlendAmount,
  };
  content._model = ModelExperimental.fromGltf(modelOptions);
  return content;
};
 
ModelExperimental3DTileContent.fromB3dm = function (
  tileset,
  tile,
  resource,
  arrayBuffer,
  byteOffset
) {
  var content = new ModelExperimental3DTileContent(tileset, tile, resource);
 
  var modelOptions = {
    arrayBuffer: arrayBuffer,
    byteOffset: byteOffset,
    resource: resource,
    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
    modelMatrix: tile.computedTransform,
    upAxis: tileset._gltfUpAxis,
    forwardAxis: Axis.X,
    incrementallyLoadTextures: false,
    customShader: tileset.customShader,
    content: content,
    colorBlendMode: tileset.colorBlendMode,
    colorBlendAmount: tileset.colorBlendAmount,
  };
  content._model = ModelExperimental.fromB3dm(modelOptions);
  return content;
};