manage.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. var g_ProjectName=window.location.pathname.substring(window.location.pathname.indexOf("/")+1,window.location.pathname.lastIndexOf("/"));
  2. var g_Prefix="https://super.4dage.com/";
  3. // var g_Prefix=window.location.href.substring(0,window.location.href.indexOf("/index.html")+1);
  4. var s = window.location.href.split('/');
  5. s.pop();
  6. //var g_Prefix = s.join('/');
  7. var g_index=null;
  8. var g_modeldata=null;
  9. var g_weixinTitle=null;
  10. var g_Hots=null;
  11. var g_HotMeshes=[];
  12. var g_HotMeshSize = {
  13. g_HotMeshWidth: 0.3,
  14. g_HotMeshHeight:0.3
  15. };
  16. //add表示添加,delete表示删除
  17. var g_HotStatus=null;
  18. var g_newHot = [];//存储新加热点
  19. var g_HotImage= {
  20. "point":"https://super.4dage.com/images/4dagePoint2.png",
  21. "point2":"https://super.4dage.com/images/4dagePoint.png"
  22. };
  23. var g_saveHot=false;
  24. var g_TextColor=0x7777ff;
  25. var g_Text=null;
  26. var g_TextPlaneMesh=[];
  27. var g_TextIconMesh=[];
  28. var g_TextIcon="./images/text.png";
  29. var g_SelectTextIndex=null;
  30. var g_TextShow=null;
  31. var g_audioPlay=false;
  32. var g_background=null;
  33. var g_roof=null;
  34. var g_data2 = null;//加载的data2.js的内容
  35. var g_bgAudio=null;//背景音乐
  36. var g_tourAudio=null;//导览音乐
  37. var g_play = 1;//表示播放图标状态
  38. var g_playAudio = null;//当前在播放或当继续播放时应该播放的,是g_bgAudio或g_tourAudio
  39. var g_currentHot = null;//当前打开的热点
  40. //var g_Texture=null;
  41. //var g_ChunknameTexture={}; //chunkname和贴图名称对应
  42. var g_NormalTexture=false;
  43. var g_SpecularTexture=false;
  44. var g_DirectionalLight=null;
  45. var g_snapShotWidth = 200; //截图下载图片的大小
  46. var g_snapShotHeight = 140;
  47. //微信分享
  48. var g_weixinObj = {
  49. "title": document.querySelector("head title").innerHTML,
  50. "lineLink" : window.location.href,
  51. "imgUrl" : "https://www.4dmodel.com/SuperPanoramic/images/weixintitle.jpg",
  52. "desc" : "四维时代提供技术支持",
  53. }
  54. var settings = {
  55. hotClickEvent:{
  56. video:{
  57. playAndPause:true,
  58. examine:false,
  59. openHot:false
  60. },
  61. photo:{
  62. examine:false,
  63. openHot:false
  64. },
  65. shine:{
  66. examine:true,
  67. openHot:true
  68. }
  69. },
  70. //默认的:
  71. teleportTime: 1500,//瞬间过渡的时间
  72. /* flytimeDistanceMultiplier:150,
  73. flyTime:750, */
  74. //dontExamHot:true
  75. transparentBg: false,
  76. bgImg: null
  77. }
  78. if(window.number == '725'||window.number == '724'){
  79. settings.mobileNavHigh = true
  80. }
  81. //--------------------------------------
  82. //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
  83. var Manage = function(){
  84. this.weixinURL = "https://res.wx.qq.com/open/js/jweixin-1.2.0.js",
  85. this.time = "?"+new Date().getTime();
  86. this.loadAudio();
  87. this.loadWeixin();
  88. }
  89. //动态加载js文件
  90. Manage.prototype.LoadJs = function(_files, succes){
  91. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  92. var classcodes = [];
  93. var FileArray = [];
  94. if (typeof _files === "object") {
  95. FileArray = _files;
  96. } else {
  97. /*如果文件列表是字符串,则用,切分成数组*/
  98. if (typeof _files === "string") {
  99. FileArray = _files.split(",");
  100. }
  101. }
  102. if (FileArray != null && FileArray.length > 0) {
  103. var LoadedCount = 0;
  104. for (var i = 0; i < FileArray.length; i++) {
  105. loadFile(FileArray[i], function() {
  106. LoadedCount++;
  107. if (LoadedCount == FileArray.length) {
  108. try {
  109. succes();
  110. }
  111. catch(err) {
  112. console.log("err: 您未定义回调");
  113. }
  114. }
  115. })
  116. }
  117. }
  118. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  119. function loadFile(url, success) {
  120. if (!FileIsExt(classcodes, url)) {
  121. var _ThisType = GetFileType(url);
  122. var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0,_ThisType.indexOf("?"));
  123. var fileObj = null;
  124. if (ThisType == ".js") {
  125. fileObj = document.createElement('script');
  126. fileObj.src = url;
  127. } else if (ThisType == ".css") {
  128. fileObj = document.createElement('link');
  129. fileObj.href = url;
  130. fileObj.type = "text/css";
  131. fileObj.rel = "stylesheet";
  132. } else if (ThisType == ".less") {
  133. fileObj = document.createElement('link');
  134. fileObj.href = url;
  135. fileObj.type = "text/css";
  136. fileObj.rel = "stylesheet/less";
  137. }
  138. success = success || function() {};
  139. fileObj.onload = fileObj.onreadystatechange = function() {
  140. if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
  141. success();
  142. classcodes.push(url)
  143. }
  144. }
  145. document.getElementsByTagName('head')[0].appendChild(fileObj);
  146. } else {
  147. success();
  148. }
  149. }
  150. /*获取文件类型,后缀名,小写*/
  151. function GetFileType(url) {
  152. if (url != null && url.length > 0) {
  153. return url.substr(url.lastIndexOf(".")).toLowerCase();
  154. }
  155. return "";
  156. }
  157. /*文件是否已加载*/
  158. function FileIsExt(FileArray, _url) {
  159. if (FileArray != null && FileArray.length > 0) {
  160. var len = FileArray.length;
  161. for (var i = 0; i < len; i++) {
  162. if (FileArray[i] == _url) {
  163. return true;
  164. }
  165. }
  166. }
  167. return false;
  168. }
  169. };
  170. //获取页面url后面的参数
  171. Manage.prototype.number = function(variable) {
  172. var query = window.location.search.substring(1);
  173. var vars = query.split("&");
  174. for (var i=0;i<vars.length;i++) {
  175. var pair = vars[i].split("=");
  176. if(pair[0] == variable){return pair[1];}
  177. }
  178. return(false);
  179. };
  180. Manage.prototype.loadWeixin = function() {
  181. var that = this;
  182. this.LoadJs(that.weixinURL+that.time,function(){ });
  183. }
  184. Manage.prototype.weixinShare = function() {
  185. console.log("weixinShare")
  186. $.ajax({
  187. url:'https://www.4dage.com/wechat/jssdk/',
  188. type: "post",
  189. data : {
  190. 'url' : location.href.split('#')[0]
  191. },
  192. dataType:"jsonp",
  193. jsonpCallback:"success_jsonp",
  194. success:function(data,textStatus){
  195. console.log("weixinShare success")
  196. console.log(data.appId)
  197. wx.config({
  198. // debug : true,
  199. appId : data.appId,
  200. timestamp : data.timestamp,
  201. nonceStr : data.nonceStr,
  202. signature : data.signature,
  203. jsApiList : [ 'checkJsApi', 'onMenuShareTimeline',
  204. 'onMenuShareAppMessage', 'onMenuShareQQ',
  205. 'onMenuShareWeibo', 'hideMenuItems',
  206. 'showMenuItems', 'hideAllNonBaseMenuItem',
  207. 'showAllNonBaseMenuItem', 'translateVoice',
  208. 'startRecord', 'stopRecord', 'onRecordEnd',
  209. 'playVoice', 'pauseVoice', 'stopVoice',
  210. 'uploadVoice', 'downloadVoice', 'chooseImage',
  211. 'previewImage', 'uploadImage', 'downloadImage',
  212. 'getNetworkType', 'openLocation', 'getLocation',
  213. 'hideOptionMenu', 'showOptionMenu', 'closeWindow',
  214. 'scanQRCode', 'chooseWXPay',
  215. 'openProductSpecificView', 'addCard', 'chooseCard',
  216. 'openCard' ]
  217. });
  218. },
  219. error:function(XMLHttpRequest,textStatus,errorThrown){
  220. console.log("jsonp.error:"+textStatus);
  221. }
  222. });
  223. var success_jsonp = function(json){
  224. console.log(json);
  225. };
  226. wx.ready(function(){
  227. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  228. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  229. //分享到朋友圈
  230. console.log(g_weixinObj)
  231. wx.onMenuShareTimeline({
  232. title: g_weixinObj.title, // 分享标题
  233. link: g_weixinObj.lineLink, // 分享链接
  234. imgUrl: g_weixinObj.imgUrl, // 分享图标
  235. desc: g_weixinObj.desc
  236. });
  237. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  238. wx.onMenuShareAppMessage({
  239. title: g_weixinObj.title, // 分享标题
  240. desc: g_weixinObj.desc, // 分享描述
  241. link: g_weixinObj.lineLink, // 分享链接
  242. imgUrl: g_weixinObj.imgUrl, // 分享图标
  243. type: '', // 分享类型,music、video或link,不填默认为link
  244. dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空
  245. });
  246. wx.onMenuShareWeibo({
  247. title: g_weixinObj.title, // 分享标题
  248. desc: g_weixinObj.desc, // 分享描述
  249. link: g_weixinObj.lineLink, // 分享链接
  250. imgUrl: g_weixinObj.imgUrl, // 分享图标
  251. success: function () {
  252. // 用户确认分享后执行的回调函数
  253. },
  254. cancel: function () {
  255. // 用户取消分享后执行的回调函数
  256. }
  257. });
  258. wx.onMenuShareQZone({
  259. title: g_weixinObj.title, // 分享标题
  260. desc: g_weixinObj.desc, // 分享描述
  261. link: g_weixinObj.lineLink, // 分享链接
  262. imgUrl: g_weixinObj.imgUrl, // 分享图标
  263. success: function () {
  264. // 用户确认分享后执行的回调函数
  265. },
  266. cancel: function () {
  267. // 用户取消分享后执行的回调函数
  268. }
  269. });
  270. wx.onMenuShareQQ({
  271. title: g_weixinObj.title, // 分享标题
  272. desc: g_weixinObj.desc, // 分享描述
  273. link: g_weixinObj.lineLink, // 分享链接
  274. imgUrl: g_weixinObj.imgUrl, // 分享图标
  275. success: function () {
  276. // 用户确认分享后执行的回调函数
  277. },
  278. cancel: function () {
  279. // 用户取消分享后执行的回调函数
  280. }
  281. });
  282. wx.error(function(res){
  283. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  284. });
  285. });
  286. }
  287. Manage.prototype.dealURL = function(src, type){
  288. //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
  289. //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
  290. if(window.isLocal && settings.localPrefix!=void 0){//本地将线上的前缀替换
  291. var oldPrefix = 'super.4dage.com/'; //最简单的地址写一个,如果有其他完全不一样的地址就用数组逐个判断
  292. var index = src.indexOf(oldPrefix);
  293. if(index>-1){
  294. var wholeOldPrefix = src.slice(0, index+oldPrefix.length);
  295. return src.replace(wholeOldPrefix, settings.localPrefix)
  296. }
  297. console.error("没有找到合适的本地链接")
  298. return src
  299. }else{
  300. //add https://
  301. var prefix = g_Prefix.replace('https://','').replace('http://','')
  302. if(!src.includes('http:/') && !src.includes('https:/') && src.includes(prefix)){
  303. src = 'https://'+src
  304. }
  305. return src
  306. }
  307. }
  308. Manage.prototype.removeSrcPostMark = function(url){//去除texture.load时自动加上的'?'
  309. var index = url.indexOf('?')
  310. if(index>-1){
  311. return url.slice(0, index)
  312. }else return url
  313. }
  314. Manage.prototype.showInfo = function (o) { // ({result:true, title:"发布成功"});
  315. var box = $(".resultBox");
  316. var title = o.title || o || i18n.get('保存成功');
  317. box.children().eq(0).html(title)
  318. //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000);
  319. var time = o.time || THREE.Math.clamp(title.length*130 ,1300, 5000);
  320. o.time || console.log("showtime " + time)
  321. //实际有一半的时间在渐变透明度
  322. this.showInfoTimer && clearTimeout(this.showInfoTimer)
  323. box.removeClass("animate");//如果之后不久又要showinfo一个的话,先停止前面的animate
  324. setTimeout(function () {
  325. box.css(
  326. {
  327. '-webkit-animation-duration': time + 'ms',
  328. 'animation-duration': time + 'ms'
  329. }
  330. )
  331. if(o.top){
  332. box.children().css('top', o.top + "%");
  333. }else{
  334. box.children().css('top', '' )
  335. }
  336. box.removeClass("hide");
  337. box.addClass("animate");
  338. if (o.dontInteract) {//遮挡对屏幕的操作
  339. box.css('pointer-events', 'auto')
  340. } else {
  341. box.css('pointer-events', 'none')
  342. }
  343. this.showInfoTimer = setTimeout(function () {
  344. box.removeClass("animate");
  345. box.addClass("hide");
  346. this.showInfoTimer = null;
  347. }.bind(this), time + 20)
  348. }.bind(this), 50)//这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧
  349. }//like: manage.showInfo({title:'a', top:20})
  350. //公用的函数
  351. function getQueryVariable(variable)
  352. {
  353. var query = window.location.search.substring(1);
  354. var vars = query.split("&");
  355. for (var i=0;i<vars.length;i++) {
  356. var pair = vars[i].split("=");
  357. if(pair[0] == variable){return pair[1];}
  358. }
  359. return(false);
  360. }
  361. //隐藏公司Logo
  362. function showLogo(){
  363. $("#myCompany").hide();
  364. $("#loaderCoBrandName").hide();
  365. $("#title-logo").hide();
  366. $(".title-container").css("justify-content","center")
  367. }
  368. //czj 添加随机的时间
  369. function randomTime(){
  370. return new Date()
  371. };
  372. function matcher(data){
  373. if(!data || !g_version ) return data;
  374. delete data.model.vision_version;
  375. var _data = {
  376. files: {
  377. "templates": ["images/images{{number}}/{{filename}}"]
  378. },
  379. model :{
  380. sid :window.number,
  381. camera_start:
  382. data.model.images && data.model.images.length != 0 ?
  383. {
  384. camera: {
  385. zoom: "-1",
  386. quaternion: [
  387. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  388. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  389. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  390. JSON.parse(data.model.images[0].metadata).camera_quaternion.y
  391. ]
  392. },
  393. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  394. mode: "0"
  395. }
  396. : ''
  397. },
  398. sid: window.number,
  399. hoticon: {
  400. default: "https://super.4dage.com/images/4dagePoint2.png",
  401. higt: "https://super.4dage.com/images/4dagePoint.png"
  402. },
  403. special: "false",
  404. weixinDesc: ""
  405. };
  406. $.extend(true,data,_data)
  407. return data;
  408. }
  409. function hotMatcher(data={}){
  410. //if(!data || !g_version) return data;
  411. if(g_version) {
  412. data.tourAudio = data.audio || {};
  413. }else{
  414. data.tourAudio = {}
  415. }
  416. return data;
  417. }
  418. var GifTexDeal = {
  419. animateObjects : [],
  420. animateTexs : [] ,
  421. addAnimation : function(texture, owner, info, id){
  422. /* if(this.animateObjects.find(e=>
  423. e.texture == texture && !ifSame(info, e.info)
  424. )) */
  425. var animation
  426. var tex = this.animateTexs.find(e=>e.texture == texture)
  427. if(tex){
  428. animation = tex
  429. }else{
  430. animation = {texture,info }
  431. this.animateTexs.push(animation)
  432. this.setRepeart(animation)
  433. }
  434. var object = {
  435. animation, //默认相同的texture对应的info是一样的, 对应一个animation
  436. owner,
  437. }
  438. this.animateObjects.push(object)
  439. return object
  440. },
  441. remove : function(object){
  442. var index = this.animateObjects.indexOf(object)
  443. if(index>-1){
  444. this.animateObjects.splice(index, 1)
  445. if(!this.animateObjects.find(e=>e.animation == object.animation)){
  446. let i = this.animateTexs.indexOf(object.animation)
  447. this.animateTexs.splice(i, 1)
  448. object.animation.texture.repeat.set(1,1)
  449. }
  450. this.stop(object)
  451. }
  452. },
  453. setRepeart : function(animation){
  454. animation.texture.repeat.set(1/animation.info.cellXcount, 1/animation.info.cellYcount)
  455. },
  456. start: function(object){
  457. if(!object || object.started )return;
  458. object.started = true
  459. if(object.animation.started)return;
  460. object.animation.started = true
  461. var info = object.animation.info
  462. var count = info.cellXcount * info.cellYcount - (info.voidCount || 0)
  463. if(count <= 1)return;
  464. transitions.start( (progress)=>{
  465. var index = Math.floor(count * progress);
  466. var indexX = index % info.cellXcount
  467. var indexY = info.cellYcount - Math.floor(index /info.cellXcount ) - 1; //uv.offset.y是从下到上的
  468. object.animation.texture.offset.x = indexX / info.cellXcount;
  469. object.animation.texture.offset.y = indexY / info.cellYcount;
  470. //console.log(object.id + " : "+ object.texture.offset.toArray())
  471. } , info.duration * (-1), null,/* ()=>{//done (-1):循环
  472. object.started = false
  473. object.texture.offset.x = 0;
  474. object.texture.offset.y = 0;
  475. this.start(object)
  476. }, */ 0 ,null, object.id, "gif_"+object.animation.texture.id);
  477. },
  478. stop: function(object){
  479. if(!object || !object.started)return;
  480. object.started = false
  481. //只有该object对应的texture对应的所有object都停止了,才能真的停止动画:
  482. if(this.animateObjects.find(e=>e.animation == object.animation && e.started)) return;
  483. transitions.cancelById("gif_"+object.animation.texture.id);
  484. object.animation.texture.offset.set(0,0)
  485. object.animation.started = false
  486. }
  487. }
  488. var CloneObject = function(copyObj, result, isSimpleCopy, extraReplace) {
  489. //isSimpleCopy只复制最外层
  490. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  491. if(!copyObj)return copyObj //0 null undefined ''
  492. result = result || {};
  493. if (copyObj instanceof Array) {
  494. /* if (copyObj[0]instanceof Object) {
  495. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  496. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  497. }
  498. return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object
  499. return copyObj.map(e=>{
  500. if(e instanceof Object){
  501. return CloneObject(e)
  502. }else return e
  503. })
  504. }else{
  505. if(copyObj.clone instanceof Function ){ //解决一部分
  506. return copyObj.clone()
  507. }
  508. }
  509. for (var key in copyObj) {
  510. if (copyObj[key] instanceof Object && !isSimpleCopy)
  511. result[key] = CloneObject(copyObj[key]);
  512. else
  513. result[key] = copyObj[key];
  514. //如果是函数类同基本数据,即复制引用
  515. }
  516. return result;
  517. }
  518. ;
  519. var ifSame = function(object1, object2){
  520. if(object1 == object2 )return true // 0 != undefined , 0 == ''
  521. else if(!object1 || !object2) return false
  522. else if(object1.constructor != object2.constructor){
  523. return false
  524. }else if(object1 instanceof Array ) {
  525. if(object1.length != object2.length)return false;
  526. var _object2 = object2.slice(0);
  527. for(let i=0;i<object1.length;i++){
  528. var u = _object2.find(e=>ifSame(object1[i], e));
  529. if(u == void 0 && !_object2.includes(u) && !object1.includes(u))return false;
  530. else{
  531. let index = _object2.indexOf(u);
  532. _object2.splice(index,1);
  533. }
  534. }
  535. return true
  536. }else if(object1.equals instanceof Function ){//复杂数据仅支持这种,其他的可能卡住?
  537. return object1.equals(object2)
  538. }else if(typeof object1 == 'number' || typeof object1 == 'string'){
  539. if(isNaN(object1) && isNaN(object2))return true
  540. else return object1 == object2
  541. }else if(typeof object1 == "object"){
  542. var keys1 = Object.keys(object1)
  543. var keys2 = Object.keys(object2)
  544. if(!ifSame(keys1,keys2))return false;
  545. for(let i in object1){
  546. var same = ifSame(object1[i], object2[i]);
  547. if(!same)return false
  548. }
  549. return true
  550. }else{
  551. console.log('isSame出现例外')
  552. }
  553. }
  554. /* var SoundManager = {//暂不支持同时播放
  555. currentAudio:null,//当前正在播放list中的哪一个
  556. list:[
  557. {
  558. name:"bg",
  559. level : 0,//越大优先级越高
  560. canBeInterrupted : true ,
  561. },
  562. {
  563. name:"boxVideo",
  564. level : 1,
  565. canBeInterrupted : true,
  566. checkIfNeedPlay:function(){
  567. }
  568. },
  569. {
  570. name:"hot",
  571. level : 2,
  572. canBeInterrupted : true
  573. },
  574. {
  575. name:"tour",
  576. level : 3,
  577. canBeInterrupted : true
  578. },
  579. ],
  580. switchPlay:function(){
  581. },
  582. register:function(){
  583. }
  584. }
  585. */
  586. //最好能知道应该播放到的currentTime
  587. var SoundManager = {//暂不支持同时播放
  588. currentAudio:null,//当前正在播放list中的哪一个
  589. enableSound:true,//是否允许有声音
  590. playHistory:[],//被打断的加入播放历史
  591. list:[ ],//同一级别可以互相打断 //暂时不做多级别
  592. play:function(name, src, currentTime){
  593. var object = this.list.find(e=>e.name == name)
  594. if(object){
  595. if(this.currentAudio){
  596. this.pause(this.currentAudio.name, false, true)
  597. }
  598. {//将当前要播放的播放历史中清除
  599. let index = this.playHistory.indexOf(object)
  600. if(index>-1)this.playHistory.splice(index,1);
  601. }
  602. this.currentAudio = object
  603. if(src){
  604. this.setSrc(name, src)
  605. }
  606. if(currentTime!=void 0){
  607. object.audio.currentTime = currentTime
  608. }
  609. if(object.audio){
  610. object.audio.load(); // iOS 9 还需要额外的 load 一下, 否则直接 play 无效 *///https://www.cnblogs.com/interdrp/p/4211883.html 部分资料
  611. object.audio.play();
  612. object.callback && object.callback(true)
  613. }
  614. Log(name + ' 播放 ' )
  615. }
  616. },
  617. pause:function(name, autoReplayLast, isInterrupt){//需要能自动恢复上一个被打算的音频。恢复前判断是否还需要播放
  618. var object = this.list.find(e=>e.name == name)
  619. if(object){
  620. this.currentAudio = null
  621. if(object.audio){
  622. object.audio.pause()
  623. object.callback && object.callback(false)
  624. Log(name + ' 中断音频 '+ "("+common.getFileNameFromUrl(object.audio.src)+')' )
  625. }
  626. if(isInterrupt){//一般主动调用不需要加这个
  627. this.playHistory.push(object)//如果是被中断的,加入播放历史,等待恢复播放
  628. }
  629. if(autoReplayLast){ //播放之前的音频。它们是被打断过的。
  630. while(this.playHistory.length){
  631. var last = this.playHistory.pop();
  632. if(last.src && last.canplay(last.audio)){
  633. this.play(last.name )
  634. }
  635. }
  636. }
  637. }
  638. },
  639. setSrc : function(name, src){//不能直接给audio赋src!一定要用这个函数!因为我要拿这里的src来判断有无src,因为貌似audio的src会自动变,''时会变成html的链接
  640. var object = this.list.find(e=>e.name == name)
  641. object.src = src
  642. object.audio.src = src
  643. Log(`${object.name} 设置src: ${src}`)
  644. },
  645. createAudio:function(object={}){//name, level, canplay
  646. if(!object.fake){
  647. object.audio = new Audio();
  648. object.audio.loop = !!object.loop;
  649. //object.audio.autoplay = true;
  650. object.audio.addEventListener('ended', ()=>{
  651. if(object.loop){//循环
  652. Log(`${object.name} 播放完毕,重新播放`)
  653. object.audio.play()
  654. }else{
  655. this.pause(object.name, true);//停止后的后续处理
  656. }
  657. });
  658. object.audio.oncanplaythrough = ()=>{
  659. Log(`${object.name} canplaythrough `)
  660. }
  661. }
  662. this.list.push(object)
  663. },
  664. initAutoPlay:function(){ //处理设备自动播放限制
  665. let play = function(){
  666. if(this.currentAudio && this.currentAudio.audio){
  667. this.currentAudio.audio.play()
  668. Log(`${this.currentAudio.name} 自动播放成功`) //即使设置src在这之后好像也能成功播放
  669. }else{
  670. }
  671. document.removeEventListener("touchstart",play);
  672. document.removeEventListener("click",play);
  673. $('#player')[0].removeEventListener("touchstart", play);
  674. }.bind(this);
  675. document.addEventListener("WeixinJSBridgeReady", play, false);
  676. document.addEventListener("touchstart", play);//ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
  677. document.addEventListener("click", play);
  678. $('#player')[0].addEventListener("touchstart", play);
  679. }
  680. }
  681. function Log(value, color, fontSize){
  682. color = color || '#13f'
  683. fontSize = fontSize || 14
  684. console.warn(`%c${value}`, `color:${color};font-size:${fontSize}px`)
  685. }
  686. Manage.prototype.loadAudio = function() { //相关:g_tourAudio \ g_playAudio
  687. //热点页面因为挡住了界面,所以暂时不存在别的音频阻止热点音频的可能
  688. //box视频都静音,所以暂时不考虑
  689. SoundManager.createAudio({
  690. name:'bgm',
  691. level:0,
  692. src:'',
  693. loop:true,
  694. canplay:(audio)=>{
  695. return this.bgmShouldPlay
  696. },
  697. callback:(state)=>{//play或pause时随之触发的函数(即使还没开始播放)
  698. if(state){
  699. $("#volume a img").attr("src", "./images/Volume btn_off.png")
  700. $("#volume").attr("title", "关闭声音");
  701. }else{
  702. $("#volume a img").attr("src", "./images/Volume btn_on.png")
  703. $("#volume").attr("title", "打开声音");
  704. }
  705. }
  706. })
  707. SoundManager.createAudio({
  708. name:'tour',
  709. level:0,
  710. src:'',
  711. loop:false,
  712. canplay:(audio)=>{
  713. return player.director && player.director.tourIsPlaying && player.director.getAudio()
  714. }
  715. })
  716. SoundManager.createAudio({
  717. name:'hot',
  718. fake:true,//实际上没有audio. 只是为了来停止和续播其他音频
  719. level:1,
  720. src:'',
  721. loop:false,
  722. canplay:(audio)=>{
  723. }
  724. })
  725. $("#volume").find("a").on("click", ()=> {
  726. if($("#volume img")[0].src.indexOf("btn_on.png")>-1)
  727. {
  728. this.switchBgmState(true);
  729. }
  730. else if($("#volume img")[0].src.indexOf("btn_off.png")>-1)
  731. {
  732. this.switchBgmState(false);
  733. }
  734. })
  735. this.switchBgmState(true);//初始设置允许播放bgm
  736. SoundManager.initAutoPlay()
  737. }
  738. Manage.prototype.switchBgmState = function(state){//按钮的状态完全代表是否应该播放bgm,即使还没加载完
  739. this.bgmShouldPlay = state
  740. if(state){
  741. SoundManager.play('bgm')
  742. }else{
  743. SoundManager.pause('bgm')
  744. }
  745. /* if(!g_bgAudio || !g_bgAudio.src) return;
  746. var played = function(){
  747. console.log('begin play bgm');
  748. g_play = 1;
  749. g_playAudio = g_bgAudio;
  750. g_tourAudio && g_tourAudio.pause()
  751. }
  752. var paused = function(){
  753. g_play = 0;
  754. g_playAudio == g_bgAudio && (g_playAudio = null)
  755. }
  756. if(state ){
  757. g_bgAudio.play();
  758. if(g_bgAudio.paused){
  759. paused()
  760. }else{
  761. played()
  762. return true
  763. }
  764. }else{
  765. g_bgAudio.pause();
  766. paused()
  767. }
  768. g_bgAudio.pauseByHot = false
  769. g_bgAudio.pauseByTour = false */
  770. }
  771. var manage = new Manage();
  772. //兼容一代的場景
  773. //請求地址統一管理
  774. var g_onePregix = "https://bigscene.4dage.com/" //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
  775. var g_version = manage.number("version");
  776. g_version === "one" ? g_Prefix = g_onePregix : '';