webgl_rxdz_720.vue 20 KB

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