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. window.isLocal = true
  5. var s = window.location.href.split('/')
  6. s.pop()
  7. //var g_Prefix = s.join('/');
  8. var g_index = null
  9. var g_modeldata = null
  10. var g_weixinTitle = null
  11. var g_Hots = null
  12. var g_HotMeshes = []
  13. var g_HotMeshSize = {
  14. g_HotMeshWidth: 0.3,
  15. g_HotMeshHeight: 0.3
  16. }
  17. //add表示添加,delete表示删除
  18. var g_HotStatus = null
  19. var g_newHot = [] //存储新加热点
  20. var g_HotImage = {
  21. point: 'https://super.4dage.com/images/4dagePoint2.png',
  22. point2: 'https://super.4dage.com/images/4dagePoint.png'
  23. }
  24. var g_saveHot = false
  25. var g_TextColor = 0x7777ff
  26. var g_Text = null
  27. var g_TextPlaneMesh = []
  28. var g_TextIconMesh = []
  29. var g_TextIcon = './images/text.png'
  30. var g_SelectTextIndex = null
  31. var g_TextShow = null
  32. var g_audioPlay = false
  33. var g_background = null
  34. var g_roof = null
  35. var g_data2 = null //加载的data2.js的内容
  36. var g_bgAudio = null //背景音乐
  37. var g_tourAudio = null //导览音乐
  38. var g_play = 1 //表示播放图标状态
  39. var g_playAudio = null //当前在播放或当继续播放时应该播放的,是g_bgAudio或g_tourAudio
  40. var g_currentHot = null //当前打开的热点
  41. //var g_Texture=null;
  42. //var g_ChunknameTexture={}; //chunkname和贴图名称对应
  43. var g_NormalTexture = false
  44. var g_SpecularTexture = false
  45. var g_DirectionalLight = null
  46. var g_snapShotWidth = 200 //截图下载图片的大小
  47. var g_snapShotHeight = 140
  48. //微信分享
  49. var g_weixinObj = {
  50. title: document.querySelector('head title').innerHTML,
  51. lineLink: window.location.href,
  52. imgUrl: 'https://www.4dmodel.com/SuperPanoramic/images/weixintitle.jpg',
  53. desc: '四维时代提供技术支持'
  54. }
  55. window.browser = {
  56. //提前定义
  57. isMobile: function () {
  58. var e = navigator.userAgent || navigator.vendor || window.opera
  59. return (
  60. /(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(
  61. e
  62. ) ||
  63. /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(
  64. e.substr(0, 4)
  65. )
  66. )
  67. },
  68. isFullscreen: function () {
  69. return document.fullscreenElement || document.mozFullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement
  70. },
  71. valueFromHash: function (e, t) {
  72. var i = new RegExp('[#&?]' + e + '=([^#&?]*)'),
  73. n = i.exec(window.location.href)
  74. if (!n) return t
  75. var r = n[1]
  76. return 'boolean' == typeof t ? 'true' === r || '1' === r : 'number' == typeof t ? parseFloat(r) : window.decodeURIComponent(r)
  77. },
  78. urlHasValue: function (key, isGetValue) {
  79. let querys = window.location.search.substr(1).split('&')
  80. if (isGetValue) {
  81. for (let i = 0; i < querys.length; i++) {
  82. let keypair = querys[i].split('=')
  83. if (keypair.length === 2 && keypair[0] === key) {
  84. return keypair[1]
  85. }
  86. }
  87. return ''
  88. } else {
  89. for (let i = 0; i < querys.length; i++) {
  90. let keypair = querys[i].split('=')
  91. if (keypair[0] == key) {
  92. return true
  93. }
  94. }
  95. return false
  96. }
  97. }
  98. }
  99. var settings = {
  100. hotClickEvent: {
  101. video: {
  102. playAndPause: true,
  103. examine: false,
  104. openHot: false
  105. },
  106. photo: {
  107. examine: false,
  108. openHot: false
  109. },
  110. shine: {
  111. examine: true,
  112. openHot: true
  113. }
  114. },
  115. hotClickActions: ['playAndPause', 'examine', 'openHot', 'fastTran'],
  116. markerHeight: 0.05, //距离地板高出多少,
  117. //默认的:
  118. teleportTime: 1500, //瞬间过渡的时间
  119. /* flytimeDistanceMultiplier:150,
  120. flyTime:750, */
  121. tourRotTime: 2, //默认停留2秒
  122. //dontExamHot:true,
  123. hotFastTran: false,
  124. transparentBg: false,
  125. bgImg: null,
  126. localPrefix: '',
  127. tileClass: {
  128. //默认全景贴图加载的清晰度
  129. pc: {
  130. nav: '2k',
  131. max: '4k'
  132. },
  133. bigMobile: {
  134. //width和height都超过一定值
  135. nav: browser.urlHasValue('padNav', true) || '2k',
  136. max: browser.urlHasValue('padMax', true) || '4k' //'2k',
  137. },
  138. mobile: {
  139. nav: browser.urlHasValue('phoneNav', true) || '1k', //不放大时
  140. max: browser.urlHasValue('phoneMax', true) || '4k' //放到最大
  141. }
  142. } //可以稍后自行修改
  143. }
  144. if (window.number == '725' || window.number == '724') {
  145. //settings.mobileNavHigh = true
  146. settings.tileClass.mobile = { nav: '2k', max: '2k' }
  147. }
  148. //共用函数:
  149. window.common = null
  150. window.MathLight = null
  151. window.math = null
  152. window.easing = null
  153. window.lerp = null
  154. window.transitions = null
  155. function watch(object, propName, initialValue) {
  156. //监听某个属性的变化
  157. let v = initialValue
  158. Object.defineProperty(object, propName, {
  159. get: function () {
  160. return v
  161. },
  162. set: function (e) {
  163. console.log('watch:', propName, e)
  164. v = e
  165. }
  166. })
  167. }
  168. var toPrecision = function (e, t) {
  169. function i(e, t) {
  170. var i = Math.pow(10, t)
  171. return Math.round(e * i) / i
  172. }
  173. if (e instanceof Array) {
  174. for (var n = 0; n < e.length; n++) e[n] = i(e[n], t)
  175. return e
  176. }
  177. return i(e, t)
  178. }
  179. var dealMap = (map, o = {}) => {
  180. //使不resize when image is not power of two ,但缩小时会有锯齿
  181. if (!o.ignoreResize) {
  182. if (!map.image || !THREE.Math.isPowerOfTwo(map.image.width) || !THREE.Math.isPowerOfTwo(map.image.height)) {
  183. map.wrapS = map.wrapT = THREE.ClampToEdgeWrapping
  184. map.minFilter = THREE.LinearFilter
  185. //map.generateMipmaps = true;
  186. }
  187. }
  188. if (!browser.isMobile()) map.anisotropy = 3
  189. }
  190. var dom = {
  191. getOffset: function (type, element, parent) {
  192. left = type == 'left' ? element.offsetLeft : element.offsetTop
  193. if (!parent) parent = $('body')[0]
  194. while ((element = element.offsetParent)) {
  195. if (element == parent) break
  196. left += type == 'left' ? element.offsetLeft : element.offsetTop
  197. }
  198. return left
  199. }
  200. }
  201. var getTransformSid = function () {
  202. var name
  203. if (player.mode == 'panorama') {
  204. name = player.currentPano ? player.currentPano.id : 'outside'
  205. } else {
  206. name = 'outside'
  207. }
  208. return name
  209. }
  210. var LineDraw = {
  211. /* createLine: function(posArr, o) {
  212. var e = new THREE.BufferGeometry
  213. , p = new Float32Array(6);
  214. e.addAttribute("position", new THREE.BufferAttribute(p,3));
  215. //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
  216. var p = e.attributes.position.array;
  217. for (var i = 0; i < 2; i++) {
  218. p[i * 3] = posArr[i].x;
  219. p[i * 3 + 1] = posArr[i].y;
  220. p[i * 3 + 2] = posArr[i].z;
  221. }
  222. var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
  223. linewidth: o.width || 1,
  224. //windows无效。 似乎mac/ios上粗细有效 ?
  225. color: o.color || defaultColor,
  226. transparent: o.dontAlwaysSeen ? false : true,
  227. depthTest: o.dontAlwaysSeen ? true : false
  228. })
  229. var line = new THREE.Line(e,mat);
  230. line.renderOrder = o.renderOrder || 4
  231. //同tagStem; //如果不加高,可能会部分被model遮住
  232. return line;
  233. } */
  234. createLine: function (posArr, o = {}) {
  235. //多段普通线 (第二个点和第三个点之间是没有线段的, 所以不用在意线段顺序)
  236. var mat
  237. if (o.mat) {
  238. mat = o.mat
  239. } else {
  240. let prop = {
  241. color: o.color || defaultColor,
  242. transparent: o.dontAlwaysSeen ? false : true,
  243. depthTest: o.dontAlwaysSeen ? true : false,
  244. opacity: o.opacity != void 0 ? o.opacity : 1
  245. }
  246. if (o.deshed) {
  247. ;(prop.dashSize = o.dashSize || 0.1), (prop.gapSize = o.gapSize || 0.1)
  248. }
  249. mat = new THREE[o.deshed ? 'LineDashedMaterial' : 'LineBasicMaterial'](prop)
  250. }
  251. var line = new THREE.LineSegments(new THREE.BufferGeometry(), mat)
  252. line.renderOrder = o.renderOrder || 4
  253. this.moveLine(line, posArr)
  254. return line
  255. },
  256. moveLine: function (line, posArr) {
  257. if (posArr.length == 0) return
  258. let position = new Float32Array(posArr.length * 3) //[]
  259. for (var i = 0; i < 2; i++) {
  260. position[i * 3] = posArr[i].x
  261. position[i * 3 + 1] = posArr[i].y
  262. position[i * 3 + 2] = posArr[i].z
  263. }
  264. line.geometry.addAttribute('position', new THREE.BufferAttribute(position, 3))
  265. //line.geometry.setAttribute('position', new THREE.Float32BufferAttribute(new Float32Array(position), 3));
  266. line.geometry.attributes.position.needsUpdate = true
  267. line.geometry.computeBoundingSphere()
  268. /* if(line.material instanceof THREE.LineDashedMaterial){
  269. line.computeLineDistances() //只有非buffer的geometry才有
  270. } */
  271. }
  272. }
  273. var convertTool = {
  274. getPos2d: function (point, camera, dom) {
  275. //获取一个三维坐标对应屏幕中的二维坐标
  276. var camera = camera || player.camera
  277. var dom = dom || player.domElement
  278. if (!camera) return
  279. 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);
  280. var x, y
  281. x = ((pos.x + 1) / 2) * dom.clientWidth
  282. y = (1 - (pos.y + 1) / 2) * dom.clientHeight
  283. var inSight =
  284. x <= dom.clientWidth &&
  285. x >= 0 && //是否在屏幕中
  286. y <= dom.clientHeight &&
  287. y >= 0
  288. return {
  289. pos: new THREE.Vector2(x, y), // 屏幕像素坐标
  290. vector: pos, //(范围 -1 ~ 1)
  291. trueSide: pos.z < 1, //trueSide为false时,即使在屏幕范围内可见,也是反方向的另一个不可以被渲染的点 参见Tag.update
  292. inSight: inSight //在屏幕范围内可见
  293. }
  294. },
  295. ifShelter: function (pos3d, pos2d, camera, floorIndex) {
  296. //检测某点在视线中是否被mesh遮挡
  297. if (!pos2d) pos2d = convertTool.getPos2d(pos3d)
  298. camera = camera || player.camera
  299. var ori = new THREE.Vector3(pos2d.x, pos2d.y, -1).unproject(camera) //找到视线原点
  300. var dir = pos3d.clone().sub(ori).normalize()
  301. var ray = new THREE.Raycaster(ori, dir) //由外向里 因为模型从内侧是可见的所以从外侧
  302. /* if(config.isEdit && publicObjectSet.editor.mainDesign.editing){
  303. var o = ray.intersectObjects(publicObjectSet.editor.mainDesign.wallMeshes);
  304. }else{ */
  305. let colliders = player.model.allFloorsVisible ? player.model.colliders : (floorIndex != void 0 ? player.model.floors.index[floorIndex] : player.model.currentFloor).collider.children
  306. //let colliders = (floorIndex == void 0 ) ? player.model.colliders : player.model.floors.index[floorIndex].collider.children
  307. var o = ray.intersectObjects(colliders)
  308. //}
  309. var len = pos3d.distanceTo(ori)
  310. if (o && o.length) {
  311. for (var i = 0; i < o.length; i++) {
  312. if (o[i].distance < len) {
  313. return true
  314. } //有遮挡
  315. }
  316. }
  317. },
  318. /*
  319. 拖拽时,获取鼠标在拖拽面上的位置(需要借助另一个intersectPlane面来计算,即和相机方向一样的面,可保证铺满屏幕)
  320. 但是不一定能获取到,比如鼠标射线不朝向拖拽面时,即使获取也会是一个意外的反方向的交点。
  321. */
  322. getPosAtPlane: function (pos, info /* , mouse, camera */) {
  323. //pos:与intersectPlane的交点 见笔记
  324. var A = pos
  325. var player = player
  326. var mouse = player.mouse
  327. var O = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(player.camera)
  328. if (info.y != void 0) {
  329. //地面线的
  330. var y = info.y
  331. if (player.mode == 'floorplan' /* || Math.abs(O.x-pos.x)<0.0001 && Math.abs(O.z-pos.z)<0.0001) */) {
  332. //intersectPlane和地面平行,无交点
  333. var x = pos.x,
  334. z = pos.z
  335. } else {
  336. if (y < player.camera.position.y && O.y <= A.y /* || y>player.camera.position.y && O.y >= A.y */) return null //鼠标射线向上。因为相机一定位于地面以上(地面不会抬高到相机上吧?),所以无交点。
  337. if (O.y == A.y) {
  338. console.log('一样??')
  339. return
  340. }
  341. if (A.y == y) {
  342. console.log('一样2??')
  343. return
  344. }
  345. var r = (O.y - y) / (A.y - y)
  346. var x = (r * A.x - O.x) / (r - 1)
  347. var z = (r * A.z - O.z) / (r - 1)
  348. }
  349. } else {
  350. //垂直的也有越过消失点以后反向变化的情况,但使用时影响不大
  351. var N = info.normalVec
  352. var P = info.pullPos
  353. if (N.y != 0) {
  354. console.log('N.y != 0')
  355. return
  356. } //仅仅支持垂直于地面的的墙壁,目前都是
  357. if (O.z == A.z) {
  358. console.log('O.z==A.z?')
  359. return
  360. }
  361. if (N.z != 0 && N.x != 0) {
  362. //直接用这个通用的也可以,支持斜线的墙
  363. //console.log('N.z==0 && N.x == 0?');
  364. var c = N.x * (A.x - O.x) + N.y * (A.y - O.y) + N.z * (A.z - O.z)
  365. if (c == 0) {
  366. console.log('分母为0?? return;')
  367. return
  368. }
  369. 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
  370. var x = t * (A.x - O.x) + O.x
  371. var y = t * (A.y - O.y) + O.y
  372. var z = t * (A.z - O.z) + O.z
  373. /*原理: 已知空间直线L:(x-a)/m=(x-b)/n=(z-c)/p和空间平面π:Ax+By+Cz+D=0;
  374. 求直线L与平面π的交点的坐标。
  375. 把直线方程改写成参数形式:设(x-a)/m=(x-b)/n=(z-c)/p=t;
  376. 则x=mt+a;y=nt+b;z=pt+c;代入平面π的方程得:
  377. A(mt+a)+B(nt+b)+C(pt+c)+D=0
  378. 由此解得t=-(Aa+Bb+Cc+D)/(Am+Bn+Cp)
  379. 再代入参数方程即得交点的坐标(x,y,z). */
  380. } else if (N.x == 0) {
  381. //z与pullPos相等
  382. var z = P.z
  383. if (O.y == A.y) {
  384. console.log('一样??')
  385. return
  386. }
  387. if (A.y == y) {
  388. console.log('一样2??')
  389. return
  390. }
  391. if (A.z == z) {
  392. console.log('一样3??')
  393. return
  394. }
  395. var r = (O.z - z) / (A.z - z)
  396. var x = (r * A.x - O.x) / (r - 1)
  397. var y = (r * A.y - O.y) / (r - 1)
  398. } else if (N.z == 0) {
  399. //x与pullPos相等
  400. var x = P.x
  401. if (O.y == A.y) {
  402. console.log('一样??')
  403. return
  404. }
  405. if (A.y == y) {
  406. console.log('一样2??')
  407. return
  408. }
  409. if (A.x == x) {
  410. console.log('一样3??')
  411. return
  412. }
  413. var r = (O.x - x) / (A.x - x)
  414. var y = (r * A.y - O.y) / (r - 1)
  415. var z = (r * A.z - O.z) / (r - 1)
  416. }
  417. }
  418. return new THREE.Vector3(x, y, z)
  419. },
  420. getMouseIntersect: function (camera, meshes, mouse) {
  421. //获取鼠标和meshes交点
  422. var raycaster = new THREE.Raycaster()
  423. camera.updateMatrixWorld()
  424. var origin = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(camera),
  425. end = new THREE.Vector3(mouse.x, mouse.y, 1).unproject(camera)
  426. var dir = end.sub(origin).normalize()
  427. raycaster.set(origin, dir)
  428. var n = raycaster.intersectObjects(meshes)
  429. if (0 === n.length) return null
  430. return n[0]
  431. },
  432. ifIntersectChunks: function (A, B, options = {}) {
  433. //获取某个线段/射线和meshes的交点
  434. var dir = B.clone().sub(A).normalize()
  435. var len = options.InfinityLen ? Infinity : A.distanceTo(B) + (options.extLen || 0)
  436. var ray = new THREE.Raycaster(A.clone(), dir, 0, len)
  437. var o = ray.intersectObjects(options.model || player.model.colliders)
  438. if (o && o.length) return o
  439. if (options.throughWidth) {
  440. //允许最小宽度,防止穿过极小的缝隙导致撞墙感
  441. var normal = math.getNormal({
  442. points: [
  443. { x: A.x, y: A.z },
  444. { x: B.x, y: B.z }
  445. ]
  446. }) //线段法线
  447. normal.multiplyScalar(options.throughWidth)
  448. var normalVec3 = new THREE.Vector3(normal.x, 0, normal.y)
  449. var A2 = A.clone().add(normalVec3)
  450. ray.set(A2, dir)
  451. var o2 = ray.intersectObjects(options.model || player.model.colliders)
  452. ray.set(A.clone().add(normalVec3.negate()), dir)
  453. if (o2 && o2.length) return o2
  454. var o3 = ray.intersectObjects(options.model || player.model.colliders)
  455. if (o3 && o3.length) return o3
  456. }
  457. return null
  458. },
  459. getPosAtSphere: function (pos3d, toPanoPos) {
  460. var dir = pos3d.clone().sub(toPanoPos)
  461. dir.normalize() //然后计算在球中
  462. dir.multiplyScalar(Constants.skyRadius)
  463. dir.add(toPanoPos)
  464. return dir
  465. },
  466. getScaleForConstantSize: function (op = {}) {
  467. //获得规定二维大小的mesh的scale值。可以避免因camera的projection造成的mesh视觉大小改变。 来源:tag.updateDisc
  468. var w
  469. var i = new THREE.Vector3(),
  470. o = new THREE.Vector3(),
  471. l = new THREE.Vector3(),
  472. c = new THREE.Vector3(),
  473. h = new THREE.Vector3()
  474. if (!op.resolution) {
  475. let renderSize = player.sceneRenderer.renderer.getSize()
  476. op.resolution = { x: renderSize.width, y: renderSize.height }
  477. }
  478. if (!op.camera) {
  479. let camera = player.cameraControls.activeControl ? player.cameraControls.activeControl.camera : player.camera
  480. let camera2 = camera.clone()
  481. camera2.matrixWorld.copy(player.camera.matrixWorld) //因为其他原因该camera的matrixWorld被还原了,而player.camera的是正确的
  482. op.camera = camera2
  483. }
  484. if (op.width2d) w = op.width2d //如果恒定二维宽度
  485. else {
  486. //否则考虑上距离,加一丢丢近大远小的效果
  487. var currentDis, nearBound, farBound
  488. if (op.camera.type == 'OrthographicCamera') {
  489. currentDis = (op.camera.right - op.camera.left) / op.camera.zoom
  490. } else {
  491. currentDis = op.position.distanceTo(op.camera.position)
  492. }
  493. w = op.maxSize - (op.maxSize - op.minSize) * THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound)
  494. //maxSize : mesh要表现的最大像素宽度; nearBound: 最近距离,若比nearBound近,则使用maxSize
  495. }
  496. i.copy(op.position).project(op.camera), //tag中心在屏幕上的二维坐标
  497. o.set(op.resolution.x / 2, op.resolution.y / 2, 1).multiply(i), //转化成px -w/2 到 w/2的范围
  498. l.set(w / 2, 0, 0).add(o), //加上tag宽度的一半
  499. c.set(2 / op.resolution.x, 2 / op.resolution.y, 1).multiply(l), //再转回 -1 到 1的范围
  500. h.copy(c).unproject(op.camera) //再转成三维坐标,求得tag边缘的位置
  501. let halfMeter = h.distanceTo(op.position) //就能得到tag的三维半径
  502. return halfMeter //可能NAN 当相机和position重叠时
  503. },
  504. updateVisible: function (object, reason, ifShow, level = 0, type) {
  505. //当所有加入的条件都不为false时才显示. reason='force'一般是强制、临时的
  506. if (!object.unvisibleReasons) object.unvisibleReasons = [] //如果length>0代表不可见
  507. if (!object.visibleReasons) object.visibleReasons = [] //在同级时,优先可见
  508. var update = function () {
  509. //先按从高到低的level排列
  510. object.unvisibleReasons = object.unvisibleReasons.sort((a, b) => b.level - a.level)
  511. object.visibleReasons = object.visibleReasons.sort((a, b) => b.level - a.level)
  512. var maxVisiLevel = object.visibleReasons[0] ? object.visibleReasons[0].level : -1
  513. var maxunVisiLevel = object.unvisibleReasons[0] ? object.unvisibleReasons[0].level : -1
  514. var shouldVisi = maxVisiLevel >= maxunVisiLevel
  515. var visiBefore = object.visible
  516. if (visiBefore != shouldVisi) {
  517. object.visible = shouldVisi
  518. object.dispatchEvent({
  519. type: 'isVisible',
  520. visible: shouldVisi,
  521. reason
  522. })
  523. }
  524. }
  525. if (ifShow) {
  526. var index = object.unvisibleReasons.findIndex(e => e.reason == reason)
  527. if (index > -1) {
  528. type = 'cancel'
  529. object.unvisibleReasons.splice(index, 1)
  530. }
  531. if (type == 'add') {
  532. if (!object.visibleReasons.some(e => e.reason == reason)) {
  533. object.visibleReasons.push({ reason, level })
  534. }
  535. }
  536. } else {
  537. var index = object.visibleReasons.findIndex(e => e.reason == reason)
  538. if (index > -1) {
  539. type = 'cancel'
  540. object.visibleReasons.splice(index, 1)
  541. }
  542. if (type != 'cancel') {
  543. if (!object.unvisibleReasons.some(e => e.reason == reason)) {
  544. object.unvisibleReasons.push({ reason, level })
  545. }
  546. }
  547. }
  548. update()
  549. },
  550. getObjVisiByReason: function (object, reason) {
  551. //获取在某条件下是否可见. 注: 用户在数据集选择可不可见为"datasetSelection"
  552. if (object.visible) return true
  553. else {
  554. return !object.unvisibleReasons || !object.unvisibleReasons.some(e => e.reason == reason)
  555. }
  556. }
  557. }
  558. window.expandCommon = function (common) {
  559. Object.assign(common, {
  560. intervalTool: {
  561. //延时update,防止卡顿
  562. list: [],
  563. isWaiting: function (name, func, delayTime /* , autoCycle */) {
  564. let item = this.list.find(e => e.name == name)
  565. if (!item) {
  566. //如果没有该项, 则加入循环
  567. let ifContinue = func()
  568. item = { name, func, delayTime }
  569. this.list.push(item)
  570. setTimeout(() => {
  571. var a = this.list.indexOf(item)
  572. this.list.splice(a, 1)
  573. let { func, delayTime } = item
  574. if (item.requestUpdate || ifContinue) this.isWaiting(name, func, delayTime) //循环
  575. }, delayTime)
  576. } else {
  577. //如果有该项,说明现在请求下一次继续更新
  578. //更新属性
  579. item.func = func
  580. item.delayTime = delayTime
  581. item.requestUpdate = true
  582. }
  583. }
  584. },
  585. sortByScore: function (list, request, rank) {
  586. var i = request ? common.filterAll(list, request) : list
  587. return 0 === i.length
  588. ? null
  589. : (i = i
  590. .map(function (e) {
  591. let scores = rank.map(function (f) {
  592. return f(e)
  593. }) //add
  594. return {
  595. item: e,
  596. scores,
  597. score: scores.reduce(function (t, i) {
  598. return t + i
  599. }, 0)
  600. }
  601. })
  602. .sort(function (e, t) {
  603. return t.score - e.score
  604. }))
  605. },
  606. getVisiblePano: function (positions = [], panos, options = {}) {
  607. //add
  608. var visiblePanos = []
  609. options.posAtPanos = options.posAtPanos || {} //在不同漫游点的positions
  610. panos.forEach(pano => {
  611. if (!pano.isAligned()) return
  612. var A = pano.position.clone()
  613. var posB = options.posAtPanos[pano.id] || positions
  614. var posLength = posB.length
  615. for (let i = 0; i < posLength; i++) {
  616. var B = posB[i]
  617. var ray = new THREE.Raycaster(A.clone(), B.clone().sub(A).normalize(), 0, A.distanceTo(B) - (options.tolerance || 0))
  618. var o = ray.intersectObjects(options.model || player.model.colliders, true)
  619. if (!o || !o.length) {
  620. //只要有一点可见,就算整体可见
  621. visiblePanos.push(pano.id)
  622. break
  623. }
  624. }
  625. })
  626. return visiblePanos
  627. },
  628. realVisible: function (object) {
  629. var v = true
  630. var parent = object
  631. var lastParent
  632. while (parent) {
  633. if (parent.visible === false) {
  634. v = false
  635. break
  636. }
  637. lastParent = parent
  638. parent = parent.parent
  639. }
  640. if (v && !(lastParent instanceof THREE.Scene)) {
  641. //已被删除
  642. v = false
  643. }
  644. return v
  645. }
  646. })
  647. }
  648. window.expandMath = function (math) {
  649. Object.assign(math, {
  650. linearClamp(value, xArr, yArr) {
  651. if (arguments.length == 5) {
  652. xArr = [arguments[1], arguments[2]]
  653. yArr = [arguments[3], arguments[4]]
  654. }
  655. let len = xArr.length
  656. if (value <= xArr[0]) return yArr[0]
  657. if (value >= xArr[len - 1]) return yArr[len - 1]
  658. let i = 0
  659. while (++i < len) {
  660. if (value < xArr[i]) {
  661. let x1 = xArr[i - 1],
  662. x2 = xArr[i],
  663. y1 = yArr[i - 1],
  664. y2 = yArr[i]
  665. value = y1 + ((y2 - y1) * (value - x1)) / (x2 - x1)
  666. break
  667. }
  668. }
  669. return value
  670. }
  671. })
  672. }
  673. //--------------------------------------
  674. //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
  675. var Manage = function () {
  676. ;(this.weixinURL = 'https://res.wx.qq.com/open/js/jweixin-1.2.0.js'), (this.time = '?' + new Date().getTime())
  677. this.loadAudio()
  678. this.loadWeixin()
  679. }
  680. //动态加载js文件
  681. Manage.prototype.LoadJs = function (_files, succes) {
  682. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  683. var classcodes = []
  684. var FileArray = []
  685. if (typeof _files === 'object') {
  686. FileArray = _files
  687. } else {
  688. /*如果文件列表是字符串,则用,切分成数组*/
  689. if (typeof _files === 'string') {
  690. FileArray = _files.split(',')
  691. }
  692. }
  693. if (FileArray != null && FileArray.length > 0) {
  694. var LoadedCount = 0
  695. for (var i = 0; i < FileArray.length; i++) {
  696. loadFile(FileArray[i], function () {
  697. LoadedCount++
  698. if (LoadedCount == FileArray.length) {
  699. try {
  700. succes()
  701. } catch (err) {
  702. console.log('err: 您未定义回调')
  703. }
  704. }
  705. })
  706. }
  707. }
  708. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  709. function loadFile(url, success) {
  710. if (!FileIsExt(classcodes, url)) {
  711. var _ThisType = GetFileType(url)
  712. var ThisType = _ThisType.indexOf('?') == -1 ? _ThisType : _ThisType.substring(0, _ThisType.indexOf('?'))
  713. var fileObj = null
  714. if (ThisType == '.js') {
  715. fileObj = document.createElement('script')
  716. fileObj.src = url
  717. } else if (ThisType == '.css') {
  718. fileObj = document.createElement('link')
  719. fileObj.href = url
  720. fileObj.type = 'text/css'
  721. fileObj.rel = 'stylesheet'
  722. } else if (ThisType == '.less') {
  723. fileObj = document.createElement('link')
  724. fileObj.href = url
  725. fileObj.type = 'text/css'
  726. fileObj.rel = 'stylesheet/less'
  727. }
  728. success = success || function () {}
  729. fileObj.onload = fileObj.onreadystatechange = function () {
  730. if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
  731. success()
  732. classcodes.push(url)
  733. }
  734. }
  735. document.getElementsByTagName('head')[0].appendChild(fileObj)
  736. } else {
  737. success()
  738. }
  739. }
  740. /*获取文件类型,后缀名,小写*/
  741. function GetFileType(url) {
  742. if (url != null && url.length > 0) {
  743. return url.substr(url.lastIndexOf('.')).toLowerCase()
  744. }
  745. return ''
  746. }
  747. /*文件是否已加载*/
  748. function FileIsExt(FileArray, _url) {
  749. if (FileArray != null && FileArray.length > 0) {
  750. var len = FileArray.length
  751. for (var i = 0; i < len; i++) {
  752. if (FileArray[i] == _url) {
  753. return true
  754. }
  755. }
  756. }
  757. return false
  758. }
  759. }
  760. //获取页面url后面的参数
  761. Manage.prototype.number = function (variable) {
  762. var query = window.location.search.substring(1)
  763. var vars = query.split('&')
  764. for (var i = 0; i < vars.length; i++) {
  765. var pair = vars[i].split('=')
  766. if (pair[0] == variable) {
  767. return pair[1]
  768. }
  769. }
  770. return false
  771. }
  772. Manage.prototype.loadWeixin = function () {
  773. var that = this
  774. this.LoadJs(that.weixinURL + that.time, function () {})
  775. }
  776. Manage.prototype.weixinShare = function () {
  777. console.log({ str: 'weixinShare', level: 1 })
  778. $.ajax({
  779. url: 'https://www.4dage.com/wechat/jssdk/',
  780. type: 'post',
  781. data: {
  782. url: location.href.split('#')[0]
  783. },
  784. dataType: 'jsonp',
  785. jsonpCallback: 'success_jsonp',
  786. success: function (data, textStatus) {
  787. console.log({ str: '微信 success,' + data.appId, level: 1 })
  788. wx.config({
  789. // debug : true,
  790. appId: data.appId,
  791. timestamp: data.timestamp,
  792. nonceStr: data.nonceStr,
  793. signature: data.signature,
  794. jsApiList: [
  795. 'checkJsApi',
  796. 'onMenuShareTimeline',
  797. 'onMenuShareAppMessage',
  798. 'onMenuShareQQ',
  799. 'onMenuShareWeibo',
  800. 'hideMenuItems',
  801. 'showMenuItems',
  802. 'hideAllNonBaseMenuItem',
  803. 'showAllNonBaseMenuItem',
  804. 'translateVoice',
  805. 'startRecord',
  806. 'stopRecord',
  807. 'onRecordEnd',
  808. 'playVoice',
  809. 'pauseVoice',
  810. 'stopVoice',
  811. 'uploadVoice',
  812. 'downloadVoice',
  813. 'chooseImage',
  814. 'previewImage',
  815. 'uploadImage',
  816. 'downloadImage',
  817. 'getNetworkType',
  818. 'openLocation',
  819. 'getLocation',
  820. 'hideOptionMenu',
  821. 'showOptionMenu',
  822. 'closeWindow',
  823. 'scanQRCode',
  824. 'chooseWXPay',
  825. 'openProductSpecificView',
  826. 'addCard',
  827. 'chooseCard',
  828. 'openCard'
  829. ]
  830. })
  831. },
  832. error: function (XMLHttpRequest, textStatus, errorThrown) {
  833. console.error({ str: '微信分享失败! textStatus:' + textStatus, level: 1 })
  834. }
  835. })
  836. var success_jsonp = function (json) {
  837. console.log({ str: 'success_jsonp:' + json, level: 1 })
  838. }
  839. wx.ready(function () {
  840. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  841. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  842. //分享到朋友圈
  843. console.log({ str: '微信 ready', level: 1 })
  844. wx.onMenuShareTimeline({
  845. title: g_weixinObj.title, // 分享标题
  846. link: g_weixinObj.lineLink, // 分享链接
  847. imgUrl: g_weixinObj.imgUrl, // 分享图标
  848. desc: g_weixinObj.desc
  849. })
  850. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  851. wx.onMenuShareAppMessage({
  852. title: g_weixinObj.title, // 分享标题
  853. desc: g_weixinObj.desc, // 分享描述
  854. link: g_weixinObj.lineLink, // 分享链接
  855. imgUrl: g_weixinObj.imgUrl, // 分享图标
  856. type: '', // 分享类型,music、video或link,不填默认为link
  857. dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空
  858. })
  859. wx.onMenuShareWeibo({
  860. title: g_weixinObj.title, // 分享标题
  861. desc: g_weixinObj.desc, // 分享描述
  862. link: g_weixinObj.lineLink, // 分享链接
  863. imgUrl: g_weixinObj.imgUrl, // 分享图标
  864. success: function () {
  865. // 用户确认分享后执行的回调函数
  866. },
  867. cancel: function () {
  868. // 用户取消分享后执行的回调函数
  869. }
  870. })
  871. wx.onMenuShareQZone({
  872. title: g_weixinObj.title, // 分享标题
  873. desc: g_weixinObj.desc, // 分享描述
  874. link: g_weixinObj.lineLink, // 分享链接
  875. imgUrl: g_weixinObj.imgUrl, // 分享图标
  876. success: function () {
  877. // 用户确认分享后执行的回调函数
  878. },
  879. cancel: function () {
  880. // 用户取消分享后执行的回调函数
  881. }
  882. })
  883. wx.onMenuShareQQ({
  884. title: g_weixinObj.title, // 分享标题
  885. desc: g_weixinObj.desc, // 分享描述
  886. link: g_weixinObj.lineLink, // 分享链接
  887. imgUrl: g_weixinObj.imgUrl, // 分享图标
  888. success: function () {
  889. // 用户确认分享后执行的回调函数
  890. },
  891. cancel: function () {
  892. // 用户取消分享后执行的回调函数
  893. }
  894. })
  895. wx.error(function (res) {
  896. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  897. })
  898. })
  899. }
  900. Manage.prototype.dealURL = function (src, type) {
  901. //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
  902. //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
  903. if (window.isLocal && settings.localPrefix != void 0) {
  904. //本地将线上的前缀替换
  905. var oldPrefix = 'super.4dage.com/' //最简单的地址写一个,如果有其他完全不一样的地址就用数组逐个判断
  906. var index = src.indexOf(oldPrefix)
  907. if (index > -1) {
  908. var wholeOldPrefix = src.slice(0, index + oldPrefix.length)
  909. return src.replace(wholeOldPrefix, settings.localPrefix)
  910. } else console.error('没有找到合适的本地链接')
  911. return src
  912. } else {
  913. //add https://
  914. var prefix = g_Prefix.replace('https://', '').replace('http://', '')
  915. if (!src.includes('http:/') && !src.includes('https:/') && src.includes(prefix)) {
  916. src = 'https://' + src
  917. }
  918. return src
  919. }
  920. }
  921. Manage.prototype.removeSrcPostMark = function (url) {
  922. //去除texture.load时自动加上的'?'
  923. var index = url.indexOf('?')
  924. if (index > -1) {
  925. return url.slice(0, index)
  926. } else return url
  927. }
  928. Manage.prototype.showInfo = function (o) {
  929. // ({result:true, title:"发布成功"});
  930. var box = $('.resultBox')
  931. var title = o.title || o || i18n.get('保存成功')
  932. box.children().eq(0).html(title)
  933. //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000);
  934. var time = o.time || THREE.Math.clamp(title.length * 130, 1300, 5000)
  935. o.time || console.log('showtime ' + time)
  936. //实际有一半的时间在渐变透明度
  937. this.showInfoTimer && clearTimeout(this.showInfoTimer)
  938. box.removeClass('animate') //如果之后不久又要showinfo一个的话,先停止前面的animate
  939. setTimeout(
  940. function () {
  941. box.css({
  942. '-webkit-animation-duration': time + 'ms',
  943. 'animation-duration': time + 'ms'
  944. })
  945. if (o.top) {
  946. box.children().css('top', o.top + '%')
  947. } else {
  948. box.children().css('top', '')
  949. }
  950. box.removeClass('hide')
  951. box.addClass('animate')
  952. if (o.dontInteract) {
  953. //遮挡对屏幕的操作
  954. box.css('pointer-events', 'auto')
  955. } else {
  956. box.css('pointer-events', 'none')
  957. }
  958. this.showInfoTimer = setTimeout(
  959. function () {
  960. box.removeClass('animate')
  961. box.addClass('hide')
  962. this.showInfoTimer = null
  963. }.bind(this),
  964. time + 20
  965. )
  966. }.bind(this),
  967. 50
  968. ) //这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧
  969. } //like: manage.showInfo({title:'a', top:20})
  970. //公用的函数
  971. function getQueryVariable(variable) {
  972. var query = window.location.search.substring(1)
  973. var vars = query.split('&')
  974. for (var i = 0; i < vars.length; i++) {
  975. var pair = vars[i].split('=')
  976. if (pair[0] == variable) {
  977. return pair[1]
  978. }
  979. }
  980. return false
  981. }
  982. //隐藏公司Logo
  983. function showLogo() {
  984. $('#myCompany').hide()
  985. $('#loaderCoBrandName').hide()
  986. $('#title-logo').hide()
  987. $('.title-container').css('justify-content', 'center')
  988. }
  989. //czj 添加随机的时间
  990. function randomTime() {
  991. return new Date()
  992. }
  993. function matcher(data) {
  994. if (!data || !g_version) return data
  995. delete data.model.vision_version
  996. var _data = {
  997. files: {
  998. templates: ['images/images{{number}}/{{filename}}']
  999. },
  1000. model: {
  1001. sid: window.number,
  1002. camera_start:
  1003. data.model.images && data.model.images.length != 0
  1004. ? {
  1005. camera: {
  1006. zoom: '-1',
  1007. quaternion: [
  1008. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  1009. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  1010. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  1011. JSON.parse(data.model.images[0].metadata).camera_quaternion.y
  1012. ]
  1013. },
  1014. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  1015. mode: '0'
  1016. }
  1017. : ''
  1018. },
  1019. sid: window.number,
  1020. hoticon: {
  1021. default: 'https://super.4dage.com/images/4dagePoint2.png',
  1022. higt: 'https://super.4dage.com/images/4dagePoint.png'
  1023. },
  1024. special: 'false',
  1025. weixinDesc: ''
  1026. }
  1027. $.extend(true, data, _data)
  1028. return data
  1029. }
  1030. function hotMatcher(data = {}) {
  1031. //if(!data || !g_version) return data;
  1032. if (g_version) {
  1033. data.tourAudio = data.audio || {}
  1034. } else {
  1035. data.tourAudio = {}
  1036. }
  1037. return data
  1038. }
  1039. var GifTexDeal = {
  1040. animateObjects: [],
  1041. animateTexs: [],
  1042. addAnimation: function (texture, owner, info, id) {
  1043. /* if(this.animateObjects.find(e=>
  1044. e.texture == texture && !ifSame(info, e.info)
  1045. )) */
  1046. var animation
  1047. var tex = this.animateTexs.find(e => e.texture == texture)
  1048. if (tex) {
  1049. animation = tex
  1050. } else {
  1051. animation = { texture, info }
  1052. this.animateTexs.push(animation)
  1053. this.setRepeart(animation)
  1054. }
  1055. var object = {
  1056. animation, //默认相同的texture对应的info是一样的, 对应一个animation
  1057. owner
  1058. }
  1059. this.animateObjects.push(object)
  1060. return object
  1061. },
  1062. remove: function (object) {
  1063. var index = this.animateObjects.indexOf(object)
  1064. if (index > -1) {
  1065. this.animateObjects.splice(index, 1)
  1066. if (!this.animateObjects.find(e => e.animation == object.animation)) {
  1067. let i = this.animateTexs.indexOf(object.animation)
  1068. this.animateTexs.splice(i, 1)
  1069. object.animation.texture.repeat.set(1, 1)
  1070. }
  1071. this.stop(object)
  1072. }
  1073. },
  1074. setRepeart: function (animation) {
  1075. animation.texture.repeat.set(1 / animation.info.cellXcount, 1 / animation.info.cellYcount)
  1076. },
  1077. start: function (object) {
  1078. if (!object || object.started) return
  1079. object.started = true
  1080. if (object.animation.started) return
  1081. object.animation.started = true
  1082. var info = object.animation.info
  1083. var count = info.cellXcount * info.cellYcount - (info.voidCount || 0)
  1084. if (count <= 1) return
  1085. transitions.start(
  1086. progress => {
  1087. var index = Math.floor((count - 1) * progress)
  1088. var indexX = index % info.cellXcount
  1089. var indexY = info.cellYcount - Math.floor(index / info.cellXcount) - 1 //uv.offset.y是从下到上的
  1090. object.animation.texture.offset.x = indexX / info.cellXcount
  1091. object.animation.texture.offset.y = indexY / info.cellYcount
  1092. //console.log(object.id + " : "+ object.texture.offset.toArray())
  1093. },
  1094. info.duration * -1,
  1095. null,
  1096. /* ()=>{//done (-1):循环
  1097. object.started = false
  1098. object.texture.offset.x = 0;
  1099. object.texture.offset.y = 0;
  1100. this.start(object)
  1101. }, */ 0,
  1102. null,
  1103. object.id,
  1104. 'gif_' + object.animation.texture.id
  1105. )
  1106. },
  1107. stop: function (object) {
  1108. if (!object || !object.started) return
  1109. object.started = false
  1110. //只有该object对应的texture对应的所有object都停止了,才能真的停止动画:
  1111. if (this.animateObjects.find(e => e.animation == object.animation && e.started)) return
  1112. transitions.cancelById('gif_' + object.animation.texture.id)
  1113. object.animation.texture.offset.set(0, 0)
  1114. object.animation.started = false
  1115. }
  1116. }
  1117. var CloneObject = function (copyObj, result, isSimpleCopy, extraReplace) {
  1118. //isSimpleCopy只复制最外层
  1119. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  1120. if (!copyObj) return copyObj //0 null undefined ''
  1121. result = result || {}
  1122. if (copyObj instanceof Array) {
  1123. /* if (copyObj[0]instanceof Object) {
  1124. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  1125. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  1126. }
  1127. return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object
  1128. return copyObj.map(e => {
  1129. if (e instanceof Object) {
  1130. return CloneObject(e)
  1131. } else return e
  1132. })
  1133. } else {
  1134. if (copyObj.clone instanceof Function) {
  1135. //解决一部分
  1136. return copyObj.clone()
  1137. }
  1138. }
  1139. for (var key in copyObj) {
  1140. if (copyObj[key] instanceof Object && !isSimpleCopy) result[key] = CloneObject(copyObj[key])
  1141. else result[key] = copyObj[key]
  1142. //如果是函数类同基本数据,即复制引用
  1143. }
  1144. return result
  1145. }
  1146. var ifSame = function (object1, object2) {
  1147. if (object1 == object2) 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) : ''