manage.js 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289
  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. window.browser = { //提前定义
  55. isMobile: function() {
  56. var e = navigator.userAgent || navigator.vendor || window.opera;
  57. return /(android|bb\d+|meego).+mobile|android|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(e) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(e.substr(0, 4))
  58. },
  59. isFullscreen: function() {
  60. return document.fullscreenElement || document.mozFullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement
  61. },
  62. valueFromHash: function(e, t) {
  63. var i = new RegExp("[#&?]" + e + "=([^#&?]*)")
  64. , n = i.exec(window.location.href);
  65. if (!n)
  66. return t;
  67. var r = n[1];
  68. return "boolean" == typeof t ? "true" === r || "1" === r : "number" == typeof t ? parseFloat(r) : window.decodeURIComponent(r)
  69. },
  70. urlHasValue: function(key, isGetValue) {
  71. let querys = window.location.search.substr(1).split("&")
  72. if (isGetValue) {
  73. for (let i = 0; i < querys.length; i++) {
  74. let keypair = querys[i].split("=")
  75. if (keypair.length === 2 && keypair[0] === key) {
  76. return keypair[1]
  77. }
  78. }
  79. return ""
  80. } else {
  81. for (let i = 0; i < querys.length; i++) {
  82. let keypair = querys[i].split("=")
  83. if (keypair[0] == key) {
  84. return true
  85. }
  86. }
  87. return false
  88. }
  89. },
  90. }
  91. var settings = {
  92. hotClickEvent:{
  93. video:{
  94. playAndPause:true,
  95. examine:false,
  96. openHot:false
  97. },
  98. photo:{
  99. examine:false,
  100. openHot:false
  101. },
  102. shine:{
  103. examine:true,
  104. openHot:true
  105. }
  106. },
  107. hotClickActions:['playAndPause','examine','openHot','fastTran'],
  108. //默认的:
  109. teleportTime: 1500,//瞬间过渡的时间
  110. /* flytimeDistanceMultiplier:150,
  111. flyTime:750, */
  112. tourRotTime:2, //默认停留2秒
  113. //dontExamHot:true,
  114. hotFastTran:false,
  115. transparentBg: false,
  116. bgImg: null,
  117. tileClass:{//默认全景贴图加载的清晰度
  118. pc:{
  119. nav: '2k',
  120. max: '4k',
  121. },
  122. bigMobile:{ //width和height都超过一定值
  123. nav: browser.urlHasValue('padNav',true) || '2k',
  124. max: browser.urlHasValue('padMax',true) || '4k',//'2k',
  125. },
  126. mobile:{
  127. nav: browser.urlHasValue('phoneNav',true) || '1k', //不放大时
  128. max: browser.urlHasValue('phoneMax',true) || '4k', //放到最大
  129. }
  130. }, //可以稍后自行修改
  131. }
  132. if(window.number == '725'||window.number == '724'){
  133. //settings.mobileNavHigh = true
  134. settings.tileClass.mobile = {nav:'2k', max: '2k'}
  135. }
  136. //共用函数:
  137. window.common = null;
  138. window.MathLight = null;
  139. window.math = null
  140. window.easing = null
  141. window.lerp = null
  142. window.transitions = null
  143. function watch(object, propName, initialValue){ //监听某个属性的变化
  144. let v = initialValue
  145. Object.defineProperty(object, propName, {
  146. get: function() {
  147. return v
  148. },
  149. set: function(e) {
  150. console.log('watch:',propName, e)
  151. v = e
  152. }
  153. })
  154. }
  155. var toPrecision = function(e, t) {
  156. function i(e, t) {
  157. var i = Math.pow(10, t);
  158. return Math.round(e * i) / i
  159. }
  160. if (e instanceof Array) {
  161. for (var n = 0; n < e.length; n++)
  162. e[n] = i(e[n], t);
  163. return e
  164. }
  165. return i(e, t)
  166. }
  167. var dealMap = (map, o={} )=>{
  168. //使不resize when image is not power of two ,但缩小时会有锯齿
  169. if(!o.ignoreResize){
  170. if(!map.image || !THREE.Math.isPowerOfTwo(map.image.width ) || !THREE.Math.isPowerOfTwo(map.image.height )){
  171. map.wrapS = map.wrapT = THREE.ClampToEdgeWrapping;
  172. map.minFilter = THREE.LinearFilter;
  173. //map.generateMipmaps = true;
  174. }
  175. }
  176. if(!browser.isMobile()) map.anisotropy = 3
  177. }
  178. var dom = {
  179. getOffset: function(type, element, parent) {
  180. left = (type == "left") ? element.offsetLeft : element.offsetTop;
  181. if (!parent) parent = $("body")[0];
  182. while (element = element.offsetParent) {
  183. if (element == parent) break;
  184. left += (type == "left") ? element.offsetLeft : element.offsetTop;
  185. }
  186. return left;
  187. }
  188. };
  189. var getTransformSid = function(){
  190. var name
  191. if(player.mode == 'panorama'){
  192. name = player.currentPano ? player.currentPano.id : 'outside'
  193. }else{
  194. name = 'outside'
  195. }
  196. return name
  197. }
  198. var LineDraw = {
  199. /* createLine: function(posArr, o) {
  200. var e = new THREE.BufferGeometry
  201. , p = new Float32Array(6);
  202. e.addAttribute("position", new THREE.BufferAttribute(p,3));
  203. //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
  204. var p = e.attributes.position.array;
  205. for (var i = 0; i < 2; i++) {
  206. p[i * 3] = posArr[i].x;
  207. p[i * 3 + 1] = posArr[i].y;
  208. p[i * 3 + 2] = posArr[i].z;
  209. }
  210. var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
  211. linewidth: o.width || 1,
  212. //windows无效。 似乎mac/ios上粗细有效 ?
  213. color: o.color || defaultColor,
  214. transparent: o.dontAlwaysSeen ? false : true,
  215. depthTest: o.dontAlwaysSeen ? true : false
  216. })
  217. var line = new THREE.Line(e,mat);
  218. line.renderOrder = o.renderOrder || 4
  219. //同tagStem; //如果不加高,可能会部分被model遮住
  220. return line;
  221. } */
  222. createLine: function (posArr, o={}) {
  223. //多段普通线 (第二个点和第三个点之间是没有线段的, 所以不用在意线段顺序)
  224. var mat
  225. if(o.mat){
  226. mat = o.mat
  227. }else{
  228. let prop = {
  229. color: o.color || defaultColor,
  230. transparent: o.dontAlwaysSeen ? false : true,
  231. depthTest: o.dontAlwaysSeen ? true : false,
  232. opacity: o.opacity != void 0 ? o.opacity : 1,
  233. }
  234. if(o.deshed ){
  235. prop.dashSize = o.dashSize || 0.1,
  236. prop.gapSize = o.gapSize || 0.1
  237. }
  238. mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"](prop)
  239. }
  240. var line = new THREE.LineSegments(new THREE.BufferGeometry, mat);
  241. line.renderOrder = o.renderOrder || 4
  242. this.moveLine(line, posArr)
  243. return line;
  244. },
  245. moveLine: function (line, posArr) {
  246. if(posArr.length == 0)return
  247. let position = new Float32Array(posArr.length * 3); //[]
  248. for (var i = 0; i < 2; i++) {
  249. position[i * 3] = posArr[i].x;
  250. position[i * 3 + 1] = posArr[i].y;
  251. position[i * 3 + 2] = posArr[i].z;
  252. }
  253. line.geometry.addAttribute("position", new THREE.BufferAttribute(position,3));
  254. //line.geometry.setAttribute('position', new THREE.Float32BufferAttribute(new Float32Array(position), 3));
  255. line.geometry.attributes.position.needsUpdate = true;
  256. line.geometry.computeBoundingSphere();
  257. /* if(line.material instanceof THREE.LineDashedMaterial){
  258. line.computeLineDistances() //只有非buffer的geometry才有
  259. } */
  260. }
  261. ,
  262. }
  263. var convertTool = {
  264. getPos2d : function(point, camera, dom){//获取一个三维坐标对应屏幕中的二维坐标
  265. var camera = camera || player.camera;
  266. var dom = dom || player.domElement;
  267. if(!camera)return
  268. var pos = point.clone().project(camera) //比之前hotspot的计算方式写得简单 project用于3转2(求法同shader); unproject用于2转3 :new r.Vector3(e.x, e.y, -1).unproject(this.camera);
  269. var x,y;
  270. x = (pos.x + 1) / 2 * dom.clientWidth;
  271. y = (1 - (pos.y + 1) / 2) * dom.clientHeight;
  272. var inSight = x <= dom.clientWidth && x >= 0 //是否在屏幕中
  273. && y <= dom.clientHeight && y >= 0
  274. return {
  275. pos: new THREE.Vector2(x,y), // 屏幕像素坐标
  276. vector: pos, //(范围 -1 ~ 1)
  277. trueSide : pos.z<1, //trueSide为false时,即使在屏幕范围内可见,也是反方向的另一个不可以被渲染的点 参见Tag.update
  278. inSight : inSight //在屏幕范围内可见
  279. };
  280. },
  281. ifShelter: function (pos3d, pos2d, camera, floorIndex) {
  282. //检测某点在视线中是否被mesh遮挡
  283. if (!pos2d) pos2d = convertTool.getPos2d(pos3d )
  284. camera = camera || player.camera
  285. var ori = new THREE.Vector3(pos2d.x, pos2d.y, -1).unproject(camera) //找到视线原点
  286. var dir = pos3d.clone().sub(ori).normalize()
  287. var ray = new THREE.Raycaster(ori, dir); //由外向里 因为模型从内侧是可见的所以从外侧
  288. /* if(config.isEdit && publicObjectSet.editor.mainDesign.editing){
  289. var o = ray.intersectObjects(publicObjectSet.editor.mainDesign.wallMeshes);
  290. }else{ */
  291. let colliders = player.model.allFloorsVisible ? player.model.colliders : (floorIndex != void 0 ? player.model.floors.index[floorIndex] : player.model.currentFloor).collider.children
  292. //let colliders = (floorIndex == void 0 ) ? player.model.colliders : player.model.floors.index[floorIndex].collider.children
  293. var o = ray.intersectObjects(colliders);
  294. //}
  295. var len = pos3d.distanceTo(ori);
  296. if (o && o.length) {
  297. for(var i=0;i<o.length;i++){
  298. if(o[i].distance < len){ return true; }//有遮挡
  299. }
  300. }
  301. },
  302. /*
  303. 拖拽时,获取鼠标在拖拽面上的位置(需要借助另一个intersectPlane面来计算,即和相机方向一样的面,可保证铺满屏幕)
  304. 但是不一定能获取到,比如鼠标射线不朝向拖拽面时,即使获取也会是一个意外的反方向的交点。
  305. */
  306. getPosAtPlane : function(pos, info/* , mouse, camera */){ //pos:与intersectPlane的交点 见笔记
  307. var A = pos;
  308. var player = player;
  309. var mouse = player.mouse;
  310. var O = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(player.camera);
  311. if(info.y != void 0){//地面线的
  312. var y = info.y;
  313. if(player.mode == "floorplan"/* || Math.abs(O.x-pos.x)<0.0001 && Math.abs(O.z-pos.z)<0.0001) */){
  314. //intersectPlane和地面平行,无交点
  315. var x = pos.x, z = pos.z;
  316. }else{
  317. if(y<player.camera.position.y && O.y <= A.y /* || y>player.camera.position.y && O.y >= A.y */)return null; //鼠标射线向上。因为相机一定位于地面以上(地面不会抬高到相机上吧?),所以无交点。
  318. if(O.y == A.y){console.log('一样??');return;}
  319. if(A.y == y){console.log('一样2??');return;}
  320. var r = (O.y-y)/(A.y-y);
  321. var x = (r*A.x-O.x)/(r-1);
  322. var z = (r*A.z-O.z)/(r-1);
  323. }
  324. }else{//垂直的也有越过消失点以后反向变化的情况,但使用时影响不大
  325. var N = info.normalVec;
  326. var P = info.pullPos;
  327. if(N.y != 0 ){console.log('N.y != 0');return;} //仅仅支持垂直于地面的的墙壁,目前都是
  328. if(O.z==A.z){console.log('O.z==A.z?');return;}
  329. if(N.z!=0 && N.x != 0){//直接用这个通用的也可以,支持斜线的墙
  330. //console.log('N.z==0 && N.x == 0?');
  331. var c = ( N.x*(A.x-O.x) + N.y*(A.y-O.y) + N.z*(A.z-O.z));
  332. if(c == 0){console.log("分母为0?? return;");return;}
  333. var t = -((N.x*O.x + N.y*O.y + N.z*O.z) - (P.x*N.x + P.y*N.y + P.z*N.z) ) / c
  334. var x = t * (A.x - O.x) + O.x;
  335. var y = t * (A.y - O.y) + O.y;
  336. var z = t * (A.z - O.z) + O.z;
  337. /*原理: 已知空间直线L:(x-a)/m=(x-b)/n=(z-c)/p和空间平面π:Ax+By+Cz+D=0;
  338. 求直线L与平面π的交点的坐标。
  339. 把直线方程改写成参数形式:设(x-a)/m=(x-b)/n=(z-c)/p=t;
  340. 则x=mt+a;y=nt+b;z=pt+c;代入平面π的方程得:
  341. A(mt+a)+B(nt+b)+C(pt+c)+D=0
  342. 由此解得t=-(Aa+Bb+Cc+D)/(Am+Bn+Cp)
  343. 再代入参数方程即得交点的坐标(x,y,z). */
  344. }else if(N.x ==0 ){ //z与pullPos相等
  345. var z = P.z;
  346. if(O.y == A.y){console.log('一样??');return;}
  347. if(A.y == y){console.log('一样2??');return;}
  348. if(A.z == z){console.log('一样3??');return;}
  349. var r = (O.z-z)/(A.z-z);
  350. var x = (r*A.x-O.x)/(r-1);
  351. var y = (r*A.y-O.y)/(r-1);
  352. }else if(N.z == 0){//x与pullPos相等
  353. var x = P.x;
  354. if(O.y == A.y){console.log('一样??');return;}
  355. if(A.y == y){console.log('一样2??');return;}
  356. if(A.x == x){console.log('一样3??');return;}
  357. var r = (O.x-x)/(A.x-x);
  358. var y = (r*A.y-O.y)/(r-1);
  359. var z = (r*A.z-O.z)/(r-1);
  360. }
  361. }
  362. return new THREE.Vector3(x,y,z);
  363. },
  364. getMouseIntersect : function(camera, meshes, mouse){//获取鼠标和meshes交点
  365. var raycaster = new THREE.Raycaster;
  366. camera.updateMatrixWorld();
  367. var origin = new THREE.Vector3(mouse.x,mouse.y,-1).unproject(camera)
  368. , end = new THREE.Vector3(mouse.x,mouse.y,1).unproject(camera);
  369. var dir = end.sub(origin).normalize()
  370. raycaster.set(origin, dir);
  371. var n = raycaster.intersectObjects(meshes);
  372. if (0 === n.length)
  373. return null;
  374. return n[0];
  375. },
  376. ifIntersectChunks : function(A,B,options={}){//获取某个线段/射线和meshes的交点
  377. var dir = B.clone().sub(A).normalize();
  378. var len = options.InfinityLen ? Infinity : A.distanceTo(B) + (options.extLen||0);
  379. var ray = new THREE.Raycaster(A.clone(), dir, 0, len);
  380. var o = ray.intersectObjects(options.model || player.model.colliders);
  381. if (o && o.length)return o;
  382. if(options.throughWidth){ //允许最小宽度,防止穿过极小的缝隙导致撞墙感
  383. var normal = math.getNormal({points:[{x:A.x, y:A.z},{x:B.x, y:B.z}]});//线段法线
  384. normal.multiplyScalar(options.throughWidth)
  385. var normalVec3 = new THREE.Vector3(normal.x, 0, normal.y);
  386. var A2 = A.clone().add(normalVec3)
  387. ray.set(A2, dir);
  388. var o2 = ray.intersectObjects(options.model || player.model.colliders);
  389. ray.set(A.clone().add(normalVec3.negate()), dir);
  390. if (o2 && o2.length)return o2;
  391. var o3 = ray.intersectObjects(options.model || player.model.colliders);
  392. if (o3 && o3.length)return o3;
  393. }
  394. return null;
  395. },
  396. getPosAtSphere : function(pos3d, toPanoPos){
  397. var dir = pos3d.clone().sub(toPanoPos);
  398. dir.normalize();//然后计算在球中
  399. dir.multiplyScalar(Constants.skyRadius);
  400. dir.add(toPanoPos);
  401. return dir;
  402. } ,
  403. getScaleForConstantSize : function(op={}){ //获得规定二维大小的mesh的scale值。可以避免因camera的projection造成的mesh视觉大小改变。 来源:tag.updateDisc
  404. var w;
  405. var i = new THREE.Vector3, o = new THREE.Vector3, l = new THREE.Vector3, c = new THREE.Vector3, h = new THREE.Vector3
  406. if(!op.resolution){
  407. let renderSize = player.sceneRenderer.renderer.getSize()
  408. op.resolution = {x:renderSize.width, y:renderSize.height}
  409. }
  410. if(!op.camera){
  411. let camera = player.cameraControls.activeControl ? player.cameraControls.activeControl.camera : player.camera
  412. let camera2 = camera.clone();
  413. camera2.matrixWorld.copy(player.camera.matrixWorld) //因为其他原因该camera的matrixWorld被还原了,而player.camera的是正确的
  414. op.camera = camera2
  415. }
  416. if(op.width2d) w = op.width2d //如果恒定二维宽度
  417. else{//否则考虑上距离,加一丢丢近大远小的效果
  418. var currentDis, nearBound, farBound
  419. if(op.camera.type == "OrthographicCamera"){
  420. currentDis = (op.camera.right - op.camera.left) / op.camera.zoom
  421. }else{
  422. currentDis = op.position.distanceTo(op.camera.position);
  423. }
  424. w = op.maxSize - ( op.maxSize - op.minSize) * THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
  425. //maxSize : mesh要表现的最大像素宽度; nearBound: 最近距离,若比nearBound近,则使用maxSize
  426. }
  427. i.copy(op.position).project(op.camera), //tag中心在屏幕上的二维坐标
  428. o.set(op.resolution.x / 2, op.resolution.y / 2, 1).multiply(i), //转化成px -w/2 到 w/2的范围
  429. l.set(w / 2, 0, 0).add(o), //加上tag宽度的一半
  430. c.set(2 / op.resolution.x, 2 / op.resolution.y, 1).multiply(l), //再转回 -1 到 1的范围
  431. h.copy(c).unproject(op.camera);//再转成三维坐标,求得tag边缘的位置
  432. var g = h.distanceTo(op.position)//就能得到tag的三维半径
  433. return g //可能NAN 当相机和position重叠时
  434. } ,
  435. updateVisible : function(object, reason, ifShow, level=0, type){//当所有加入的条件都不为false时才显示. reason='force'一般是强制、临时的
  436. if(!object.unvisibleReasons) object.unvisibleReasons = []; //如果length>0代表不可见
  437. if(!object.visibleReasons) object.visibleReasons = []; //在同级时,优先可见
  438. var update = function(){
  439. //先按从高到低的level排列
  440. object.unvisibleReasons = object.unvisibleReasons.sort((a,b)=>b.level-a.level)
  441. object.visibleReasons = object.visibleReasons.sort((a,b)=>b.level-a.level)
  442. var maxVisiLevel = object.visibleReasons[0] ? object.visibleReasons[0].level : -1
  443. var maxunVisiLevel = object.unvisibleReasons[0] ? object.unvisibleReasons[0].level : -1
  444. var shouldVisi = maxVisiLevel >= maxunVisiLevel
  445. var visiBefore = object.visible
  446. if(visiBefore != shouldVisi){
  447. object.visible = shouldVisi
  448. object.dispatchEvent({
  449. type: 'isVisible',
  450. visible: shouldVisi,
  451. reason,
  452. })
  453. }
  454. }
  455. if(ifShow){
  456. var index = object.unvisibleReasons.findIndex(e=>e.reason == reason)
  457. if(index > -1){
  458. type = 'cancel'
  459. object.unvisibleReasons.splice(index, 1);
  460. }
  461. if(type == 'add' ){
  462. if(!object.visibleReasons.some(e=>e.reason == reason)){
  463. object.visibleReasons.push({reason,level})
  464. }
  465. }
  466. }else{
  467. var index = object.visibleReasons.findIndex(e=>e.reason == reason)
  468. if(index > -1){
  469. type = 'cancel'
  470. object.visibleReasons.splice(index, 1);
  471. }
  472. if(type != 'cancel' ){
  473. if(!object.unvisibleReasons.some(e=>e.reason == reason)){
  474. object.unvisibleReasons.push({reason,level})
  475. }
  476. }
  477. }
  478. update()
  479. },
  480. getObjVisiByReason : function(object,reason){//获取在某条件下是否可见. 注: 用户在数据集选择可不可见为"datasetSelection"
  481. if(object.visible)return true
  482. else{
  483. return !object.unvisibleReasons || !object.unvisibleReasons.some(e=>e.reason == reason)
  484. }
  485. }
  486. }
  487. window.expandCommon = function(common){
  488. Object.assign(common,{
  489. intervalTool : { //延时update,防止卡顿
  490. list:[],
  491. isWaiting:function(name, func, delayTime/* , autoCycle */){
  492. let item = this.list.find(e=>e.name == name);
  493. if(!item){ //如果没有该项, 则加入循环
  494. let ifContinue = func();
  495. item = {name, func, delayTime};
  496. this.list.push(item);
  497. setTimeout(()=>{
  498. var a = this.list.indexOf(item);
  499. this.list.splice(a,1);
  500. let {func, delayTime} = item;
  501. if(item.requestUpdate || ifContinue ) this.isWaiting(name, func, delayTime); //循环
  502. },delayTime);
  503. }else {//如果有该项,说明现在请求下一次继续更新
  504. //更新属性
  505. item.func = func;
  506. item.delayTime = delayTime;
  507. item.requestUpdate = true;
  508. }
  509. },
  510. },
  511. sortByScore : function(list, request, rank) {
  512. var i = request ? common.filterAll(list, request) : list
  513. return 0 === i.length ? null : i = i.map(function(e) {
  514. let scores = rank.map(function(f){return f(e)}) //add
  515. return {
  516. item: e,
  517. scores,
  518. score: scores.reduce(function(t, i) {
  519. return t + i
  520. }, 0)
  521. }
  522. }).sort(function(e, t) {
  523. return t.score - e.score;
  524. })
  525. },
  526. getVisiblePano : function(positions = [], panos, options={}){//add
  527. var visiblePanos = [];
  528. options.posAtPanos = options.posAtPanos || {}//在不同漫游点的positions
  529. panos.forEach((pano)=>{
  530. if(!pano.isAligned())return;
  531. var A = pano.position.clone();
  532. var posB = options.posAtPanos[pano.id] || positions;
  533. var posLength = posB.length
  534. for(let i=0;i<posLength;i++){
  535. var B = posB[i];
  536. var ray = new THREE.Raycaster(A.clone(), B.clone().sub(A).normalize(), 0, A.distanceTo(B) - (options.tolerance||0) )
  537. var o = ray.intersectObjects(options.model || player.model.colliders, true);
  538. if (!o || !o.length){ //只要有一点可见,就算整体可见
  539. visiblePanos.push(pano.id);
  540. break;
  541. }
  542. }
  543. })
  544. return visiblePanos
  545. }
  546. })
  547. }
  548. //--------------------------------------
  549. //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
  550. var Manage = function(){
  551. this.weixinURL = "https://res.wx.qq.com/open/js/jweixin-1.2.0.js",
  552. this.time = "?"+new Date().getTime();
  553. this.loadAudio();
  554. this.loadWeixin();
  555. }
  556. //动态加载js文件
  557. Manage.prototype.LoadJs = function(_files, succes){
  558. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  559. var classcodes = [];
  560. var FileArray = [];
  561. if (typeof _files === "object") {
  562. FileArray = _files;
  563. } else {
  564. /*如果文件列表是字符串,则用,切分成数组*/
  565. if (typeof _files === "string") {
  566. FileArray = _files.split(",");
  567. }
  568. }
  569. if (FileArray != null && FileArray.length > 0) {
  570. var LoadedCount = 0;
  571. for (var i = 0; i < FileArray.length; i++) {
  572. loadFile(FileArray[i], function() {
  573. LoadedCount++;
  574. if (LoadedCount == FileArray.length) {
  575. try {
  576. succes();
  577. }
  578. catch(err) {
  579. console.log("err: 您未定义回调");
  580. }
  581. }
  582. })
  583. }
  584. }
  585. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  586. function loadFile(url, success) {
  587. if (!FileIsExt(classcodes, url)) {
  588. var _ThisType = GetFileType(url);
  589. var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0,_ThisType.indexOf("?"));
  590. var fileObj = null;
  591. if (ThisType == ".js") {
  592. fileObj = document.createElement('script');
  593. fileObj.src = url;
  594. } else if (ThisType == ".css") {
  595. fileObj = document.createElement('link');
  596. fileObj.href = url;
  597. fileObj.type = "text/css";
  598. fileObj.rel = "stylesheet";
  599. } else if (ThisType == ".less") {
  600. fileObj = document.createElement('link');
  601. fileObj.href = url;
  602. fileObj.type = "text/css";
  603. fileObj.rel = "stylesheet/less";
  604. }
  605. success = success || function() {};
  606. fileObj.onload = fileObj.onreadystatechange = function() {
  607. if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
  608. success();
  609. classcodes.push(url)
  610. }
  611. }
  612. document.getElementsByTagName('head')[0].appendChild(fileObj);
  613. } else {
  614. success();
  615. }
  616. }
  617. /*获取文件类型,后缀名,小写*/
  618. function GetFileType(url) {
  619. if (url != null && url.length > 0) {
  620. return url.substr(url.lastIndexOf(".")).toLowerCase();
  621. }
  622. return "";
  623. }
  624. /*文件是否已加载*/
  625. function FileIsExt(FileArray, _url) {
  626. if (FileArray != null && FileArray.length > 0) {
  627. var len = FileArray.length;
  628. for (var i = 0; i < len; i++) {
  629. if (FileArray[i] == _url) {
  630. return true;
  631. }
  632. }
  633. }
  634. return false;
  635. }
  636. };
  637. //获取页面url后面的参数
  638. Manage.prototype.number = function(variable) {
  639. var query = window.location.search.substring(1);
  640. var vars = query.split("&");
  641. for (var i=0;i<vars.length;i++) {
  642. var pair = vars[i].split("=");
  643. if(pair[0] == variable){return pair[1];}
  644. }
  645. return(false);
  646. };
  647. Manage.prototype.loadWeixin = function() {
  648. var that = this;
  649. this.LoadJs(that.weixinURL+that.time,function(){ });
  650. }
  651. Manage.prototype.weixinShare = function() {
  652. console.log("weixinShare")
  653. $.ajax({
  654. url:'https://www.4dage.com/wechat/jssdk/',
  655. type: "post",
  656. data : {
  657. 'url' : location.href.split('#')[0]
  658. },
  659. dataType:"jsonp",
  660. jsonpCallback:"success_jsonp",
  661. success:function(data,textStatus){
  662. console.log("weixinShare success")
  663. console.log(data.appId)
  664. wx.config({
  665. // debug : true,
  666. appId : data.appId,
  667. timestamp : data.timestamp,
  668. nonceStr : data.nonceStr,
  669. signature : data.signature,
  670. jsApiList : [ 'checkJsApi', 'onMenuShareTimeline',
  671. 'onMenuShareAppMessage', 'onMenuShareQQ',
  672. 'onMenuShareWeibo', 'hideMenuItems',
  673. 'showMenuItems', 'hideAllNonBaseMenuItem',
  674. 'showAllNonBaseMenuItem', 'translateVoice',
  675. 'startRecord', 'stopRecord', 'onRecordEnd',
  676. 'playVoice', 'pauseVoice', 'stopVoice',
  677. 'uploadVoice', 'downloadVoice', 'chooseImage',
  678. 'previewImage', 'uploadImage', 'downloadImage',
  679. 'getNetworkType', 'openLocation', 'getLocation',
  680. 'hideOptionMenu', 'showOptionMenu', 'closeWindow',
  681. 'scanQRCode', 'chooseWXPay',
  682. 'openProductSpecificView', 'addCard', 'chooseCard',
  683. 'openCard' ]
  684. });
  685. },
  686. error:function(XMLHttpRequest,textStatus,errorThrown){
  687. console.log("jsonp.error:"+textStatus);
  688. }
  689. });
  690. var success_jsonp = function(json){
  691. console.log(json);
  692. };
  693. wx.ready(function(){
  694. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  695. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  696. //分享到朋友圈
  697. console.log(g_weixinObj)
  698. wx.onMenuShareTimeline({
  699. title: g_weixinObj.title, // 分享标题
  700. link: g_weixinObj.lineLink, // 分享链接
  701. imgUrl: g_weixinObj.imgUrl, // 分享图标
  702. desc: g_weixinObj.desc
  703. });
  704. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  705. wx.onMenuShareAppMessage({
  706. title: g_weixinObj.title, // 分享标题
  707. desc: g_weixinObj.desc, // 分享描述
  708. link: g_weixinObj.lineLink, // 分享链接
  709. imgUrl: g_weixinObj.imgUrl, // 分享图标
  710. type: '', // 分享类型,music、video或link,不填默认为link
  711. dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空
  712. });
  713. wx.onMenuShareWeibo({
  714. title: g_weixinObj.title, // 分享标题
  715. desc: g_weixinObj.desc, // 分享描述
  716. link: g_weixinObj.lineLink, // 分享链接
  717. imgUrl: g_weixinObj.imgUrl, // 分享图标
  718. success: function () {
  719. // 用户确认分享后执行的回调函数
  720. },
  721. cancel: function () {
  722. // 用户取消分享后执行的回调函数
  723. }
  724. });
  725. wx.onMenuShareQZone({
  726. title: g_weixinObj.title, // 分享标题
  727. desc: g_weixinObj.desc, // 分享描述
  728. link: g_weixinObj.lineLink, // 分享链接
  729. imgUrl: g_weixinObj.imgUrl, // 分享图标
  730. success: function () {
  731. // 用户确认分享后执行的回调函数
  732. },
  733. cancel: function () {
  734. // 用户取消分享后执行的回调函数
  735. }
  736. });
  737. wx.onMenuShareQQ({
  738. title: g_weixinObj.title, // 分享标题
  739. desc: g_weixinObj.desc, // 分享描述
  740. link: g_weixinObj.lineLink, // 分享链接
  741. imgUrl: g_weixinObj.imgUrl, // 分享图标
  742. success: function () {
  743. // 用户确认分享后执行的回调函数
  744. },
  745. cancel: function () {
  746. // 用户取消分享后执行的回调函数
  747. }
  748. });
  749. wx.error(function(res){
  750. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  751. });
  752. });
  753. }
  754. Manage.prototype.dealURL = function(src, type){
  755. //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
  756. //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
  757. if(window.isLocal && settings.localPrefix!=void 0){//本地将线上的前缀替换
  758. var oldPrefix = 'super.4dage.com/'; //最简单的地址写一个,如果有其他完全不一样的地址就用数组逐个判断
  759. var index = src.indexOf(oldPrefix);
  760. if(index>-1){
  761. var wholeOldPrefix = src.slice(0, index+oldPrefix.length);
  762. return src.replace(wholeOldPrefix, settings.localPrefix)
  763. }else console.error("没有找到合适的本地链接")
  764. return src
  765. }else{
  766. //add https://
  767. var prefix = g_Prefix.replace('https://','').replace('http://','')
  768. if(!src.includes('http:/') && !src.includes('https:/') && src.includes(prefix)){
  769. src = 'https://'+src
  770. }
  771. return src
  772. }
  773. }
  774. Manage.prototype.removeSrcPostMark = function(url){//去除texture.load时自动加上的'?'
  775. var index = url.indexOf('?')
  776. if(index>-1){
  777. return url.slice(0, index)
  778. }else return url
  779. }
  780. Manage.prototype.showInfo = function (o) { // ({result:true, title:"发布成功"});
  781. var box = $(".resultBox");
  782. var title = o.title || o || i18n.get('保存成功');
  783. box.children().eq(0).html(title)
  784. //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000);
  785. var time = o.time || THREE.Math.clamp(title.length*130 ,1300, 5000);
  786. o.time || console.log("showtime " + time)
  787. //实际有一半的时间在渐变透明度
  788. this.showInfoTimer && clearTimeout(this.showInfoTimer)
  789. box.removeClass("animate");//如果之后不久又要showinfo一个的话,先停止前面的animate
  790. setTimeout(function () {
  791. box.css(
  792. {
  793. '-webkit-animation-duration': time + 'ms',
  794. 'animation-duration': time + 'ms'
  795. }
  796. )
  797. if(o.top){
  798. box.children().css('top', o.top + "%");
  799. }else{
  800. box.children().css('top', '' )
  801. }
  802. box.removeClass("hide");
  803. box.addClass("animate");
  804. if (o.dontInteract) {//遮挡对屏幕的操作
  805. box.css('pointer-events', 'auto')
  806. } else {
  807. box.css('pointer-events', 'none')
  808. }
  809. this.showInfoTimer = setTimeout(function () {
  810. box.removeClass("animate");
  811. box.addClass("hide");
  812. this.showInfoTimer = null;
  813. }.bind(this), time + 20)
  814. }.bind(this), 50)//这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧
  815. }//like: manage.showInfo({title:'a', top:20})
  816. //公用的函数
  817. function getQueryVariable(variable)
  818. {
  819. var query = window.location.search.substring(1);
  820. var vars = query.split("&");
  821. for (var i=0;i<vars.length;i++) {
  822. var pair = vars[i].split("=");
  823. if(pair[0] == variable){return pair[1];}
  824. }
  825. return(false);
  826. }
  827. //隐藏公司Logo
  828. function showLogo(){
  829. $("#myCompany").hide();
  830. $("#loaderCoBrandName").hide();
  831. $("#title-logo").hide();
  832. $(".title-container").css("justify-content","center")
  833. }
  834. //czj 添加随机的时间
  835. function randomTime(){
  836. return new Date()
  837. };
  838. function matcher(data){
  839. if(!data || !g_version ) return data;
  840. delete data.model.vision_version;
  841. var _data = {
  842. files: {
  843. "templates": ["images/images{{number}}/{{filename}}"]
  844. },
  845. model :{
  846. sid :window.number,
  847. camera_start:
  848. data.model.images && data.model.images.length != 0 ?
  849. {
  850. camera: {
  851. zoom: "-1",
  852. quaternion: [
  853. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  854. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  855. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  856. JSON.parse(data.model.images[0].metadata).camera_quaternion.y
  857. ]
  858. },
  859. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  860. mode: "0"
  861. }
  862. : ''
  863. },
  864. sid: window.number,
  865. hoticon: {
  866. default: "https://super.4dage.com/images/4dagePoint2.png",
  867. higt: "https://super.4dage.com/images/4dagePoint.png"
  868. },
  869. special: "false",
  870. weixinDesc: ""
  871. };
  872. $.extend(true,data,_data)
  873. return data;
  874. }
  875. function hotMatcher(data={}){
  876. //if(!data || !g_version) return data;
  877. if(g_version) {
  878. data.tourAudio = data.audio || {};
  879. }else{
  880. data.tourAudio = {}
  881. }
  882. return data;
  883. }
  884. var GifTexDeal = {
  885. animateObjects : [],
  886. animateTexs : [] ,
  887. addAnimation : function(texture, owner, info, id){
  888. /* if(this.animateObjects.find(e=>
  889. e.texture == texture && !ifSame(info, e.info)
  890. )) */
  891. var animation
  892. var tex = this.animateTexs.find(e=>e.texture == texture)
  893. if(tex){
  894. animation = tex
  895. }else{
  896. animation = {texture,info }
  897. this.animateTexs.push(animation)
  898. this.setRepeart(animation)
  899. }
  900. var object = {
  901. animation, //默认相同的texture对应的info是一样的, 对应一个animation
  902. owner,
  903. }
  904. this.animateObjects.push(object)
  905. return object
  906. },
  907. remove : function(object){
  908. var index = this.animateObjects.indexOf(object)
  909. if(index>-1){
  910. this.animateObjects.splice(index, 1)
  911. if(!this.animateObjects.find(e=>e.animation == object.animation)){
  912. let i = this.animateTexs.indexOf(object.animation)
  913. this.animateTexs.splice(i, 1)
  914. object.animation.texture.repeat.set(1,1)
  915. }
  916. this.stop(object)
  917. }
  918. },
  919. setRepeart : function(animation){
  920. animation.texture.repeat.set(1/animation.info.cellXcount, 1/animation.info.cellYcount)
  921. },
  922. start: function(object){
  923. if(!object || object.started )return;
  924. object.started = true
  925. if(object.animation.started)return;
  926. object.animation.started = true
  927. var info = object.animation.info
  928. var count = info.cellXcount * info.cellYcount - (info.voidCount || 0)
  929. if(count <= 1)return;
  930. transitions.start( (progress)=>{
  931. var index = Math.floor((count-1) * progress);
  932. var indexX = index % info.cellXcount
  933. var indexY = info.cellYcount - Math.floor(index /info.cellXcount ) - 1; //uv.offset.y是从下到上的
  934. object.animation.texture.offset.x = indexX / info.cellXcount;
  935. object.animation.texture.offset.y = indexY / info.cellYcount;
  936. //console.log(object.id + " : "+ object.texture.offset.toArray())
  937. } , info.duration * (-1), null,/* ()=>{//done (-1):循环
  938. object.started = false
  939. object.texture.offset.x = 0;
  940. object.texture.offset.y = 0;
  941. this.start(object)
  942. }, */ 0 ,null, object.id, "gif_"+object.animation.texture.id);
  943. },
  944. stop: function(object){
  945. if(!object || !object.started)return;
  946. object.started = false
  947. //只有该object对应的texture对应的所有object都停止了,才能真的停止动画:
  948. if(this.animateObjects.find(e=>e.animation == object.animation && e.started)) return;
  949. transitions.cancelById("gif_"+object.animation.texture.id);
  950. object.animation.texture.offset.set(0,0)
  951. object.animation.started = false
  952. }
  953. }
  954. var CloneObject = function(copyObj, result, isSimpleCopy, extraReplace) {
  955. //isSimpleCopy只复制最外层
  956. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  957. if(!copyObj)return copyObj //0 null undefined ''
  958. result = result || {};
  959. if (copyObj instanceof Array) {
  960. /* if (copyObj[0]instanceof Object) {
  961. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  962. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  963. }
  964. return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object
  965. return copyObj.map(e=>{
  966. if(e instanceof Object){
  967. return CloneObject(e)
  968. }else return e
  969. })
  970. }else{
  971. if(copyObj.clone instanceof Function ){ //解决一部分
  972. return copyObj.clone()
  973. }
  974. }
  975. for (var key in copyObj) {
  976. if (copyObj[key] instanceof Object && !isSimpleCopy)
  977. result[key] = CloneObject(copyObj[key]);
  978. else
  979. result[key] = copyObj[key];
  980. //如果是函数类同基本数据,即复制引用
  981. }
  982. return result;
  983. }
  984. ;
  985. var ifSame = function(object1, object2){
  986. if(object1 == object2 )return true // 0 != undefined , 0 == ''
  987. else if(!object1 || !object2) return false
  988. else if(object1.constructor != object2.constructor){
  989. return false
  990. }else if(object1 instanceof Array ) {
  991. if(object1.length != object2.length)return false;
  992. var _object2 = object2.slice(0);
  993. for(let i=0;i<object1.length;i++){
  994. var u = _object2.find(e=>ifSame(object1[i], e));
  995. if(u == void 0 && !_object2.includes(u) && !object1.includes(u))return false;
  996. else{
  997. let index = _object2.indexOf(u);
  998. _object2.splice(index,1);
  999. }
  1000. }
  1001. return true
  1002. }else if(object1.equals instanceof Function ){//复杂数据仅支持这种,其他的可能卡住?
  1003. return object1.equals(object2)
  1004. }else if(typeof object1 == 'number' || typeof object1 == 'string'){
  1005. if(isNaN(object1) && isNaN(object2))return true
  1006. else return object1 == object2
  1007. }else if(typeof object1 == "object"){
  1008. var keys1 = Object.keys(object1)
  1009. var keys2 = Object.keys(object2)
  1010. if(!ifSame(keys1,keys2))return false;
  1011. for(let i in object1){
  1012. var same = ifSame(object1[i], object2[i]);
  1013. if(!same)return false
  1014. }
  1015. return true
  1016. }else{
  1017. console.log('isSame出现例外')
  1018. }
  1019. }
  1020. function initByTHREE(THREE){
  1021. window.bus = new THREE.EventDispatcher();//因为player一开始总是没创建好,所以加一个事件传递器
  1022. THREE.TransitionPass = function ( scene, camera ) {
  1023. this.renderScene = scene;
  1024. this.renderCamera = camera;
  1025. this.coverRenderTarget = new THREE.WebGLRenderTarget( 100, 100, {
  1026. minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter,
  1027. format: THREE.RGBAFormat
  1028. });
  1029. this.coverTex = this.coverRenderTarget.texture;
  1030. this.enabled = false;
  1031. this.oldClearColor = new THREE.Color();
  1032. this.oldClearAlpha = 1;
  1033. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  1034. this.scene = new THREE.Scene();
  1035. this.material = this.getMaskMaterial()
  1036. var copyShader = THREE.CopyShader;
  1037. this.materialCopy = new THREE.ShaderMaterial( {
  1038. uniforms: this.copyUniforms,
  1039. vertexShader: copyShader.vertexShader,
  1040. fragmentShader: copyShader.fragmentShader,
  1041. blending: THREE.NoBlending,
  1042. depthTest: false,
  1043. depthWrite: false,
  1044. transparent: true
  1045. } );
  1046. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), this.material);
  1047. this.quad.frustumCulled = false; // Avoid getting clipped
  1048. this.scene.add( this.quad );
  1049. }
  1050. THREE.TransitionPass.prototype = {//波形扩散,出下一个画面
  1051. constructor: THREE.TransitionPass,
  1052. setSize: function ( width, height ) {
  1053. this.coverRenderTarget.setSize( width, height );
  1054. },
  1055. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  1056. var oldAutoClear = renderer.autoClear;
  1057. renderer.autoClear = false;
  1058. var uniforms = this.quad.material.uniforms
  1059. uniforms.bgTex.value = readBuffer.texture; //更新
  1060. uniforms.coverTex.value = this.coverTex;
  1061. uniforms.progress.value = player.model.skybox.material.uniforms.progress.value//
  1062. uniforms.screenRatio.value = player.domElement.clientWidth / player.domElement.clientHeight;// 使波纹为圆形
  1063. uniforms.screenRatio.value *= uniforms.screenRatio.value
  1064. renderer.render( this.scene, this.camera);
  1065. renderer.autoClear = oldAutoClear;
  1066. },
  1067. start:function(sceneRenderer){
  1068. this.enabled = true
  1069. //draw coverTex
  1070. this.quad.material.uniforms.progress.value = 1;
  1071. sceneRenderer.renderer.render( sceneRenderer.scene, sceneRenderer.camera, this.coverRenderTarget, true );
  1072. console.log('start111')
  1073. },
  1074. stop:function(){
  1075. this.enabled = false
  1076. console.log('stop111')
  1077. }
  1078. ,
  1079. getMaskMaterial :function(){
  1080. return new THREE.ShaderMaterial( {
  1081. uniforms: {
  1082. coverTex: {
  1083. type: "t",
  1084. value: null
  1085. },
  1086. bgTex: {
  1087. type: "t",
  1088. value: null
  1089. },
  1090. progress:{
  1091. type: "f",
  1092. value: 0
  1093. },
  1094. screenRatio:{
  1095. type: "f",
  1096. value: 1
  1097. }
  1098. },
  1099. vertexShader: `
  1100. varying vec2 vUv;
  1101. void main()
  1102. {
  1103. vUv = uv;
  1104. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  1105. }
  1106. `,
  1107. fragmentShader: `
  1108. uniform sampler2D coverTex;
  1109. uniform sampler2D bgTex;
  1110. uniform float progress;
  1111. uniform float screenRatio;
  1112. varying vec2 vUv;
  1113. void main() {
  1114. const float maxRadius = 0.708; // sqrt(0.5^2+0.5^2)
  1115. const float minRadius = 0.0 ;
  1116. float radius = screenRatio>1.0 ? sqrt((vUv.x - 0.5)*(vUv.x - 0.5) + (vUv.y - 0.5)*(vUv.y - 0.5)/screenRatio) : sqrt((vUv.x - 0.5)*(vUv.x - 0.5)*screenRatio+ (vUv.y - 0.5)*(vUv.y - 0.5));
  1117. float diff = 0.292; //1.0-maxRadius;
  1118. float radiusIn = maxRadius * progress + minRadius * (1.0-progress);
  1119. float radiusOut = radiusIn + diff;
  1120. if(radius < radiusIn) {
  1121. gl_FragColor = texture2D(bgTex, vUv);
  1122. //gl_FragColor = vec4(0.0,0.0,1.0,1.0);//
  1123. }else if(radius>radiusOut){
  1124. gl_FragColor = texture2D(coverTex, vUv) ;
  1125. //gl_FragColor = vec4(1.0,1.0,0.0,1.0);//
  1126. }else{
  1127. vec4 color1 = texture2D(bgTex, vUv);
  1128. vec4 color2 = texture2D(coverTex, vUv);
  1129. float rotio = smoothstep(radiusIn ,radiusOut,radius);
  1130. gl_FragColor = mix(color1, color2, rotio);
  1131. }
  1132. }
  1133. `
  1134. } );
  1135. },
  1136. }
  1137. let labels = []
  1138. class Label2D extends THREE.EventDispatcher{
  1139. constructor(o={}){
  1140. super()
  1141. this.position = o.position
  1142. this.elem = $(o.innerHTML || '<div ><a></a></div>');
  1143. $(o.domElement).append(this.elem)
  1144. this.pos2d = new THREE.Vector3
  1145. this.elem.css({position: 'absolute', 'z-index':999})
  1146. this.clickFun = o.clickFun;
  1147. this.clickFun && this.elem.on('click',this.clickFun.bind(this))
  1148. if(o.autoUpdate){
  1149. let update = (e)=>{if(e.cameraChanged) this.update()}
  1150. player.on("view.changed",update) //确保player存在
  1151. this.addEventListener('dispose', (e)=>{
  1152. player.off("view.changed",update)
  1153. })
  1154. }
  1155. this.visible = true
  1156. this.shelterByModel = o.shelterByModel
  1157. this.floorIndex = o.floorIndex
  1158. labels.push(this)
  1159. if(window.player.model){
  1160. this.init()
  1161. }else{
  1162. let f = ()=>{
  1163. window.bus.removeEventListener('playerAndModelReady',f)
  1164. this.init()
  1165. }
  1166. window.bus.addEventListener('playerAndModelReady',f)
  1167. }
  1168. }
  1169. init(){
  1170. if(this.floorIndex != void 0){
  1171. player.model.on("floor.changed",(currentFloor, mode, oldFloor)=>{
  1172. this.update(currentFloor) //注: currentFloor 这时候还没成为 model.currentFloor
  1173. })
  1174. }
  1175. }
  1176. update(currentFloor){
  1177. if(!this.position)return
  1178. if(!this.visible && this.unvisibleReasons.some(e=>e.level == 1) && !this.unvisibleReasons.some(e=>e.level>1) )return;
  1179. /*
  1180. 规定一下level共四层
  1181. level3 是notTrueSide层,权重最高。
  1182. level2 是强制可见层,如editSelected
  1183. level1 是强制不可见,如isPanorama
  1184. level0 是shelter层
  1185. 其中当visible==false时, 若导致不可见的原因是level1 代表不需要计算直接return, 否则还是要执行update 以计算更新可见性
  1186. 所以外部写的setVisible的level必须>0
  1187. */
  1188. var p = convertTool.getPos2d(this.position);
  1189. if(!p || !p.trueSide){
  1190. return this.setVisible(false, 'notTrueSide', 3, null, true)
  1191. //this.elem.css('display','none'); return;
  1192. }
  1193. this.setVisible(true, 'notTrueSide', 3, null, true)
  1194. this.setVisible(true, 'shelter', 0, null, true)
  1195. //判断label是否被模型遮挡,遮挡则消失(如果是漫游模式最好提前计算visiblePanos)
  1196. if(player.mode != 'panorama'){
  1197. currentFloor = currentFloor || player.model.currentFloor
  1198. if(!player.model.allFloorsVisible && this.floorIndex != void 0 && this.floorIndex!= currentFloor.floorIndex){
  1199. this.setVisible(false, 'shelter', 0, null, true)
  1200. //this.elem.css('display','none'); return;
  1201. if(!this.visible)return
  1202. }
  1203. if(this.shelterByModel && convertTool.ifShelter(this.position , p.vector, player.camera, this.floorIndex )){
  1204. //this.elem.css('display','none'); return;
  1205. this.setVisible(false, 'shelter', 0, null, true)
  1206. if(!this.visible)return
  1207. }
  1208. }
  1209. this.elem.css({
  1210. left: p.pos.x +'px',
  1211. top: p.pos.y +'px'
  1212. })
  1213. /* if(settings.vrEnabled){
  1214. this.elem.css({transform:'rotate('+window.screenFaceOrient+'deg)'})
  1215. }else{
  1216. this.elem.css({transform:''})
  1217. } */
  1218. //this.elem.css('display','block');
  1219. this.pos2d = p.vector;
  1220. }
  1221. setVisible(visi, reason, level=1, type, updating){
  1222. let visiOld = this.visible
  1223. convertTool.updateVisible(this, reason, visi, level, type )
  1224. updating || this.update() //再次更新可见性并计算位置
  1225. this.elem.css('display',this.visible?'block':'none');
  1226. /* if(!this.visible){
  1227. this.elem.css('display','none');
  1228. }else{
  1229. if(!visiOld){
  1230. updating || this.update()
  1231. this.elem.css('display','block');
  1232. }
  1233. } */
  1234. }
  1235. setPos(pos){
  1236. this.position = pos;
  1237. this.update()
  1238. }
  1239. dispose(){
  1240. this.elem.remove();
  1241. this._listeners = {}
  1242. this.dispatchEvent({type:'dispose'})
  1243. let index = labels.indexOf(this)
  1244. index > -1 && labels.splice(index,1)
  1245. }
  1246. }
  1247. window.Label2D = Label2D
  1248. class RoomLabel extends Label2D{
  1249. constructor(o){
  1250. if(o.position instanceof Array) o.position = new THREE.Vector3().fromArray(o.position)
  1251. o.innerHTML = `<div class="room-label" ><a><p><span>${o.title}</span></p></a></div>`
  1252. o.domElement = $(".widgets-doll-labels")[0]
  1253. o.shelterByModel = true , o.autoUpdate = true
  1254. o.clickFun = ()=>{
  1255. if(player.roomLebelClickUnabled)return
  1256. let result = common.sortByScore(player.model.floors.index[this.floorIndex].panos, [], [(pano)=>{
  1257. return -pano.position.distanceToSquared(this.position)
  1258. }]);
  1259. player.flyToPano({
  1260. pano : result && result[0] && result[0].item
  1261. })
  1262. }
  1263. super(o)
  1264. this.setTitle(o.title )
  1265. }
  1266. init(){
  1267. super.init()
  1268. //飞入后不可见
  1269. player.on("mode.changing",(oldMode, mode, pano, duration)=>{//准备飞
  1270. this.setStyle(oldMode, mode, duration)
  1271. })
  1272. this.setStyle()
  1273. }
  1274. setStyle(oldMode, mode, duration){
  1275. if(!mode) mode = player.modeTran.split('-')[1] || player.mode //要变成的mode或当前mode
  1276. if(mode == 'panorama'){
  1277. this.setVisible(false, 'isPanorama', 1)
  1278. }else if(oldMode == 'panorama'){
  1279. setTimeout(()=>{
  1280. this.setVisible(true, 'isPanorama', 1)
  1281. },duration*0.7)
  1282. }
  1283. }
  1284. setTitle(title){
  1285. this.title = title || ''
  1286. this.elem.html(`<a><p><span>${this.title}</span></p></a>`)
  1287. }
  1288. setEditSelect(state){//编辑页面用
  1289. this.editing = !!state
  1290. this.setVisible(state, 'editSelected', 2, state ? 'add':'cancel') //强制可见
  1291. }
  1292. }
  1293. window.RoomLabel = RoomLabel
  1294. class HistoryRecord extends THREE.EventDispatcher{
  1295. constructor(o){
  1296. super()
  1297. this.undoList = []
  1298. this.redoList = []
  1299. this.applyData = o.applyData //应用数据的方法
  1300. this.getData = o.getData //获取数据的方法
  1301. this.dataBefore
  1302. window.addEventListener('keydown',(e)=>{
  1303. if(e.keyCode == 90 && e.ctrlKey){//Z
  1304. this.undo()
  1305. }else if(e.keyCode == 89 && e.ctrlKey){//Y
  1306. this.redo()
  1307. }
  1308. })
  1309. }
  1310. undo(){//回退
  1311. let length = this.undoList.length
  1312. if(length>0){
  1313. let unExist
  1314. let last = this.undoList.pop();
  1315. this.applyData && (unExist = !this.applyData(last.before))
  1316. unExist || this.redoList.push(last);
  1317. unExist && this.undo()//找不到就回退下一个。
  1318. this.dispatchEvent('undo')
  1319. //console.log('undo',last)
  1320. }
  1321. }
  1322. redo(){//撤销回退
  1323. let length = this.undoList.length
  1324. let last = this.redoList.pop();
  1325. if(last){
  1326. //注意:每行的顺序不能乱
  1327. this.undoList.push(last)
  1328. this.applyData && this.applyData(last.after)
  1329. this.dispatchEvent('redo')
  1330. //console.log('redo',last)
  1331. }
  1332. }
  1333. beforeChange(o){//在变化之前(可能执行好几次直到变化完,但只有第一次有效)。 o的内容完全根据getData怎么定义
  1334. if(!this.dataBefore){
  1335. let data = this.getData(o)
  1336. data && (this.dataBefore = data)
  1337. }
  1338. }
  1339. afterChange(o){//变化结束,从beforeChange到此算一次操作。
  1340. if(this.dataBefore){
  1341. this.writeIn({before:this.dataBefore, after:this.getData(o)} ) //写入某物体变化前和变化后的状态
  1342. this.dataBefore = null
  1343. }
  1344. }
  1345. writeIn(data ){
  1346. this.redoList.length = 0; //一旦录入新的操作,就不允许undo了
  1347. this.undoList.push(data );
  1348. //console.log('新增undo', data)
  1349. }
  1350. clear(){
  1351. this.redoList.length = 0
  1352. this.undoList.length = 0
  1353. this.dataBefore = null
  1354. }
  1355. }
  1356. window.HistoryRecord = HistoryRecord
  1357. /* class VideoPlayer extends THREE.EventDispatcher{
  1358. constructor(player) {
  1359. super()
  1360. this.instances = new Map()
  1361. this.isFlv = false
  1362. }
  1363. addVideo(src) {
  1364. let video = this._createVideo(src)
  1365. this.instances.set(src, video)
  1366. return video
  1367. }
  1368. getVideo(src) {
  1369. let video = this.instances.get(src)
  1370. if (!video) {
  1371. video = this.addVideo(src)
  1372. }
  1373. return video
  1374. }
  1375. _createVideo(src) {
  1376. let video = document.createElement('video')
  1377. video.setAttribute('crossOrigin', 'anonymous')
  1378. video.setAttribute('playsinline', 'true')
  1379. video.setAttribute('x5-playsinline', 'true')
  1380. video.setAttribute('webkit-playsinline', 'true')
  1381. video.setAttribute('x5-video-player-type', 'h5')
  1382. video.setAttribute('controls', 'true')
  1383. video.setAttribute('controlslist', 'nodownload')
  1384. video.setAttribute('preload', 'meta') //注意,src赋值就会自动加载, preload="meta" 只加载元数据,提高加载速度,否则一开始卡
  1385. video.autoplay = false
  1386. video.muted = true
  1387. video.loop = true
  1388. video.style.position = 'fixed'
  1389. video.style.left = '0'
  1390. video.style.top = '0'
  1391. video.style.zIndex = '1000'
  1392. video.style.width = '200px'
  1393. video.style.display = 'none'
  1394. //document.body.appendChild(video)
  1395. //video.style.display = browser.urlHasValue('debug') ? 'block' : 'none'
  1396. video.src = src
  1397. if(this.isFlv) this.attachFlv(video)
  1398. return video
  1399. }
  1400. attachFlv(video){ 四维看看的会把视频转码成flv和mp4存在服务器, 但是大场景不会,所以安卓(如vivo)加载不了。flv必须用flvjs播放,且苹果有的支持不了
  1401. if(video.flvjsPlayer)return
  1402. let player = flvjs.createPlayer({ type: 'flv', url: video.src }) //需要是flv格式才行
  1403. player.videoElement = video
  1404. player.attachMediaElement(video)
  1405. player.on(flvjs.Events.ERROR, this._onPlayerError.bind(this))
  1406. player.load()
  1407. video.flvjsPlayer = player;
  1408. }
  1409. _onPlayerError() {
  1410. console.warn('视频加载失败')
  1411. }
  1412. changeTypeToFlv(){
  1413. this.isFlv = true
  1414. for(let [key,value] of this.instances){
  1415. this.attachFlv(value)
  1416. }
  1417. }
  1418. } */
  1419. {
  1420. let f = ()=>{
  1421. window.bus.removeEventListener('playerAndModelReady',f)
  1422. player.on("mode.changing",(currentMode, mode, pano, duration)=>{
  1423. let noLine = mode == 'floorplan';
  1424. if(noLine){
  1425. $('.widgets-doll-labels').addClass('noLine').addClass('noCorner')
  1426. }else{
  1427. $('.widgets-doll-labels').removeClass('noLine').removeClass('noCorner')
  1428. }
  1429. })
  1430. player.on("view.changed",(e)=>{
  1431. if(e.cameraChanged){
  1432. //if(needUpdateZIndex){ //如果某个label显示时需要更新index的话,加个参数
  1433. let label_ = labels.filter(e=>e.elem[0].style.display == 'block')
  1434. label_.sort((a,b)=>b.pos2d.z - a.pos2d.z)
  1435. label_.forEach((e,index)=>e.elem.css('z-index', index+1000));
  1436. //}
  1437. }
  1438. })
  1439. player.model.hotGroup.children.length ? logSth() : player.on('gotHotAndStartload',logSth);
  1440. /* {//如果是flv格式的话
  1441. window.videoPlayer = new VideoPlayer()
  1442. if(browser.detectAndroidMobile()){//安卓常常播放不了
  1443. let scriptdom = document.querySelector('#flvJs')
  1444. if(scriptdom){
  1445. scriptdom.src = 'js/lib/flv.min.js'
  1446. scriptdom.onload = ()=>{
  1447. window.videoPlayer.changeTypeToFlv()
  1448. window.bus.dispatchEvent('VideoPlayerReady' )
  1449. //Hot.startLoad()
  1450. }
  1451. }
  1452. }
  1453. } */
  1454. }
  1455. window.bus.addEventListener('playerAndModelReady',f) //player model currentPano都已有
  1456. }
  1457. window.bus.dispatchEvent({type: 'THREE_inited'})
  1458. }
  1459. //最好能知道应该播放到的currentTime
  1460. var SoundManager = {//暂不支持同时播放
  1461. currentAudio:null,//当前正在播放list中的哪一个
  1462. enableSound:true,//是否允许有声音
  1463. playHistory:[],//被打断的加入播放历史
  1464. list:[ ],//同一级别可以互相打断 //暂时不做多级别
  1465. play:function(name, src, currentTime){
  1466. var object = this.list.find(e=>e.name == name)
  1467. if(object){
  1468. if(this.currentAudio){
  1469. this.pause(this.currentAudio.name, false, true)
  1470. }
  1471. {//将当前要播放的播放历史中清除
  1472. let index = this.playHistory.indexOf(object)
  1473. if(index>-1)this.playHistory.splice(index,1);
  1474. }
  1475. this.currentAudio = object
  1476. if(src){
  1477. this.setSrc(name, src)
  1478. }
  1479. if(currentTime!=void 0){
  1480. object.audio.currentTime = currentTime
  1481. }
  1482. if(object.audio && object.src){
  1483. object.audio.load(); // iOS 9 还需要额外的 load 一下, 否则直接 play 无效 *///https://www.cnblogs.com/interdrp/p/4211883.html 部分资料
  1484. object.audio.play();
  1485. object.audio.paused || object.callback && object.callback(true)
  1486. Log(name + ' 播放 ' )
  1487. }
  1488. }
  1489. },
  1490. pause:function(name, autoReplayLast, isInterrupt){//需要能自动恢复上一个被打算的音频。恢复前判断是否还需要播放
  1491. var object = this.list.find(e=>e.name == name)
  1492. if(object && this.currentAudio == object){
  1493. this.currentAudio = null
  1494. if(object.audio){
  1495. object.audio.pause()
  1496. object.callback && object.callback(false)
  1497. object.audio.src && Log(name + ' 中断音频 '+ "("+common.getFileNameFromUrl(object.audio.src)+')' )
  1498. }
  1499. if(isInterrupt){//一般主动调用不需要加这个
  1500. this.playHistory.push(object)//如果是被中断的,加入播放历史,等待恢复播放
  1501. }
  1502. if(autoReplayLast){ //播放之前的音频。它们是被打断过的。
  1503. while(this.playHistory.length){
  1504. var last = this.playHistory.pop();
  1505. if(last.src && last.canplay(last.audio)){
  1506. this.play(last.name )
  1507. }
  1508. }
  1509. }
  1510. }
  1511. },
  1512. setSrc : function(name, src){//不能直接给audio赋src!一定要用这个函数!因为我要拿这里的src来判断有无src,因为貌似audio的src会自动变,''时会变成html的链接
  1513. var object = this.list.find(e=>e.name == name)
  1514. object.src = src
  1515. object.audio.src = src
  1516. Log(`${object.name} 设置src: ${src}`)
  1517. },
  1518. createAudio:function(object={}){//name, level, canplay
  1519. if(!object.fake){
  1520. object.audio = new Audio();
  1521. object.audio.loop = !!object.loop;
  1522. //object.audio.autoplay = true;
  1523. object.audio.addEventListener('ended', ()=>{
  1524. if(object.loop){//循环
  1525. Log(`${object.name} 播放完毕,重新播放`)
  1526. object.audio.play()
  1527. }else{
  1528. this.pause(object.name, true);//停止后的后续处理
  1529. }
  1530. });
  1531. object.audio.oncanplaythrough = ()=>{
  1532. Log(`${object.name} canplaythrough `)
  1533. }
  1534. }
  1535. this.list.push(object)
  1536. },
  1537. initAutoPlay:function(){ //处理设备自动播放限制
  1538. let play = function(){
  1539. if (this.currentAudio && this.currentAudio.audio && this.currentAudio.src && this.currentAudio.audio.paused ) {
  1540. this.currentAudio.audio.play() //一般触屏了都会播放成功,就不识别paused了
  1541. this.currentAudio.callback && this.currentAudio.callback(true)
  1542. Log(`${this.currentAudio.name} 自动播放成功`) //即使设置src在这之后好像也能成功播放
  1543. }else{
  1544. }
  1545. document.removeEventListener("touchstart",play);
  1546. document.removeEventListener("click",play);
  1547. $('#player')[0].removeEventListener("touchstart", play);
  1548. }.bind(this);
  1549. document.addEventListener("WeixinJSBridgeReady", play, false);
  1550. document.addEventListener("touchstart", play);//ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
  1551. document.addEventListener("click", play);
  1552. $('#player')[0].addEventListener("touchstart", play);
  1553. }
  1554. }
  1555. function Log(value, color, fontSize){
  1556. color = color || '#13f'
  1557. fontSize = fontSize || 14
  1558. console.warn(`%c${value}`, `color:${color};font-size:${fontSize}px`)
  1559. }
  1560. Manage.prototype.loadAudio = function() { //相关:g_tourAudio \ g_playAudio
  1561. //热点页面因为挡住了界面,所以暂时不存在别的音频阻止热点音频的可能
  1562. //box视频都静音,所以暂时不考虑
  1563. SoundManager.createAudio({
  1564. name:'bgm',
  1565. level:0,
  1566. src:'',
  1567. loop:true,
  1568. canplay:(audio)=>{
  1569. return this.bgmShouldPlay
  1570. },
  1571. callback:(state)=>{//play或pause时随之触发的函数(即使还没开始播放)
  1572. if(state){
  1573. $("#volume a img").attr("src", "./images/Volume btn_off.png")
  1574. $("#volume").attr("title", "关闭声音");
  1575. }else{
  1576. $("#volume a img").attr("src", "./images/Volume btn_on.png")
  1577. $("#volume").attr("title", "打开声音");
  1578. }
  1579. }
  1580. })
  1581. SoundManager.createAudio({
  1582. name:'tour',
  1583. level:0,
  1584. src:'',
  1585. loop:false,
  1586. canplay:(audio)=>{
  1587. return player.director && player.director.tourIsPlaying && player.director.getAudio()
  1588. }
  1589. })
  1590. SoundManager.createAudio({
  1591. name:'hot',
  1592. fake:true,//实际上没有audio. 只是为了来停止和续播其他音频
  1593. level:1,
  1594. src:'',
  1595. loop:false,
  1596. canplay:(audio)=>{
  1597. }
  1598. })
  1599. $("#volume").find("a").on("click", ()=> {
  1600. if($("#volume img")[0].src.indexOf("btn_on.png")>-1)
  1601. {
  1602. this.switchBgmState(true);
  1603. }
  1604. else if($("#volume img")[0].src.indexOf("btn_off.png")>-1)
  1605. {
  1606. this.switchBgmState(false);
  1607. }
  1608. })
  1609. this.switchBgmState(true);//初始设置允许播放bgm
  1610. SoundManager.initAutoPlay()
  1611. }
  1612. Manage.prototype.switchBgmState = function(state){//按钮的状态完全代表是否应该播放bgm,即使还没加载完
  1613. this.bgmShouldPlay = state
  1614. if(state){
  1615. SoundManager.play('bgm')
  1616. }else{
  1617. SoundManager.pause('bgm')
  1618. }
  1619. /* if(!g_bgAudio || !g_bgAudio.src) return;
  1620. var played = function(){
  1621. console.log('begin play bgm');
  1622. g_play = 1;
  1623. g_playAudio = g_bgAudio;
  1624. g_tourAudio && g_tourAudio.pause()
  1625. }
  1626. var paused = function(){
  1627. g_play = 0;
  1628. g_playAudio == g_bgAudio && (g_playAudio = null)
  1629. }
  1630. if(state ){
  1631. g_bgAudio.play();
  1632. if(g_bgAudio.paused){
  1633. paused()
  1634. }else{
  1635. played()
  1636. return true
  1637. }
  1638. }else{
  1639. g_bgAudio.pause();
  1640. paused()
  1641. }
  1642. g_bgAudio.pauseByHot = false
  1643. g_bgAudio.pauseByTour = false */
  1644. }
  1645. var manage = new Manage();
  1646. //处理cursor优先级
  1647. var CursorDeal = {
  1648. priorityEvent : [//在前面的优先级高
  1649. {"noIntersect":'not-allowed'},
  1650. {"addHot":'cell'},
  1651. {"hoverFootIcon":'pointer'},
  1652. {"hoverHot":'pointer'},
  1653. {"addLabel":'cell'},
  1654. {"moveLabel":'grab'},
  1655. ],
  1656. domElements :[$('#player')[0]],
  1657. list:[], //当前存在的cursor状态
  1658. currentCursorIndex:null,
  1659. /* init : function(viewer){
  1660. this.priorityEvent.forEach(e=>{//刚开始Potree.resourcePath没值,现在换
  1661. for(let i in e){
  1662. e[i] = Common.replaceAll(e[i],'{Potree.resourcePath}',Potree.resourcePath)
  1663. }
  1664. })
  1665. this.domElements = [viewer.renderArea, viewer.mapViewer.renderArea];
  1666. viewer.addEventListener("CursorChange",(e)=>{
  1667. if(e.action == 'add'){
  1668. this.add(e.name)
  1669. }else{
  1670. this.remove(e.name)
  1671. }
  1672. })
  1673. }, */
  1674. add : function(name){
  1675. var priorityItem = this.priorityEvent.find(e=>e[name])
  1676. if(!priorityItem){
  1677. console.error('CursorDeal 未定义优先级 name:'+ name);
  1678. return
  1679. }
  1680. if(!this.list.includes(name)){
  1681. this.judge({addItem: priorityItem, name})
  1682. this.list.push(name)
  1683. }
  1684. },
  1685. remove : function(name){
  1686. var index = this.list.indexOf(name);
  1687. if(index > -1){
  1688. this.list.splice(index, 1)
  1689. this.judge()
  1690. }
  1691. },
  1692. judge:function(o={}){
  1693. //console.log(o,this.list)
  1694. if(o.addItem){
  1695. var addIndex = this.priorityEvent.indexOf(o.addItem)
  1696. if(addIndex < this.currentCursorIndex || this.currentCursorIndex == void 0){
  1697. this.domElements.forEach(e=>e.style.cursor = o.addItem[o.name] )
  1698. this.currentCursorIndex = addIndex
  1699. }
  1700. }else{
  1701. var levelMax = {index:Infinity, cursor:null }
  1702. this.list.forEach(name=>{
  1703. var priorityItem = this.priorityEvent.find(e=>e[name])
  1704. var index = this.priorityEvent.indexOf(priorityItem)
  1705. if(index < levelMax.index){
  1706. levelMax.index = index;
  1707. levelMax.cursor = priorityItem[name]
  1708. }
  1709. })
  1710. this.currentCursorIndex = levelMax.index
  1711. this.domElements.forEach(e=>e.style.cursor = levelMax.cursor || '')
  1712. }
  1713. }
  1714. }
  1715. function logSth(){
  1716. let hotCount = player.model.hotGroup.children.length
  1717. let videoCount = player.model.hotGroup.children.filter(e=>e.texType == 'video').length
  1718. let photoCount = player.model.hotGroup.children.filter(e=>e.texType == 'photo').length
  1719. let shineCount = player.model.hotGroup.children.filter(e=>e.texType == 'shine').length
  1720. let aniCount = player.model.hotGroup.children.filter(e=>e.info.animateInfo).length
  1721. let objCount = player.model.hotGroup.children.filter(e=>e.objObject).length
  1722. let chunkLen = player.model.chunks.length
  1723. let vertexC = player.model.chunks.reduce(function(total, chunk ){return total+chunk.geometry.attributes.position.count}, 0)
  1724. let panoCount = player.model.panos.list.length
  1725. Log(`共有chunk个数 ${chunkLen} ( 顶点数 ${vertexC} )
  1726. 热点个数 ${hotCount} ( vedio ${videoCount} 个,photo ${photoCount} 个,shine ${shineCount}个。 gif ${aniCount} 个,obj ${objCount} 个
  1727. 漫游点数 ${panoCount} 个)`, '#FF4399', 14)
  1728. }
  1729. window.sceneFrom = number.slice(0,3) == 'KJ-' ? 'kankan' : '' //看看or看见转来的
  1730. //兼容一代的場景
  1731. //請求地址統一管理
  1732. var g_onePregix = "https://bigscene.4dage.com/" //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
  1733. var g_version = manage.number("version");
  1734. g_version === "one" ? g_Prefix = g_onePregix : '';