var g_ProjectName=window.location.pathname.substring(window.location.pathname.indexOf("/")+1,window.location.pathname.lastIndexOf("/")); var g_Prefix="https://super.4dage.com/"; // var g_Prefix=window.location.href.substring(0,window.location.href.indexOf("/index.html")+1); var s = window.location.href.split('/'); s.pop(); //var g_Prefix = s.join('/'); var g_index=null; var g_modeldata=null; var g_weixinTitle=null; var g_Hots=null; var g_HotMeshes=[]; var g_HotMeshSize = { g_HotMeshWidth: 0.3, g_HotMeshHeight:0.3 }; //add表示添加,delete表示删除 var g_HotStatus=null; var g_newHot = [];//存储新加热点 var g_HotImage= { "point":"https://super.4dage.com/images/4dagePoint2.png", "point2":"https://super.4dage.com/images/4dagePoint.png" }; var g_saveHot=false; var g_TextColor=0x7777ff; var g_Text=null; var g_TextPlaneMesh=[]; var g_TextIconMesh=[]; var g_TextIcon="./images/text.png"; var g_SelectTextIndex=null; var g_TextShow=null; var g_audioPlay=false; var g_background=null; var g_roof=null; var g_data2 = null;//加载的data2.js的内容 var g_bgAudio=null;//背景音乐 var g_tourAudio=null;//导览音乐 var g_play = 1;//表示播放图标状态 var g_playAudio = null;//当前在播放或当继续播放时应该播放的,是g_bgAudio或g_tourAudio var g_currentHot = null;//当前打开的热点 //var g_Texture=null; //var g_ChunknameTexture={}; //chunkname和贴图名称对应 var g_NormalTexture=false; var g_SpecularTexture=false; var g_DirectionalLight=null; var g_snapShotWidth = 200; //截图下载图片的大小 var g_snapShotHeight = 140; //微信分享 var g_weixinObj = { "title": document.querySelector("head title").innerHTML, "lineLink" : window.location.href, "imgUrl" : "https://www.4dmodel.com/SuperPanoramic/images/weixintitle.jpg", "desc" : "四维时代提供技术支持", } var settings = { hotClickEvent:{ video:{ playAndPause:true, examine:false, openHot:false }, photo:{ examine:false, openHot:false }, shine:{ examine:true, openHot:true } }, //默认的: teleportTime: 1500,//瞬间过渡的时间 /* flytimeDistanceMultiplier:150, flyTime:750, */ //dontExamHot:true transparentBg: false, bgImg: null } if(window.number == '725'||window.number == '724'){ settings.mobileNavHigh = true } //-------------------------------------- //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main var Manage = function(){ this.weixinURL = "https://res.wx.qq.com/open/js/jweixin-1.2.0.js", this.time = "?"+new Date().getTime(); this.loadAudio(); this.loadWeixin(); } //动态加载js文件 Manage.prototype.LoadJs = function(_files, succes){ /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/ var classcodes = []; var FileArray = []; if (typeof _files === "object") { FileArray = _files; } else { /*如果文件列表是字符串,则用,切分成数组*/ if (typeof _files === "string") { FileArray = _files.split(","); } } if (FileArray != null && FileArray.length > 0) { var LoadedCount = 0; for (var i = 0; i < FileArray.length; i++) { loadFile(FileArray[i], function() { LoadedCount++; if (LoadedCount == FileArray.length) { try { succes(); } catch(err) { console.log("err: 您未定义回调"); } } }) } } /*加载JS文件,url:文件路径,success:加载成功回调函数*/ function loadFile(url, success) { if (!FileIsExt(classcodes, url)) { var _ThisType = GetFileType(url); var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0,_ThisType.indexOf("?")); var fileObj = null; if (ThisType == ".js") { fileObj = document.createElement('script'); fileObj.src = url; } else if (ThisType == ".css") { fileObj = document.createElement('link'); fileObj.href = url; fileObj.type = "text/css"; fileObj.rel = "stylesheet"; } else if (ThisType == ".less") { fileObj = document.createElement('link'); fileObj.href = url; fileObj.type = "text/css"; fileObj.rel = "stylesheet/less"; } success = success || function() {}; fileObj.onload = fileObj.onreadystatechange = function() { if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) { success(); classcodes.push(url) } } document.getElementsByTagName('head')[0].appendChild(fileObj); } else { success(); } } /*获取文件类型,后缀名,小写*/ function GetFileType(url) { if (url != null && url.length > 0) { return url.substr(url.lastIndexOf(".")).toLowerCase(); } return ""; } /*文件是否已加载*/ function FileIsExt(FileArray, _url) { if (FileArray != null && FileArray.length > 0) { var len = FileArray.length; for (var i = 0; i < len; i++) { if (FileArray[i] == _url) { return true; } } } return false; } }; //获取页面url后面的参数 Manage.prototype.number = function(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i-1){ var wholeOldPrefix = src.slice(0, index+oldPrefix.length); return src.replace(wholeOldPrefix, settings.localPrefix) } console.error("没有找到合适的本地链接") return src }else{ //add https:// var prefix = g_Prefix.replace('https://','').replace('http://','') if(!src.includes('http:/') && !src.includes('https:/') && src.includes(prefix)){ src = 'https://'+src } return src } } Manage.prototype.removeSrcPostMark = function(url){//去除texture.load时自动加上的'?' var index = url.indexOf('?') if(index>-1){ return url.slice(0, index) }else return url } Manage.prototype.showInfo = function (o) { // ({result:true, title:"发布成功"}); var box = $(".resultBox"); var title = o.title || o || i18n.get('保存成功'); box.children().eq(0).html(title) //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000); var time = o.time || THREE.Math.clamp(title.length*130 ,1300, 5000); o.time || console.log("showtime " + time) //实际有一半的时间在渐变透明度 this.showInfoTimer && clearTimeout(this.showInfoTimer) box.removeClass("animate");//如果之后不久又要showinfo一个的话,先停止前面的animate setTimeout(function () { box.css( { '-webkit-animation-duration': time + 'ms', 'animation-duration': time + 'ms' } ) if(o.top){ box.children().css('top', o.top + "%"); }else{ box.children().css('top', '' ) } box.removeClass("hide"); box.addClass("animate"); if (o.dontInteract) {//遮挡对屏幕的操作 box.css('pointer-events', 'auto') } else { box.css('pointer-events', 'none') } this.showInfoTimer = setTimeout(function () { box.removeClass("animate"); box.addClass("hide"); this.showInfoTimer = null; }.bind(this), time + 20) }.bind(this), 50)//这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧 }//like: manage.showInfo({title:'a', top:20}) //公用的函数 function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i e.texture == texture && !ifSame(info, e.info) )) */ var animation var tex = this.animateTexs.find(e=>e.texture == texture) if(tex){ animation = tex }else{ animation = {texture,info } this.animateTexs.push(animation) this.setRepeart(animation) } var object = { animation, //默认相同的texture对应的info是一样的, 对应一个animation owner, } this.animateObjects.push(object) return object }, remove : function(object){ var index = this.animateObjects.indexOf(object) if(index>-1){ this.animateObjects.splice(index, 1) if(!this.animateObjects.find(e=>e.animation == object.animation)){ let i = this.animateTexs.indexOf(object.animation) this.animateTexs.splice(i, 1) object.animation.texture.repeat.set(1,1) } this.stop(object) } }, setRepeart : function(animation){ animation.texture.repeat.set(1/animation.info.cellXcount, 1/animation.info.cellYcount) }, start: function(object){ if(!object || object.started )return; object.started = true if(object.animation.started)return; object.animation.started = true var info = object.animation.info var count = info.cellXcount * info.cellYcount - (info.voidCount || 0) if(count <= 1)return; transitions.start( (progress)=>{ var index = Math.floor(count * progress); var indexX = index % info.cellXcount var indexY = info.cellYcount - Math.floor(index /info.cellXcount ) - 1; //uv.offset.y是从下到上的 object.animation.texture.offset.x = indexX / info.cellXcount; object.animation.texture.offset.y = indexY / info.cellYcount; //console.log(object.id + " : "+ object.texture.offset.toArray()) } , info.duration * (-1), null,/* ()=>{//done (-1):循环 object.started = false object.texture.offset.x = 0; object.texture.offset.y = 0; this.start(object) }, */ 0 ,null, object.id, "gif_"+object.animation.texture.id); }, stop: function(object){ if(!object || !object.started)return; object.started = false //只有该object对应的texture对应的所有object都停止了,才能真的停止动画: if(this.animateObjects.find(e=>e.animation == object.animation && e.started)) return; transitions.cancelById("gif_"+object.animation.texture.id); object.animation.texture.offset.set(0,0) object.animation.started = false } } var CloneObject = function(copyObj, result, isSimpleCopy, extraReplace) { //isSimpleCopy只复制最外层 //复制json result的可能:普通数字或字符串、普通数组、复杂对象 if(!copyObj)return copyObj //0 null undefined '' result = result || {}; if (copyObj instanceof Array) { /* if (copyObj[0]instanceof Object) { //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持 console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...") } return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object return copyObj.map(e=>{ if(e instanceof Object){ return CloneObject(e) }else return e }) }else{ if(copyObj.clone instanceof Function ){ //解决一部分 return copyObj.clone() } } for (var key in copyObj) { if (copyObj[key] instanceof Object && !isSimpleCopy) result[key] = CloneObject(copyObj[key]); else result[key] = copyObj[key]; //如果是函数类同基本数据,即复制引用 } return result; } ; var ifSame = function(object1, object2){ if(object1 == object2 )return true // 0 != undefined , 0 == '' else if(!object1 || !object2) return false else if(object1.constructor != object2.constructor){ return false }else if(object1 instanceof Array ) { if(object1.length != object2.length)return false; var _object2 = object2.slice(0); for(let i=0;iifSame(object1[i], e)); if(u == void 0 && !_object2.includes(u) && !object1.includes(u))return false; else{ let index = _object2.indexOf(u); _object2.splice(index,1); } } return true }else if(object1.equals instanceof Function ){//复杂数据仅支持这种,其他的可能卡住? return object1.equals(object2) }else if(typeof object1 == 'number' || typeof object1 == 'string'){ if(isNaN(object1) && isNaN(object2))return true else return object1 == object2 }else if(typeof object1 == "object"){ var keys1 = Object.keys(object1) var keys2 = Object.keys(object2) if(!ifSame(keys1,keys2))return false; for(let i in object1){ var same = ifSame(object1[i], object2[i]); if(!same)return false } return true }else{ console.log('isSame出现例外') } } /* var SoundManager = {//暂不支持同时播放 currentAudio:null,//当前正在播放list中的哪一个 list:[ { name:"bg", level : 0,//越大优先级越高 canBeInterrupted : true , }, { name:"boxVideo", level : 1, canBeInterrupted : true, checkIfNeedPlay:function(){ } }, { name:"hot", level : 2, canBeInterrupted : true }, { name:"tour", level : 3, canBeInterrupted : true }, ], switchPlay:function(){ }, register:function(){ } } */ //最好能知道应该播放到的currentTime var SoundManager = {//暂不支持同时播放 currentAudio:null,//当前正在播放list中的哪一个 enableSound:true,//是否允许有声音 playHistory:[],//被打断的加入播放历史 list:[ ],//同一级别可以互相打断 //暂时不做多级别 play:function(name, src, currentTime){ var object = this.list.find(e=>e.name == name) if(object){ if(this.currentAudio){ this.pause(this.currentAudio.name, false, true) } {//将当前要播放的播放历史中清除 let index = this.playHistory.indexOf(object) if(index>-1)this.playHistory.splice(index,1); } this.currentAudio = object if(src){ this.setSrc(name, src) } if(currentTime!=void 0){ object.audio.currentTime = currentTime } if(object.audio){ object.audio.load(); // iOS 9 还需要额外的 load 一下, 否则直接 play 无效 *///https://www.cnblogs.com/interdrp/p/4211883.html 部分资料 object.audio.play(); object.callback && object.callback(true) } Log(name + ' 播放 ' ) } }, pause:function(name, autoReplayLast, isInterrupt){//需要能自动恢复上一个被打算的音频。恢复前判断是否还需要播放 var object = this.list.find(e=>e.name == name) if(object){ this.currentAudio = null if(object.audio){ object.audio.pause() object.callback && object.callback(false) Log(name + ' 中断音频 '+ "("+common.getFileNameFromUrl(object.audio.src)+')' ) } if(isInterrupt){//一般主动调用不需要加这个 this.playHistory.push(object)//如果是被中断的,加入播放历史,等待恢复播放 } if(autoReplayLast){ //播放之前的音频。它们是被打断过的。 while(this.playHistory.length){ var last = this.playHistory.pop(); if(last.src && last.canplay(last.audio)){ this.play(last.name ) } } } } }, setSrc : function(name, src){//不能直接给audio赋src!一定要用这个函数!因为我要拿这里的src来判断有无src,因为貌似audio的src会自动变,''时会变成html的链接 var object = this.list.find(e=>e.name == name) object.src = src object.audio.src = src Log(`${object.name} 设置src: ${src}`) }, createAudio:function(object={}){//name, level, canplay if(!object.fake){ object.audio = new Audio(); object.audio.loop = !!object.loop; //object.audio.autoplay = true; object.audio.addEventListener('ended', ()=>{ if(object.loop){//循环 Log(`${object.name} 播放完毕,重新播放`) object.audio.play() }else{ this.pause(object.name, true);//停止后的后续处理 } }); object.audio.oncanplaythrough = ()=>{ Log(`${object.name} canplaythrough `) } } this.list.push(object) }, initAutoPlay:function(){ //处理设备自动播放限制 let play = function(){ if(this.currentAudio && this.currentAudio.audio){ this.currentAudio.audio.play() Log(`${this.currentAudio.name} 自动播放成功`) //即使设置src在这之后好像也能成功播放 }else{ } document.removeEventListener("touchstart",play); document.removeEventListener("click",play); $('#player')[0].removeEventListener("touchstart", play); }.bind(this); document.addEventListener("WeixinJSBridgeReady", play, false); document.addEventListener("touchstart", play);//ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件 document.addEventListener("click", play); $('#player')[0].addEventListener("touchstart", play); } } function Log(value, color, fontSize){ color = color || '#13f' fontSize = fontSize || 14 console.warn(`%c${value}`, `color:${color};font-size:${fontSize}px`) } Manage.prototype.loadAudio = function() { //相关:g_tourAudio \ g_playAudio //热点页面因为挡住了界面,所以暂时不存在别的音频阻止热点音频的可能 //box视频都静音,所以暂时不考虑 SoundManager.createAudio({ name:'bgm', level:0, src:'', loop:true, canplay:(audio)=>{ return this.bgmShouldPlay }, callback:(state)=>{//play或pause时随之触发的函数(即使还没开始播放) if(state){ $("#volume a img").attr("src", "./images/Volume btn_off.png") $("#volume").attr("title", "关闭声音"); }else{ $("#volume a img").attr("src", "./images/Volume btn_on.png") $("#volume").attr("title", "打开声音"); } } }) SoundManager.createAudio({ name:'tour', level:0, src:'', loop:false, canplay:(audio)=>{ return player.director && player.director.tourIsPlaying && player.director.getAudio() } }) SoundManager.createAudio({ name:'hot', fake:true,//实际上没有audio. 只是为了来停止和续播其他音频 level:1, src:'', loop:false, canplay:(audio)=>{ } }) $("#volume").find("a").on("click", ()=> { if($("#volume img")[0].src.indexOf("btn_on.png")>-1) { this.switchBgmState(true); } else if($("#volume img")[0].src.indexOf("btn_off.png")>-1) { this.switchBgmState(false); } }) this.switchBgmState(true);//初始设置允许播放bgm SoundManager.initAutoPlay() } Manage.prototype.switchBgmState = function(state){//按钮的状态完全代表是否应该播放bgm,即使还没加载完 this.bgmShouldPlay = state if(state){ SoundManager.play('bgm') }else{ SoundManager.pause('bgm') } /* if(!g_bgAudio || !g_bgAudio.src) return; var played = function(){ console.log('begin play bgm'); g_play = 1; g_playAudio = g_bgAudio; g_tourAudio && g_tourAudio.pause() } var paused = function(){ g_play = 0; g_playAudio == g_bgAudio && (g_playAudio = null) } if(state ){ g_bgAudio.play(); if(g_bgAudio.paused){ paused() }else{ played() return true } }else{ g_bgAudio.pause(); paused() } g_bgAudio.pauseByHot = false g_bgAudio.pauseByTour = false */ } var manage = new Manage(); //兼容一代的場景 //請求地址統一管理 var g_onePregix = "https://bigscene.4dage.com/" //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55 var g_version = manage.number("version"); g_version === "one" ? g_Prefix = g_onePregix : '';