manage.js 117 KB

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