index.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <!DOCTYPE html>
  2. <html lang="">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width,initial-scale=1.0">
  7. <link rel="icon" href="<%= BASE_URL %>favicon.ico">
  8. <!-- <title><%= htmlWebpackPlugin.options.title %></title>-->
  9. <script src="./videoFusion/threejs/three.js"></script>
  10. <script defer="defer" src="./videoFusion/threejs/OBJLoader.js"></script>
  11. <script src="./videoFusion/flv.js"></script>
  12. <script id="vertexShader" type="x-shader/x-vertex">
  13. precision highp float;
  14. uniform mat4 modelViewMatrixToFrustum;
  15. varying highp vec4 vWorldPos;
  16. varying highp vec4 vCameraPos;
  17. varying vec3 vColor;
  18. varying vec2 textureCoord;
  19. varying vec3 vNormal;
  20. void main() {
  21. vColor = color;
  22. vWorldPos = modelMatrix * vec4(position, 1.0);
  23. vCameraPos = modelViewMatrixToFrustum * vec4(position, 1.0);
  24. textureCoord = uv;
  25. vNormal = normal;
  26. gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
  27. gl_Position.z -= 0.20;
  28. }
  29. </script>
  30. <script id="fragmentShader" type="x-shader/x-fragment">
  31. precision highp sampler2D;
  32. precision highp float;
  33. uniform vec3 baseColor;
  34. uniform vec3 frustum[5];
  35. uniform sampler2D baseTexture;
  36. uniform sampler2D cameraTexture;
  37. uniform int isPreview;
  38. uniform bool hasBaseTexture;
  39. uniform bool hasVertexColor;
  40. uniform vec4 distCoeff;
  41. uniform bool isFishEyeModel;
  42. uniform bool useUndistort;
  43. uniform bool isTransparent;
  44. varying vec3 vColor;
  45. varying highp vec4 vWorldPos;
  46. varying highp vec4 vCameraPos;
  47. varying vec2 textureCoord;
  48. varying vec3 vNormal;
  49. float perspectiveDepthToViewZ( float invClipZ, float near, float far ) {
  50. return ( near * far ) / ( ( far - near ) * invClipZ - far );
  51. }
  52. float viewZToOrthographicDepth( float viewZ, float near, float far ) {
  53. return ( viewZ + near ) / ( near - far );
  54. }
  55. float readDepth( sampler2D depthSampler, vec2 coord ) {
  56. float fragCoordZ = texture2D( depthSampler, coord ).x;
  57. float viewZ = perspectiveDepthToViewZ( fragCoordZ, 0.1, 2000000. );
  58. return viewZ;
  59. }
  60. // port from https://github.com/mrdoob/three.js/blob/35ae830a7c4544582ed2759e5b18c5d6ef37c6d9/src/math/Vector3.js#L559
  61. vec3 projectOnVector(vec3 a, vec3 b){
  62. float dist = length(b);
  63. return b * ( dot(a, b) / (dist * dist) );
  64. }
  65. float calculateCos(vec3 a, vec3 b){
  66. float dista = length(a);
  67. float distb = length(b);
  68. return (dot(a, b) / (dista * distb));
  69. }
  70. void main() {
  71. // shadowMap = true;
  72. vec3 baseTextureColor;
  73. vec3 color;
  74. baseTextureColor = texture2D(baseTexture, textureCoord).rgb;
  75. if (hasBaseTexture) {
  76. gl_FragColor = vec4(baseColor * baseTextureColor, 1.0);
  77. } else if (hasVertexColor){
  78. gl_FragColor = vec4(vColor, 1.0);
  79. }else {
  80. vec3 view_nv = normalize(vNormal);
  81. vec3 nv_color = view_nv * 0.5 + 0.5;
  82. gl_FragColor = vec4(isTransparent ? vec3( 0.0, 0.0, 0.0 ) : nv_color, isTransparent ? 0.0 : 1.0);
  83. // gl_FragColor = vec4(vNormal, 1.0);
  84. }
  85. if (isPreview == 1){
  86. vec3 dir = vCameraPos.xyz - frustum[0];
  87. vec3 center = (frustum[1] + frustum[2] + frustum[3] + frustum[4]) * 0.25;
  88. // if ( length(vCameraPos.xyz) <= 100.0){
  89. // gl_FragColor = vec4(1.0, 0., 0., 1.0);
  90. // }
  91. vec3 frustumAxis = center - frustum[0];
  92. vec3 projected = projectOnVector(dir, frustumAxis);
  93. float scalar = length(frustumAxis) / length(projected);
  94. vec3 planeProj = ( dir * scalar ) + frustum[0];
  95. if (calculateCos(dir, frustumAxis) > 0.4) {
  96. // UVs
  97. vec3 uvBase = planeProj - frustum[1]; // from top-left corner
  98. vec3 cBase = planeProj - center;
  99. vec3 sub12 = frustum[2] - frustum[1];
  100. vec3 sub13 = frustum[3] - frustum[1];
  101. vec3 sub12uv = projectOnVector(uvBase, sub12);
  102. vec3 sub13uv = projectOnVector(uvBase, sub13);
  103. float ou = length(sub12uv) * sign(dot(sub12, sub12uv)) / length(sub12);
  104. float ov = 1. - length(sub13uv) * sign(dot(sub13, sub13uv)) / length(sub13);
  105. if (useUndistort) {
  106. if (isFishEyeModel){
  107. float a = (length(sub12uv) * sign(dot(sub12, sub12uv)) - length(sub12) / 2.) / length(frustumAxis);
  108. float b = (-(length(sub13uv) * sign(dot(sub13, sub13uv))) + length(sub13) / 2.) / length(frustumAxis);
  109. float r = sqrt(a * a + b * b);
  110. float theta = atan(r);
  111. float thetaD = theta * ( 1. + distCoeff.x * pow(theta, 2.) + distCoeff.y * pow(theta, 4.) + distCoeff.z * pow(theta, 6.) + distCoeff.w * pow(theta, 8.));
  112. if (theta > 80. / 180. * 3.1415 ){
  113. return;
  114. }
  115. float x2 = r > 1e-8 ? (thetaD / r)*a : a;
  116. float y2 = r > 1e-8 ? (thetaD / r)*b : b;
  117. // float u = length(sub12uv) * sign(dot(sub12, sub12uv)) / length(sub12);
  118. float u = (x2 * length(frustumAxis) + length(sub12) / 2.) / length(sub12);
  119. // float v = length(sub13uv) * sign(dot(sub13, sub13uv)) / length(sub13);
  120. float v = (-y2 * length(frustumAxis) + length(sub13) / 2.) / length(sub13);
  121. v = 1. - v;
  122. if ( calculateCos(dir, frustumAxis) > 0.0) {
  123. if ( max( u,v ) <= 1. && min( u, v ) >= 0. ) {
  124. color = texture2D(cameraTexture, vec2(u, v)).rgb * 0.8 + baseTextureColor * (0.2);
  125. gl_FragColor = vec4(baseColor * color, 1.0);
  126. }
  127. }
  128. } else {
  129. float a = (length(sub12uv) * sign(dot(sub12, sub12uv)) - length(sub12) / 2.) / length(frustumAxis);
  130. float b = (-(length(sub13uv) * sign(dot(sub13, sub13uv))) + length(sub13) / 2.) / length(frustumAxis);
  131. float r = sqrt(a * a + b * b);
  132. float x2 = a * ( 1. + distCoeff.x * pow(r, 2.) + distCoeff.y * pow(r, 4.) + distCoeff.z * pow(r, 6.) );
  133. float y2 = b * ( 1. + distCoeff.x * pow(r, 2.) + distCoeff.y * pow(r, 4.) + distCoeff.z * pow(r, 6.) );
  134. float u = (x2 * length(frustumAxis) + length(sub12) / 2.) / length(sub12);
  135. float v = (-y2 * length(frustumAxis) + length(sub13) / 2.) / length(sub13);
  136. v = 1. - v;
  137. // if ( calculateCos(dir, frustumAxis) > 0.0) {
  138. if ( max( u,v ) <= 1. && min( u, v ) >= 0. ) {
  139. float opacity = 1.0;
  140. if ( u <= 0.1 || u >= 0.9) {
  141. opacity = 10. * min(u, 1.0-u);
  142. }
  143. if ( v <= 0.1 || v >= 0.9) {
  144. opacity = 10. * min(v, 1.0-v);
  145. }
  146. color = texture2D(cameraTexture, vec2(u, v)).rgb * 1.0 + baseTextureColor * (0.0);
  147. gl_FragColor = vec4(baseColor * color, opacity);
  148. // gl_FragColor = vec4(0.5, 0.0, 0.0, 1.0);
  149. }
  150. // }
  151. }
  152. }else{
  153. float u = length(sub12uv) * sign(dot(sub12, sub12uv)) / length(sub12);
  154. float v = length(sub13uv) * sign(dot(sub13, sub13uv)) / length(sub13);
  155. v = 1. - v;
  156. if ( calculateCos(dir, frustumAxis) > 0.0) {
  157. if ( max( u,v ) <= 1. && min( u, v ) >= 0. ) {
  158. color = texture2D(cameraTexture, vec2(u, v)).rgb * 0.8 + baseTextureColor * (0.2);
  159. // gl_FragColor = vec4(baseColor * color, 1.0);
  160. gl_FragColor = vec4(0.5, 0.0, 0.0, 1.0);
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. </script>
  168. </head>
  169. <body>
  170. <noscript>
  171. <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
  172. </noscript>
  173. <div id="app"></div>
  174. <!-- built files will be auto injected -->
  175. <video id="flv-video" muted loop webkit-playsinline style="display: none"></video>
  176. <script>
  177. let flvPlayer;
  178. let videoElement = document.getElementById("flv-videoFusion");
  179. //播放视频
  180. function PlayCameraVideo() {
  181. flvPlayer = flvjs.createPlayer({
  182. type: "flv",
  183. // url: `http://192.168.112.100:8000/hls/CHY_yk1.flv`, //院内
  184. url: "http://192.168.112.100:8000/hls/CHY_WuNingRoad_3.flv", //院外
  185. islive: true,
  186. hasAudio: false,
  187. // enableStashBuffer: false
  188. });
  189. flvPlayer.attachMediaElement(videoElement);
  190. flvPlayer.load();
  191. flvPlayer.play();
  192. setTimeout(() => {
  193. videoElement.currentTime = 0;
  194. }, 1000);
  195. }
  196. //停止视频
  197. function StopCameraVideo() {
  198. if (flvPlayer) {
  199. flvPlayer.unload();
  200. }
  201. }
  202. PlayCameraVideo();
  203. document.addEventListener("visibilitychange", () => {
  204. if (!document.hidden) {
  205. let buffered = videoElement.buffered;
  206. if (buffered.length > 0) {
  207. let end = buffered.end(0);
  208. if (end - videoElement.currentTime > 180) {
  209. StopCameraVideo();
  210. PlayCameraVideo();
  211. } else if (end - videoElement.currentTime > 0.2) {
  212. videoElement.currentTime = end - 0.25;
  213. }
  214. }
  215. }
  216. });
  217. //关闭窗口,去除查询结果的graphic
  218. $(document).off("click", ".esri-popup__button").on("click", ".esri-popup__button", function () {
  219. if ($(this).prop("className") == "esri-popup__button") {
  220. if (window.agsGlobal.view.map.findLayerById("vecShGraLayer")) {
  221. window.agsGlobal.view.map.findLayerById("vecShGraLayer").graphics.removeAll();
  222. }
  223. }
  224. });
  225. </script>
  226. </body>
  227. </html>