manage.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
  2. var Manage = function(){
  3. this.weixinURL = "https://res.wx.qq.com/open/js/jweixin-1.2.0.js",
  4. this.time = "?"+new Date().getTime();
  5. this.loadAudio();
  6. //this.musicShouldPlay = true //一开始默认打开
  7. this.switchMusicState(true)//一开始默认打开
  8. }
  9. //动态加载js文件
  10. Manage.prototype.LoadJs = function(_files, succes){
  11. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  12. var classcodes = [];
  13. var FileArray = [];
  14. if (typeof _files === "object") {
  15. FileArray = _files;
  16. } else {
  17. /*如果文件列表是字符串,则用,切分成数组*/
  18. if (typeof _files === "string") {
  19. FileArray = _files.split(",");
  20. }
  21. }
  22. if (FileArray != null && FileArray.length > 0) {
  23. var LoadedCount = 0;
  24. for (var i = 0; i < FileArray.length; i++) {
  25. loadFile(FileArray[i], function() {
  26. LoadedCount++;
  27. if (LoadedCount == FileArray.length) {
  28. try {
  29. succes();
  30. }
  31. catch(err) {
  32. console.log("err: 您未定义回调");
  33. }
  34. }
  35. })
  36. }
  37. }
  38. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  39. function loadFile(url, success) {
  40. if (!FileIsExt(classcodes, url)) {
  41. var _ThisType = GetFileType(url);
  42. var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0,_ThisType.indexOf("?"));
  43. var fileObj = null;
  44. if (ThisType == ".js") {
  45. fileObj = document.createElement('script');
  46. fileObj.src = url;
  47. } else if (ThisType == ".css") {
  48. fileObj = document.createElement('link');
  49. fileObj.href = url;
  50. fileObj.type = "text/css";
  51. fileObj.rel = "stylesheet";
  52. } else if (ThisType == ".less") {
  53. fileObj = document.createElement('link');
  54. fileObj.href = url;
  55. fileObj.type = "text/css";
  56. fileObj.rel = "stylesheet/less";
  57. }
  58. success = success || function() {};
  59. fileObj.onload = fileObj.onreadystatechange = function() {
  60. if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
  61. success();
  62. classcodes.push(url)
  63. }
  64. }
  65. document.getElementsByTagName('head')[0].appendChild(fileObj);
  66. } else {
  67. success();
  68. }
  69. }
  70. /*获取文件类型,后缀名,小写*/
  71. function GetFileType(url) {
  72. if (url != null && url.length > 0) {
  73. return url.substr(url.lastIndexOf(".")).toLowerCase();
  74. }
  75. return "";
  76. }
  77. /*文件是否已加载*/
  78. function FileIsExt(FileArray, _url) {
  79. if (FileArray != null && FileArray.length > 0) {
  80. var len = FileArray.length;
  81. for (var i = 0; i < len; i++) {
  82. if (FileArray[i] == _url) {
  83. return true;
  84. }
  85. }
  86. }
  87. return false;
  88. }
  89. };
  90. //获取页面url后面的参数
  91. Manage.prototype.number = function(variable) {
  92. var query = window.location.search.substring(1);
  93. var vars = query.split("&");
  94. for (var i=0;i<vars.length;i++) {
  95. var pair = vars[i].split("=");
  96. if(pair[0] == variable){return pair[1];}
  97. }
  98. return(false);
  99. };
  100. Manage.prototype.loadWeixin = function() {
  101. var that = this;
  102. this.LoadJs(that.weixinURL+that.time,function(){ });
  103. }
  104. Manage.prototype.loadAudio = function() { //相关:g_tourAudio \ g_playAudio
  105. g_bgAudio = new Audio;
  106. //g_bgAudio.loop = true;
  107. g_bgAudio.autoplay = true;
  108. g_bgAudio.id = "bgaudio";
  109. //https://www.cnblogs.com/interdrp/p/4211883.html 部分资料
  110. g_bgAudio.load(); // iOS 9 还需要额外的 load 一下, 否则直接 play 无效
  111. var play = function(){
  112. //if(window.tourAudioSta) return;
  113. this.musicShouldPlay && !g_tourAudio.shouldPlay && this.switchBgmState(true)
  114. document.removeEventListener("touchstart",play);
  115. document.removeEventListener("click",play);
  116. $('#player')[0].removeEventListener("touchstart", play);
  117. }.bind(this);
  118. g_bgAudio.oncanplay = ()=>{
  119. this.musicShouldPlay && !g_tourAudio.shouldPlay && this.switchBgmState(true)
  120. }
  121. document.addEventListener("WeixinJSBridgeReady", ()=> {
  122. this.musicShouldPlay && !g_tourAudio.shouldPlay && this.switchBgmState(true)
  123. }, false);
  124. document.addEventListener("touchstart", play);//ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
  125. document.addEventListener("click", play);
  126. $('#player')[0].addEventListener("touchstart", play);
  127. g_bgAudio.addEventListener('ended', ()=>{
  128. //间隔5s
  129. setTimeout(()=>{
  130. this.musicShouldPlay && !g_tourAudio.shouldPlay && this.switchBgmState(true)
  131. },5000)
  132. });
  133. $("#volume").find("a").on("click", ()=> {
  134. if($("#volume img")[0].src.indexOf("btn_on.png")>-1)
  135. {
  136. this.switchMusicState(true);
  137. }
  138. else if($("#volume img")[0].src.indexOf("btn_off.png")>-1)
  139. {
  140. this.switchMusicState(false);
  141. }
  142. })
  143. }
  144. Manage.prototype.ifTourCanPlay = function(){//只有导览在播放时才能继续播放导览音频,如果是点击导览片段飞过去,一旦停止就不会再播
  145. return player.director && player.director.tourIsPlaying && player.director.getAudio()
  146. }
  147. Manage.prototype.switchMusicState = function(state){ //按钮按钮掌管全局音频,导览优先,没有了才放bgm
  148. this.musicShouldPlay = state
  149. if(state){
  150. if(! (this.ifTourCanPlay() && player.director.playAudio())){
  151. this.switchBgmState(true)
  152. }else{
  153. //this.currentPlay = 'tour'
  154. }
  155. $("#volume a img").attr("src", "./images/Volume btn_off.png")
  156. $("#volume").attr("title", "关闭声音");
  157. }else{
  158. g_tourAudio.pause()
  159. this.switchBgmState(false)
  160. $("#volume a img").attr("src", "./images/Volume btn_on.png")
  161. $("#volume").attr("title", "打开声音");
  162. }
  163. }
  164. Manage.prototype.switchBgmState = function(state){
  165. if(!this.musicShouldPlay)return
  166. if(!g_bgAudio || !g_bgAudio.src) return;
  167. //this.currentPlay = 'bgm'
  168. var played = function(){
  169. console.log('begin play bgm '+ g_bgAudio.src);
  170. g_play = 1;
  171. g_playAudio = g_bgAudio;
  172. g_tourAudio && g_tourAudio.pause()
  173. //SoundOnVideo && switchSoundBtn(SoundOnVideo)
  174. }
  175. var paused = function(){
  176. g_play = 0;
  177. g_playAudio == g_bgAudio && (g_playAudio = null)
  178. }
  179. if(state ){
  180. g_bgAudio.play();
  181. if(g_bgAudio.paused){
  182. paused()
  183. }else{
  184. played()
  185. return true
  186. }
  187. }else{
  188. g_bgAudio.pause();
  189. paused()
  190. }
  191. g_bgAudio.pauseByHot = false
  192. g_bgAudio.pauseByTour = false
  193. g_bgAudio.pauseByVideo = false
  194. }
  195. Manage.prototype.weixinShare = function() {
  196. console.log("weixinShare")
  197. $.ajax({
  198. url:'https://www.4dage.com/wechat/jssdk/',
  199. type: "post",
  200. data : {
  201. 'url' : location.href.split('#')[0]
  202. },
  203. dataType:"jsonp",
  204. jsonpCallback:"success_jsonp",
  205. success:function(data,textStatus){
  206. console.log("weixinShare success")
  207. console.log(data.appId)
  208. wx.config({
  209. // debug : true,
  210. appId : data.appId,
  211. timestamp : data.timestamp,
  212. nonceStr : data.nonceStr,
  213. signature : data.signature,
  214. jsApiList : [ 'checkJsApi', 'onMenuShareTimeline',
  215. 'onMenuShareAppMessage', 'onMenuShareQQ',
  216. 'onMenuShareWeibo', 'hideMenuItems',
  217. 'showMenuItems', 'hideAllNonBaseMenuItem',
  218. 'showAllNonBaseMenuItem', 'translateVoice',
  219. 'startRecord', 'stopRecord', 'onRecordEnd',
  220. 'playVoice', 'pauseVoice', 'stopVoice',
  221. 'uploadVoice', 'downloadVoice', 'chooseImage',
  222. 'previewImage', 'uploadImage', 'downloadImage',
  223. 'getNetworkType', 'openLocation', 'getLocation',
  224. 'hideOptionMenu', 'showOptionMenu', 'closeWindow',
  225. 'scanQRCode', 'chooseWXPay',
  226. 'openProductSpecificView', 'addCard', 'chooseCard',
  227. 'openCard' ]
  228. });
  229. },
  230. error:function(XMLHttpRequest,textStatus,errorThrown){
  231. console.log("jsonp.error:"+textStatus);
  232. }
  233. });
  234. var success_jsonp = function(json){
  235. console.log(json);
  236. };
  237. wx.ready(function(){
  238. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  239. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  240. //分享到朋友圈
  241. console.log(g_weixinObj)
  242. wx.onMenuShareTimeline({
  243. title: g_weixinObj.title, // 分享标题
  244. link: g_weixinObj.lineLink, // 分享链接
  245. imgUrl: g_weixinObj.imgUrl, // 分享图标
  246. desc: g_weixinObj.desc
  247. });
  248. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  249. wx.onMenuShareAppMessage({
  250. title: g_weixinObj.title, // 分享标题
  251. desc: g_weixinObj.desc, // 分享描述
  252. link: g_weixinObj.lineLink, // 分享链接
  253. imgUrl: g_weixinObj.imgUrl, // 分享图标
  254. type: '', // 分享类型,music、video或link,不填默认为link
  255. dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空
  256. });
  257. wx.onMenuShareWeibo({
  258. title: g_weixinObj.title, // 分享标题
  259. desc: g_weixinObj.desc, // 分享描述
  260. link: g_weixinObj.lineLink, // 分享链接
  261. imgUrl: g_weixinObj.imgUrl, // 分享图标
  262. success: function () {
  263. // 用户确认分享后执行的回调函数
  264. },
  265. cancel: function () {
  266. // 用户取消分享后执行的回调函数
  267. }
  268. });
  269. wx.onMenuShareQZone({
  270. title: g_weixinObj.title, // 分享标题
  271. desc: g_weixinObj.desc, // 分享描述
  272. link: g_weixinObj.lineLink, // 分享链接
  273. imgUrl: g_weixinObj.imgUrl, // 分享图标
  274. success: function () {
  275. // 用户确认分享后执行的回调函数
  276. },
  277. cancel: function () {
  278. // 用户取消分享后执行的回调函数
  279. }
  280. });
  281. wx.onMenuShareQQ({
  282. title: g_weixinObj.title, // 分享标题
  283. desc: g_weixinObj.desc, // 分享描述
  284. link: g_weixinObj.lineLink, // 分享链接
  285. imgUrl: g_weixinObj.imgUrl, // 分享图标
  286. success: function () {
  287. // 用户确认分享后执行的回调函数
  288. },
  289. cancel: function () {
  290. // 用户取消分享后执行的回调函数
  291. }
  292. });
  293. wx.error(function(res){
  294. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  295. });
  296. });
  297. }
  298. Manage.prototype.dealURL = function(src, type){
  299. //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
  300. //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
  301. if(window.isLocal && settings.localPrefix!=void 0){//本地将线上的前缀替换
  302. var oldPrefixs = ["https://super.4dage.com/", "http://super.4dage.com/", "///super.4dage.com/"]
  303. for(let i=0;i<oldPrefixs.length;i++){
  304. if(src.includes(oldPrefixs[i])){
  305. return src.replace(oldPrefixs[i], settings.localPrefix)
  306. break;
  307. }
  308. }
  309. console.error("没有找到合适的本地链接")
  310. return src
  311. }else{
  312. return src
  313. }
  314. }
  315. var manage = new Manage();
  316. //公用的函数
  317. function getQueryVariable(variable)
  318. {
  319. var query = window.location.search.substring(1);
  320. var vars = query.split("&");
  321. for (var i=0;i<vars.length;i++) {
  322. var pair = vars[i].split("=");
  323. if(pair[0] == variable){return pair[1];}
  324. }
  325. return(false);
  326. }
  327. //隐藏公司Logo
  328. function showLogo(){
  329. $("#myCompany").hide();
  330. $("#loaderCoBrandName").hide();
  331. $("#title-logo").hide();
  332. $(".title-container").css("justify-content","center")
  333. }
  334. //czj 添加随机的时间
  335. function randomTime(){
  336. return new Date()
  337. };
  338. function matcher(data){
  339. if(!data || !g_version ) return data;
  340. delete data.model.vision_version;
  341. var _data = {
  342. files: {
  343. "templates": ["images/images{{number}}/{{filename}}"]
  344. },
  345. model :{
  346. sid :window.number,
  347. camera_start:
  348. data.model.images && data.model.images.length != 0 ?
  349. {
  350. camera: {
  351. zoom: "-1",
  352. quaternion: [
  353. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  354. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  355. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  356. JSON.parse(data.model.images[0].metadata).camera_quaternion.y
  357. ]
  358. },
  359. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  360. mode: "0"
  361. }
  362. : ''
  363. },
  364. sid: window.number,
  365. hoticon: {
  366. default: "https://super.4dage.com/images/4dagePoint2.png",
  367. higt: "https://super.4dage.com/images/4dagePoint.png"
  368. },
  369. special: "false",
  370. weixinDesc: ""
  371. };
  372. $.extend(true,data,_data)
  373. return data;
  374. }
  375. function hotMatcher(data){
  376. if(!data || !g_version) return data;
  377. data.tourAudio = data.audio;
  378. return data;
  379. }
  380. var GifTexDeal = {
  381. animateObjects : [],
  382. addAnimation : function(texture, owner, info, id){
  383. var object = {
  384. texture,
  385. owner,
  386. info,
  387. id
  388. }
  389. this.setRepeart(object)
  390. this.animateObjects.push(object)
  391. return object
  392. },
  393. remove : function(object){
  394. var index = this.animateObjects.indexOf(object)
  395. if(index>-1){
  396. this.stop(object)
  397. object.texture.repeat.set(1,1)
  398. this.animateObjects.splice(index, 1)
  399. }
  400. },
  401. setRepeart : function(object){
  402. object.texture.repeat.set(1/object.info.cellXcount, 1/object.info.cellYcount)
  403. },
  404. start: function(object){
  405. /* var b = this
  406. , offset = this.cursor.material.map.offset
  407. , f = function(a) {
  408. return Math.floor(17 * a) / 17 //对应17个精灵图片段
  409. };
  410. b.canStartAnimation = !1,
  411. this.cursorAnimate = new TWEEN.Tween(offset).to({
  412. x: 1 //100%
  413. }, 1e3).onStart(function() {
  414. b.canStartAnimation = !1
  415. }).onStop(function() {
  416. b.canStartAnimation = !0,
  417. this.x = 0,
  418. offset.x = 0
  419. }).onUpdate(function() {}).onComplete(function() {
  420. done(),
  421. offset.x = 0,
  422. setTimeout(function() {
  423. b.canStartAnimation = !0
  424. }, 1500)
  425. }),
  426. this.cursorAnimate.easing(f),
  427. this.cursorAnimate.start()
  428. */
  429. if(!object || object.started)return;
  430. var count = object.info.cellXcount * object.info.cellYcount
  431. if(count == 1 )return;
  432. transitions.start( (progress)=>{
  433. var index = Math.floor(count * progress);
  434. var indexX = index % object.info.cellXcount
  435. var indexY = object.info.cellYcount - Math.floor(index / object.info.cellXcount ) - 1; //uv.offset.y是从下到上的
  436. object.texture.offset.x = indexX / object.info.cellXcount;
  437. object.texture.offset.y = indexY / object.info.cellYcount;
  438. //console.log(object.id + " : "+ object.texture.offset.toArray())
  439. } , object.info.duration, ()=>{//done
  440. object.started = false
  441. object.texture.offset.x = 0;
  442. object.texture.offset.y = 0;
  443. this.start(object)
  444. }, 0 ,null, object.id, "gif_"+object.id);
  445. object.started = true
  446. },
  447. startAnimations : function(o={}){
  448. this.animateObjects.forEach(e=>{this.start(e)})
  449. }
  450. ,
  451. stop: function(object){
  452. if(!object || !object.started)return;
  453. transitions.cancelById("gif_"+object.id);
  454. object.texture.offset.set(0,0)
  455. object.started = false
  456. }
  457. }
  458. var CloneObject = function(copyObj, result, isSimpleCopy) {
  459. //isSimpleCopy只复制最外层
  460. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  461. if(!copyObj)return null
  462. result = result || {};
  463. if (copyObj instanceof Array) {
  464. if (copyObj[0]instanceof Object) {
  465. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  466. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  467. }
  468. return copyObj.slice(0);
  469. //如果是数组,直接复制返回(排除数组内是object
  470. }
  471. for (var key in copyObj) {
  472. if (copyObj[key]instanceof Object && !isSimpleCopy)
  473. result[key] = CloneObject(copyObj[key]);
  474. else
  475. result[key] = copyObj[key];
  476. //如果是函数类同基本数据,即复制引用
  477. }
  478. return result;
  479. }
  480. ;
  481. //兼容一代的場景
  482. //請求地址統一管理
  483. var g_onePregix = "https://bigscene.4dage.com/" //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
  484. var g_version = manage.number("version");
  485. g_version === "one" ? g_Prefix = g_onePregix : '';