yzt
2023-05-08 24e1c6a1c3d5331b5a4f1111dcbae3ef148eda1a
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
import {
  Cartesian3,
  ImplicitSubtree,
  ImplicitTileCoordinates,
  ImplicitTileset,
  ImplicitTileMetadata,
  MetadataClass,
  MetadataSchema,
  Resource,
} from "../../Source/Cesium.js";
import ImplicitTilingTester from "../ImplicitTilingTester.js";
 
describe("Scene/ImplicitTileMetadata", function () {
  var highlightColors = [
    [255, 0, 0],
    [255, 255, 0],
    [255, 0, 255],
  ];
 
  var buildingCounts = [100, 350, 200];
 
  var tileTableDescription = {
    name: "Tiles",
    class: "tile",
    properties: {
      highlightColor: highlightColors,
      buildingCount: buildingCounts,
    },
  };
 
  var schema = {
    classes: {
      tile: {
        properties: {
          highlightColor: {
            type: "VEC3",
            componentType: "UINT8",
            semantic: "_HIGHLIGHT_COLOR",
          },
          buildingCount: {
            componentType: "UINT16",
          },
        },
      },
    },
  };
 
  var tileClass = new MetadataClass({
    id: "tile",
    class: schema.classes.tile,
  });
 
  var propertyTablesDescription = {
    schema: schema,
    propertyTables: [tileTableDescription],
  };
 
  var subtreeDescription = {
    tileAvailability: {
      descriptor: "10011",
      lengthBits: 5,
      isInternal: true,
      includeAvailableCount: true,
    },
    contentAvailability: [
      {
        descriptor: "10011",
        lengthBits: 5,
        isInternal: true,
      },
    ],
    childSubtreeAvailability: {
      descriptor: 0,
      lengthBits: 16,
      isInternal: true,
    },
    metadata: {
      isInternal: true,
      propertyTables: propertyTablesDescription,
    },
  };
 
  var bufferResults = ImplicitTilingTester.generateSubtreeBuffers(
    subtreeDescription
  );
 
  var tilesetResource = new Resource({
    url: "https://example.com/tileset.json",
  });
 
  var subtreeResource = new Resource({
    url: "https://example.com/test.subtree",
  });
 
  var mockTilesetWithMetadata = {
    metadata: {
      schema: new MetadataSchema(schema),
    },
  };
 
  var metadataSchema = mockTilesetWithMetadata.metadata.schema;
 
  var implicitQuadtreeJson = {
    geometricError: 500,
    refine: "ADD",
    boundingVolume: {
      region: [0, 0, Math.PI / 24, Math.PI / 24, 0, 1000.0],
    },
    content: {
      uri: "https://example.com/{level}/{x}/{y}.b3dm",
    },
    extensions: {
      "3DTILES_implicit_tiling": {
        subdivisionScheme: "QUADTREE",
        subtreeLevels: 2,
        maximumLevel: 1,
        subtrees: {
          uri: "https://example.com/{level}/{x}/{y}.subtree",
        },
      },
    },
  };
 
  var metadataQuadtree = new ImplicitTileset(
    tilesetResource,
    implicitQuadtreeJson,
    metadataSchema
  );
 
  var rootCoordinates = new ImplicitTileCoordinates({
    subdivisionScheme: metadataQuadtree.subdivisionScheme,
    subtreeLevels: metadataQuadtree.subtreeLevels,
    x: 0,
    y: 0,
    level: 0,
  });
 
  var implicitCoordinates = new ImplicitTileCoordinates({
    subdivisionScheme: metadataQuadtree.subdivisionScheme,
    subtreeLevels: metadataQuadtree.subtreeLevels,
    x: 0,
    y: 1,
    level: 1,
  });
 
  var subtree;
  beforeAll(function () {
    subtree = new ImplicitSubtree(
      subtreeResource,
      bufferResults.subtreeBuffer,
      metadataQuadtree,
      rootCoordinates
    );
 
    return subtree.readyPromise;
  });
 
  var tileMetadata;
  beforeEach(function () {
    tileMetadata = new ImplicitTileMetadata({
      implicitSubtree: subtree,
      implicitCoordinates: implicitCoordinates,
      class: tileClass,
    });
  });
 
  it("throws without implicitSubtree", function () {
    expect(function () {
      tileMetadata = new ImplicitTileMetadata({
        implicitSubtree: undefined,
        implicitCoordinates: implicitCoordinates,
        class: tileClass,
      });
    }).toThrowDeveloperError();
  });
 
  it("throws without implicitCoordinates", function () {
    expect(function () {
      tileMetadata = new ImplicitTileMetadata({
        implicitSubtree: subtree,
        implicitCoordinates: undefined,
        class: tileClass,
      });
    }).toThrowDeveloperError();
  });
 
  it("creates tile metadata", function () {
    tileMetadata = new ImplicitTileMetadata({
      implicitSubtree: subtree,
      implicitCoordinates: implicitCoordinates,
      class: tileClass,
    });
    expect(tileMetadata.class).toBe(tileClass);
    expect(tileMetadata.extras).toBe(undefined);
    expect(tileMetadata.extensions).toBe(undefined);
  });
 
  it("hasProperty returns true if the tile has this property", function () {
    expect(tileMetadata.hasProperty("highlightColor")).toBe(true);
  });
 
  it("hasProperty returns false if the tile does not have this property", function () {
    expect(tileMetadata.hasProperty("numberOfPoints")).toBe(false);
  });
 
  it("hasPropertyBySemantic returns true if the tile has a property with the given semantic", function () {
    expect(tileMetadata.hasPropertyBySemantic("_HIGHLIGHT_COLOR")).toBe(true);
  });
 
  it("hasPropertyBySemantic returns false if the tile does not have a property with the given semantic", function () {
    expect(tileMetadata.hasPropertyBySemantic("_NUMBER_OF_POINTS")).toBe(false);
  });
 
  it("getPropertyIds returns array of property IDs", function () {
    var propertyIds = tileMetadata.getPropertyIds([]);
    propertyIds.sort();
    expect(propertyIds).toEqual(["buildingCount", "highlightColor"]);
  });
 
  it("getProperty returns undefined if a property does not exist", function () {
    expect(tileMetadata.getProperty("numberOfPoints")).not.toBeDefined();
  });
 
  it("getProperty returns the property value", function () {
    expect(tileMetadata.getProperty("highlightColor")).toEqual(
      new Cartesian3(255, 255, 0)
    );
    expect(tileMetadata.getProperty("buildingCount")).toBe(350);
  });
 
  it("setProperty does not create property if it doesn't exist", function () {
    expect(tileMetadata.setProperty("numberOfPoints", 10)).toBe(false);
  });
 
  it("setProperty sets property value", function () {
    expect(tileMetadata.getProperty("buildingCount")).toBe(350);
    expect(tileMetadata.setProperty("buildingCount", 400)).toBe(true);
    expect(tileMetadata.getProperty("buildingCount")).toBe(400);
  });
 
  it("getPropertyBySemantic returns undefined when there's no property with the given semantic", function () {
    expect(
      tileMetadata.getPropertyBySemantic("HORIZON_OCCLUSION_POINT")
    ).not.toBeDefined();
  });
 
  it("getPropertyBySemantic returns the property value", function () {
    expect(tileMetadata.getPropertyBySemantic("_HIGHLIGHT_COLOR")).toEqual(
      new Cartesian3(255, 255, 0)
    );
  });
 
  it("setPropertyBySemantic sets property value", function () {
    expect(tileMetadata.getPropertyBySemantic("_HIGHLIGHT_COLOR")).toEqual(
      new Cartesian3(255, 255, 0)
    );
    expect(
      tileMetadata.setPropertyBySemantic(
        "_HIGHLIGHT_COLOR",
        new Cartesian3(0, 0, 0)
      )
    ).toBe(true);
    expect(tileMetadata.getPropertyBySemantic("_HIGHLIGHT_COLOR")).toEqual(
      new Cartesian3(0, 0, 0)
    );
  });
 
  it("setPropertyBySemantic returns false if the semantic does not exist", function () {
    expect(tileMetadata.setPropertyBySemantic("NAME", "Test Tile")).toBe(false);
  });
});