一些技术路线测试,增加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
<!--
 * @Author       : yuan
 * @Date         : 2025-08-05 10:02:04
 * @LastEditors  : yuan
 * @LastEditTime : 2025-08-07 10:40:16
 * @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>
 
    <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>heading</div>
            <div>
                <button onclick="optionsChange('videoHeading', 1, 1)">+1</button>
            </div>
            <div>
                <button onclick="optionsChange('videoHeading', 2, 1)">-1</button>
            </div>
        </div>
        <div>
            <div>pitch</div>
            <div>
                <button onclick="optionsChange('videoPitch', 1, 1)">+1</button>
            </div>
            <div>
                <button onclick="optionsChange('videoPitch', 2, 1)">-1</button>
            </div>
        </div>
        <div>
            <div>roll</div>
            <div>
                <button onclick="optionsChange('videoRoll', 1, 1)">+1</button>
            </div>
            <div>
                <button onclick="optionsChange('videoRoll', 2, 1)">-1</button>
            </div>
        </div>
    </div>
 
    <video src="./5b49f586a6ad3.mp4" 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=1581F8HGX252L00A01CG-99-0-0-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, 1500)//定义飞行终点的坐标
 
        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=ec574ab1eecd3b998ca8c92f91d3242e`,
            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()
            }
 
            // 创建视锥体和轮廓线
            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.width / this.height),
                    // 近面距视点的距离
                    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 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.width / this.height),
                    // 近面距视点的距离
                    near: this.near,
                    // 远面距视点的距离
                    far: this.far,
                })
 
                const position = Cesium.Cartesian3.fromDegrees(
                    this.position.longitude,
                    this.position.latitude,
                    this.position.altitude
                )
 
 
                let hpr = Cesium.HeadingPitchRoll.fromDegrees(this.heading, this.pitch, this.roll)
                let orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr)
 
                const frustumGeometry = new Cesium.FrustumOutlineGeometry({
                    frustum: frustum,
                    origin: position,
                    orientation: orientation,
                    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,
                        translucent: true
                    }),
                    asynchronous: false,
                })
                this.outlinePrimitive = this.viewer.scene.primitives.add(primitive)
 
                if (!this.videoScreen) {
                    this.initVideoMesh({
                        orientation: orientation,
                        cameraPosition: position,
                        hpr: hpr
                    })
                }
            }
 
            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 hpr = Cesium.HeadingPitchRoll.fromDegrees(this.heading, this.pitch, this.roll)
 
                let matrix = Cesium.Matrix3.fromQuaternion(
                    Cesium.Transforms.headingPitchRollQuaternion(
                        position,
                        hpr
                    ),
                    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 (data) {
                let element = document.getElementById('VIDEO')
 
                if (element === '') return
 
                this.videoScreen = new VideoScreen({
                    viewer: this.viewer,
                    options: {
                        element,
                        ...data,
                        stRotation: 90 // 视频画面的旋转角度
                    }
                })
            }
        }
 
        function computeFarCenter (position, hpr, far) {
            const quaternion = Cesium.Transforms.headingPitchRollQuaternion(position, hpr)
            const rotMat = Cesium.Matrix3.fromQuaternion(quaternion)
            const dirLocal = new Cesium.Cartesian3(0, 0, far)
            const dirWorld = Cesium.Matrix3.multiplyByVector(rotMat, dirLocal, new Cesium.Cartesian3())
            return Cesium.Cartesian3.add(position, dirWorld, new Cesium.Cartesian3())
        }
 
        /**
         * 视频幕布
         */
        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,
                    orientation,
                    cameraPosition,
                    hpr
                } = this.options
 
                let width = option.far * Math.tan(Cesium.Math.toRadians(option.fov) * 0.5) * 2
                let height = width / (option.videoWidth / option.videoHeight)
 
                const mesh = this._entityVideoDataSource.entities.add({
                    position: new Cesium.CallbackProperty(() => {
                        return computeFarCenter(cameraPosition, hpr, option.far)
                    }, false),
                    orientation: new Cesium.CallbackProperty(() => {
                        return orientation
                    }, false),
                    plane: {
                        plane: new Cesium.Plane(new Cesium.Cartesian3(0, 0, -1), 0),
                        dimensions: new Cesium.Cartesian2(width, height),
                        material: element,
                    },
                })
 
                this.curMesh = mesh
            }
 
            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: 0,
            roll: 0,
            heading: 90,
 
            fov: 64,
            far: 250,
 
            videoWidth: 960,
            videoHeight: 720,
 
            videoHeading: -360,
            videoPitch: 0,
            videoRoll: 0,
        }
 
        let viewInfoFrustum = new CreateFrustum(viewer, {
            position: {
                longitude: option?.longitude,
                latitude: option?.latitude,
                altitude: option?.height,
            },
 
            width: option?.videoWidth,
            height: option?.videoHeight,
 
            fov: option.fov,
            near: 0.01,
            far: option.far,
 
            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>