123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- <!DOCTYPE html>
- <html lang="">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width,initial-scale=1.0">
- <link rel="icon" href="<%= BASE_URL %>favicon.ico">
- <!-- <title><%= htmlWebpackPlugin.options.title %></title>-->
- <script src="./videoFusion/threejs/three.js"></script>
- <script defer="defer" src="./videoFusion/threejs/OBJLoader.js"></script>
- <script src="./videoFusion/flv.js"></script>
- <script id="vertexShader" type="x-shader/x-vertex">
- precision highp float;
- uniform mat4 modelViewMatrixToFrustum;
- varying highp vec4 vWorldPos;
- varying highp vec4 vCameraPos;
- varying vec3 vColor;
- varying vec2 textureCoord;
- varying vec3 vNormal;
- void main() {
- vColor = color;
- vWorldPos = modelMatrix * vec4(position, 1.0);
- vCameraPos = modelViewMatrixToFrustum * vec4(position, 1.0);
- textureCoord = uv;
- vNormal = normal;
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
- gl_Position.z -= 0.20;
- }
- </script>
- <script id="fragmentShader" type="x-shader/x-fragment">
- precision highp sampler2D;
- precision highp float;
- uniform vec3 baseColor;
- uniform vec3 frustum[5];
- uniform sampler2D baseTexture;
- uniform sampler2D cameraTexture;
- uniform int isPreview;
- uniform bool hasBaseTexture;
- uniform bool hasVertexColor;
- uniform vec4 distCoeff;
- uniform bool isFishEyeModel;
- uniform bool useUndistort;
- uniform bool isTransparent;
- varying vec3 vColor;
- varying highp vec4 vWorldPos;
- varying highp vec4 vCameraPos;
- varying vec2 textureCoord;
- varying vec3 vNormal;
- float perspectiveDepthToViewZ( float invClipZ, float near, float far ) {
- return ( near * far ) / ( ( far - near ) * invClipZ - far );
- }
- float viewZToOrthographicDepth( float viewZ, float near, float far ) {
- return ( viewZ + near ) / ( near - far );
- }
- float readDepth( sampler2D depthSampler, vec2 coord ) {
- float fragCoordZ = texture2D( depthSampler, coord ).x;
- float viewZ = perspectiveDepthToViewZ( fragCoordZ, 0.1, 2000000. );
- return viewZ;
- }
- // port from https://github.com/mrdoob/three.js/blob/35ae830a7c4544582ed2759e5b18c5d6ef37c6d9/src/math/Vector3.js#L559
- vec3 projectOnVector(vec3 a, vec3 b){
- float dist = length(b);
- return b * ( dot(a, b) / (dist * dist) );
- }
- float calculateCos(vec3 a, vec3 b){
- float dista = length(a);
- float distb = length(b);
- return (dot(a, b) / (dista * distb));
- }
- void main() {
- // shadowMap = true;
- vec3 baseTextureColor;
- vec3 color;
- baseTextureColor = texture2D(baseTexture, textureCoord).rgb;
- if (hasBaseTexture) {
- gl_FragColor = vec4(baseColor * baseTextureColor, 1.0);
- } else if (hasVertexColor){
- gl_FragColor = vec4(vColor, 1.0);
- }else {
- vec3 view_nv = normalize(vNormal);
- vec3 nv_color = view_nv * 0.5 + 0.5;
- gl_FragColor = vec4(isTransparent ? vec3( 0.0, 0.0, 0.0 ) : nv_color, isTransparent ? 0.0 : 1.0);
- // gl_FragColor = vec4(vNormal, 1.0);
- }
- if (isPreview == 1){
- vec3 dir = vCameraPos.xyz - frustum[0];
- vec3 center = (frustum[1] + frustum[2] + frustum[3] + frustum[4]) * 0.25;
- // if ( length(vCameraPos.xyz) <= 100.0){
- // gl_FragColor = vec4(1.0, 0., 0., 1.0);
- // }
- vec3 frustumAxis = center - frustum[0];
- vec3 projected = projectOnVector(dir, frustumAxis);
- float scalar = length(frustumAxis) / length(projected);
- vec3 planeProj = ( dir * scalar ) + frustum[0];
- if (calculateCos(dir, frustumAxis) > 0.4) {
- // UVs
- vec3 uvBase = planeProj - frustum[1]; // from top-left corner
- vec3 cBase = planeProj - center;
- vec3 sub12 = frustum[2] - frustum[1];
- vec3 sub13 = frustum[3] - frustum[1];
- vec3 sub12uv = projectOnVector(uvBase, sub12);
- vec3 sub13uv = projectOnVector(uvBase, sub13);
- float ou = length(sub12uv) * sign(dot(sub12, sub12uv)) / length(sub12);
- float ov = 1. - length(sub13uv) * sign(dot(sub13, sub13uv)) / length(sub13);
- if (useUndistort) {
- if (isFishEyeModel){
- float a = (length(sub12uv) * sign(dot(sub12, sub12uv)) - length(sub12) / 2.) / length(frustumAxis);
- float b = (-(length(sub13uv) * sign(dot(sub13, sub13uv))) + length(sub13) / 2.) / length(frustumAxis);
- float r = sqrt(a * a + b * b);
- float theta = atan(r);
- float thetaD = theta * ( 1. + distCoeff.x * pow(theta, 2.) + distCoeff.y * pow(theta, 4.) + distCoeff.z * pow(theta, 6.) + distCoeff.w * pow(theta, 8.));
- if (theta > 80. / 180. * 3.1415 ){
- return;
- }
- float x2 = r > 1e-8 ? (thetaD / r)*a : a;
- float y2 = r > 1e-8 ? (thetaD / r)*b : b;
- // float u = length(sub12uv) * sign(dot(sub12, sub12uv)) / length(sub12);
- float u = (x2 * length(frustumAxis) + length(sub12) / 2.) / length(sub12);
- // float v = length(sub13uv) * sign(dot(sub13, sub13uv)) / length(sub13);
- float v = (-y2 * length(frustumAxis) + length(sub13) / 2.) / length(sub13);
- v = 1. - v;
- if ( calculateCos(dir, frustumAxis) > 0.0) {
- if ( max( u,v ) <= 1. && min( u, v ) >= 0. ) {
- color = texture2D(cameraTexture, vec2(u, v)).rgb * 0.8 + baseTextureColor * (0.2);
- gl_FragColor = vec4(baseColor * color, 1.0);
- }
- }
- } else {
- float a = (length(sub12uv) * sign(dot(sub12, sub12uv)) - length(sub12) / 2.) / length(frustumAxis);
- float b = (-(length(sub13uv) * sign(dot(sub13, sub13uv))) + length(sub13) / 2.) / length(frustumAxis);
- float r = sqrt(a * a + b * b);
- float x2 = a * ( 1. + distCoeff.x * pow(r, 2.) + distCoeff.y * pow(r, 4.) + distCoeff.z * pow(r, 6.) );
- float y2 = b * ( 1. + distCoeff.x * pow(r, 2.) + distCoeff.y * pow(r, 4.) + distCoeff.z * pow(r, 6.) );
- float u = (x2 * length(frustumAxis) + length(sub12) / 2.) / length(sub12);
- float v = (-y2 * length(frustumAxis) + length(sub13) / 2.) / length(sub13);
- v = 1. - v;
- // if ( calculateCos(dir, frustumAxis) > 0.0) {
- if ( max( u,v ) <= 1. && min( u, v ) >= 0. ) {
- float opacity = 1.0;
- if ( u <= 0.1 || u >= 0.9) {
- opacity = 10. * min(u, 1.0-u);
- }
- if ( v <= 0.1 || v >= 0.9) {
- opacity = 10. * min(v, 1.0-v);
- }
- color = texture2D(cameraTexture, vec2(u, v)).rgb * 1.0 + baseTextureColor * (0.0);
- gl_FragColor = vec4(baseColor * color, opacity);
- // gl_FragColor = vec4(0.5, 0.0, 0.0, 1.0);
- }
- // }
- }
- }else{
- float u = length(sub12uv) * sign(dot(sub12, sub12uv)) / length(sub12);
- float v = length(sub13uv) * sign(dot(sub13, sub13uv)) / length(sub13);
- v = 1. - v;
- if ( calculateCos(dir, frustumAxis) > 0.0) {
- if ( max( u,v ) <= 1. && min( u, v ) >= 0. ) {
- color = texture2D(cameraTexture, vec2(u, v)).rgb * 0.8 + baseTextureColor * (0.2);
- // gl_FragColor = vec4(baseColor * color, 1.0);
- gl_FragColor = vec4(0.5, 0.0, 0.0, 1.0);
- }
- }
- }
- }
- }
- }
- </script>
- </head>
- <body>
- <noscript>
- <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
- </noscript>
- <div id="app"></div>
- <!-- built files will be auto injected -->
- <video id="flv-video" muted loop webkit-playsinline style="display: none"></video>
- <script>
- let flvPlayer;
- let videoElement = document.getElementById("flv-videoFusion");
- //播放视频
- function PlayCameraVideo() {
- flvPlayer = flvjs.createPlayer({
- type: "flv",
- // url: `http://192.168.112.100:8000/hls/CHY_yk1.flv`, //院内
- url: "http://192.168.112.100:8000/hls/CHY_WuNingRoad_3.flv", //院外
- islive: true,
- hasAudio: false,
- // enableStashBuffer: false
- });
- flvPlayer.attachMediaElement(videoElement);
- flvPlayer.load();
- flvPlayer.play();
- setTimeout(() => {
- videoElement.currentTime = 0;
- }, 1000);
- }
- //停止视频
- function StopCameraVideo() {
- if (flvPlayer) {
- flvPlayer.unload();
- }
- }
- PlayCameraVideo();
- document.addEventListener("visibilitychange", () => {
- if (!document.hidden) {
- let buffered = videoElement.buffered;
- if (buffered.length > 0) {
- let end = buffered.end(0);
- if (end - videoElement.currentTime > 180) {
- StopCameraVideo();
- PlayCameraVideo();
- } else if (end - videoElement.currentTime > 0.2) {
- videoElement.currentTime = end - 0.25;
- }
- }
- }
- });
- //关闭窗口,去除查询结果的graphic
- $(document).off("click", ".esri-popup__button").on("click", ".esri-popup__button", function () {
- if ($(this).prop("className") == "esri-popup__button") {
- if (window.agsGlobal.view.map.findLayerById("vecShGraLayer")) {
- window.agsGlobal.view.map.findLayerById("vecShGraLayer").graphics.removeAll();
- }
- }
- });
- </script>
- </body>
- </html>
|