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
import {
  PropertyTextureProperty,
  Matrix3,
  MetadataClass,
  PixelDatatype,
  PixelFormat,
  Texture,
} from "../../Source/Cesium.js";
import createContext from "../createContext.js";
 
describe("Scene/PropertyTextureProperty", function () {
  var classProperty;
  var context;
  var texture;
  var extras;
  var extensions;
  var propertyTextureProperty;
 
  beforeAll(function () {
    var classDefinition = new MetadataClass({
      id: "map",
      class: {
        properties: {
          color: {
            type: "ARRAY",
            componentType: "UINT8",
            componentCount: 3,
          },
        },
      },
    });
 
    classProperty = classDefinition.properties.color;
 
    context = createContext();
 
    texture = new Texture({
      context: context,
      pixelFormat: PixelFormat.RGBA,
      pixelDatatype: PixelDatatype.UNSIGNED_BYTE,
      source: {
        arrayBufferView: new Uint8Array([1, 2, 3, 4]),
        width: 1,
        height: 1,
      },
    });
 
    extras = {
      description: "Extra",
    };
 
    extensions = {
      EXT_other_extension: {},
    };
 
    var property = {
      channels: "rgb",
      texture: {
        index: 0,
        texCoord: 0,
        extensions: {
          KHR_texture_transform: {
            offset: [0.5, 0.5],
            scale: [0.1, 0.2],
            texCoord: 1,
          },
        },
      },
      extras: extras,
      extensions: extensions,
    };
 
    propertyTextureProperty = new PropertyTextureProperty({
      property: property,
      classProperty: classProperty,
      textures: {
        0: texture,
      },
    });
  });
 
  afterAll(function () {
    texture.destroy();
    context.destroyForSpecs();
  });
 
  it("creates feature texture property", function () {
    expect(propertyTextureProperty.extras).toBe(extras);
    expect(propertyTextureProperty.extensions).toBe(extensions);
 
    // prettier-ignore
    var expectedTransform = new Matrix3(
      0.1, 0.0, 0.5,
      0.0, 0.2, 0.5,
      0.0, 0.0, 1.0
    );
 
    var modelTextureReader = propertyTextureProperty.textureReader;
    expect(modelTextureReader.texture).toBe(texture);
    expect(modelTextureReader.texCoord).toBe(1);
    expect(modelTextureReader.transform).toEqual(expectedTransform);
    expect(modelTextureReader.channels).toBe("rgb");
  });
 
  it("constructor throws without property", function () {
    expect(function () {
      return new PropertyTextureProperty({
        classProperty: classProperty,
        textures: {},
      });
    }).toThrowDeveloperError();
  });
 
  it("constructor throws without class", function () {
    expect(function () {
      return new PropertyTextureProperty({
        property: {},
        textures: {},
      });
    }).toThrowDeveloperError();
  });
 
  it("constructor throws without textures", function () {
    expect(function () {
      return new PropertyTextureProperty({
        property: {},
        classProperty: classProperty,
      });
    }).toThrowDeveloperError();
  });
});