manage.js 90 KB

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