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
import { Cartesian3 } from "../../Source/Cesium.js";
import { FrustumGeometry } from "../../Source/Cesium.js";
import { Math as CesiumMath } from "../../Source/Cesium.js";
import { PerspectiveFrustum } from "../../Source/Cesium.js";
import { Quaternion } from "../../Source/Cesium.js";
import { VertexFormat } from "../../Source/Cesium.js";
import createPackableSpecs from "../createPackableSpecs.js";
 
describe("Core/FrustumGeometry", function () {
  it("constructor throws without options", function () {
    expect(function () {
      return new FrustumGeometry();
    }).toThrowDeveloperError();
  });
 
  it("constructor throws without frustum", function () {
    expect(function () {
      return new FrustumGeometry({
        origin: Cartesian3.ZERO,
        orientation: Quaternion.IDENTITY,
      });
    }).toThrowDeveloperError();
  });
 
  it("constructor throws without position", function () {
    expect(function () {
      return new FrustumGeometry({
        frustum: new PerspectiveFrustum(),
        orientation: Quaternion.IDENTITY,
      });
    }).toThrowDeveloperError();
  });
 
  it("constructor throws without orientation", function () {
    expect(function () {
      return new FrustumGeometry({
        frustum: new PerspectiveFrustum(),
        origin: Cartesian3.ZERO,
      });
    }).toThrowDeveloperError();
  });
 
  it("constructor computes all vertex attributes", function () {
    var frustum = new PerspectiveFrustum();
    frustum.fov = CesiumMath.toRadians(30.0);
    frustum.aspectRatio = 1920.0 / 1080.0;
    frustum.near = 1.0;
    frustum.far = 3.0;
 
    var m = FrustumGeometry.createGeometry(
      new FrustumGeometry({
        frustum: frustum,
        origin: Cartesian3.ZERO,
        orientation: Quaternion.IDENTITY,
        vertexFormat: VertexFormat.ALL,
      })
    );
 
    var numVertices = 24; //3 components x 8 corners
    var numTriangles = 12; //6 sides x 2 triangles per side
    expect(m.attributes.position.values.length).toEqual(numVertices * 3);
    expect(m.attributes.normal.values.length).toEqual(numVertices * 3);
    expect(m.attributes.tangent.values.length).toEqual(numVertices * 3);
    expect(m.attributes.bitangent.values.length).toEqual(numVertices * 3);
    expect(m.attributes.st.values.length).toEqual(numVertices * 2);
 
    expect(m.indices.length).toEqual(numTriangles * 3);
 
    expect(m.boundingSphere.center).toEqual(new Cartesian3(0.0, 0.0, 2.0));
    expect(m.boundingSphere.radius).toBeGreaterThan(1.0);
    expect(m.boundingSphere.radius).toBeLessThan(2.0);
  });
 
  var packableFrustum = new PerspectiveFrustum();
  packableFrustum.fov = 1.0;
  packableFrustum.aspectRatio = 2.0;
  packableFrustum.near = 3.0;
  packableFrustum.far = 4.0;
 
  createPackableSpecs(
    FrustumGeometry,
    new FrustumGeometry({
      frustum: packableFrustum,
      origin: Cartesian3.ZERO,
      orientation: Quaternion.IDENTITY,
      vertexFormat: VertexFormat.POSITION_ONLY,
    }),
    [
      0.0,
      1.0,
      2.0,
      3.0,
      4.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      1.0,
      1.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
      1.0,
    ]
  );
});