manage.js 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032
  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 g_Prefix= '/scene/';
  5. var s = window.location.href.split('/');
  6. s.pop();
  7. //var g_Prefix = s.join('/');
  8. window.isLocal = true;
  9. var g_index=null;
  10. var g_modeldata=null;
  11. var g_weixinTitle=null;
  12. var g_Hots=null;
  13. var g_HotMeshes=[];
  14. var g_HotMeshSize = {
  15. g_HotMeshWidth: 0.3,
  16. g_HotMeshHeight:0.3
  17. };
  18. //add表示添加,delete表示删除
  19. var g_HotStatus=null;
  20. var g_newHot = [];//存储新加热点
  21. var g_HotImage= {
  22. "point":"https://super.4dage.com/images/4dagePoint2.png",
  23. "point2":"https://super.4dage.com/images/4dagePoint.png"
  24. };
  25. var g_saveHot=false;
  26. var g_TextColor=0x7777ff;
  27. var g_Text=null;
  28. var g_TextPlaneMesh=[];
  29. var g_TextIconMesh=[];
  30. var g_TextIcon="./images/text.png";
  31. var g_SelectTextIndex=null;
  32. var g_TextShow=null;
  33. var g_audioPlay=false;
  34. var g_background=null;
  35. var g_roof=null;
  36. var g_data2 = null;//加载的data2.js的内容
  37. var g_bgAudio=null;//背景音乐
  38. var g_tourAudio=null;//导览音乐
  39. var g_play = 1;//表示播放图标状态
  40. var g_playAudio = null;//当前在播放或当继续播放时应该播放的,是g_bgAudio或g_tourAudio
  41. var g_currentHot = null;//当前打开的热点
  42. //var g_Texture=null;
  43. //var g_ChunknameTexture={}; //chunkname和贴图名称对应
  44. var g_NormalTexture=false;
  45. var g_SpecularTexture=false;
  46. var g_DirectionalLight=null;
  47. var g_snapShotWidth = 200; //截图下载图片的大小
  48. var g_snapShotHeight = 140;
  49. //微信分享
  50. var g_weixinObj = {
  51. "title": document.querySelector("head title").innerHTML,
  52. "lineLink" : window.location.href,
  53. "imgUrl" : "https://www.4dmodel.com/SuperPanoramic/images/weixintitle.jpg",
  54. "desc" : "四维时代提供技术支持",
  55. }
  56. window.browser = { //提前定义
  57. isMobile: function() {
  58. var e = navigator.userAgent || navigator.vendor || window.opera;
  59. 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))
  60. },
  61. isFullscreen: function() {
  62. return document.fullscreenElement || document.mozFullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement
  63. },
  64. valueFromHash: function(e, t) {
  65. var i = new RegExp("[#&?]" + e + "=([^#&?]*)")
  66. , n = i.exec(window.location.href);
  67. if (!n)
  68. return t;
  69. var r = n[1];
  70. return "boolean" == typeof t ? "true" === r || "1" === r : "number" == typeof t ? parseFloat(r) : window.decodeURIComponent(r)
  71. },
  72. urlHasValue: function(key, isGetValue) {
  73. let querys = window.location.search.substr(1).split("&")
  74. if (isGetValue) {
  75. for (let i = 0; i < querys.length; i++) {
  76. let keypair = querys[i].split("=")
  77. if (keypair.length === 2 && keypair[0] === key) {
  78. return keypair[1]
  79. }
  80. }
  81. return ""
  82. } else {
  83. for (let i = 0; i < querys.length; i++) {
  84. let keypair = querys[i].split("=")
  85. if (keypair[0] == key) {
  86. return true
  87. }
  88. }
  89. return false
  90. }
  91. },
  92. }
  93. var settings = {
  94. hotClickEvent:{
  95. video:{
  96. playAndPause:true,
  97. examine:false,
  98. openHot:false
  99. },
  100. photo:{
  101. examine:false,
  102. openHot:false
  103. },
  104. shine:{
  105. examine:true,
  106. openHot:true
  107. }
  108. },
  109. hotClickActions:['playAndPause','examine','openHot','fastTran'],
  110. markerHeight: 0.05,//距离地板高出多少,
  111. //默认的:
  112. teleportTime: 1500,//瞬间过渡的时间
  113. /* flytimeDistanceMultiplier:150,
  114. flyTime:750, */
  115. tourRotTime:2, //默认停留2秒
  116. //dontExamHot:true,
  117. hotFastTran:false,
  118. transparentBg: false,
  119. bgImg: null,
  120. localPrefix: '',
  121. tileClass:{//默认全景贴图加载的清晰度
  122. pc:{
  123. nav: '2k',
  124. max: '4k',
  125. },
  126. bigMobile:{ //width和height都超过一定值
  127. nav: browser.urlHasValue('padNav',true) || '2k',
  128. max: browser.urlHasValue('padMax',true) || '4k',//'2k',
  129. },
  130. mobile:{
  131. nav: browser.urlHasValue('phoneNav',true) || '1k', //不放大时
  132. max: browser.urlHasValue('phoneMax',true) || '4k', //放到最大
  133. }
  134. }, //可以稍后自行修改
  135. /* extractFloor : { //提取一部分chunk作为新的floor,该floor不在楼层列表里显示,一般用于飞出后隐藏屋顶
  136. 'KJ-t-tHpdpKvb0ew' : [1,2,3,4,5,6,7,8], //第0层的第1,2,3个chunk是屋顶
  137. } */
  138. }
  139. if(window.number == '725'||window.number == '724'){
  140. //settings.mobileNavHigh = true
  141. settings.tileClass.mobile = {nav:'2k', max: '2k'}
  142. }
  143. //共用函数:
  144. window.common = null;
  145. window.MathLight = null;
  146. window.math = null
  147. window.easing = null
  148. window.lerp = null
  149. window.transitions = null
  150. function watch(object, propName, initialValue){ //监听某个属性的变化
  151. let v = initialValue
  152. Object.defineProperty(object, propName, {
  153. get: function() {
  154. return v
  155. },
  156. set: function(e) {
  157. console.log('watch:',propName, e)
  158. v = e
  159. }
  160. })
  161. }
  162. var toPrecision = function(e, t) {
  163. function i(e, t) {
  164. var i = Math.pow(10, t);
  165. return Math.round(e * i) / i
  166. }
  167. if (e instanceof Array) {
  168. for (var n = 0; n < e.length; n++)
  169. e[n] = i(e[n], t);
  170. return e
  171. }
  172. return i(e, t)
  173. }
  174. var dealMap = (map, o={} )=>{
  175. //使不resize when image is not power of two ,但缩小时会有锯齿
  176. if(!o.ignoreResize){
  177. if(!map.image || !THREE.Math.isPowerOfTwo(map.image.width ) || !THREE.Math.isPowerOfTwo(map.image.height )){
  178. map.wrapS = map.wrapT = THREE.ClampToEdgeWrapping;
  179. map.minFilter = THREE.LinearFilter;
  180. //map.generateMipmaps = true;
  181. }
  182. }
  183. if(!browser.isMobile()) map.anisotropy = 3
  184. }
  185. var dom = {
  186. getOffset: function(type, element, parent) {
  187. left = (type == "left") ? element.offsetLeft : element.offsetTop;
  188. if (!parent) parent = $("body")[0];
  189. while (element = element.offsetParent) {
  190. if (element == parent) break;
  191. left += (type == "left") ? element.offsetLeft : element.offsetTop;
  192. }
  193. return left;
  194. }
  195. };
  196. var getTransformSid = function(){
  197. var name
  198. if(player.mode == 'panorama'){
  199. name = player.currentPano ? player.currentPano.id : 'outside'
  200. }else{
  201. name = 'outside'
  202. }
  203. return name
  204. }
  205. var LineDraw = {
  206. /* createLine: function(posArr, o) {
  207. var e = new THREE.BufferGeometry
  208. , p = new Float32Array(6);
  209. e.addAttribute("position", new THREE.BufferAttribute(p,3));
  210. //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
  211. var p = e.attributes.position.array;
  212. for (var i = 0; i < 2; i++) {
  213. p[i * 3] = posArr[i].x;
  214. p[i * 3 + 1] = posArr[i].y;
  215. p[i * 3 + 2] = posArr[i].z;
  216. }
  217. var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
  218. linewidth: o.width || 1,
  219. //windows无效。 似乎mac/ios上粗细有效 ?
  220. color: o.color || defaultColor,
  221. transparent: o.dontAlwaysSeen ? false : true,
  222. depthTest: o.dontAlwaysSeen ? true : false
  223. })
  224. var line = new THREE.Line(e,mat);
  225. line.renderOrder = o.renderOrder || 4
  226. //同tagStem; //如果不加高,可能会部分被model遮住
  227. return line;
  228. } */
  229. createLine: function (posArr, o={}) {
  230. //多段普通线 (第二个点和第三个点之间是没有线段的, 所以不用在意线段顺序)
  231. var mat
  232. if(o.mat){
  233. mat = o.mat
  234. }else{
  235. let prop = {
  236. color: o.color || defaultColor,
  237. transparent: o.dontAlwaysSeen ? false : true,
  238. depthTest: o.dontAlwaysSeen ? true : false,
  239. opacity: o.opacity != void 0 ? o.opacity : 1,
  240. }
  241. if(o.deshed ){
  242. prop.dashSize = o.dashSize || 0.1,
  243. prop.gapSize = o.gapSize || 0.1
  244. }
  245. mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"](prop)
  246. }
  247. var line = new THREE.LineSegments(new THREE.BufferGeometry, mat);
  248. line.renderOrder = o.renderOrder || 4
  249. this.moveLine(line, posArr)
  250. return line;
  251. },
  252. moveLine: function (line, posArr) {
  253. if(posArr.length == 0)return
  254. let position = new Float32Array(posArr.length * 3); //[]
  255. for (var i = 0; i < 2; i++) {
  256. position[i * 3] = posArr[i].x;
  257. position[i * 3 + 1] = posArr[i].y;
  258. position[i * 3 + 2] = posArr[i].z;
  259. }
  260. line.geometry.addAttribute("position", new THREE.BufferAttribute(position,3));
  261. //line.geometry.setAttribute('position', new THREE.Float32BufferAttribute(new Float32Array(position), 3));
  262. line.geometry.attributes.position.needsUpdate = true;
  263. line.geometry.computeBoundingSphere();
  264. /* if(line.material instanceof THREE.LineDashedMaterial){
  265. line.computeLineDistances() //只有非buffer的geometry才有
  266. } */
  267. }
  268. ,
  269. }
  270. var convertTool = {
  271. getPos2d : function(point, camera, dom){//获取一个三维坐标对应屏幕中的二维坐标
  272. var camera = camera || player.camera;
  273. var dom = dom || player.domElement;
  274. if(!camera)return
  275. 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);
  276. var x,y;
  277. x = (pos.x + 1) / 2 * dom.clientWidth;
  278. y = (1 - (pos.y + 1) / 2) * dom.clientHeight;
  279. var inSight = x <= dom.clientWidth && x >= 0 //是否在屏幕中
  280. && y <= dom.clientHeight && y >= 0
  281. return {
  282. pos: new THREE.Vector2(x,y), // 屏幕像素坐标
  283. vector: pos, //(范围 -1 ~ 1)
  284. trueSide : pos.z<1, //trueSide为false时,即使在屏幕范围内可见,也是反方向的另一个不可以被渲染的点 参见Tag.update
  285. inSight : inSight //在屏幕范围内可见
  286. };
  287. },
  288. ifShelter: function (pos3d, pos2d, camera, floorIndex) {
  289. //检测某点在视线中是否被mesh遮挡
  290. if (!pos2d) pos2d = convertTool.getPos2d(pos3d )
  291. camera = camera || player.camera
  292. var ori = new THREE.Vector3(pos2d.x, pos2d.y, -1).unproject(camera) //找到视线原点
  293. var dir = pos3d.clone().sub(ori).normalize()
  294. var ray = new THREE.Raycaster(ori, dir); //由外向里 因为模型从内侧是可见的所以从外侧
  295. /* if(config.isEdit && publicObjectSet.editor.mainDesign.editing){
  296. var o = ray.intersectObjects(publicObjectSet.editor.mainDesign.wallMeshes);
  297. }else{ */
  298. let colliders = player.model.allFloorsVisible ? player.model.colliders : (floorIndex != void 0 ? player.model.floors.index[floorIndex] : player.model.currentFloor).collider.children
  299. //let colliders = (floorIndex == void 0 ) ? player.model.colliders : player.model.floors.index[floorIndex].collider.children
  300. var o = ray.intersectObjects(colliders);
  301. //}
  302. var len = pos3d.distanceTo(ori);
  303. if (o && o.length) {
  304. for(var i=0;i<o.length;i++){
  305. if(o[i].distance < len){ return true; }//有遮挡
  306. }
  307. }
  308. },
  309. /*
  310. 拖拽时,获取鼠标在拖拽面上的位置(需要借助另一个intersectPlane面来计算,即和相机方向一样的面,可保证铺满屏幕)
  311. 但是不一定能获取到,比如鼠标射线不朝向拖拽面时,即使获取也会是一个意外的反方向的交点。
  312. */
  313. getPosAtPlane : function(pos, info/* , mouse, camera */){ //pos:与intersectPlane的交点 见笔记
  314. var A = pos;
  315. var player = player;
  316. var mouse = player.mouse;
  317. var O = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(player.camera);
  318. if(info.y != void 0){//地面线的
  319. var y = info.y;
  320. if(player.mode == "floorplan"/* || Math.abs(O.x-pos.x)<0.0001 && Math.abs(O.z-pos.z)<0.0001) */){
  321. //intersectPlane和地面平行,无交点
  322. var x = pos.x, z = pos.z;
  323. }else{
  324. if(y<player.camera.position.y && O.y <= A.y /* || y>player.camera.position.y && O.y >= A.y */)return null; //鼠标射线向上。因为相机一定位于地面以上(地面不会抬高到相机上吧?),所以无交点。
  325. if(O.y == A.y){console.log('一样??');return;}
  326. if(A.y == y){console.log('一样2??');return;}
  327. var r = (O.y-y)/(A.y-y);
  328. var x = (r*A.x-O.x)/(r-1);
  329. var z = (r*A.z-O.z)/(r-1);
  330. }
  331. }else{//垂直的也有越过消失点以后反向变化的情况,但使用时影响不大
  332. var N = info.normalVec;
  333. var P = info.pullPos;
  334. if(N.y != 0 ){console.log('N.y != 0');return;} //仅仅支持垂直于地面的的墙壁,目前都是
  335. if(O.z==A.z){console.log('O.z==A.z?');return;}
  336. if(N.z!=0 && N.x != 0){//直接用这个通用的也可以,支持斜线的墙
  337. //console.log('N.z==0 && N.x == 0?');
  338. var c = ( N.x*(A.x-O.x) + N.y*(A.y-O.y) + N.z*(A.z-O.z));
  339. if(c == 0){console.log("分母为0?? return;");return;}
  340. 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
  341. var x = t * (A.x - O.x) + O.x;
  342. var y = t * (A.y - O.y) + O.y;
  343. var z = t * (A.z - O.z) + O.z;
  344. /*原理: 已知空间直线L:(x-a)/m=(x-b)/n=(z-c)/p和空间平面π:Ax+By+Cz+D=0;
  345. 求直线L与平面π的交点的坐标。
  346. 把直线方程改写成参数形式:设(x-a)/m=(x-b)/n=(z-c)/p=t;
  347. 则x=mt+a;y=nt+b;z=pt+c;代入平面π的方程得:
  348. A(mt+a)+B(nt+b)+C(pt+c)+D=0
  349. 由此解得t=-(Aa+Bb+Cc+D)/(Am+Bn+Cp)
  350. 再代入参数方程即得交点的坐标(x,y,z). */
  351. }else if(N.x ==0 ){ //z与pullPos相等
  352. var z = P.z;
  353. if(O.y == A.y){console.log('一样??');return;}
  354. if(A.y == y){console.log('一样2??');return;}
  355. if(A.z == z){console.log('一样3??');return;}
  356. var r = (O.z-z)/(A.z-z);
  357. var x = (r*A.x-O.x)/(r-1);
  358. var y = (r*A.y-O.y)/(r-1);
  359. }else if(N.z == 0){//x与pullPos相等
  360. var x = P.x;
  361. if(O.y == A.y){console.log('一样??');return;}
  362. if(A.y == y){console.log('一样2??');return;}
  363. if(A.x == x){console.log('一样3??');return;}
  364. var r = (O.x-x)/(A.x-x);
  365. var y = (r*A.y-O.y)/(r-1);
  366. var z = (r*A.z-O.z)/(r-1);
  367. }
  368. }
  369. return new THREE.Vector3(x,y,z);
  370. },
  371. getMouseIntersect : function(camera, meshes, mouse){//获取鼠标和meshes交点
  372. var raycaster = new THREE.Raycaster;
  373. camera.updateMatrixWorld();
  374. var origin = new THREE.Vector3(mouse.x,mouse.y,-1).unproject(camera)
  375. , end = new THREE.Vector3(mouse.x,mouse.y,1).unproject(camera);
  376. var dir = end.sub(origin).normalize()
  377. raycaster.set(origin, dir);
  378. var n = raycaster.intersectObjects(meshes);
  379. if (0 === n.length)
  380. return null;
  381. return n[0];
  382. },
  383. ifIntersectChunks : function(A,B,options={}){//获取某个线段/射线和meshes的交点
  384. var dir = B.clone().sub(A).normalize();
  385. var len = options.InfinityLen ? Infinity : A.distanceTo(B) + (options.extLen||0);
  386. var ray = new THREE.Raycaster(A.clone(), dir, 0, len);
  387. var o = ray.intersectObjects(options.model || player.model.colliders);
  388. if (o && o.length)return o;
  389. if(options.throughWidth){ //允许最小宽度,防止穿过极小的缝隙导致撞墙感
  390. var normal = math.getNormal({points:[{x:A.x, y:A.z},{x:B.x, y:B.z}]});//线段法线
  391. normal.multiplyScalar(options.throughWidth)
  392. var normalVec3 = new THREE.Vector3(normal.x, 0, normal.y);
  393. var A2 = A.clone().add(normalVec3)
  394. ray.set(A2, dir);
  395. var o2 = ray.intersectObjects(options.model || player.model.colliders);
  396. ray.set(A.clone().add(normalVec3.negate()), dir);
  397. if (o2 && o2.length)return o2;
  398. var o3 = ray.intersectObjects(options.model || player.model.colliders);
  399. if (o3 && o3.length)return o3;
  400. }
  401. return null;
  402. },
  403. getPosAtSphere : function(pos3d, toPanoPos){
  404. var dir = pos3d.clone().sub(toPanoPos);
  405. dir.normalize();//然后计算在球中
  406. dir.multiplyScalar(Constants.skyRadius);
  407. dir.add(toPanoPos);
  408. return dir;
  409. } ,
  410. getScaleForConstantSize : function(op={}){ //获得规定二维大小的mesh的scale值。可以避免因camera的projection造成的mesh视觉大小改变。 来源:tag.updateDisc
  411. var w;
  412. var i = new THREE.Vector3, o = new THREE.Vector3, l = new THREE.Vector3, c = new THREE.Vector3, h = new THREE.Vector3
  413. if(!op.resolution){
  414. let renderSize = player.sceneRenderer.renderer.getSize()
  415. op.resolution = {x:renderSize.width, y:renderSize.height}
  416. }
  417. if(!op.camera){
  418. let camera = player.cameraControls.activeControl ? player.cameraControls.activeControl.camera : player.camera
  419. let camera2 = camera.clone();
  420. camera2.matrixWorld.copy(player.camera.matrixWorld) //因为其他原因该camera的matrixWorld被还原了,而player.camera的是正确的
  421. op.camera = camera2
  422. }
  423. if(op.width2d) w = op.width2d //如果恒定二维宽度
  424. else{//否则考虑上距离,加一丢丢近大远小的效果
  425. var currentDis, nearBound, farBound
  426. if(op.camera.type == "OrthographicCamera"){
  427. currentDis = (op.camera.right - op.camera.left) / op.camera.zoom
  428. }else{
  429. currentDis = op.position.distanceTo(op.camera.position);
  430. }
  431. w = op.maxSize - ( op.maxSize - op.minSize) * THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
  432. //maxSize : mesh要表现的最大像素宽度; nearBound: 最近距离,若比nearBound近,则使用maxSize
  433. }
  434. i.copy(op.position).project(op.camera), //tag中心在屏幕上的二维坐标
  435. o.set(op.resolution.x / 2, op.resolution.y / 2, 1).multiply(i), //转化成px -w/2 到 w/2的范围
  436. l.set(w / 2, 0, 0).add(o), //加上tag宽度的一半
  437. c.set(2 / op.resolution.x, 2 / op.resolution.y, 1).multiply(l), //再转回 -1 到 1的范围
  438. h.copy(c).unproject(op.camera);//再转成三维坐标,求得tag边缘的位置
  439. let halfMeter = h.distanceTo(op.position)//就能得到tag的三维半径
  440. return halfMeter //可能NAN 当相机和position重叠时
  441. } ,
  442. updateVisible : function(object, reason, ifShow, level=0, type){//当所有加入的条件都不为false时才显示. reason='force'一般是强制、临时的
  443. if(!object.unvisibleReasons) object.unvisibleReasons = []; //如果length>0代表不可见
  444. if(!object.visibleReasons) object.visibleReasons = []; //在同级时,优先可见
  445. var update = function(){
  446. //先按从高到低的level排列
  447. object.unvisibleReasons = object.unvisibleReasons.sort((a,b)=>b.level-a.level)
  448. object.visibleReasons = object.visibleReasons.sort((a,b)=>b.level-a.level)
  449. var maxVisiLevel = object.visibleReasons[0] ? object.visibleReasons[0].level : -1
  450. var maxunVisiLevel = object.unvisibleReasons[0] ? object.unvisibleReasons[0].level : -1
  451. var shouldVisi = maxVisiLevel >= maxunVisiLevel
  452. var visiBefore = object.visible
  453. if(visiBefore != shouldVisi){
  454. object.visible = shouldVisi
  455. object.dispatchEvent({
  456. type: 'isVisible',
  457. visible: shouldVisi,
  458. reason,
  459. })
  460. }
  461. }
  462. if(ifShow){
  463. var index = object.unvisibleReasons.findIndex(e=>e.reason == reason)
  464. if(index > -1){
  465. type = 'cancel'
  466. object.unvisibleReasons.splice(index, 1);
  467. }
  468. if(type == 'add' ){
  469. if(!object.visibleReasons.some(e=>e.reason == reason)){
  470. object.visibleReasons.push({reason,level})
  471. }
  472. }
  473. }else{
  474. var index = object.visibleReasons.findIndex(e=>e.reason == reason)
  475. if(index > -1){
  476. type = 'cancel'
  477. object.visibleReasons.splice(index, 1);
  478. }
  479. if(type != 'cancel' ){
  480. if(!object.unvisibleReasons.some(e=>e.reason == reason)){
  481. object.unvisibleReasons.push({reason,level})
  482. }
  483. }
  484. }
  485. update()
  486. },
  487. getObjVisiByReason : function(object,reason){//获取在某条件下是否可见. 注: 用户在数据集选择可不可见为"datasetSelection"
  488. if(object.visible)return true
  489. else{
  490. return !object.unvisibleReasons || !object.unvisibleReasons.some(e=>e.reason == reason)
  491. }
  492. }
  493. }
  494. window.expandCommon = function(common){
  495. Object.assign(common,{
  496. intervalTool : { //延时update,防止卡顿
  497. list:[],
  498. isWaiting:function(name, func, delayTime/* , autoCycle */){
  499. let item = this.list.find(e=>e.name == name);
  500. if(!item){ //如果没有该项, 则加入循环
  501. let ifContinue = func();
  502. item = {name, func, delayTime};
  503. this.list.push(item);
  504. setTimeout(()=>{
  505. var a = this.list.indexOf(item);
  506. this.list.splice(a,1);
  507. let {func, delayTime} = item;
  508. if(item.requestUpdate || ifContinue ) this.isWaiting(name, func, delayTime); //循环
  509. },delayTime);
  510. }else {//如果有该项,说明现在请求下一次继续更新
  511. //更新属性
  512. item.func = func;
  513. item.delayTime = delayTime;
  514. item.requestUpdate = true;
  515. }
  516. },
  517. },
  518. sortByScore : function(list, request, rank) {
  519. var i = request ? common.filterAll(list, request) : list
  520. return 0 === i.length ? null : i = i.map(function(e) {
  521. let scores = rank.map(function(f){return f(e)}) //add
  522. return {
  523. item: e,
  524. scores,
  525. score: scores.reduce(function(t, i) {
  526. return t + i
  527. }, 0)
  528. }
  529. }).sort(function(e, t) {
  530. return t.score - e.score;
  531. })
  532. },
  533. getVisiblePano : function(positions = [], panos, options={}){//add
  534. var visiblePanos = [];
  535. options.posAtPanos = options.posAtPanos || {}//在不同漫游点的positions
  536. panos.forEach((pano)=>{
  537. if(!pano.isAligned())return;
  538. var A = pano.position.clone();
  539. var posB = options.posAtPanos[pano.id] || positions;
  540. var posLength = posB.length
  541. for(let i=0;i<posLength;i++){
  542. var B = posB[i];
  543. var ray = new THREE.Raycaster(A.clone(), B.clone().sub(A).normalize(), 0, A.distanceTo(B) - (options.tolerance||0) )
  544. var o = ray.intersectObjects(options.model || player.model.colliders, true);
  545. if (!o || !o.length){ //只要有一点可见,就算整体可见
  546. visiblePanos.push(pano.id);
  547. break;
  548. }
  549. }
  550. })
  551. return visiblePanos
  552. } ,
  553. realVisible : function (object) {
  554. var v = true;
  555. var parent = object;
  556. var lastParent;
  557. while (parent) {
  558. if (parent.visible === false) {
  559. v = false;
  560. break
  561. }
  562. lastParent = parent;
  563. parent = parent.parent;
  564. }
  565. if (v && !(lastParent instanceof THREE.Scene)) {
  566. //已被删除
  567. v = false;
  568. }
  569. return v
  570. },
  571. getMaxCubemapSize() {//在renderer创建完前获取
  572. let size = player.sceneRenderer?.renderer?.capabilities.maxCubemapSize
  573. if(size){
  574. return size
  575. }
  576. try {
  577. var e = document.createElement('canvas'),
  578. t = e.getContext('webgl')
  579. t || (t = e.getContext('experimental-webgl'))
  580. var i = t.getParameter(t.MAX_CUBE_MAP_TEXTURE_SIZE)
  581. return i
  582. } catch (e) {
  583. return 0
  584. }
  585. }
  586. })
  587. }
  588. window.expandMath = function(math){
  589. Object.assign(math,{
  590. linearClamp(value, xArr, yArr) {
  591. if (arguments.length == 5) {
  592. xArr = [arguments[1], arguments[2]]
  593. yArr = [arguments[3], arguments[4]]
  594. }
  595. let len = xArr.length
  596. if (value <= xArr[0]) return yArr[0]
  597. if (value >= xArr[len - 1]) return yArr[len - 1]
  598. let i = 0
  599. while (++i < len) {
  600. if (value < xArr[i]) {
  601. let x1 = xArr[i - 1],
  602. x2 = xArr[i],
  603. y1 = yArr[i - 1],
  604. y2 = yArr[i]
  605. value = y1 + ((y2 - y1) * (value - x1)) / (x2 - x1)
  606. break
  607. }
  608. }
  609. return value
  610. },
  611. getBaseLog(x, y) {//返回以 x 为底 y 的对数(即 logx y) . Math.log 返回一个数的自然对数
  612. return Math.log(y) / Math.log(x);
  613. },
  614. getSpreadRatio(n){//n为整数,返回的0-1的数。 目的是获得较为平均的数字,主要用于颜色hue。数字含义:按顺序将1不停平分下去,每刀都切在每段的二分之一处,则第n刀在原先整体的几分之几处
  615. if(n==0)return 0
  616. let k = Math.floor(math.getBaseLog(2,n)) //是2的几次幂
  617. let r = ((n - Math.pow(2,k) ) * 2 + 1)/ Math.pow(2,k+1)
  618. console.log('getSpreadRatio',n,r)
  619. return r
  620. }
  621. })
  622. }
  623. //--------------------------------------
  624. //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
  625. var Manage = function(){
  626. this.weixinURL = "https://res.wx.qq.com/open/js/jweixin-1.2.0.js",
  627. this.time = "?"+new Date().getTime();
  628. this.loadAudio();
  629. // this.loadWeixin();
  630. }
  631. //动态加载js文件
  632. Manage.prototype.LoadJs = function(_files, succes){
  633. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  634. var classcodes = [];
  635. var FileArray = [];
  636. if (typeof _files === "object") {
  637. FileArray = _files;
  638. } else {
  639. /*如果文件列表是字符串,则用,切分成数组*/
  640. if (typeof _files === "string") {
  641. FileArray = _files.split(",");
  642. }
  643. }
  644. if (FileArray != null && FileArray.length > 0) {
  645. var LoadedCount = 0;
  646. for (var i = 0; i < FileArray.length; i++) {
  647. loadFile(FileArray[i], function() {
  648. LoadedCount++;
  649. if (LoadedCount == FileArray.length) {
  650. try {
  651. succes();
  652. }
  653. catch(err) {
  654. console.log("err: 您未定义回调");
  655. }
  656. }
  657. })
  658. }
  659. }
  660. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  661. function loadFile(url, success) {
  662. if (!FileIsExt(classcodes, url)) {
  663. var _ThisType = GetFileType(url);
  664. var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0,_ThisType.indexOf("?"));
  665. var fileObj = null;
  666. if (ThisType == ".js") {
  667. fileObj = document.createElement('script');
  668. fileObj.src = url;
  669. } else if (ThisType == ".css") {
  670. fileObj = document.createElement('link');
  671. fileObj.href = url;
  672. fileObj.type = "text/css";
  673. fileObj.rel = "stylesheet";
  674. } else if (ThisType == ".less") {
  675. fileObj = document.createElement('link');
  676. fileObj.href = url;
  677. fileObj.type = "text/css";
  678. fileObj.rel = "stylesheet/less";
  679. }
  680. success = success || function() {};
  681. fileObj.onload = fileObj.onreadystatechange = function() {
  682. if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
  683. success();
  684. classcodes.push(url)
  685. }
  686. }
  687. document.getElementsByTagName('head')[0].appendChild(fileObj);
  688. } else {
  689. success();
  690. }
  691. }
  692. /*获取文件类型,后缀名,小写*/
  693. function GetFileType(url) {
  694. if (url != null && url.length > 0) {
  695. return url.substr(url.lastIndexOf(".")).toLowerCase();
  696. }
  697. return "";
  698. }
  699. /*文件是否已加载*/
  700. function FileIsExt(FileArray, _url) {
  701. if (FileArray != null && FileArray.length > 0) {
  702. var len = FileArray.length;
  703. for (var i = 0; i < len; i++) {
  704. if (FileArray[i] == _url) {
  705. return true;
  706. }
  707. }
  708. }
  709. return false;
  710. }
  711. };
  712. //获取页面url后面的参数
  713. Manage.prototype.number = function(variable) {
  714. var query = window.location.search.substring(1);
  715. var vars = query.split("&");
  716. for (var i=0;i<vars.length;i++) {
  717. var pair = vars[i].split("=");
  718. if(pair[0] == variable){return pair[1];}
  719. }
  720. return(false);
  721. };
  722. Manage.prototype.loadWeixin = function() {
  723. var that = this;
  724. this.LoadJs(that.weixinURL+that.time,function(){ });
  725. }
  726. Manage.prototype.weixinShare = function() {
  727. console.log({str:"weixinShare",level:1})
  728. $.ajax({
  729. url:'https://www.4dage.com/wechat/jssdk/',
  730. type: "post",
  731. data : {
  732. 'url' : location.href.split('#')[0]
  733. },
  734. dataType:"jsonp",
  735. jsonpCallback:"success_jsonp",
  736. success:function(data, textStatus){
  737. console.log({str:"微信 success,"+data.appId, level:1})
  738. wx.config({
  739. // debug : true,
  740. appId : data.appId,
  741. timestamp : data.timestamp,
  742. nonceStr : data.nonceStr,
  743. signature : data.signature,
  744. jsApiList : [ 'checkJsApi', 'onMenuShareTimeline',
  745. 'onMenuShareAppMessage', 'onMenuShareQQ',
  746. 'onMenuShareWeibo', 'hideMenuItems',
  747. 'showMenuItems', 'hideAllNonBaseMenuItem',
  748. 'showAllNonBaseMenuItem', 'translateVoice',
  749. 'startRecord', 'stopRecord', 'onRecordEnd',
  750. 'playVoice', 'pauseVoice', 'stopVoice',
  751. 'uploadVoice', 'downloadVoice', 'chooseImage',
  752. 'previewImage', 'uploadImage', 'downloadImage',
  753. 'getNetworkType', 'openLocation', 'getLocation',
  754. 'hideOptionMenu', 'showOptionMenu', 'closeWindow',
  755. 'scanQRCode', 'chooseWXPay',
  756. 'openProductSpecificView', 'addCard', 'chooseCard',
  757. 'openCard' ]
  758. });
  759. },
  760. error:function(XMLHttpRequest,textStatus,errorThrown){
  761. console.error({str:"微信分享失败! textStatus:"+textStatus, level:1})
  762. }
  763. });
  764. var success_jsonp = function(json){
  765. console.log({str:"success_jsonp:"+json, level:1});
  766. };
  767. wx.ready(function(){
  768. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  769. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  770. //分享到朋友圈
  771. console.log({str:"微信 ready",level:1})
  772. wx.onMenuShareTimeline({
  773. title: g_weixinObj.title, // 分享标题
  774. link: g_weixinObj.lineLink, // 分享链接
  775. imgUrl: g_weixinObj.imgUrl, // 分享图标
  776. desc: g_weixinObj.desc
  777. });
  778. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  779. wx.onMenuShareAppMessage({
  780. title: g_weixinObj.title, // 分享标题
  781. desc: g_weixinObj.desc, // 分享描述
  782. link: g_weixinObj.lineLink, // 分享链接
  783. imgUrl: g_weixinObj.imgUrl, // 分享图标
  784. type: '', // 分享类型,music、video或link,不填默认为link
  785. dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空
  786. });
  787. wx.onMenuShareWeibo({
  788. title: g_weixinObj.title, // 分享标题
  789. desc: g_weixinObj.desc, // 分享描述
  790. link: g_weixinObj.lineLink, // 分享链接
  791. imgUrl: g_weixinObj.imgUrl, // 分享图标
  792. success: function () {
  793. // 用户确认分享后执行的回调函数
  794. },
  795. cancel: function () {
  796. // 用户取消分享后执行的回调函数
  797. }
  798. });
  799. wx.onMenuShareQZone({
  800. title: g_weixinObj.title, // 分享标题
  801. desc: g_weixinObj.desc, // 分享描述
  802. link: g_weixinObj.lineLink, // 分享链接
  803. imgUrl: g_weixinObj.imgUrl, // 分享图标
  804. success: function () {
  805. // 用户确认分享后执行的回调函数
  806. },
  807. cancel: function () {
  808. // 用户取消分享后执行的回调函数
  809. }
  810. });
  811. wx.onMenuShareQQ({
  812. title: g_weixinObj.title, // 分享标题
  813. desc: g_weixinObj.desc, // 分享描述
  814. link: g_weixinObj.lineLink, // 分享链接
  815. imgUrl: g_weixinObj.imgUrl, // 分享图标
  816. success: function () {
  817. // 用户确认分享后执行的回调函数
  818. },
  819. cancel: function () {
  820. // 用户取消分享后执行的回调函数
  821. }
  822. });
  823. wx.error(function(res){
  824. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  825. });
  826. });
  827. }
  828. Manage.prototype.dealURL = function(src, type){
  829. //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
  830. //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
  831. if(window.isLocal && settings.localPrefix!=void 0){//本地将线上的前缀替换
  832. var oldPrefix = 'super.4dage.com/'; //最简单的地址写一个,如果有其他完全不一样的地址就用数组逐个判断
  833. var index = src.indexOf(oldPrefix);
  834. if(index>-1){
  835. var wholeOldPrefix = src.slice(0, index+oldPrefix.length);
  836. return src.replace(wholeOldPrefix, settings.localPrefix)
  837. }else console.error("没有找到合适的本地链接")
  838. return src
  839. }else{
  840. //add https://
  841. var prefix = g_Prefix.replace('https://','').replace('http://','')
  842. if(!src.includes('http:/') && !src.includes('https:/') && src.includes(prefix)){
  843. src = 'https://'+src
  844. }
  845. return src
  846. }
  847. }
  848. Manage.prototype.removeSrcPostMark = function(url){//去除texture.load时自动加上的'?'
  849. var index = url.indexOf('?')
  850. if(index>-1){
  851. return url.slice(0, index)
  852. }else return url
  853. }
  854. Manage.prototype.showInfo = function (o) { // ({result:true, title:"发布成功"});
  855. var box = $(".resultBox");
  856. var title = o.title || o || i18n.get('保存成功');
  857. box.children().eq(0).html(title)
  858. //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000);
  859. var time = o.time || THREE.Math.clamp(title.length*130 ,1300, 5000);
  860. o.time || console.log("showtime " + time)
  861. //实际有一半的时间在渐变透明度
  862. this.showInfoTimer && clearTimeout(this.showInfoTimer)
  863. box.removeClass("animate");//如果之后不久又要showinfo一个的话,先停止前面的animate
  864. setTimeout(function () {
  865. box.css(
  866. {
  867. '-webkit-animation-duration': time + 'ms',
  868. 'animation-duration': time + 'ms'
  869. }
  870. )
  871. if(o.top){
  872. box.children().css('top', o.top + "%");
  873. }else{
  874. box.children().css('top', '' )
  875. }
  876. box.removeClass("hide");
  877. box.addClass("animate");
  878. if (o.dontInteract) {//遮挡对屏幕的操作
  879. box.css('pointer-events', 'auto')
  880. } else {
  881. box.css('pointer-events', 'none')
  882. }
  883. this.showInfoTimer = setTimeout(function () {
  884. box.removeClass("animate");
  885. box.addClass("hide");
  886. this.showInfoTimer = null;
  887. }.bind(this), time + 20)
  888. }.bind(this), 50)//这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧
  889. }//like: manage.showInfo({title:'a', top:20})
  890. //公用的函数
  891. function getQueryVariable(variable)
  892. {
  893. var query = window.location.search.substring(1);
  894. var vars = query.split("&");
  895. for (var i=0;i<vars.length;i++) {
  896. var pair = vars[i].split("=");
  897. if(pair[0] == variable){return pair[1];}
  898. }
  899. return(false);
  900. }
  901. //隐藏公司Logo
  902. function showLogo(){
  903. $("#myCompany").hide();
  904. $("#loaderCoBrandName").hide();
  905. $("#title-logo").hide();
  906. $(".title-container").css("justify-content","center")
  907. }
  908. // 隐藏顶部介绍
  909. function topTextHide(){
  910. console.log('------------------隐藏顶部');
  911. $('.pinTop').hide()
  912. }
  913. //czj 添加随机的时间
  914. function randomTime(){
  915. return new Date()
  916. };
  917. function matcher(data){
  918. if(!data || !g_version ) return data;
  919. delete data.model.vision_version;
  920. var _data = {
  921. files: {
  922. "templates": ["images/images{{number}}/{{filename}}"]
  923. },
  924. model :{
  925. sid :window.number,
  926. camera_start:
  927. data.model.images && data.model.images.length != 0 ?
  928. {
  929. camera: {
  930. zoom: "-1",
  931. quaternion: [
  932. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  933. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  934. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  935. JSON.parse(data.model.images[0].metadata).camera_quaternion.y
  936. ]
  937. },
  938. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  939. mode: "0"
  940. }
  941. : ''
  942. },
  943. sid: window.number,
  944. hoticon: {
  945. default: "https://super.4dage.com/images/4dagePoint2.png",
  946. higt: "https://super.4dage.com/images/4dagePoint.png"
  947. },
  948. special: "false",
  949. weixinDesc: ""
  950. };
  951. $.extend(true,data,_data)
  952. return data;
  953. }
  954. function hotMatcher(data={}){
  955. //if(!data || !g_version) return data;
  956. if(g_version) {
  957. data.tourAudio = data.audio || {};
  958. }else{
  959. data.tourAudio = {}
  960. }
  961. return data;
  962. }
  963. var GifTexDeal = {
  964. animateObjects : [],
  965. animateTexs : [] ,
  966. addAnimation : function(texture, owner, info, id){
  967. /* if(this.animateObjects.find(e=>
  968. e.texture == texture && !ifSame(info, e.info)
  969. )) */
  970. var animation
  971. var tex = this.animateTexs.find(e=>e.texture == texture)
  972. if(tex){
  973. animation = tex
  974. }else{
  975. animation = {texture,info }
  976. this.animateTexs.push(animation)
  977. this.setRepeart(animation)
  978. }
  979. var object = {
  980. animation, //默认相同的texture对应的info是一样的, 对应一个animation
  981. owner,
  982. }
  983. this.animateObjects.push(object)
  984. return object
  985. },
  986. remove : function(object){
  987. var index = this.animateObjects.indexOf(object)
  988. if(index>-1){
  989. this.animateObjects.splice(index, 1)
  990. if(!this.animateObjects.find(e=>e.animation == object.animation)){
  991. let i = this.animateTexs.indexOf(object.animation)
  992. this.animateTexs.splice(i, 1)
  993. object.animation.texture.repeat.set(1,1)
  994. }
  995. this.stop(object)
  996. }
  997. },
  998. setRepeart : function(animation){
  999. animation.texture.repeat.set(1/animation.info.cellXcount, 1/animation.info.cellYcount)
  1000. },
  1001. start: function(object){
  1002. if(!object || object.started )return;
  1003. object.started = true
  1004. if(object.animation.started)return;
  1005. object.animation.started = true
  1006. var info = object.animation.info
  1007. var count = info.cellXcount * info.cellYcount - (info.voidCount || 0)
  1008. if(count <= 1)return;
  1009. transitions.start( (progress)=>{
  1010. var index = Math.floor((count-1) * progress);
  1011. var indexX = index % info.cellXcount
  1012. var indexY = info.cellYcount - Math.floor(index /info.cellXcount ) - 1; //uv.offset.y是从下到上的
  1013. object.animation.texture.offset.x = indexX / info.cellXcount;
  1014. object.animation.texture.offset.y = indexY / info.cellYcount;
  1015. //console.log(object.id + " : "+ object.texture.offset.toArray())
  1016. } , info.duration * (-1), null,/* ()=>{//done (-1):循环
  1017. object.started = false
  1018. object.texture.offset.x = 0;
  1019. object.texture.offset.y = 0;
  1020. this.start(object)
  1021. }, */ 0 ,null, object.id, "gif_"+object.animation.texture.id);
  1022. },
  1023. stop: function(object){
  1024. if(!object || !object.started)return;
  1025. object.started = false
  1026. //只有该object对应的texture对应的所有object都停止了,才能真的停止动画:
  1027. if(this.animateObjects.find(e=>e.animation == object.animation && e.started)) return;
  1028. transitions.cancelById("gif_"+object.animation.texture.id);
  1029. object.animation.texture.offset.set(0,0)
  1030. object.animation.started = false
  1031. }
  1032. }
  1033. var CloneObject = function(copyObj, result, isSimpleCopy, extraReplace) {
  1034. //isSimpleCopy只复制最外层
  1035. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  1036. if(!copyObj)return copyObj //0 null undefined ''
  1037. result = result || {};
  1038. if (copyObj instanceof Array) {
  1039. /* if (copyObj[0]instanceof Object) {
  1040. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  1041. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  1042. }
  1043. return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object
  1044. return copyObj.map(e=>{
  1045. if(e instanceof Object){
  1046. return CloneObject(e)
  1047. }else return e
  1048. })
  1049. }else{
  1050. if(copyObj.clone instanceof Function ){ //解决一部分
  1051. return copyObj.clone()
  1052. }
  1053. }
  1054. for (var key in copyObj) {
  1055. if (copyObj[key] instanceof Object && !isSimpleCopy)
  1056. result[key] = CloneObject(copyObj[key]);
  1057. else
  1058. result[key] = copyObj[key];
  1059. //如果是函数类同基本数据,即复制引用
  1060. }
  1061. return result;
  1062. }
  1063. ;
  1064. var ifSame = function(object1, object2){
  1065. if(object1 == object2 )return true // 0 != undefined , 0 == ''
  1066. else if(!object1 || !object2) return false
  1067. else if(object1.constructor != object2.constructor){
  1068. return false
  1069. }else if(object1 instanceof Array ) {
  1070. if(object1.length != object2.length)return false;
  1071. var _object2 = object2.slice(0);
  1072. for(let i=0;i<object1.length;i++){
  1073. var u = _object2.find(e=>ifSame(object1[i], e));
  1074. if(u == void 0 && !_object2.includes(u) && !object1.includes(u))return false;
  1075. else{
  1076. let index = _object2.indexOf(u);
  1077. _object2.splice(index,1);
  1078. }
  1079. }
  1080. return true
  1081. }else if(object1.equals instanceof Function ){//复杂数据仅支持这种,其他的可能卡住?
  1082. return object1.equals(object2)
  1083. }else if(typeof object1 == 'number' || typeof object1 == 'string'){
  1084. if(isNaN(object1) && isNaN(object2))return true
  1085. else return object1 == object2
  1086. }else if(typeof object1 == "object"){
  1087. var keys1 = Object.keys(object1)
  1088. var keys2 = Object.keys(object2)
  1089. if(!ifSame(keys1,keys2))return false;
  1090. for(let i in object1){
  1091. var same = ifSame(object1[i], object2[i]);
  1092. if(!same)return false
  1093. }
  1094. return true
  1095. }else{
  1096. console.log('isSame出现例外')
  1097. }
  1098. }
  1099. function initByTHREE(THREE){
  1100. window.bus = new THREE.EventDispatcher();//因为player一开始总是没创建好,所以加一个事件传递器
  1101. THREE.TransitionPass = function ( scene, camera ) {
  1102. this.renderScene = scene;
  1103. this.renderCamera = camera;
  1104. this.coverRenderTarget = new THREE.WebGLRenderTarget( 100, 100, {
  1105. minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter,
  1106. format: THREE.RGBAFormat
  1107. });
  1108. this.coverTex = this.coverRenderTarget.texture;
  1109. this.enabled = false;
  1110. this.oldClearColor = new THREE.Color();
  1111. this.oldClearAlpha = 1;
  1112. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  1113. this.scene = new THREE.Scene();
  1114. this.material = this.getMaskMaterial()
  1115. var copyShader = THREE.CopyShader;
  1116. this.materialCopy = new THREE.ShaderMaterial( {
  1117. uniforms: this.copyUniforms,
  1118. vertexShader: copyShader.vertexShader,
  1119. fragmentShader: copyShader.fragmentShader,
  1120. blending: THREE.NoBlending,
  1121. depthTest: false,
  1122. depthWrite: false,
  1123. transparent: true
  1124. } );
  1125. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), this.material);
  1126. this.quad.frustumCulled = false; // Avoid getting clipped
  1127. this.scene.add( this.quad );
  1128. }
  1129. THREE.TransitionPass.prototype = {//波形扩散,出下一个画面
  1130. constructor: THREE.TransitionPass,
  1131. setSize: function ( width, height ) {
  1132. this.coverRenderTarget.setSize( width, height );
  1133. },
  1134. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  1135. var oldAutoClear = renderer.autoClear;
  1136. renderer.autoClear = false;
  1137. var uniforms = this.quad.material.uniforms
  1138. uniforms.bgTex.value = readBuffer.texture; //更新
  1139. uniforms.coverTex.value = this.coverTex;
  1140. uniforms.progress.value = player.model.skybox.material.uniforms.progress.value//
  1141. uniforms.screenRatio.value = player.domElement.clientWidth / player.domElement.clientHeight;// 使波纹为圆形
  1142. uniforms.screenRatio.value *= uniforms.screenRatio.value
  1143. renderer.render( this.scene, this.camera);
  1144. renderer.autoClear = oldAutoClear;
  1145. },
  1146. start:function(sceneRenderer){
  1147. this.enabled = true
  1148. //draw coverTex
  1149. this.quad.material.uniforms.progress.value = 1;
  1150. sceneRenderer.renderer.render( sceneRenderer.scene, sceneRenderer.camera, this.coverRenderTarget, true );
  1151. },
  1152. stop:function(){
  1153. this.enabled = false
  1154. }
  1155. ,
  1156. getMaskMaterial :function(){
  1157. return new THREE.ShaderMaterial( {
  1158. uniforms: {
  1159. coverTex: {
  1160. type: "t",
  1161. value: null
  1162. },
  1163. bgTex: {
  1164. type: "t",
  1165. value: null
  1166. },
  1167. progress:{
  1168. type: "f",
  1169. value: 0
  1170. },
  1171. screenRatio:{
  1172. type: "f",
  1173. value: 1
  1174. }
  1175. },
  1176. vertexShader: `
  1177. varying vec2 vUv;
  1178. void main()
  1179. {
  1180. vUv = uv;
  1181. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  1182. }
  1183. `,
  1184. fragmentShader: `
  1185. uniform sampler2D coverTex;
  1186. uniform sampler2D bgTex;
  1187. uniform float progress;
  1188. uniform float screenRatio;
  1189. varying vec2 vUv;
  1190. void main() {
  1191. const float maxRadius = 0.708; // sqrt(0.5^2+0.5^2)
  1192. const float minRadius = 0.0 ;
  1193. 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));
  1194. float diff = 0.292; //1.0-maxRadius;
  1195. float radiusIn = maxRadius * progress + minRadius * (1.0-progress);
  1196. float radiusOut = radiusIn + diff;
  1197. if(radius < radiusIn) {
  1198. gl_FragColor = texture2D(bgTex, vUv);
  1199. //gl_FragColor = vec4(0.0,0.0,1.0,1.0);//
  1200. }else if(radius>radiusOut){
  1201. gl_FragColor = texture2D(coverTex, vUv) ;
  1202. //gl_FragColor = vec4(1.0,1.0,0.0,1.0);//
  1203. }else{
  1204. vec4 color1 = texture2D(bgTex, vUv);
  1205. vec4 color2 = texture2D(coverTex, vUv);
  1206. float rotio = smoothstep(radiusIn ,radiusOut,radius);
  1207. gl_FragColor = mix(color1, color2, rotio);
  1208. }
  1209. }
  1210. `
  1211. } );
  1212. },
  1213. }
  1214. Object.assign(Manage.prototype, THREE.EventDispatcher.prototype)
  1215. let labels = []
  1216. class Label2D extends THREE.EventDispatcher{
  1217. constructor(o={}){
  1218. super()
  1219. this.position = o.position
  1220. this.elem = $(o.innerHTML || '<div ><a></a></div>');
  1221. $(o.domElement).append(this.elem)
  1222. this.pos2d = new THREE.Vector3
  1223. this.elem.css({position: 'absolute', 'z-index':999})
  1224. this.clickFun = o.clickFun;
  1225. this.clickFun && this.elem.on('click',this.clickFun.bind(this))
  1226. if(o.autoUpdate){
  1227. let update = (e)=>{if(e.cameraChanged) this.update()}
  1228. player.on("view.changed",update) //确保player存在
  1229. this.addEventListener('dispose', (e)=>{
  1230. player.removeListener("view.changed",update)
  1231. })
  1232. }
  1233. this.visible = true
  1234. this.shelterByModel = o.shelterByModel
  1235. this.floorIndex = o.floorIndex
  1236. labels.push(this)
  1237. if(window.player.model){
  1238. this.init()
  1239. }else{
  1240. let f = ()=>{
  1241. window.bus.removeEventListener('playerAndModelReady',f)
  1242. this.init()
  1243. }
  1244. window.bus.addEventListener('playerAndModelReady',f)
  1245. }
  1246. }
  1247. init(){
  1248. if(this.floorIndex != void 0){
  1249. player.model.on("floor.changed",(currentFloor, mode, oldFloor)=>{
  1250. this.update(currentFloor) //注: currentFloor 这时候还没成为 model.currentFloor
  1251. })
  1252. }
  1253. }
  1254. update(currentFloor){
  1255. if(!this.position)return
  1256. if(!this.visible && this.unvisibleReasons.some(e=>e.level == 1) && !this.unvisibleReasons.some(e=>e.level>1) )return;
  1257. /*
  1258. 规定一下level共四层
  1259. level3 是notTrueSide层,权重最高。
  1260. level2 是强制可见层,如editSelected
  1261. level1 是强制不可见,如isPanorama
  1262. level0 是shelter层
  1263. 其中当visible==false时, 若导致不可见的原因是level1 代表不需要计算直接return, 否则还是要执行update 以计算更新可见性
  1264. 所以外部写的setVisible的level必须>0
  1265. */
  1266. var p = convertTool.getPos2d(this.position);
  1267. if(!p || !p.trueSide){
  1268. return this.setVisible(false, 'notTrueSide', 3, null, true)
  1269. //this.elem.css('display','none'); return;
  1270. }
  1271. this.setVisible(true, 'notTrueSide', 3, null, true)
  1272. this.setVisible(true, 'shelter', 0, null, true)
  1273. //判断label是否被模型遮挡,遮挡则消失(如果是漫游模式最好提前计算visiblePanos)
  1274. if(player.mode != 'panorama'){
  1275. currentFloor = currentFloor || player.model.currentFloor
  1276. if(!player.model.allFloorsVisible && this.floorIndex != void 0 && this.floorIndex!= currentFloor.floorIndex){
  1277. this.setVisible(false, 'shelter', 0, null, true)
  1278. //this.elem.css('display','none'); return;
  1279. if(!this.visible)return
  1280. }
  1281. if(this.shelterByModel && convertTool.ifShelter(this.position , p.vector, player.camera, this.floorIndex )){
  1282. //this.elem.css('display','none'); return;
  1283. this.setVisible(false, 'shelter', 0, null, true)
  1284. if(!this.visible)return
  1285. }
  1286. }
  1287. this.elem.css({
  1288. left: p.pos.x +'px',
  1289. top: p.pos.y +'px'
  1290. })
  1291. /* if(settings.vrEnabled){
  1292. this.elem.css({transform:'rotate('+window.screenFaceOrient+'deg)'})
  1293. }else{
  1294. this.elem.css({transform:''})
  1295. } */
  1296. //this.elem.css('display','block');
  1297. this.pos2d = p.vector;
  1298. }
  1299. setVisible(visi, reason, level=1, type, updating){
  1300. let visiOld = this.visible
  1301. convertTool.updateVisible(this, reason, visi, level, type )
  1302. updating || this.update() //再次更新可见性并计算位置
  1303. this.elem.css('display',this.visible?'block':'none');
  1304. /* if(!this.visible){
  1305. this.elem.css('display','none');
  1306. }else{
  1307. if(!visiOld){
  1308. updating || this.update()
  1309. this.elem.css('display','block');
  1310. }
  1311. } */
  1312. }
  1313. setPos(pos){
  1314. this.position = pos;
  1315. this.update()
  1316. }
  1317. dispose(){
  1318. this.elem.remove();
  1319. this.dispatchEvent({type:'dispose'})
  1320. let index = labels.indexOf(this)
  1321. index > -1 && labels.splice(index,1)
  1322. }
  1323. }
  1324. window.Label2D = Label2D
  1325. class RoomLabel extends Label2D{
  1326. constructor(o){
  1327. if(o.position instanceof Array) o.position = new THREE.Vector3().fromArray(o.position)
  1328. o.innerHTML = `<div class="room-label" ><a><p><span>${o.title}</span></p></a></div>`
  1329. o.domElement = $(".widgets-doll-labels")[0]
  1330. o.shelterByModel = true , o.autoUpdate = true
  1331. o.clickFun = ()=>{
  1332. if(player.roomLebelClickUnabled)return
  1333. let result = common.sortByScore(player.model.floors.index[this.floorIndex].panos, [], [(pano)=>{
  1334. return -pano.position.distanceToSquared(this.position)
  1335. }]);
  1336. let pano = result && result[0] && result[0].item
  1337. if(pano){
  1338. const minDisSquard = 200
  1339. if(pano.position.distanceToSquared(this.position) > minDisSquard){
  1340. pano = null
  1341. }
  1342. }
  1343. if(pano){
  1344. player.flyToPano({
  1345. pano
  1346. })
  1347. }else{
  1348. player.focusPoint({aim: this.position, radius: 20, dur:1000})
  1349. }
  1350. }
  1351. super(o)
  1352. this.setTitle(o.title )
  1353. }
  1354. init(){
  1355. super.init()
  1356. //飞入后不可见
  1357. player.on("mode.changing",(oldMode, mode, pano, duration)=>{//准备飞
  1358. this.setStyle(oldMode, mode, duration)
  1359. })
  1360. this.setStyle()
  1361. }
  1362. setStyle(oldMode, mode, duration){
  1363. if(!mode) mode = player.modeTran.split('-')[1] || player.mode //要变成的mode或当前mode
  1364. if(mode == 'panorama'){
  1365. this.setVisible(false, 'isPanorama', 1)
  1366. }else if(oldMode == 'panorama'){
  1367. setTimeout(()=>{
  1368. this.setVisible(true, 'isPanorama', 1)
  1369. },duration*0.7)
  1370. }
  1371. }
  1372. setTitle(title){
  1373. this.title = title || ''
  1374. this.elem.html(`<a><p><span>${this.title}</span></p></a>`)
  1375. }
  1376. setEditSelect(state){//编辑页面用
  1377. this.editing = !!state
  1378. this.setVisible(state, 'editSelected', 2, state ? 'add':'cancel') //强制可见
  1379. }
  1380. }
  1381. window.RoomLabel = RoomLabel
  1382. class HistoryRecord extends THREE.EventDispatcher{
  1383. constructor(o){
  1384. super()
  1385. this.undoList = []
  1386. this.redoList = []
  1387. this.applyData = o.applyData //应用数据的方法
  1388. this.getData = o.getData //获取数据的方法
  1389. this.dataBefore
  1390. window.addEventListener('keydown',(e)=>{
  1391. if(e.keyCode == 90 && e.ctrlKey){//Z
  1392. this.undo()
  1393. }else if(e.keyCode == 89 && e.ctrlKey){//Y
  1394. this.redo()
  1395. }
  1396. })
  1397. }
  1398. undo(){//回退
  1399. let length = this.undoList.length
  1400. if(length>0){
  1401. let unExist
  1402. let last = this.undoList.pop();
  1403. this.applyData && (unExist = !this.applyData(last.before))
  1404. unExist || this.redoList.push(last);
  1405. unExist && this.undo()//找不到就回退下一个。
  1406. this.dispatchEvent('undo')
  1407. //console.log('undo',last)
  1408. }
  1409. }
  1410. redo(){//撤销回退
  1411. let length = this.undoList.length
  1412. let last = this.redoList.pop();
  1413. if(last){
  1414. //注意:每行的顺序不能乱
  1415. this.undoList.push(last)
  1416. this.applyData && this.applyData(last.after)
  1417. this.dispatchEvent('redo')
  1418. //console.log('redo',last)
  1419. }
  1420. }
  1421. beforeChange(o){//在变化之前(可能执行好几次直到变化完,但只有第一次有效)。 o的内容完全根据getData怎么定义
  1422. if(!this.dataBefore){
  1423. let data = this.getData(o)
  1424. data && (this.dataBefore = data)
  1425. }
  1426. }
  1427. afterChange(o){//变化结束,从beforeChange到此算一次操作。
  1428. if(this.dataBefore){
  1429. this.writeIn({before:this.dataBefore, after:this.getData(o)} ) //写入某物体变化前和变化后的状态
  1430. this.dataBefore = null
  1431. }
  1432. }
  1433. writeIn(data ){
  1434. this.redoList.length = 0; //一旦录入新的操作,就不允许undo了
  1435. this.undoList.push(data );
  1436. //console.log('新增undo', data)
  1437. }
  1438. clear(){
  1439. this.redoList.length = 0
  1440. this.undoList.length = 0
  1441. this.dataBefore = null
  1442. }
  1443. }
  1444. window.HistoryRecord = HistoryRecord
  1445. let planeGeo = new THREE.PlaneBufferGeometry(1, 1, 1, 1)
  1446. class TextSprite extends THREE.Object3D {
  1447. constructor(options = {}) {
  1448. super()
  1449. let map = new THREE.Texture()
  1450. this.root = options.root || this
  1451. this.sprite = new THREE.Mesh(
  1452. planeGeo,
  1453. new THREE.MeshBasicMaterial({
  1454. map,
  1455. color: 0xffffff,
  1456. transparent: true,
  1457. depthTest: false,
  1458. depthWrite: false,
  1459. })
  1460. )
  1461. this.add(this.sprite)
  1462. this.sprite.renderOrder = options.renderOrder != void 0 ? options.renderOrder : 2
  1463. this.fontWeight = options.fontWeight == void 0 ? /* 'Bold' */ '' : options.fontWeight
  1464. this.rectBorderThick = options.rectBorderThick || 0
  1465. this.textBorderThick = options.textBorderThick || 0
  1466. this.fontface = 'Arial'
  1467. this.fontsize = options.fontsize || 16
  1468. this.textBorderColor = options.textBorderColor || { r: 0, g: 0, b: 0, a: 0.0 }
  1469. this.backgroundColor = options.backgroundColor || { r: 255, g: 255, b: 255, a: 1.0 }
  1470. this.textColor = options.textColor || { r: 0, g: 0, b: 0, a: 1.0 }
  1471. this.borderColor = options.borderColor || { r: 0, g: 0, b: 0, a: 0.0 }
  1472. this.borderRadius = options.borderRadius == void 0 ? 6 : options.borderRadius
  1473. this.margin = options.margin
  1474. this.textshadowColor = options.textshadowColor
  1475. this.name = options.name
  1476. this.sizeInfo = options.sizeInfo
  1477. this.addEventListener('dispose', this.dispose.bind(this))
  1478. this.fixOrient = options.fixOrient
  1479. this.events = {
  1480. updatePose: (e)=>{
  1481. e.cameraChanged && this.updatePose()
  1482. },
  1483. }
  1484. player.on("view.changed", this.events.updatePose)
  1485. this.addEventListener('isVisible', e => {
  1486. if (e.visible) {
  1487. this.updatePose()
  1488. }
  1489. })
  1490. if (options.text != void 0) this.setText(options.text)
  1491. setTimeout(()=>{
  1492. this.updatePose()
  1493. },1)
  1494. }
  1495. updatePose() {
  1496. //if (lastFrameChanged) this.needsUpdate = true
  1497. if (!common.realVisible(this) /* || !this.needsUpdate */) return
  1498. //this.needsUpdate = false
  1499. let camera = player.mode == 'floorplan' ? player.cameraControls.activeControl.camera : player.camera //floorplan 时要用到OrthographicCamera
  1500. if (!this.fixOrient) {
  1501. let parentQua = this.root.parent.getWorldQuaternion(new THREE.Quaternion())
  1502. this.root.quaternion.multiplyQuaternions(parentQua.inverse(), camera.quaternion) //乘上parentQua.invert()是为了中和掉父结点的qua,使只剩下camera.quaternion
  1503. }
  1504. if (this.sizeInfo) {
  1505. var s = convertTool.getScaleForConstantSize(
  1506. Object.assign(
  1507. {
  1508. },
  1509. this.sizeInfo,
  1510. {
  1511. farBound: player.mode == 'floorplan' ? this.sizeInfo.farBoundPlan || this.sizeInfo.farBound : this.sizeInfo.farBound,
  1512. position: this.root.getWorldPosition(new THREE.Vector3()),
  1513. }
  1514. )
  1515. )
  1516. this.scale.set(s, s, s)
  1517. }
  1518. }
  1519. setText(text) {
  1520. if (this.text !== text) {
  1521. if (!(text instanceof Array)) {
  1522. this.text = [text + '']
  1523. } else this.text = text
  1524. this.updateTexture()
  1525. this.needsUpdate = true
  1526. }
  1527. }
  1528. setPos(pos) {
  1529. this.position.copy(pos)
  1530. this.needsUpdate = true //updatePose
  1531. }
  1532. setTextColor(color) {
  1533. this.textColor = color
  1534. this.updateTexture()
  1535. }
  1536. setBorderColor(color) {
  1537. this.borderColor = color
  1538. this.updateTexture()
  1539. }
  1540. setBackgroundColor(color) {
  1541. this.backgroundColor = color
  1542. this.updateTexture()
  1543. }
  1544. setVisible(v) {
  1545. this.visible = v
  1546. }
  1547. setUniforms(name, value) {
  1548. this.sprite.setUniforms(name, value)
  1549. }
  1550. updateTexture() {
  1551. let canvas = document.createElement('canvas')
  1552. let context = canvas.getContext('2d')
  1553. context.font = this.fontWeight + ' ' + this.fontsize + 'px ' + this.fontface
  1554. //context["font-weight"] = 100; //语法与 CSS font 属性相同。
  1555. // get size data (height depends only on font size)
  1556. //this.text = 'f 啊啊啊 jg'
  1557. let textMaxWidth = 0,
  1558. infos = []
  1559. for (let text of this.text) {
  1560. let metrics = context.measureText(text)
  1561. let textWidth = metrics.width
  1562. infos.push(metrics)
  1563. textMaxWidth = Math.max(textMaxWidth, textWidth)
  1564. }
  1565. let margin = this.margin || new THREE.Vector2(this.fontsize, Math.max(this.fontsize * 0.4, 10))
  1566. const lineSpace = (this.fontsize + margin.y) * 0.5
  1567. let spriteWidth = 2 * margin.x + textMaxWidth + 2 * this.rectBorderThick
  1568. let spriteHeight = 2 * margin.y + this.fontsize * this.text.length + 2 * this.rectBorderThick + lineSpace * (this.text.length - 1)
  1569. context.canvas.width = spriteWidth
  1570. context.canvas.height = spriteHeight
  1571. context.font = this.fontWeight + ' ' + this.fontsize + 'px ' + this.fontface
  1572. let expand = Math.max(1, Math.pow(this.fontsize / 12, 1.4)) // 针对英文大部分在baseLine之上所以降低一点,或者可以识别当不包含jgqp时才加这个值
  1573. //canvas原点在左上角
  1574. context.textBaseline = 'alphabetic' // "middle" //设置文字基线。当起点y设置为0时,只有该线以下的部分被绘制出来。middle时文字显示一半(但是对该字体所有字的一半,有的字是不一定显示一半的,尤其汉字),alphabetic时是英文字母的那条基线。
  1575. // border color
  1576. context.strokeStyle = 'rgba(' + this.borderColor.r + ',' + this.borderColor.g + ',' + this.borderColor.b + ',' + this.borderColor.a + ')'
  1577. context.lineWidth = this.rectBorderThick
  1578. // background color
  1579. context.fillStyle = 'rgba(' + this.backgroundColor.r + ',' + this.backgroundColor.g + ',' + this.backgroundColor.b + ',' + this.backgroundColor.a + ')'
  1580. this.roundRect(context, this.rectBorderThick / 2, this.rectBorderThick / 2, spriteWidth - this.rectBorderThick, spriteHeight - this.rectBorderThick, this.borderRadius)
  1581. context.fillStyle = 'rgba(' + this.textColor.r + ',' + this.textColor.g + ',' + this.textColor.b + ',' + this.textColor.a + ')'
  1582. let y = margin.y
  1583. for (let i = 0; i < this.text.length; i++) {
  1584. //let actualHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent // 当前文本字符串在这个字体下用的实际高度
  1585. //文字y向距离从textBaseline向上算
  1586. let actualBoundingBoxAscent = infos[i].actualBoundingBoxAscent == void 0 ? this.fontsize * 0.8 : infos[i].actualBoundingBoxAscent //有的流览器没有。只能大概给一个
  1587. y += actualBoundingBoxAscent + expand
  1588. //console.log(actualBoundingBoxAscent)
  1589. //console.log(this.text, 'y' , y, 'actualBoundingBoxAscent', metrics.actualBoundingBoxAscent,'expand',expand )
  1590. let textLeftSpace = (textMaxWidth - infos[i].width) / 2
  1591. let x = this.rectBorderThick + margin.x + textLeftSpace
  1592. // text color
  1593. if (this.textBorderThick) {
  1594. context.strokeStyle = 'rgba(' + this.textBorderColor.r + ',' + this.textBorderColor.g + ',' + this.textBorderColor.b + ',' + this.textBorderColor.a + ')'
  1595. context.lineWidth = this.textBorderThick
  1596. context.strokeText(this.text[i], x, y)
  1597. }
  1598. if (this.textshadowColor) {
  1599. context.shadowOffsetX = 0
  1600. context.shadowOffsetY = 0
  1601. context.shadowColor = this.textshadowColor
  1602. context.shadowBlur = 0.3 * this.fontsize
  1603. }
  1604. context.fillText(this.text[i], x, y)
  1605. y += lineSpace
  1606. }
  1607. let texture = new THREE.Texture(canvas)
  1608. texture.minFilter = THREE.LinearFilter
  1609. texture.magFilter = THREE.LinearFilter
  1610. texture.anisotropy = 4
  1611. texture.needsUpdate = true
  1612. //this.material.needsUpdate = true;
  1613. if (this.sprite.material.map) {
  1614. this.sprite.material.map.dispose()
  1615. }
  1616. this.sprite.material.map = texture
  1617. this.sprite.scale.set(spriteWidth * 0.01, spriteHeight * 0.01, 1.0)
  1618. }
  1619. roundRect(ctx, x, y, w, h, r) {
  1620. ctx.beginPath()
  1621. ctx.moveTo(x + r, y)
  1622. ctx.lineTo(x + w - r, y)
  1623. ctx.arcTo(x + w, y, x + w, y + r, r) //圆弧。前四个参数同quadraticCurveTo
  1624. //ctx.quadraticCurveTo(x + w, y, x + w, y + r); //二次贝塞尔曲线需要两个点。第一个点是用于二次贝塞尔计算中的控制点,第二个点是曲线的结束点。
  1625. ctx.lineTo(x + w, y + h - r)
  1626. ctx.arcTo(x + w, y + h, x + w - r, y + h, r)
  1627. ctx.lineTo(x + r, y + h)
  1628. ctx.arcTo(x, y + h, x, y + h - r, r)
  1629. ctx.lineTo(x, y + r)
  1630. ctx.arcTo(x, y, x + r, y, r)
  1631. ctx.closePath()
  1632. ctx.fill()
  1633. ctx.stroke()
  1634. }
  1635. dispose() {
  1636. this.sprite.material.map.dispose()
  1637. this.sprite.material.dispose()
  1638. this.parent && this.parent.remove(this)
  1639. this.sprite.dispatchEvent({ type: 'dispose' })
  1640. this._listeners = []
  1641. this.events.updatePos && player.removeEventListener('view.changed', this.events.updatePose)
  1642. }
  1643. }
  1644. window.TextSprite = TextSprite
  1645. /* class VideoPlayer extends THREE.EventDispatcher{
  1646. constructor(player) {
  1647. super()
  1648. this.instances = new Map()
  1649. this.isFlv = false
  1650. }
  1651. addVideo(src) {
  1652. let video = this._createVideo(src)
  1653. this.instances.set(src, video)
  1654. return video
  1655. }
  1656. getVideo(src) {
  1657. let video = this.instances.get(src)
  1658. if (!video) {
  1659. video = this.addVideo(src)
  1660. }
  1661. return video
  1662. }
  1663. _createVideo(src) {
  1664. let video = document.createElement('video')
  1665. video.setAttribute('crossOrigin', 'anonymous')
  1666. video.setAttribute('playsinline', 'true')
  1667. video.setAttribute('x5-playsinline', 'true')
  1668. video.setAttribute('webkit-playsinline', 'true')
  1669. video.setAttribute('x5-video-player-type', 'h5')
  1670. video.setAttribute('controls', 'true')
  1671. video.setAttribute('controlslist', 'nodownload')
  1672. video.setAttribute('preload', 'meta') //注意,src赋值就会自动加载, preload="meta" 只加载元数据,提高加载速度,否则一开始卡
  1673. video.autoplay = false
  1674. video.muted = true
  1675. video.loop = true
  1676. video.style.position = 'fixed'
  1677. video.style.left = '0'
  1678. video.style.top = '0'
  1679. video.style.zIndex = '1000'
  1680. video.style.width = '200px'
  1681. video.style.display = 'none'
  1682. //document.body.appendChild(video)
  1683. //video.style.display = browser.urlHasValue('debug') ? 'block' : 'none'
  1684. video.src = src
  1685. if(this.isFlv) this.attachFlv(video)
  1686. return video
  1687. }
  1688. attachFlv(video){ 四维看看的会把视频转码成flv和mp4存在服务器, 但是大场景不会,所以安卓(如vivo)加载不了。flv必须用flvjs播放,且苹果有的支持不了
  1689. if(video.flvjsPlayer)return
  1690. let player = flvjs.createPlayer({ type: 'flv', url: video.src }) //需要是flv格式才行
  1691. player.videoElement = video
  1692. player.attachMediaElement(video)
  1693. player.on(flvjs.Events.ERROR, this._onPlayerError.bind(this))
  1694. player.load()
  1695. video.flvjsPlayer = player;
  1696. }
  1697. _onPlayerError() {
  1698. console.warn('视频加载失败')
  1699. }
  1700. changeTypeToFlv(){
  1701. this.isFlv = true
  1702. for(let [key,value] of this.instances){
  1703. this.attachFlv(value)
  1704. }
  1705. }
  1706. } */
  1707. window.initRouteArrow = ()=>{
  1708. if(window.isEdit)return
  1709. if(!window.DATA.route?.data || Object.keys(window.DATA.route.data).length == 0)return
  1710. let {hide, gradualShow, opacityShine, data={}} = window.DATA.route || {} //hide 默认是否隐藏,若隐藏也可以通过函数展示
  1711. let panos = player.model.panos
  1712. panos.routeNextMap = {} //下一个
  1713. panos.routePreMap = {} //上一个
  1714. panos.list.forEach((pano,i)=>{
  1715. panos.routePreMap[pano.id] = []
  1716. panos.routeNextMap[pano.id] = data[pano.id] ? data[pano.id].map(id=>panos.get(id)) : []
  1717. })
  1718. for(let panoId in data){
  1719. data[panoId].forEach(id=>{
  1720. panos.routePreMap[id].push(panos.get(panoId))
  1721. })
  1722. }
  1723. var arrowInfo = {
  1724. animateDur : 5000,
  1725. showDur: 1000,
  1726. minOpa: 0.2,
  1727. maxOpa: 0.5
  1728. }
  1729. let arrowTex = Texture.load('images/arrow.png')
  1730. arrowTex.anisotropy = 4
  1731. let arrowMat = new THREE.MeshBasicMaterial({
  1732. name: 'arrow',
  1733. transparent:true,
  1734. map:arrowTex,
  1735. side:2,
  1736. opacity: arrowInfo.maxOpa,
  1737. //depthTest:false
  1738. depthWrite:false, //防止和导览路线重叠闪烁
  1739. })
  1740. let mats = {
  1741. default: arrowMat,
  1742. fadeIn: arrowMat.clone()
  1743. }
  1744. mats.fadeIn.name = 'fadeInArrow'
  1745. let plane = new THREE.PlaneBufferGeometry(1,1)
  1746. let arrows = new THREE.Object3D; arrows.name = 'groundArrows'
  1747. player.model.add(arrows)
  1748. var createArrow = function(mat){
  1749. var arrow = new THREE.Mesh(plane, mat)
  1750. arrow.name = 'arrow'
  1751. let s = 0.15
  1752. arrow.scale.set(s,s,s)
  1753. arrows.add(arrow)
  1754. return arrow
  1755. }
  1756. var updateArrowPose = function(from, to, mat ){
  1757. var vec = to.floorPosition.clone().clone().sub(from.floorPosition).setY(0);
  1758. let spaceDis = 0.4//箭头之间的间距
  1759. let margin = 0.3 //marker端需要留一点距离
  1760. let sliceCount = Math.max(2, Math.round((vec.length()-margin) / spaceDis)) //分段
  1761. let arrowCount = sliceCount - 1
  1762. let dir = vec.clone().normalize()
  1763. let dir2d = new THREE.Vector2(dir.x, dir.z)
  1764. let angle = dir2d.angle() - Math.PI/2
  1765. let sliceLen = (vec.length()-margin) / sliceCount
  1766. let i = arrowCount
  1767. while(i>0){
  1768. let pos = from.floorPosition.clone().add(dir.clone().multiplyScalar(margin/2 + i*sliceLen))
  1769. pos.y+=settings.markerHeight
  1770. let arrow = createArrow(mat)
  1771. arrow.name = 'arrow:'+from.id+"-"+to.id+"|"+i
  1772. arrow.rotation.set(Math.PI/2, 0, angle);
  1773. arrow.position.copy(pos)
  1774. i--
  1775. }
  1776. }
  1777. var updateArrowOpacity = function(e){//不停更新所有arrow的透明度
  1778. var transition = function(a){
  1779. if(!arrows.visible)return
  1780. var opa = a > 0.5 ? 2-a*2 : 2*a ;
  1781. opa = arrowInfo.maxOpa*opa+ arrowInfo.minOpa*(1-opa)
  1782. mats.default.opacity = opa
  1783. mats.fadeIn.opacity = opa * mats.fadeIn.opacity2
  1784. }
  1785. transitions.start(transition, arrowInfo.animateDur, updateArrowOpacity, 0, easing.easeInOutCubic, "updateArrowOpacity")
  1786. }
  1787. var fadeInArrow = function(){
  1788. transitions.cancelById('updateArrowOpacity2')
  1789. var arrows_ = arrows.children.filter(e=> e.material == mats.fadeIn)
  1790. if(arrows_.length == 0)return
  1791. mats.fadeIn.opacity = 0
  1792. var transition = function(a){
  1793. if(!opacityShine) mats.fadeIn.opacity = a * arrowInfo.maxOpa
  1794. else mats.fadeIn.opacity2 = a
  1795. }
  1796. transitions.start(transition, arrowInfo.showDur, function done(){
  1797. arrows_.forEach(e=>e.material = mats.default)
  1798. }, 0, easing.easeInOutCubic, "updateArrowOpacity", "updateArrowOpacity2")
  1799. }
  1800. var lastArrowPanos = []
  1801. var updateArrow = function(){//根据当前pano更新
  1802. if(player.mode != 'panorama' || hide){ //飞出
  1803. arrows.visible = false
  1804. lastArrowPanos = []
  1805. return;
  1806. }
  1807. arrows.visible = true
  1808. let currentPano = player.currentPano
  1809. //先获取所有需要箭头的pano
  1810. var maxDistance = 6;//该距离内pano可见箭头
  1811. var maxPathCount = 8;
  1812. var dis = 0
  1813. var curPano = currentPano;
  1814. var panos_ = [];
  1815. var getAngle = function(pano1,pano2){
  1816. let dir = new THREE.Vector3().subVectors(pano1.position,pano2.position)
  1817. dir = new THREE.Vector2(dir.x, dir.z)
  1818. return dir.angle()
  1819. }
  1820. var search = function(pano, path=[pano], angles=[]){//多分支搜寻
  1821. var neighbor = panos.routeNextMap[pano.id];
  1822. if(!neighbor || !neighbor.length)return //path.length>1 && console.log('branchPath',path);
  1823. neighbor.forEach(e=>{
  1824. let branchPath = path.slice(), angles_ = angles.slice()
  1825. if(panos_.find(arr=>arr[0]==e))return //console.log('不回头branchPath',branchPath); //不回头
  1826. dis = e.floorPosition.distanceTo(currentPano.floorPosition)
  1827. branchPath.push(e)
  1828. if(branchPath.length>2){//不折回,否则感觉在面前饶了一圈回来很难看
  1829. let i=0
  1830. while(i<branchPath.length-1){ //补全angles
  1831. if(angles_[i] == void 0){
  1832. angles_[i] = getAngle(branchPath[i], branchPath[i+1])
  1833. }
  1834. i++
  1835. }
  1836. let lastAngle = angles_[branchPath.length-2]//getAngle(branchPath[i], e)
  1837. let reverse = angles_.find((angle, n)=> {
  1838. let angleDiff = Math.abs(( lastAngle - angle) % (Math.PI*2) ) //越远限制越大
  1839. let minDiff = math.linearClamp(branchPath.length,[3,6],[0.2,0.5])
  1840. if(Math.abs(angleDiff - Math.PI ) < minDiff){
  1841. //console.log('因为折回而提前结束', n, branchPath)
  1842. return true
  1843. }
  1844. })
  1845. if(reverse != void 0){
  1846. return
  1847. }
  1848. }
  1849. if(branchPath.length<3 || dis < maxDistance){
  1850. panos_.push([pano, e])
  1851. search(e, branchPath, angles_)
  1852. }else{
  1853. //console.log('branchPath',branchPath)
  1854. }
  1855. })
  1856. }
  1857. //search(currentPano)
  1858. let disMap = new Map, cosMap = new Map
  1859. let camDir = player.getDirection()
  1860. let neighbors = currentPano.neighbourUUIDs.map(e=>panos.get(e))
  1861. .filter(p=>{
  1862. let dir = new THREE.Vector3().subVectors(p.position, currentPano.position)
  1863. let d = dir.lengthSq()
  1864. if(d < 15){//最大距离
  1865. disMap.set(p, d);
  1866. cosMap.set(p, dir.normalize().dot(camDir))
  1867. return true
  1868. }
  1869. }).sort((a,b)=>{
  1870. let score = disMap.get(a) - disMap.get(b)
  1871. score += (cosMap.get(b) - cosMap.get(a)) * 5
  1872. return score
  1873. })//从近到远,尽量在前方
  1874. let seedPanos = [currentPano, ...neighbors]//如果没有从当前点出发的箭头,就展示隔壁点的(缺点是隔壁点可能是指向当前点的,原规则是不展示来的路径的,所以会有点奇怪。虽然也可以在search后剔除啦)
  1875. for(let seed of seedPanos){
  1876. search(seed)
  1877. if(panos_.length != 0){
  1878. break;
  1879. }
  1880. }
  1881. arrows.children.slice().forEach(child=>arrows.remove(child))
  1882. panos_.forEach((panoArr,i)=>{
  1883. var isNew = !lastArrowPanos.find(e=>e[0]==panoArr[0] && e[1]==panoArr[1])//新出现的点 渐变出现
  1884. updateArrowPose(panoArr[0], panoArr[1], isNew ? mats.fadeIn : mats.default )//更新位置
  1885. })
  1886. fadeInArrow()
  1887. lastArrowPanos = panos_
  1888. }
  1889. let inited
  1890. let init = ()=>{
  1891. if(inited)return
  1892. if(gradualShow){
  1893. player.on("flying.ended", updateArrow )
  1894. }else{
  1895. //展示全部
  1896. for(let id1 in panos.routeNextMap){
  1897. for(let pano2 of panos.routeNextMap[id1]){
  1898. updateArrowPose(panos.get(id1), pano2, mats.default)
  1899. }
  1900. }
  1901. player.on("mode.changed", ()=>{
  1902. if(hide)return
  1903. arrows.visible = player.mode == 'panorama'
  1904. })
  1905. }
  1906. opacityShine && updateArrowOpacity()
  1907. inited = true
  1908. }
  1909. {//ui控制显示
  1910. let changeShow = (e)=>{
  1911. hide = !e.show
  1912. e.show && init()
  1913. gradualShow ? updateArrow() : (arrows.visible = e.show)
  1914. }
  1915. player.on('changeArrowShow',changeShow)
  1916. changeShow({show:!hide})
  1917. }
  1918. }
  1919. {
  1920. let f = ()=>{
  1921. window.bus.removeEventListener('playerAndModelReady',f)
  1922. player.on("mode.changing",(currentMode, mode, pano, duration)=>{
  1923. let noLine = mode == 'floorplan';
  1924. if(noLine){
  1925. $('.widgets-doll-labels').addClass('noLine').addClass('noCorner')
  1926. }else{
  1927. $('.widgets-doll-labels').removeClass('noLine').removeClass('noCorner')
  1928. }
  1929. })
  1930. player.on("view.changed",(e)=>{
  1931. if(e.cameraChanged){
  1932. //if(needUpdateZIndex){ //如果某个label显示时需要更新index的话,加个参数
  1933. let label_ = labels.filter(e=>e.elem[0].style.display == 'block')
  1934. label_.sort((a,b)=>b.pos2d.z - a.pos2d.z)
  1935. label_.forEach((e,index)=>e.elem.css('z-index', index+1000));
  1936. //}
  1937. }
  1938. })
  1939. player.model.hotGroup.children.length ? logSth() : player.on('gotHotAndStartload',logSth);
  1940. /* {//如果是flv格式的话
  1941. window.videoPlayer = new VideoPlayer()
  1942. if(browser.detectAndroidMobile()){//安卓常常播放不了
  1943. let scriptdom = document.querySelector('#flvJs')
  1944. if(scriptdom){
  1945. scriptdom.src = 'js/lib/flv.min.js'
  1946. scriptdom.onload = ()=>{
  1947. window.videoPlayer.changeTypeToFlv()
  1948. window.bus.dispatchEvent('VideoPlayerReady' )
  1949. //Hot.startLoad()
  1950. }
  1951. }
  1952. }
  1953. } */
  1954. initRouteArrow()
  1955. browser.urlHasValue('panoLabel') && player.model.panos.forEach(p=>p.addLabel())
  1956. /* if(number == 'SG-LF0SeEdxWjv'){ //---如果要将其中一块chunk提取出来成为单独的floor(或说在该楼层隐藏)的话
  1957. let roof = new player.model.floors.list[0].constructor(player.model, 2);//放在第三层
  1958. roof.build()
  1959. roof.addChunk(player.model.floors.list[0].chunks[1])
  1960. player.model.floors.add(roof)
  1961. player.model.floors.list[0].chunks.splice(1,1)
  1962. } */
  1963. if(settings.extractFloor){
  1964. let data = settings.extractFloor[number]
  1965. if(data){
  1966. setTimeout(()=>{
  1967. let roof = new player.model.floors.list[0].constructor(player.model, player.model.floors.length);//放在第三层 隐藏起来
  1968. roof.build()
  1969. player.model.floors.add(roof)
  1970. for(let i=0;i<data.length;i++){
  1971. let chunk = player.model.chunks[data[i]]
  1972. let oldFloor = chunk.parent
  1973. roof.addChunk(chunk)
  1974. let index = oldFloor.chunks.indexOf(chunk)
  1975. oldFloor.chunks.splice(index,1)
  1976. }
  1977. },10)
  1978. }
  1979. }
  1980. {//根据漫游点切换音频
  1981. let curAudio
  1982. let bgmObject = SoundManager.list.find(e=>e.name == 'bgm')
  1983. let setCurBgm = (pano)=>{
  1984. if(!window.DATA.panoAreas)return
  1985. let item = window.DATA.panoAreas.find(e=>e.panos.some(a=>a == pano.id))
  1986. let areaAudio = item?.audio && item.audio[1]
  1987. if(areaAudio != curAudio ){
  1988. let canPlay = !bgmObject.audio.paused || bgmObject.canplay() && !(SoundManager.currentAudio && SoundManager.currentAudio != bgmObject && SoundManager.currentAudio.src) //没有其他音频在播放的话就可以播 //!pl
  1989. SoundManager.setSrc('bgm', areaAudio || window.DATA.backgroundMusic, areaAudio ? (item.name +':'+item.audio[0]) : '全局背景音')
  1990. curAudio = areaAudio
  1991. if(canPlay){
  1992. SoundManager.play('bgm')
  1993. $("#volume").show();
  1994. }
  1995. if(areaAudio || window.DATA.backgroundMusic){
  1996. $("#volume").show()
  1997. }else{
  1998. $("#volume").hide()
  1999. }
  2000. }
  2001. }
  2002. player.on("flying.ended",(a,b,pano,d)=>{
  2003. pano && setCurBgm(pano)
  2004. })
  2005. manage.addEventListener('pauseSound',(e)=>{
  2006. if(SoundManager.playHistory.length == 0 && e.object != bgmObject){//其他都停了的话
  2007. //console.log('SoundManager.playHistory.length == 0')
  2008. setCurBgm(player.currentPano)
  2009. }
  2010. })
  2011. player.currentPano && setCurBgm(player.currentPano)
  2012. }
  2013. }
  2014. window.bus.addEventListener('playerAndModelReady',f) //player model currentPano都已有
  2015. }
  2016. window.bus.dispatchEvent({type: 'THREE_inited'})
  2017. }
  2018. {
  2019. let infoPannel = $('<div id="alert" class="closed"><div name="content"></div><div class="close"></div></div>')
  2020. $('body').append(infoPannel)
  2021. let showDur;
  2022. let close = ()=>{
  2023. infoPannel.addClass('closed')
  2024. clearTimeout(timer)
  2025. timer = null
  2026. }
  2027. let timer, currName;//定时器
  2028. infoPannel.find('.close').on('click',close);
  2029. window.alertInfo = function(text, {dur, dontAutoClose, hideCloseBtn, name}={}){
  2030. if(timer){
  2031. clearTimeout(timer)
  2032. }
  2033. infoPannel.find('[name=content]').html(text)
  2034. infoPannel.removeClass('closed')
  2035. if(hideCloseBtn){
  2036. infoPannel.find('.close').addClass('hide')
  2037. }else{
  2038. infoPannel.find('.close').removeClass('hide')
  2039. }
  2040. showDur = dur || (1500 + Math.round(text.length * 20))
  2041. if(!dontAutoClose){
  2042. timer = setTimeout(close, showDur)
  2043. }
  2044. currName = name
  2045. }
  2046. window.alertClose = function(name){
  2047. if(currName == name){
  2048. close()
  2049. }
  2050. }
  2051. }
  2052. //最好能知道应该播放到的currentTime
  2053. var SoundManager = {//暂不支持同时播放
  2054. currentAudio:null,//当前正在播放list中的哪一个
  2055. enableSound:true,//是否允许有声音
  2056. playHistory:[],//被打断的加入播放历史
  2057. list:[ ],//同一级别可以互相打断 //暂时不做多级别
  2058. play:function(name, src, currentTime){
  2059. var object = this.list.find(e=>e.name == name)
  2060. if(object){
  2061. if(this.currentAudio){
  2062. this.pause(this.currentAudio.name, false, true)
  2063. }
  2064. {//将当前要播放的播放历史中清除
  2065. let index = this.playHistory.indexOf(object)
  2066. if(index>-1)this.playHistory.splice(index,1);
  2067. }
  2068. this.currentAudio = object
  2069. if(src){
  2070. this.setSrc(name, src)
  2071. }
  2072. if(currentTime!=void 0){
  2073. object.audio.currentTime = currentTime
  2074. }
  2075. if(object.audio && object.src){
  2076. object.audio.load(); // iOS 9 还需要额外的 load 一下, 否则直接 play 无效 *///https://www.cnblogs.com/interdrp/p/4211883.html 部分资料
  2077. object.audio.play();
  2078. object.audio.paused || object.callback && object.callback(true)
  2079. Log(name + ' 播放 ' )
  2080. }
  2081. }
  2082. },
  2083. pause:function(name, autoReplayLast, isInterrupt){//需要能自动恢复上一个被打算的音频。恢复前判断是否还需要播放
  2084. var object = this.list.find(e=>e.name == name)
  2085. if(object && this.currentAudio == object){
  2086. this.currentAudio = null
  2087. if(object.audio){
  2088. !object.audio.paused && Log(name + ' 中断音频 '+ "("+common.getFileNameFromUrl(object.audio.src)+')' )
  2089. object.audio.pause()
  2090. object.callback && object.callback(false)
  2091. }
  2092. if(isInterrupt){//一般主动调用不需要加这个
  2093. this.playHistory.push(object)//如果是被中断的,加入播放历史,等待恢复播放
  2094. }
  2095. if(autoReplayLast){ //播放之前的音频。它们是被打断过的。
  2096. while(this.playHistory.length){
  2097. var last = this.playHistory.pop();
  2098. if(last.src && last.canplay(last.audio)){
  2099. this.play(last.name )
  2100. }
  2101. }
  2102. }
  2103. manage.dispatchEvent({type:'pauseSound', object})
  2104. }
  2105. },
  2106. setSrc : function(name, src='', desc=''){//不能直接给audio赋src!一定要用这个函数!因为我要拿这里的src来判断有无src,因为貌似audio的src会自动变,''时会变成html的链接
  2107. var object = this.list.find(e=>e.name == name)
  2108. object.src = src
  2109. object.audio.src = src
  2110. Log(`${object.name} ${desc} 设置src: ${src} `)
  2111. },
  2112. createAudio:function(object={}){//name, level, canplay
  2113. if(!object.fake){
  2114. object.audio = new Audio();
  2115. object.audio.loop = !!object.loop;
  2116. //object.audio.autoplay = true;
  2117. object.audio.addEventListener('ended', ()=>{
  2118. if(object.loop){//循环
  2119. Log(`${object.name} 播放完毕,重新播放`)
  2120. object.audio.play()
  2121. }else{
  2122. this.pause(object.name, true);//停止后的后续处理
  2123. }
  2124. });
  2125. object.audio.oncanplaythrough = ()=>{
  2126. //Log(`${object.name} canplaythrough `)
  2127. }
  2128. }
  2129. this.list.push(object)
  2130. },
  2131. initAutoPlay:function(){ //处理设备自动播放限制
  2132. let play = function(){
  2133. if (this.currentAudio && this.currentAudio.audio && this.currentAudio.src && this.currentAudio.audio.paused ) {
  2134. this.currentAudio.audio.play() //一般触屏了都会播放成功,就不识别paused了
  2135. this.currentAudio.callback && this.currentAudio.callback(true)
  2136. Log(`${this.currentAudio.name} 自动播放`) //即使设置src在这之后好像也能成功播放
  2137. }else{
  2138. }
  2139. document.removeEventListener("touchstart",play);
  2140. document.removeEventListener("click",play);
  2141. $('#player')[0].removeEventListener("touchstart", play);
  2142. }.bind(this);
  2143. document.addEventListener("WeixinJSBridgeReady", play, false);
  2144. document.addEventListener("touchstart", play);//ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
  2145. document.addEventListener("click", play);
  2146. $('#player')[0].addEventListener("touchstart", play);
  2147. }
  2148. }
  2149. function Log(value, color, fontSize){
  2150. color = color || '#13f'
  2151. fontSize = fontSize || 14
  2152. console.warn(`%c${value}`, `color:${color};font-size:${fontSize}px`)
  2153. }
  2154. Manage.prototype.loadAudio = function() { //相关:g_tourAudio \ g_playAudio
  2155. //热点页面因为挡住了界面,所以暂时不存在别的音频阻止热点音频的可能
  2156. //box视频都静音,所以暂时不考虑
  2157. SoundManager.createAudio({
  2158. name:'bgm',
  2159. level:0,
  2160. src:'',
  2161. loop:true,
  2162. canplay:(audio)=>{
  2163. return this.bgmShouldPlay
  2164. },
  2165. callback:(state)=>{//play或pause时随之触发的函数(即使还没开始播放)
  2166. if(state){
  2167. $("#volume a img").attr("src", "./images/Volume btn_off.png")
  2168. $("#volume").attr("title", "关闭声音");
  2169. }else{
  2170. $("#volume a img").attr("src", "./images/Volume btn_on.png")
  2171. $("#volume").attr("title", "打开声音");
  2172. }
  2173. }
  2174. })
  2175. SoundManager.createAudio({
  2176. name:'tour',
  2177. level:0,
  2178. src:'',
  2179. loop:false,
  2180. canplay:(audio)=>{
  2181. return player.director && player.director.tourIsPlaying && player.director.getAudio()
  2182. }
  2183. })
  2184. SoundManager.createAudio({
  2185. name:'hot',
  2186. fake:true,//实际上没有audio. 只是为了来停止和续播其他音频
  2187. level:2,
  2188. src:'',
  2189. loop:false,
  2190. canplay:(audio)=>{
  2191. }
  2192. })
  2193. /* SoundManager.createAudio({//区域bgm //暂定背景音乐按钮 同时控制整体和局部的播放。之后可能会改成仅单独控制bgm,或者分为两个按钮,需要再createAudio。
  2194. name:'pano',
  2195. level:1,
  2196. src:'',
  2197. loop:true,
  2198. canplay:(audio)=>{
  2199. return true
  2200. }
  2201. }) */
  2202. $("#volume").find("a").on("click", ()=> {
  2203. if($("#volume img")[0].src.indexOf("btn_on.png")>-1)
  2204. {
  2205. this.switchBgmState(true);
  2206. }
  2207. else if($("#volume img")[0].src.indexOf("btn_off.png")>-1)
  2208. {
  2209. this.switchBgmState(false);
  2210. }
  2211. })
  2212. this.switchBgmState(true);//初始设置允许播放bgm
  2213. SoundManager.initAutoPlay()
  2214. }
  2215. Manage.prototype.switchBgmState = function(state){//按钮的状态完全代表是否应该播放bgm,即使还没加载完
  2216. this.bgmShouldPlay = state
  2217. if(state){
  2218. SoundManager.play('bgm')
  2219. }else{
  2220. SoundManager.pause('bgm')
  2221. }
  2222. this.dispatchEvent && this.dispatchEvent({type:'switchBgmState'})
  2223. }
  2224. var manage = new Manage();
  2225. //处理cursor优先级
  2226. var CursorDeal = {
  2227. priorityEvent : [//在前面的优先级高
  2228. {"noIntersect":'not-allowed'},
  2229. {"addHot":'cell'},
  2230. {'hoverRouteLine':'url(images/coordinateClose.png),auto'},
  2231. {'hoverPano':'pointer'},
  2232. {"hoverFootIcon":'pointer'},
  2233. {"hoverHot":'pointer'},
  2234. {"addLabel":'cell'},
  2235. {"moveLabel":'grab'},
  2236. ],
  2237. domElements :[$('#player')[0]],
  2238. list:[], //当前存在的cursor状态
  2239. currentCursorIndex:null,
  2240. /* init : function(viewer){
  2241. this.priorityEvent.forEach(e=>{//刚开始Potree.resourcePath没值,现在换
  2242. for(let i in e){
  2243. e[i] = Common.replaceAll(e[i],'{Potree.resourcePath}',Potree.resourcePath)
  2244. }
  2245. })
  2246. this.domElements = [viewer.renderArea, viewer.mapViewer.renderArea];
  2247. viewer.addEventListener("CursorChange",(e)=>{
  2248. if(e.action == 'add'){
  2249. this.add(e.name)
  2250. }else{
  2251. this.remove(e.name)
  2252. }
  2253. })
  2254. }, */
  2255. add : function(name){
  2256. var priorityItem = this.priorityEvent.find(e=>e[name])
  2257. if(!priorityItem){
  2258. console.error('CursorDeal 未定义优先级 name:'+ name);
  2259. return
  2260. }
  2261. if(!this.list.includes(name)){
  2262. this.judge({addItem: priorityItem, name})
  2263. this.list.push(name)
  2264. }
  2265. },
  2266. remove : function(name){
  2267. var index = this.list.indexOf(name);
  2268. if(index > -1){
  2269. this.list.splice(index, 1)
  2270. this.judge()
  2271. }
  2272. },
  2273. judge:function(o={}){
  2274. //console.log(o,this.list)
  2275. if(o.addItem){
  2276. var addIndex = this.priorityEvent.indexOf(o.addItem)
  2277. if(addIndex < this.currentCursorIndex || this.currentCursorIndex == void 0){
  2278. this.domElements.forEach(e=>e.style.cursor = o.addItem[o.name] )
  2279. this.currentCursorIndex = addIndex
  2280. }
  2281. }else{
  2282. var levelMax = {index:Infinity, cursor:null }
  2283. this.list.forEach(name=>{
  2284. var priorityItem = this.priorityEvent.find(e=>e[name])
  2285. var index = this.priorityEvent.indexOf(priorityItem)
  2286. if(index < levelMax.index){
  2287. levelMax.index = index;
  2288. levelMax.cursor = priorityItem[name]
  2289. }
  2290. })
  2291. this.currentCursorIndex = levelMax.index
  2292. this.domElements.forEach(e=>e.style.cursor = levelMax.cursor || '')
  2293. }
  2294. }
  2295. }
  2296. function logSth(){
  2297. let hotCount = player.model.hotGroup.children.length
  2298. let videoCount = player.model.hotGroup.children.filter(e=>e.texType == 'video').length
  2299. let photoCount = player.model.hotGroup.children.filter(e=>e.texType == 'photo').length
  2300. let shineCount = player.model.hotGroup.children.filter(e=>e.texType == 'shine').length
  2301. let aniCount = player.model.hotGroup.children.filter(e=>e.info.animateInfo).length
  2302. let objCount = player.model.hotGroup.children.filter(e=>e.objObject).length
  2303. let chunkLen = player.model.chunks.length
  2304. let vertexC = player.model.chunks.reduce(function(total, chunk ){return total+chunk.geometry.attributes.position.count}, 0)
  2305. let panoCount = player.model.panos.list.length
  2306. Log(`共有chunk个数 ${chunkLen} ( 顶点数 ${vertexC} )
  2307. 热点个数 ${hotCount} ( vedio ${videoCount} 个,photo ${photoCount} 个,shine ${shineCount}个。 gif ${aniCount} 个,obj ${objCount} 个
  2308. 漫游点数 ${panoCount} 个)`, '#FF4399', 14)
  2309. }
  2310. /* let kankanNames = ['SG-','KJ-'] */
  2311. window.sceneFrom = (number.length > 6 && number.slice(0,3).includes('-') || browser.urlHasValue('kankan') ) ? 'kankan' : '' //看看or看见转来的
  2312. //兼容一代的場景
  2313. //請求地址統一管理
  2314. var g_onePregix = "https://bigscene.4dage.com/" //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
  2315. var g_version = manage.number("version");
  2316. g_version === "one" ? g_Prefix = g_onePregix : '';