webgl_rxdz_720.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. <template src="./webgl_rxdz_720.html">
  2. </template>
  3. <script>
  4. import * as THREE from 'three';
  5. import Stats from 'three/addons/libs/stats.module.js';
  6. import {
  7. OrbitControls
  8. } from 'three/addons/controls/OrbitControls.js';
  9. import {RGBELoader} from 'three/examples/jsm/loaders/RGBELoader'
  10. import {
  11. getStorage
  12. } from '@/utils/localStorage';
  13. var requestId = "";
  14. const util = require('@/utils/util.js').default;
  15. import commonPageMethod from '@/mixins/commonPageMethod.js';
  16. // import commonPageMethod from '@/common/commonPageMethod.js';
  17. export default {
  18. mixins: [commonPageMethod],
  19. /**
  20. * 页面的初始数据
  21. */
  22. data() {
  23. return {
  24. pvCurPageName: "webgl_720",
  25. locusBehaviorName: "720展示",
  26. pvCurPageParams: null,
  27. houseId: "",
  28. pvId: 'p_2cmina_23121201',
  29. canvas: null,
  30. navbar: {
  31. showCapsule: 1,
  32. title: '',
  33. titleColor: '#000',
  34. navPadding: 0,
  35. navPaddingBg: 'transparent',
  36. navBarColor: 'transparent',
  37. navBackColor: 'transparent',
  38. haveCallback: true, // 如果是 true 会接手 navbarBackClk
  39. fromShare: false,
  40. fromProject: 0,
  41. shareToken: "",
  42. pageName: this.pvCurPageName,
  43. },
  44. id: '', // 户型编号
  45. loader: null,
  46. scene: null,
  47. camera: null,
  48. controlStarPosition: {
  49. x: 0,
  50. y: 0,
  51. z: 0
  52. }, //控制器初始位置
  53. cameraStarPosition: {
  54. x: 0,
  55. y: 0,
  56. z: 5
  57. }, //摄像头初始位置
  58. cameraLastPosition: null, //摄像头上一次移动到的位置
  59. controlLastPosition: null, //观察点上一次移动到的位置
  60. myLoadingStatus: false,
  61. repeatFlag: false, //重复点击
  62. canvasHeight: '',
  63. isIOS: false,
  64. videoUrl: '', //绿幕视频地址
  65. bgUrl: '',
  66. coordinate: '',
  67. hasOneTouch: false,
  68. muted: true, //视频是否静音
  69. }
  70. },
  71. beforeDestroy() {
  72. cancelAnimationFrame(requestId, this.canvas)
  73. this.worker && this.worker.terminate()
  74. if (this.renderer instanceof THREE.WebGLRenderer) {
  75. // 遍历场景中的所有子对象,找到类型为Mesh的对象并移除
  76. let deleList = this.scene.children.filter(object => {
  77. if (object instanceof THREE.Mesh) {
  78. return object
  79. }
  80. })
  81. if (deleList && deleList.length > 0) {
  82. this.scene.remove(...deleList);
  83. }
  84. this.scene.traverse(function(object) {
  85. if (object instanceof THREE.Mesh) {
  86. if (object.geometry && typeof(object.geometry.dispose) == 'function') {
  87. object.geometry.dispose();
  88. }
  89. if (object.material && typeof(object.material.dispose) == 'function') {
  90. object.material.dispose();
  91. }
  92. if (object.texture && typeof(object.texture.dispose) == 'function') {
  93. object.texture.dispose();
  94. }
  95. }
  96. });
  97. this.renderer.clear();
  98. this.renderer.dispose();
  99. this.renderer.forceContextLoss();
  100. this.renderer.context = null;
  101. this.renderer.domElement = null;
  102. this.renderer = null;;
  103. }
  104. console.warn("***beforeDestroy-webgl_rxdz_720***");
  105. },
  106. mounted(options) {
  107. var that = this;
  108. console.warn("***webgl_rxdz_roam-options***", this.$route.query)
  109. this.isIOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  110. this.videoUrl = this.$route.query.videoUrl || '';
  111. this.bgUrl = this.$route.query.bgUrl ||
  112. 'https://dm.static.elab-plus.com/miniProgram/tears_of_steel_bridge_2k.jpg';
  113. this.coordinate = this.$route.query.coordinate || '';
  114. this.type = this.$route.query.type || '';
  115. let screenWidth = window.screen.width;
  116. let screenHeight = window.screen.height;
  117. if (window.innerWidth && window.screen.width) {
  118. screenWidth = Math.min(window.innerWidth, window.screen.width)
  119. }
  120. if (window.innerHeight && window.screen.height) {
  121. screenHeight = Math.min(window.innerHeight, window.screen.height)
  122. }
  123. let unit = screenWidth / 750; //单位rpm 对应 px 的值
  124. this.canvasHeight = screenHeight;
  125. this.houseId = this.$route.query.houseId ? this.$route.query.houseId : '';
  126. this.spaceId = this.$route.query.spaceId ? this.$route.query.spaceId : '';
  127. let container = this.$refs.webgl;
  128. let canvas3d = this.canvas = this.$refs.glcanvas;
  129. //uniapp 兼容写法,因为uni的页面对象的Vue 实例是$vm
  130. let camera = null,
  131. renderer = null;
  132. let needRender = false; //是否需要渲染 false表示不需要渲染;true 表示需要渲染
  133. let scene = this.scene = new THREE.Scene();
  134. let controls = null,
  135. boundary = null;
  136. let stats;
  137. let videoMeshGroup = [];
  138. let cubeCamera = null;
  139. // let lineMesh = null;
  140. let radius = 50; //全景图半径-全景图是个球体
  141. init();
  142. // this.clearEvent = clearEvent;
  143. // this.attendEvent = attendEvent;
  144. this.starRender = starRender; //对外暴露启动渲染的方法
  145. this.stopRender = stopRender; //对外暴露停止渲染的方法
  146. if (window.__wxjs_environment === 'miniprogram') {
  147. this.navbar.showCapsule = 0;
  148. }
  149. function init() {
  150. // 创建相机位置
  151. camera = new THREE.PerspectiveCamera(90, screenWidth / that.canvasHeight, 0.1, 10000);
  152. // camera.up.set(0, 1, 0);//俯视状态,将相机的up向量设置为z轴负方向 {x:0,y:1,z:0}
  153. camera.position.set(that.cameraStarPosition.x, that.cameraStarPosition.y, that.cameraStarPosition.z);
  154. scene.add(camera);
  155. that.camera = camera;
  156. // 环境光会均匀的照亮场景中的所有物体
  157. // const ambientLight = new THREE.AmbientLight(0xFFEFE0, 3.5);
  158. // scene.add(ambientLight);
  159. // 辅助方格
  160. // const axesHelper = new THREE.AxesHelper( 50 );
  161. // scene.add( axesHelper );
  162. // const gridHelper = new THREE.GridHelper(50, 10, 0xcccccc, 0xcccccc);
  163. // gridHelper.position.y = 0;
  164. // gridHelper.position.x = 0;
  165. // scene.add(gridHelper);
  166. //加载环境720贴图
  167. // let loader = new THREE.TextureLoader();
  168. // let texture = loader.load(that.bgUrl, () => {
  169. // let rt = new THREE.WebGLCubeRenderTarget(texture.image.height);
  170. // rt.fromEquirectangularTexture(renderer, texture);
  171. // scene.background = rt.texture;
  172. // });
  173. makeShaderCube();
  174. // makeInstance();
  175. //antialias 这个值得设置为false,不然IOS上截图会失效
  176. renderer = that.renderer = new THREE.WebGLRenderer({
  177. canvas: canvas3d,
  178. alpha: true,
  179. });
  180. renderer.setPixelRatio(window.devicePixelRatio);
  181. renderer.setSize(screenWidth, that.canvasHeight);
  182. container.appendChild(renderer.domElement);
  183. controls = new OrbitControls(camera, renderer.domElement);
  184. controls.enableDamping = true; //启动缓动
  185. controls.minDistance = 0.0001;
  186. controls.maxDistance = radius -10;
  187. // controls.minPolarAngle = 0; // 默认0
  188. // controls.maxPolarAngle = Math.PI / 2; // 默认Math.PI,即可以向下旋转到的视角。
  189. controls.enableZoom = true; //启用/禁用摄像机的缩放
  190. controls.enablePan = false; //启用/禁用摄像机平移
  191. controls.enableRotate = true; //启用/禁用摄像机水平或垂直旋转
  192. // 监听相机移动事件-限制只能在当前空间范围内移动
  193. // controls.addEventListener('change', () => {
  194. // // 获取OrbitControls的缩放值
  195. // var scale = controls.scale;
  196. // // 检查相机位置是否超出边界框
  197. // // if (boundary && !boundary.containsPoint(camera.position)) {
  198. // // let clampedPosition = new THREE.Vector3();
  199. // // boundary.clampPoint(camera.position, clampedPosition);
  200. // // if (clampedPosition) {
  201. // // camera.position.copy(clampedPosition);
  202. // // }
  203. // // }
  204. // });
  205. // camera.lookAt(that.controlStarPosition.x, that.controlStarPosition.y, that.controlStarPosition.z);
  206. if (that.coordinate) {
  207. let position = JSON.parse(that.coordinate);
  208. // camera.lookAt(position.x, position.y, position.z);
  209. }
  210. starRender(); //启动渲染
  211. if (that.isIOS) {
  212. document.addEventListener("WeixinJSBridgeReady", function() {
  213. if (that.type) {
  214. moreTest()
  215. } else {
  216. videoHandle({
  217. videoUrl: that.videoUrl,
  218. coordinate: that.coordinate,
  219. muted: that.muted
  220. });
  221. }
  222. }, false)
  223. }
  224. var guideMask = document.querySelector('#guide-mask');
  225. document.addEventListener("touchend", function() {
  226. guideMask.classList.add('guide-mask-hide');
  227. if (!that.isIOS && that.hasOneTouch == false) {
  228. that.hasOneTouch = true;
  229. // setTimeout(()=>{
  230. if (that.type) {
  231. moreTest()
  232. } else {
  233. videoHandle({
  234. videoUrl: that.videoUrl,
  235. coordinate: that.coordinate,
  236. muted: that.muted
  237. });
  238. }
  239. // },2000)
  240. }
  241. }, false);
  242. }
  243. //把720VR图转化为一个球体模网格型
  244. function makeShaderCube() {
  245. let loader = new THREE.TextureLoader();
  246. let resultTexture = loader.load(that.bgUrl);
  247. // 创建一个ShaderMaterial
  248. var material = new THREE.ShaderMaterial({
  249. uniforms: {
  250. mytexture: {
  251. value: resultTexture
  252. }
  253. },
  254. vertexShader: `
  255. varying vec3 vWorldPosition;
  256. varying vec2 vUv;
  257. void main() {
  258. vUv = uv;
  259. vec4 worldPosition = modelMatrix * vec4(position, 1.0);
  260. vWorldPosition = worldPosition.xyz;
  261. gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
  262. }
  263. `,
  264. fragmentShader: `
  265. varying vec2 vUv;
  266. uniform sampler2D mytexture;
  267. varying vec3 vWorldPosition;
  268. void main() {
  269. vec2 uv = vUv;
  270. vec3 direction = normalize(vWorldPosition);
  271. vec2 sampleUV = vec2(0.5 + atan(direction.z, direction.x) / (2.0 * 3.14159265359), 0.5 - asin(direction.y) / 3.14159265359);
  272. vec2 sampleUV1 = vec2(1.0 - uv.x, uv.y);
  273. gl_FragColor = texture2D(mytexture, sampleUV1);
  274. }
  275. `,
  276. side: THREE.BackSide
  277. });
  278. //创建一个球体几何体
  279. var sphereGeometry = new THREE.SphereGeometry(radius, 60, 40);
  280. //创建一个球体并应用材质
  281. var sphere = new THREE.Mesh(sphereGeometry, material);
  282. scene.add(sphere);
  283. // 创建一个圆柱几何体
  284. // var cylinderGeometry = new THREE.CylinderGeometry(50, 50, 100, 60, 1, true);
  285. // var cylinder = new THREE.Mesh(cylinderGeometry, material);
  286. // scene.add(cylinder);
  287. }
  288. function makeInstance() {
  289. // let geometry = new THREE.BoxGeometry(10, 10, 10);
  290. // //加载环境720贴图
  291. // var loader1 = new THREE.TextureLoader();
  292. // var texture1 = loader1.load(that.bgUrl, () => {
  293. // let cubeRenderTarget = new THREE.WebGLCubeRenderTarget(texture1.image.height);
  294. // cubeRenderTarget.fromEquirectangularTexture(renderer, texture1);
  295. // // scene.background = cubeRenderTarget.texture;
  296. // // 创建一个立方体贴图相机
  297. // cubeCamera = new THREE.CubeCamera(1, 1000, cubeRenderTarget);
  298. // // 创建材质并应用纹理
  299. // let material = new THREE.MeshBasicMaterial({ envMap: cubeRenderTarget.texture,side:THREE.BackSide });
  300. // // const material = new THREE.MeshPhongMaterial({color});
  301. // let cube = new THREE.Mesh(geometry, material);
  302. // cube.position.set(0,0,0);
  303. // scene.add(cube);
  304. // });
  305. // 创建一个立方体贴图加载器
  306. var loader = new THREE.CubeTextureLoader();
  307. // 加载Equirectangular map
  308. loader.load([
  309. 'https://dm.static.elab-plus.com/miniProgram/pos-x.jpg',
  310. 'https://dm.static.elab-plus.com/miniProgram/neg-x.jpg',
  311. 'https://dm.static.elab-plus.com/miniProgram/pos-y.jpg',
  312. 'https://dm.static.elab-plus.com/miniProgram/neg-y.jpg',
  313. 'https://dm.static.elab-plus.com/miniProgram/pos-z.jpg',
  314. 'https://dm.static.elab-plus.com/miniProgram/neg-z.jpg',
  315. ], function(texture) {
  316. // 将Equirectangular map 应用到天空盒的材质上
  317. //创建一个球体几何体
  318. var sphereGeometry = new THREE.SphereGeometry(10, 60, 40);
  319. const materials = new THREE.MeshStandardMaterial({
  320. metalness:0.8, // 金属材质
  321. roughness:0.1, // 粗糙度
  322. envMap:texture, // 环境贴图
  323. side: THREE.BackSide
  324. })
  325. const sphere = new THREE.Mesh(sphereGeometry,materials)
  326. scene.add(sphere)
  327. });
  328. }
  329. function moreTest() {
  330. let data = [{
  331. videoUrl: 'https://dm.static.elab-plus.com/miniProgram/002.mp4',
  332. coordinate: '{"x":6,"y":-5,"z":0}',
  333. muted: true,
  334. },
  335. {
  336. videoUrl: 'https://dm.static.elab-plus.com/miniProgram/004.mp4',
  337. coordinate: '{"x":-13,"y":16,"z":8}',
  338. muted: false,
  339. },
  340. {
  341. videoUrl: 'https://dm.static.elab-plus.com/miniProgram/005.mp4',
  342. coordinate: '{"x":13,"y":-14,"z":-35}',
  343. muted: true,
  344. },
  345. {
  346. videoUrl: 'https://dm.static.elab-plus.com/miniProgram/007.mp4',
  347. coordinate: '{"x":0,"y":4,"z":25}',
  348. muted: true,
  349. },
  350. {
  351. videoUrl: 'https://dm.static.elab-plus.com/miniProgram/008.mov',
  352. coordinate: '{"x":3,"y":-4,"z":-5}',
  353. muted: true,
  354. }
  355. ]
  356. data.forEach(it => {
  357. videoHandle(it);
  358. })
  359. }
  360. function videoHandle(item) {
  361. if (!item.videoUrl) {
  362. return false;
  363. }
  364. // 创建视频元素
  365. var video = document.createElement('video');
  366. video.src = item.videoUrl; // 视频文件的路径
  367. video.setAttribute("crossOrigin", "Anonymous");
  368. video.loop = true;
  369. video.muted = item.muted;
  370. video.controls = false;
  371. video.autoplay = true;
  372. video.preload = 'auto';
  373. video.setAttribute('webkit-playsinline', true);
  374. video.setAttribute('playsinline', true);
  375. video.load();
  376. console.warn("***video***", video, video.width);
  377. setTimeout(() => {
  378. video.play();
  379. // 创建视频纹理
  380. var videoTexture = new THREE.VideoTexture(video);
  381. // videoTexture.minFilter = THREE.LinearFilter;
  382. // videoTexture.format = THREE.RGBFormat;
  383. var keyColorObject = new THREE.Color("#00ff05");
  384. var myuniforms = {
  385. pointTexture: {
  386. type: "t",
  387. value: videoTexture
  388. },
  389. color: {
  390. type: "c",
  391. value: keyColorObject
  392. },
  393. videowidth: {
  394. type: "f",
  395. value: 501.0
  396. },
  397. videoheight: {
  398. type: "f",
  399. value: 1024.0
  400. },
  401. filterType: {
  402. type: "i",
  403. value: 0
  404. },
  405. lightLevel: {
  406. type: "f",
  407. value: 0.2
  408. },
  409. gridSize: {
  410. type: "f",
  411. value: 0.8
  412. }
  413. };
  414. // 创建绿幕着色器
  415. let greenScreenShader = {
  416. uniforms: myuniforms,
  417. transparent: true,
  418. vertexShader: `
  419. varying vec2 vUv;
  420. void main() {
  421. vUv = uv;
  422. vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
  423. gl_Position = projectionMatrix * mvPosition;
  424. } `,
  425. fragmentShader: `
  426. precision mediump float;
  427. uniform sampler2D pointTexture;
  428. uniform sampler2D colorlut;
  429. uniform vec3 color;
  430. uniform float videowidth;
  431. uniform float videoheight;
  432. uniform int filterType;
  433. uniform float gridSize;
  434. uniform float lightLevel;
  435. varying vec2 vUv;
  436. float alter=3.0;
  437. float u_mode=0.0;
  438. float u_threshold=1.0;
  439. float u_clipBlack=0.9;
  440. float u_clipWhite=1.0;
  441. float rgb2cb(float r, float g, float b){
  442. return 0.5 + -0.168736*r - 0.331264*g + 0.5*b;
  443. }
  444. float rgb2cr(float r, float g, float b){
  445. return 0.5 + 0.5*r - 0.418688*g - 0.081312*b;
  446. }
  447. float smoothclip(float low, float high, float x){
  448. if (x <= low){
  449. return 0.0;
  450. }
  451. if(x >= high){
  452. return 1.0;
  453. }
  454. return (x-low)/(high-low);
  455. }
  456. vec4 greenscreen(vec4 colora, float Cb_key,float Cr_key, float tola,float tolb, float clipBlack, float clipWhite){
  457. float cb = rgb2cb(colora.r,colora.g,colora.b);
  458. float cr = rgb2cr(colora.r,colora.g,colora.b);
  459. float alpha = distance(vec2(cb, cr), vec2(Cb_key, Cr_key));
  460. alpha = smoothclip(tola, tolb, alpha);
  461. float r = max(gl_FragColor.r - (1.0-alpha)*color.r, 0.0);
  462. float g = max(gl_FragColor.g - (1.0-alpha)*color.g, 0.0);
  463. float b = max(gl_FragColor.b - (1.0-alpha)*color.b, 0.0);
  464. if(alpha < clipBlack){
  465. alpha = r = g = b = 0.0;
  466. }
  467. if(alpha > clipWhite){
  468. alpha = 1.0;
  469. }
  470. if(clipWhite < 1.0){
  471. alpha = alpha/max(clipWhite, 0.9);
  472. }
  473. return vec4(r,g,b, alpha);
  474. }
  475. void main()
  476. {
  477. gl_FragColor = texture2D( pointTexture, vUv );
  478. float tola = 0.0;
  479. float tolb = u_threshold/2.0;
  480. float cb_key = rgb2cb(color.r, color.g, color.b);
  481. float cr_key = rgb2cr(color.r, color.g, color.b);
  482. gl_FragColor = greenscreen(gl_FragColor, cb_key, cr_key, tola, tolb, u_clipBlack, u_clipWhite);
  483. if(u_mode > 0.5 && u_mode < 1.5){
  484. gl_FragColor = mix(vec4(1.0, 1.0, 1.0, 1.0), gl_FragColor, gl_FragColor.a);
  485. gl_FragColor.a = 1.0;
  486. }
  487. if(u_mode > 1.5 && u_mode < 2.5){
  488. gl_FragColor = vec4(gl_FragColor.a, gl_FragColor.a, gl_FragColor.a, 1.0);
  489. }
  490. if(filterType==1){
  491. float gray = 0.2989*gl_FragColor.r+0.5870*gl_FragColor.g+0.1140*gl_FragColor.b;
  492. gl_FragColor = vec4(gray,gray,gray , gl_FragColor.a);
  493. }else if(filterType==2){
  494. vec3 tColor2 = texture2D( pointTexture, vec2(vUv[0]+(1.0/videowidth) , vUv[1]) ).rgb;
  495. vec3 tColor3 = texture2D( pointTexture, vec2(vUv[0]-(1.0/videowidth) , vUv[1]) ).rgb;
  496. vec3 tColor4 = texture2D( pointTexture, vec2(vUv[0]+(1.0/videowidth) , vUv[1]+(1.0/videoheight)) ).rgb;
  497. vec3 tColor5 = texture2D( pointTexture, vec2(vUv[0]-(1.0/videowidth) , vUv[1]-(1.0/videoheight)) ).rgb;
  498. vec3 tColor6 = texture2D( pointTexture, vec2(vUv[0]+(1.0/videowidth) , vUv[1]-(1.0/videoheight)) ).rgb;
  499. vec3 tColor7 = texture2D( pointTexture, vec2(vUv[0]-(1.0/videowidth) , vUv[1]+(1.0/videoheight)) ).rgb;
  500. vec3 tColor8 = texture2D( pointTexture, vec2(vUv[0] , vUv[1]+(1.0/videoheight)) ).rgb;
  501. vec3 tColor9 = texture2D( pointTexture, vec2(vUv[0] , vUv[1]+(1.0/videoheight)) ).rgb;
  502. vec3 tColor10 = texture2D( pointTexture, vec2(vUv[0]+(2.0/videowidth) , vUv[1]) ).rgb;
  503. vec3 tColor11 = texture2D( pointTexture, vec2(vUv[0]+(2.0/videowidth) , vUv[1]) ).rgb;
  504. gl_FragColor = vec4( (gl_FragColor.r+tColor2[0]+tColor3[0]+tColor4[0]+tColor5[0]+tColor6[0]+tColor7[0]+tColor8[0]+tColor9[0]+tColor10[0]+tColor11[0])/11.0,
  505. (gl_FragColor.g+tColor2[1]+tColor3[1]+tColor4[1]+tColor5[1]+tColor6[1]+tColor7[1]+tColor8[1]+tColor9[1]+tColor10[1]+tColor11[1])/11.0,
  506. (gl_FragColor.b+tColor2[2]+tColor3[2]+tColor4[2]+tColor5[2]+tColor6[2]+tColor7[2]+tColor8[2]+tColor9[2]+tColor10[2]+tColor11[2])/11.0,
  507. gl_FragColor.a);
  508. }else if(filterType==3){
  509. float brightr=gl_FragColor.r+lightLevel;
  510. float brightg=gl_FragColor.g+lightLevel;
  511. float brightb=gl_FragColor.b+lightLevel;
  512. gl_FragColor = vec4(brightr,brightg,brightb , gl_FragColor.a);
  513. }else if(filterType==4){
  514. float reverser=1.0 - gl_FragColor.r;
  515. float reverseg=1.0 - gl_FragColor.g;
  516. float reverseb=1.0 - gl_FragColor.b;
  517. gl_FragColor = vec4(reverser,reverseg,reverseb,gl_FragColor.a);
  518. }else if(filterType==5){
  519. float dx = fract(sin(dot(vUv ,vec2(12.9898,78.233))) * 43758.5453);
  520. vec3 cResult = gl_FragColor.rgb + gl_FragColor.rgb * clamp( 0.1 + dx, 0.0, 1.0 );
  521. vec2 sc = vec2( sin( vUv.y * 4096.0 ), cos( vUv.y * 4096.0 ) );
  522. cResult += gl_FragColor.rgb * vec3( sc.x, sc.y, sc.x ) * 0.025;
  523. cResult = gl_FragColor.rgb + clamp( 0.35, 0.0,1.0 ) * ( cResult - gl_FragColor.rgb );
  524. if( false ) {
  525. cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );
  526. }
  527. float oldr=0.393*cResult[0]+0.769*cResult[1]+0.189*cResult[2];
  528. float oldg=0.349*cResult[0]+0.686*cResult[1]+0.168*cResult[2];
  529. float oldb=0.272*cResult[0]+0.534*cResult[1]+0.131*cResult[2];
  530. gl_FragColor = vec4( oldr,oldg,oldb , gl_FragColor.a);
  531. }else if(filterType==6){
  532. float average = ( gl_FragColor.r + gl_FragColor.g + gl_FragColor.b ) / 2.0;
  533. float s = sin( 0.5 ), c = cos( 0.5 );
  534. vec2 tex = vUv * vec2(videowidth,videoheight) - vec2(0,0);
  535. vec2 point = vec2( c * tex.x - s * tex.y, s * tex.x + c * tex.y ) * gridSize;
  536. float pattern = ( sin( point.x ) * sin( point.y ) ) * 4.0;
  537. float seed = average * 10.0 - 5.0 + pattern ;
  538. gl_FragColor = vec4( seed*0.3+gl_FragColor.r*0.7,seed*0.3+gl_FragColor.g*0.7 ,seed*0.3+gl_FragColor.b*0.7, gl_FragColor.a );
  539. }
  540. }
  541. `,
  542. };
  543. // 创建绿幕材质
  544. let greenScreenMaterial = new THREE.ShaderMaterial(greenScreenShader);
  545. greenScreenMaterial.side = THREE.DoubleSide;
  546. let geometry = new THREE.PlaneGeometry(9, 16);
  547. // 应用绿幕材质到对象上
  548. let mesh = new THREE.Mesh(geometry, greenScreenMaterial);
  549. if (item.coordinate) {
  550. let position = JSON.parse(item.coordinate);
  551. mesh.position.set(position.x, position.y, position.z); //设置视频位置
  552. } else {
  553. mesh.position.set(0, -10, -10); //设置视频位置
  554. }
  555. // mesh.lookAt(camera.position);
  556. scene.add(mesh);
  557. videoMeshGroup.push(mesh);
  558. // // 创建一个PlaneGeometry
  559. // var planeGeometry = new THREE.PlaneGeometry(9, 16);
  560. // // 创建一个边框材质
  561. // var edgeMaterial = new THREE.LineBasicMaterial({ color: 0xffffff});
  562. // // 创建边框几何体
  563. // var edges = new THREE.EdgesGeometry(planeGeometry);
  564. // let line = new THREE.LineSegments(edges, edgeMaterial);
  565. // line.position.set(0, -10, -10);//设置视频位置
  566. // scene.add(line);
  567. // lineMesh = line;
  568. }, 1000)
  569. // videoMesh = mesh;
  570. }
  571. function stopRender() {
  572. needRender = false;
  573. }
  574. function starRender() {
  575. if (needRender == true) { //如果已经在渲染中了,则不能再次开启,避免渲染过多
  576. false;
  577. }
  578. needRender = true;
  579. render(); //开始渲染
  580. }
  581. function render() {
  582. if (needRender == false) {
  583. return false;
  584. }
  585. // stats.update();
  586. controls.update();
  587. if (videoMeshGroup) {
  588. videoMeshGroup.forEach(it => {
  589. it.lookAt(camera.position)
  590. })
  591. // if(lineMesh){
  592. // lineMesh.lookAt(camera.position);
  593. // lineMesh.position.copy(videoMeshGroup[0].position);
  594. // }
  595. }
  596. if (cubeCamera) {
  597. cubeCamera.update(renderer, scene);
  598. }
  599. // if(scene.background){
  600. // scene.background.scale.set(0.5,0.5,0.5)
  601. // }
  602. renderer.render(scene, camera); //单次渲染
  603. requestId = requestAnimationFrame(render, canvas3d);
  604. }
  605. },
  606. methods: {
  607. navbarBackClk() {
  608. },
  609. clearHandle() {
  610. this.clearEvent();
  611. },
  612. }
  613. }
  614. </script>
  615. <style lang="scss" scoped>
  616. @import "./webgl_rxdz_720.scss";
  617. /* @import "@/common/css/common.css"; */
  618. </style>