一些技术路线测试,增加git,方便代码还原
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
<!--
 * @Author       : yuan
 * @Date         : 2025-08-05 10:02:04
 * @LastEditors  : yuan
 * @LastEditTime : 2025-08-06 15:03:06
 * @FilePath     : \video.html
 * @Description  : 
 * Copyright 2025 OBKoro1, All Rights Reserved. 
 * 2025-08-05 10:02:04
-->
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title></title>
    <script src="./Build/Cesium.js"></script>
    <script src="./ZLMRTCClient.js"></script>
 
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <!-- <script  type="text/javascript" src="CesiumPopup.js"></script> -->
 
    <link href="https://cdn.bootcdn.net/ajax/libs/video.js/5.15.0/video-js.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/video.js/5.15.0/video.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.15.0/videojs-contrib-hls.min.js"
        type="text/javascript"></script>
    <style>
        @import url(./Build/Widgets/widgets.css);
 
        html,
        body,
        #cesiumContainer {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
 
        .box-container {
            position: fixed;
            top: 0;
            left: 0;
            z-index: 99;
            text-align: center;
            background: yellowgreen;
        }
 
        .box-container>div {
            display: flex;
            flex-wrap: wrap;
        }
 
        .box-container>div>div {
            width: 96px;
            height: 36px;
            line-height: 36px;
        }
 
        #VIDEO {
            position: fixed;
            left: 10px;
            bottom: 10px;
            width: 160px;
            height: 90px;
            z-index: 99;
        }
    </style>
 
 
</head>
 
<body>
    <div id="cesiumContainer">
 
 
    </div>
 
    <div class="box-container">
        <div>
            <div>heading</div>
            <div>
                <button onclick="optionsChange('heading', 1, 1)">+1</button>
            </div>
            <div>
                <button onclick="optionsChange('heading', 2, 1)">-1</button>
            </div>
        </div>
        <div>
            <div>pitch</div>
            <div>
                <button onclick="optionsChange('pitch', 1, 1)">+1</button>
            </div>
            <div>
                <button onclick="optionsChange('pitch', 2, 1)">-1</button>
            </div>
        </div>
        <div>
            <div>roll</div>
            <div>
                <button onclick="optionsChange('roll', 1, 1)">+1</button>
            </div>
            <div>
                <button onclick="optionsChange('roll', 2, 1)">-1</button>
            </div>
        </div>
        <div>
            <div></div>
            <div></div>
            <div></div>
        </div>
        <div>
            <div></div>
            <div></div>
            <div></div>
        </div>
        <div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
 
    <video id="VIDEO" class="video-player" controls autoplay muted playsinline>
        您的浏览器太旧,不支持HTML5视频,请升级浏览器。
    </video>
 
    <script>
        let ele = document.getElementById('VIDEO')
 
        let webrtcPlayer = new window.ZLMRTCClient.Endpoint({
            element: ele, // video 标签
            debug: true, // 是否打印日志
            zlmsdpUrl: 'https://wrj.shuixiongit.com/index/api/webrtc?app=live&stream=7CTDM7100BN4J5-165-0-7-normal-0&type=play', //流地址
            simulecast: false,
            useCamera: false,
            audioEnable: true,
            videoEnable: true,
            recvOnly: true,
            usedatachannel: false,
        })
 
        console.log(webrtcPlayer, 111111)
 
        webrtcPlayer.on(window.ZLMRTCClient.Events.WEBRTC_ICE_CANDIDATE_ERROR, e => {
            console.log(e, 'WEBRTC_ICE_CANDIDATE_ERROR')
        })
        webrtcPlayer.on(window.ZLMRTCClient.Events.WEBRTC_ON_REMOTE_STREAMS, e => {
            console.log(e, 'WEBRTC_ON_REMOTE_STREAMS')
        })
        webrtcPlayer.on(window.ZLMRTCClient.Events.WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED, e => {
            console.log(e, 'WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED')
        })
        webrtcPlayer.on(window.ZLMRTCClient.Events.WEBRTC_ON_LOCAL_STREAM, s => {
            console.log(e, 'WEBRTC_ON_LOCAL_STREAM')
        })
    </script>
 
    <script>
        Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzNjYzOTI5NC0yM2QyLTQyOTgtYWM5OS1lM2MwNTYwMGEzMjciLCJpZCI6ODQ1MjYsImlhdCI6MTY0NjM1ODM5OX0.BzsVR7Lt9RhsCia-R7E64KunaAME0HGD7Sv2-xF-RIQ'
 
        var viewer = new Cesium.Viewer('cesiumContainer', {
 
 
            imageryProvider: new Cesium.ArcGisMapServerImageryProvider({
                url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
                maximumLevel: 18,
            }),
 
            // terrainProvider: Cesium.createWorldTerrain({
            //     requestVertexNormals: true,
            //     requestWaterMask: true
            // }),
            shouldAnimate: true,
            selectionIndicator: false,
            infoBox: false,
            geocoder: false,   // 位置查找工具
            baseLayerPicker: false,// 图层选择器(地形影像服务)
            timeline: false, // 底部时间线
            homeButton: false,// 视角返回初始位置
            fullscreenButton: false, // 全屏
            animation: false,   // 左下角仪表盘(动画器件)
            sceneModePicker: false,// 选择视角的模式(球体、平铺、斜视平铺)
            navigationHelpButton: false, //导航帮助按钮
        })
        //viewer.scene.debugShowFramesPerSecond = true;
        viewer.cesiumWidget.creditContainer.style.display = "none"
        var towerJson
 
        // viewer.flyTo(tileset);
        var position = Cesium.Cartesian3.fromDegrees(114.82299452552775, 25.992290470862866, 500)//定义飞行终点的坐标
 
        viewer.camera.flyTo({
            // 设置相机前往的位置
            destination: position,
            // 相机的朝向
            orientation: {
                // 如果围绕y轴旋转,偏航角
                heading: Cesium.Math.toRadians(0),
                // 如果围绕x轴旋转,俯仰角
                pitch: Cesium.Math.toRadians(-90),
                // 如果围绕z轴旋转,翻滚角
                roll: 0.0,
            },
            duration: 1,
            complete: function () {
                // 在相机移动完成后执行
                //   console.log("已抵达北京天安门");
            },
        })
 
        viewer.scene.globe.depthTestAgainstTerrain = true
 
        const imageryProvider_stand = new Cesium.UrlTemplateImageryProvider({
            url: `https://t{s}.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=e110584a27d506da2740edca951683f4`,
            subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
            // format: 'image/jpeg',
            // show: true,
            maximumLevel: 18,
            credit: 'stand_tc',
        })
 
        viewer?.imageryLayers.addImageryProvider(imageryProvider_stand)
 
        async function loadTerrain () {
            let worldTerrain
            try {
                worldTerrain = await Cesium.createWorldTerrainAsync()
                viewer.scene.terrainProvider = worldTerrain
            } catch (error) {
                console.error('地形加载失败:', error)
            }
        }
 
        loadTerrain()
 
        class CreateFrustum {
            constructor(viewer, options) {
                this.position = options.position
                this.viewer = viewer
                this.fov = options.fov || 0
                this.near = options.near || 0
                this.far = options.far || 0
                this.heading = options.heading || 0
                this.pitch = options.pitch || 0
                this.roll = options.roll || 0
                this.width = options.width
                this.height = options.height
 
                this.videoScreen = null
                this.add()
            }
 
            UpdateWidth (value) {
                this.width = value
                this.add()
            }
            UpdateHeight (value) {
                this.height = value
                this.add()
            }
            UpdateFov (value) {
                this.fov = value
                this.add()
            }
            UpdateNear (value) {
                this.near = value
                this.add()
            }
            UpdateFar (value) {
                this.far = value
                this.add()
            }
            UpdateHeading (value) {
                this.heading = value
                this.add()
            }
            UpdatePitch (value) {
                this.pitch = value
                this.add()
            }
            UpdateRoll (value) {
                this.roll = value
                this.add()
            }
            UpdataPosition (position) {
                if (!position) return
                this.position = position
                this.add()
            }
 
            // 更新视锥体的姿态
            Update (position, headingPitchRoll) {
                this.position = Cesium.Cartesian3.fromDegrees(
                    position.longitude,
                    position.latitude,
                    position.altitude
                )
                this.orientation = Cesium.Transforms.headingPitchRollQuaternion(
                    this.position,
                    new Cesium.HeadingPitchRoll.fromDegrees(
                        headingPitchRoll.heading,
                        headingPitchRoll.pitch,
                        headingPitchRoll.roll
                    )
                )
                this.add()
            }
 
            // 创建视锥体和轮廓线
            add () {
                this.clear()
                this.viewer.scene.globe.depthTestAgainstTerrain = true
 
                this.addFrustum()
                this.addOutline()
                this.addCenterline()
            }
 
            // 清除视锥体和轮廓线
            clear () {
                this.viewer.scene.globe.depthTestAgainstTerrain = false
 
                if (this.videoScreen) {
                    this.videoScreen.destroyed()
 
                    this.videoScreen = null
                }
 
                this.clearFrustum()
                this.clearOutline()
                this.clearCenterline()
            }
 
            // 清除视锥体
            clearFrustum () {
                if (this.frustumPrimitive) {
                    this.viewer.scene.primitives.remove(this.frustumPrimitive)
                    this.frustumPrimitive = null
                }
            }
 
            // 清除轮廓线
            clearOutline () {
                if (this.outlinePrimitive) {
                    this.viewer.scene.primitives.remove(this.outlinePrimitive)
                    this.outlinePrimitive = null
                }
            }
 
            clearCenterline () {
                if (this.centerDataSource) {
                    this.centerDataSource.entities.removeAll()
                    this.viewer.dataSources.remove(this.centerDataSource)
                    this.centerDataSource = null
                }
            }
 
            // 创建视锥体
            addFrustum () {
                const frustum = new Cesium.PerspectiveFrustum({
                    // 查看的视场角,绕Z轴旋转,以弧度方式输入
                    fov: Cesium.Math.toRadians(this.fov),
                    // 视锥体的宽度/高度
                    aspectRatio: this.height / this.width,
                    // 近面距视点的距离
                    near: this.near,
                    // 远面距视点的距离
                    far: this.far,
                })
                const position = Cesium.Cartesian3.fromDegrees(
                    this.position.longitude,
                    this.position.latitude,
                    this.position.altitude
                )
                const frustumGeometry = new Cesium.FrustumGeometry({
                    frustum: frustum,
                    origin: position,
                    orientation: Cesium.Transforms.headingPitchRollQuaternion(
                        position,
                        new Cesium.HeadingPitchRoll.fromDegrees(this.heading, this.pitch, this.roll)
                    ),
                    vertexFormat: Cesium.VertexFormat.POSITION_ONLY,
                })
 
                // 取出视锥体的顶点坐标
                const geometry = Cesium.FrustumOutlineGeometry.createGeometry(frustumGeometry)
 
                console.log(geometry, 1111111111)
 
                const result = []
                for (let i = 0; i < geometry.attributes.position.values.length; i += 3) {
                    result.push(Array.from(geometry.attributes.position.values).slice(i, i + 3))
                }
 
                // 将顶点分为近面(前4个)和远面(后4个)
                const nearVertices = result.slice(0, 4)
                const farVertices = result.slice(4, 8)
 
                let videoPolygon = []
                let videoIntersectionPolygon = []
 
                let pointColor = [Cesium.Color.RED, Cesium.Color.GREEN, Cesium.Color.YELLOW, Cesium.Color.BLUE]
 
                // 处理四条棱线(近面顶点到远面对应顶点)
                for (let i = 0; i < 4; i++) {
                    const nearVertex = new Cesium.Cartesian3(...nearVertices[i])
                    const farVertex = new Cesium.Cartesian3(...farVertices[i])
 
                    this.viewer.entities.add({
                        name: 'Point with height',
                        position: farVertex,
                        point: {
                            pixelSize: 10,
                            color: pointColor[i],
                            // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND // 或 NONE, RELATIVE_TO_GROUND
                        }
                    })
 
                    const ray = new Cesium.Ray()
                    ray.origin = nearVertex
                    // 计算方向向量(终点 - 起点)并归一化
                    ray.direction = Cesium.Cartesian3.normalize(
                        Cesium.Cartesian3.subtract(farVertex, nearVertex, new Cesium.Cartesian3()),
                        new Cesium.Cartesian3()
                    )
 
                    // 检测射线与地球表面交点
                    const pickPosition = this.viewer.scene.globe.pick(ray, this.viewer.scene)
 
                    // 有交点则使用交点,否则使用远面顶点
                    if (pickPosition) {
                        videoIntersectionPolygon.push(pickPosition)
                    }
 
                    videoPolygon.push(farVertex)
                }
 
                // 获得视锥体和地面的交点,构成平面,并使用video标签做为材质
                if (videoPolygon.length === 4) {
                    if (!this.videoScreen) {
                        this.initVideoMesh()
                    }
 
                    if (videoIntersectionPolygon.length < 4) {
                        this.videoScreen.transform(videoPolygon, Cesium.Transforms.headingPitchRollQuaternion(
                            position,
                            new Cesium.HeadingPitchRoll.fromDegrees(this.heading, this.pitch, this.roll)
                        ), false)
                    } else {
                        this.videoScreen.transform(videoIntersectionPolygon, Cesium.Transforms.headingPitchRollQuaternion(
                            position,
                            new Cesium.HeadingPitchRoll.fromDegrees(this.heading, this.pitch, this.roll)
                        ), true)
                    }
                }
 
                const instance = new Cesium.GeometryInstance({
                    geometry: frustumGeometry,
                    attributes: {
                        color: Cesium.ColorGeometryInstanceAttribute.fromColor(
                            Cesium.Color.fromBytes(0, 213, 144, 20)
                        ),
                    },
                })
                const primitive = new Cesium.Primitive({
                    geometryInstances: instance,
                    releaseGeometryInstances: false,
                    appearance: new Cesium.PerInstanceColorAppearance({
                        closed: true,
                        flat: true,
                    }),
                    asynchronous: false,
                })
 
                this.frustumPrimitive = this.viewer.scene.primitives.add(primitive)
            }
 
            // 创建轮廓线
            addOutline () {
                const frustum = new Cesium.PerspectiveFrustum({
                    // 查看的视场角度,绕Z轴旋转,以弧度方式输入
                    // The angle of the field of view (FOV), in radians.
                    // This angle will be used as the horizontal FOV if the width is greater than the height, otherwise it will be the vertical FOV.
                    fov: Cesium.Math.toRadians(this.fov),
                    // 视锥体的宽度/高度
                    aspectRatio: this.height / this.width,
                    // 近面距视点的距离
                    near: this.near,
                    // 远面距视点的距离
                    far: this.far,
                })
                const position = Cesium.Cartesian3.fromDegrees(
                    this.position.longitude,
                    this.position.latitude,
                    this.position.altitude
                )
                const frustumGeometry = new Cesium.FrustumOutlineGeometry({
                    frustum: frustum,
                    origin: position,
                    orientation: Cesium.Transforms.headingPitchRollQuaternion(
                        position,
                        new Cesium.HeadingPitchRoll.fromDegrees(this.heading, this.pitch, this.roll)
                    ),
                    vertexFormat: Cesium.VertexFormat.POSITION_ONLY,
                })
 
 
                const instance = new Cesium.GeometryInstance({
                    geometry: frustumGeometry,
                    attributes: {
                        color: Cesium.ColorGeometryInstanceAttribute.fromColor(
                            Cesium.Color.fromBytes(0, 213, 144, 255)
                        ),
                    },
                })
                const primitive = new Cesium.Primitive({
                    geometryInstances: instance,
                    appearance: new Cesium.PerInstanceColorAppearance({
                        closed: true,
                        flat: true,
                    }),
                    asynchronous: false,
                })
                this.outlinePrimitive = this.viewer.scene.primitives.add(primitive)
            }
 
            addCenterline () {
                this.centerDataSource = new Cesium.CustomDataSource()
                this.viewer.dataSources.add(this.centerDataSource)
 
                const position = Cesium.Cartesian3.fromDegrees(
                    this.position.longitude,
                    this.position.latitude,
                    this.position.altitude
                )
 
                let matrix = Cesium.Matrix3.fromQuaternion(
                    Cesium.Transforms.headingPitchRollQuaternion(
                        position,
                        new Cesium.HeadingPitchRoll.fromDegrees(this.heading, this.pitch, this.roll)
                    ),
                    new Cesium.Matrix3()
                )
 
                let right1 = Cesium.Matrix3.getColumn(matrix, 0, new Cesium.Cartesian3())
                let up1 = Cesium.Matrix3.getColumn(matrix, 1, new Cesium.Cartesian3())
                let direction = Cesium.Matrix3.getColumn(matrix, 2, new Cesium.Cartesian3())
 
                // const direction = new Cartesian3(-0.10668226241650887, 0.8103322335050215, -0.5761775474872814)
 
                let frontDirect = Cesium.Cartesian3.multiplyByScalar(
                    direction,
                    this.far,
                    new Cesium.Cartesian3()
                )
                let bottomCenter = Cesium.Cartesian3.add(position, frontDirect, new Cesium.Cartesian3())
 
                // 创建Entity来显示中心线
                this.centerDataSource.entities.add({
                    name: 'Center Line of Frustum',
                    polyline: {
                        positions: [position, bottomCenter],
                        width: 1,
                        // material: Cesium.Color.RED.withAlpha(0.5)
                        material: new Cesium.PolylineDashMaterialProperty({
                            color: Cesium.Color.fromBytes(0, 213, 144, 255),
                            dashLength: 30.0,
                            gapColor: Cesium.Color.TRANSPARENT,
                            gapWidth: 1.0,
                        }),
                    },
                })
            }
 
            initVideoMesh () {
                let element = document.getElementById('VIDEO')
 
                if (element === '') return
 
                // 需要同步时钟,否则视频不会动
                // let synchronizer = new Cesium.VideoSynchronizer({
                //     clock: this.viewer.clock,
                //     element: element
                // })
                // this.viewer.clock.shouldAnimate = true
 
                this.videoScreen = new VideoScreen({
                    viewer: this.viewer,
                    options: {
                        element,
                        stRotation: 90 // 视频画面的旋转角度
                    }
                })
            }
        }
 
        /**
         * 视频幕布
         */
        class VideoScreen {
 
            // 投射多边形
            curMesh = null
 
            /**
               * @typedef {Object} Options 视频幕布配置参数
               * @property {String} src 视频源地址
               * @property {Array} [positions=[]] 视频幕布几何体顶点坐标
               * @property {number} [stRotation=90.0] 几何体纹理的旋转角度
               * @property {Boolean} [tapGround=false] 几何体是否完全贴地
               */
            options = {
                src: '',
                positions: [],
                stRotation: 0,
                tapGround: false
            }
 
            constructor(config) {
                const { viewer, options } = config
 
                if (!viewer || !options) {
                    console.error('Missing required parameters when new FrustumEditor')
                    return
                }
                this._viewer = viewer
 
                this._entityVideoDataSource = null
                this._entityVideoDataSource = new Cesium.CustomDataSource('entityVideoDataSource')
                this._viewer.dataSources.add(this._entityVideoDataSource)
 
                this.options = {
                    ...this.options,
                    ...options
                }
 
                this.init()
            }
 
            init () {
                const { element, tapGround, positions, stRotation } = this.options
 
                // 创建Polygon
                const mesh = this._entityVideoDataSource.entities.add({
                    polygon: {
                        hierarchy: new Cesium.PolygonHierarchy(positions),
                        material: element,
                        // perPositionHeight: !tapGround, // 启用每个位置的高度
 
                        // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                    }
                })
                this.curMesh = mesh
            }
 
            /**
             * 改变姿态
             * @param positions {Array} 新的顶点坐标
             */
            transform (positions, orientation, isIntersect = false) {
                if (this.curMesh) {
                    // 更新VideoPolygon的顶点
 
                    // 获取物体的heading和pitch
                    const headingInRadians = Cesium.Math.toRadians(option.heading)  // 将heading角度转换为弧度
                    const pitchInRadians = Cesium.Math.toRadians(option.pitch)      // 将pitch角度转换为弧度
 
                    // 计算纹理的旋转角度,假设纹理的旋转取决于物体的heading和pitch
                    // 例如:纹理的旋转角度可能是基于物体的旋转和视角的调整
                    let stRotation = headingInRadians + pitchInRadians
 
                    this.curMesh.polygon.perPositionHeight = !isIntersect // 启用每个位置的高度
 
                    this.curMesh.polygon.heightReference = !isIntersect ? Cesium.HeightReference.NONE : Cesium.HeightReference.CLAMP_TO_GROUND
 
                    this.curMesh.polygon.hierarchy = new Cesium.PolygonHierarchy(positions)
 
                    this.curMesh.orientation = orientation
                }
            }
 
            /**
             * 获取地球面与线的交点
             * @param p1 {lng,lat,height} 线的起点
             * @param p2 {lng,lat,height} 线的终点
             * @return {null|*}
             */
            getInterPointByLine (p1, p2) {
                const startPoint = p1 instanceof Cesium.Cartographic ? p1 : Cesium.Cartographic.fromDegrees(p1.lng, p1.lat, p1.height) // 替换为起点的经纬度和高度
                const endPoint = p2 instanceof Cesium.Cartographic ? p2 : Cesium.Cartographic.fromDegrees(p2.lng, p2.lat, p2.height) // 替换为终点的经纬度和高度
                // 创建起点和终点的笛卡尔坐标
                const startCartesian = this._viewer.scene.globe.ellipsoid.cartographicToCartesian(startPoint)
                const endCartesian = this._viewer.scene.globe.ellipsoid.cartographicToCartesian(endPoint)
                // 通过原点和方向 创建射线
                const direction = Cesium.Cartesian3.subtract(endCartesian, startCartesian, new Cesium.Cartesian3())
                const ray = new Cesium.Ray(startCartesian, direction)
 
                // 计算射线与地球表面的交点
                const result = Cesium.IntersectionTests.rayEllipsoid(ray, this._viewer.scene.globe.ellipsoid)
 
                if (result && result.start !== result.stop) {
                    // 计算交点的位置
                    console.log(`start ${result.start}, stop ${result.stop}`)
                    const intersectionPoint = Cesium.Ray.getPoint(ray, result.start)
 
                    // 将交点的笛卡尔坐标转换为地理坐标
                    const intersectionCartographic = Cesium.Cartographic.fromCartesian(intersectionPoint)
                    return intersectionCartographic
                } else {
                    console.log(`该方向上无交点 ${p1}, ${p2}`)
                    return null
                }
            }
 
            /**
               * 显示隐藏
               * @param targetVal {Boolean}
               */
            toggle (targetVal) {
                const { curMesh } = this
                if (curMesh) {
                    curMesh.show = typeof targetVal === 'boolean' ? targetVal : !curMesh.show
                }
            }
 
            destroyed () {
                if (this._entityVideoDataSource) {
                    this._entityVideoDataSource?.entities.removeAll()
                    this._viewer.dataSources.remove(this._entityVideoDataSource, true)
                    this._entityVideoDataSource = null
                }
 
                this._viewer = null
            }
        }
 
        let option = {
            longitude: 114.82299452552775,
            latitude: 25.992290470862866,
            height: 250,
            pitch: 90,
            roll: 0,
            heading: 0,
            videoWidth: 16,
            videoHeight: 9
        }
 
        let viewInfoFrustum = new CreateFrustum(viewer, {
            position: {
                longitude: option?.longitude,
                latitude: option?.latitude,
                altitude: option?.height,
            },
 
            width: option?.videoWidth,
            height: option?.videoHeight,
 
            fov: 64,
            near: 0.01,
            far: 250,
            roll: option.roll,
            pitch: option.pitch,
            heading: option.heading,
        })
 
        function optionsChange (type, changeType, val) {
            viewInfoFrustum.clear()
 
            changeType === 1 ? option[type] += 1 : option[type] -= 1
 
            viewInfoFrustum = new CreateFrustum(viewer, {
                position: {
                    longitude: option?.longitude,
                    latitude: option?.latitude,
                    altitude: option?.height,
                },
 
                width: option?.videoWidth,
                height: option?.videoHeight,
 
                fov: 64,
                near: 0.01,
                far: 250,
                roll: option.roll,
                pitch: option.pitch,
                heading: option.heading,
            })
 
        }
    </script>
</body>
 
</html>