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
import { BoundingSphere } from "../../Source/Cesium.js";
import { Cartesian3 } from "../../Source/Cesium.js";
import { ComponentDatatype } from "../../Source/Cesium.js";
import { Geometry } from "../../Source/Cesium.js";
import { GeometryAttribute } from "../../Source/Cesium.js";
import { GeometryInstance } from "../../Source/Cesium.js";
import { GeometryInstanceAttribute } from "../../Source/Cesium.js";
import { Matrix4 } from "../../Source/Cesium.js";
import { PrimitiveType } from "../../Source/Cesium.js";
 
describe("Core/GeometryInstance", function () {
  it("constructor", function () {
    var geometry = new Geometry({
      attributes: {
        position: new GeometryAttribute({
          componentDatatype: ComponentDatatype.DOUBLE,
          componentsPerAttribute: 3,
          values: new Float64Array([
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
          ]),
        }),
      },
      indices: new Uint16Array([0, 1, 2]),
      primitiveType: PrimitiveType.TRIANGLES,
      boundingSphere: new BoundingSphere(new Cartesian3(0.5, 0.5, 0.0), 1.0),
    });
    var modelMatrix = Matrix4.multiplyByTranslation(
      Matrix4.IDENTITY,
      new Cartesian3(0.0, 0.0, 9000000.0),
      new Matrix4()
    );
    var attributes = {
      color: new GeometryInstanceAttribute({
        componentDatatype: ComponentDatatype.UNSIGNED_BYTE,
        componentsPerAttribute: 4,
        normalize: true,
        value: new Uint8Array([255, 255, 0, 255]),
      }),
    };
    var instance = new GeometryInstance({
      geometry: geometry,
      modelMatrix: modelMatrix,
      id: "geometry",
      attributes: attributes,
    });
 
    expect(instance.geometry).toBe(geometry);
    expect(instance.modelMatrix).toEqual(modelMatrix);
    expect(instance.id).toEqual("geometry");
    expect(attributes).toBe(attributes);
  });
 
  it("constructor throws without geometry", function () {
    expect(function () {
      return new GeometryInstance();
    }).toThrowDeveloperError();
  });
});