manage.js 18 KB

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