manage.js 91 KB

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