manage.js 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295
  1. var g_ProjectName=window.location.pathname.substring(window.location.pathname.indexOf("/")+1,window.location.pathname.lastIndexOf("/"));
  2. // var g_Prefix="https://super.4dage.com/";
  3. // var g_Prefix=window.location.href.substring(0,window.location.href.indexOf("/index.html")+1);
  4. var g_Prefix =window.myTitUrl
  5. var s = window.location.href.split('/');
  6. s.pop();
  7. // var g_Prefix = s.join('/');
  8. window.isLocal = true
  9. var g_index=null;
  10. var g_modeldata=null;
  11. var g_weixinTitle=null;
  12. var g_Hots=null;
  13. var g_HotMeshes=[];
  14. var g_HotMeshSize = {
  15. g_HotMeshWidth: 0.3,
  16. g_HotMeshHeight:0.3
  17. };
  18. //add表示添加,delete表示删除
  19. var g_HotStatus=null;
  20. var g_newHot = [];//存储新加热点
  21. var g_HotImage= {
  22. "point":"https://super.4dage.com/images/4dagePoint2.png",
  23. "point2":"https://super.4dage.com/images/4dagePoint.png"
  24. };
  25. var g_saveHot=false;
  26. var g_TextColor=0x7777ff;
  27. var g_Text=null;
  28. var g_TextPlaneMesh=[];
  29. var g_TextIconMesh=[];
  30. var g_TextIcon="./images/text.png";
  31. var g_SelectTextIndex=null;
  32. var g_TextShow=null;
  33. var g_audioPlay=false;
  34. var g_background=null;
  35. var g_roof=null;
  36. var g_data2 = null;//加载的data2.js的内容
  37. var g_bgAudio=null;//背景音乐
  38. var g_tourAudio=null;//导览音乐
  39. var g_play = 1;//表示播放图标状态
  40. var g_playAudio = null;//当前在播放或当继续播放时应该播放的,是g_bgAudio或g_tourAudio
  41. var g_currentHot = null;//当前打开的热点
  42. //var g_Texture=null;
  43. //var g_ChunknameTexture={}; //chunkname和贴图名称对应
  44. var g_NormalTexture=false;
  45. var g_SpecularTexture=false;
  46. var g_DirectionalLight=null;
  47. var g_snapShotWidth = 200; //截图下载图片的大小
  48. var g_snapShotHeight = 140;
  49. //微信分享
  50. var g_weixinObj = {
  51. "title": document.querySelector("head title").innerHTML,
  52. "lineLink" : window.location.href,
  53. "imgUrl" : "https://www.4dmodel.com/SuperPanoramic/images/weixintitle.jpg",
  54. "desc" : "四维时代提供技术支持",
  55. }
  56. window.browser = { //提前定义
  57. isMobile: function() {
  58. var e = navigator.userAgent || navigator.vendor || window.opera;
  59. return /(android|bb\d+|meego).+mobile|android|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(e) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(e.substr(0, 4))
  60. },
  61. isFullscreen: function() {
  62. return document.fullscreenElement || document.mozFullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement
  63. },
  64. valueFromHash: function(e, t) {
  65. var i = new RegExp("[#&?]" + e + "=([^#&?]*)")
  66. , n = i.exec(window.location.href);
  67. if (!n)
  68. return t;
  69. var r = n[1];
  70. return "boolean" == typeof t ? "true" === r || "1" === r : "number" == typeof t ? parseFloat(r) : window.decodeURIComponent(r)
  71. },
  72. urlHasValue: function(key, isGetValue) {
  73. let querys = window.location.search.substr(1).split("&")
  74. if (isGetValue) {
  75. for (let i = 0; i < querys.length; i++) {
  76. let keypair = querys[i].split("=")
  77. if (keypair.length === 2 && keypair[0] === key) {
  78. return keypair[1]
  79. }
  80. }
  81. return ""
  82. } else {
  83. for (let i = 0; i < querys.length; i++) {
  84. let keypair = querys[i].split("=")
  85. if (keypair[0] == key) {
  86. return true
  87. }
  88. }
  89. return false
  90. }
  91. },
  92. }
  93. var settings = {
  94. hotClickEvent:{
  95. video:{
  96. playAndPause:true,
  97. examine:false,
  98. openHot:false
  99. },
  100. photo:{
  101. examine:false,
  102. openHot:false
  103. },
  104. shine:{
  105. examine:true,
  106. openHot:true
  107. }
  108. },
  109. hotClickActions:['playAndPause','examine','openHot','fastTran'],
  110. //默认的:
  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: '2k',
  122. max: '4k',
  123. },
  124. bigMobile:{ //width和height都超过一定值
  125. nav: browser.urlHasValue('padNav',true) || '2k',
  126. max: browser.urlHasValue('padMax',true) || '4k',//'2k',
  127. },
  128. mobile:{
  129. nav: browser.urlHasValue('phoneNav',true) || '1k', //不放大时
  130. max: browser.urlHasValue('phoneMax',true) || '4k', //放到最大
  131. }
  132. }, //可以稍后自行修改
  133. }
  134. if(window.number == '725'||window.number == '724'){
  135. //settings.mobileNavHigh = true
  136. settings.tileClass.mobile = {nav:'2k', max: '2k'}
  137. }
  138. //共用函数:
  139. window.common = null;
  140. window.MathLight = null;
  141. window.math = null
  142. window.easing = null
  143. window.lerp = null
  144. window.transitions = null
  145. function watch(object, propName, initialValue){ //监听某个属性的变化
  146. let v = initialValue
  147. Object.defineProperty(object, propName, {
  148. get: function() {
  149. return v
  150. },
  151. set: function(e) {
  152. console.log('watch:',propName, e)
  153. v = e
  154. }
  155. })
  156. }
  157. var toPrecision = function(e, t) {
  158. function i(e, t) {
  159. var i = Math.pow(10, t);
  160. return Math.round(e * i) / i
  161. }
  162. if (e instanceof Array) {
  163. for (var n = 0; n < e.length; n++)
  164. e[n] = i(e[n], t);
  165. return e
  166. }
  167. return i(e, t)
  168. }
  169. var dealMap = (map, o={} )=>{
  170. //使不resize when image is not power of two ,但缩小时会有锯齿
  171. if(!o.ignoreResize){
  172. if(!map.image || !THREE.Math.isPowerOfTwo(map.image.width ) || !THREE.Math.isPowerOfTwo(map.image.height )){
  173. map.wrapS = map.wrapT = THREE.ClampToEdgeWrapping;
  174. map.minFilter = THREE.LinearFilter;
  175. //map.generateMipmaps = true;
  176. }
  177. }
  178. if(!browser.isMobile()) map.anisotropy = 3
  179. }
  180. var dom = {
  181. getOffset: function(type, element, parent) {
  182. left = (type == "left") ? element.offsetLeft : element.offsetTop;
  183. if (!parent) parent = $("body")[0];
  184. while (element = element.offsetParent) {
  185. if (element == parent) break;
  186. left += (type == "left") ? element.offsetLeft : element.offsetTop;
  187. }
  188. return left;
  189. }
  190. };
  191. var getTransformSid = function(){
  192. var name
  193. if(player.mode == 'panorama'){
  194. name = player.currentPano ? player.currentPano.id : 'outside'
  195. }else{
  196. name = 'outside'
  197. }
  198. return name
  199. }
  200. var LineDraw = {
  201. /* createLine: function(posArr, o) {
  202. var e = new THREE.BufferGeometry
  203. , p = new Float32Array(6);
  204. e.addAttribute("position", new THREE.BufferAttribute(p,3));
  205. //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
  206. var p = e.attributes.position.array;
  207. for (var i = 0; i < 2; i++) {
  208. p[i * 3] = posArr[i].x;
  209. p[i * 3 + 1] = posArr[i].y;
  210. p[i * 3 + 2] = posArr[i].z;
  211. }
  212. var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
  213. linewidth: o.width || 1,
  214. //windows无效。 似乎mac/ios上粗细有效 ?
  215. color: o.color || defaultColor,
  216. transparent: o.dontAlwaysSeen ? false : true,
  217. depthTest: o.dontAlwaysSeen ? true : false
  218. })
  219. var line = new THREE.Line(e,mat);
  220. line.renderOrder = o.renderOrder || 4
  221. //同tagStem; //如果不加高,可能会部分被model遮住
  222. return line;
  223. } */
  224. createLine: function (posArr, o={}) {
  225. //多段普通线 (第二个点和第三个点之间是没有线段的, 所以不用在意线段顺序)
  226. var mat
  227. if(o.mat){
  228. mat = o.mat
  229. }else{
  230. let prop = {
  231. color: o.color || defaultColor,
  232. transparent: o.dontAlwaysSeen ? false : true,
  233. depthTest: o.dontAlwaysSeen ? true : false,
  234. opacity: o.opacity != void 0 ? o.opacity : 1,
  235. }
  236. if(o.deshed ){
  237. prop.dashSize = o.dashSize || 0.1,
  238. prop.gapSize = o.gapSize || 0.1
  239. }
  240. mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"](prop)
  241. }
  242. var line = new THREE.LineSegments(new THREE.BufferGeometry, mat);
  243. line.renderOrder = o.renderOrder || 4
  244. this.moveLine(line, posArr)
  245. return line;
  246. },
  247. moveLine: function (line, posArr) {
  248. if(posArr.length == 0)return
  249. let position = new Float32Array(posArr.length * 3); //[]
  250. for (var i = 0; i < 2; i++) {
  251. position[i * 3] = posArr[i].x;
  252. position[i * 3 + 1] = posArr[i].y;
  253. position[i * 3 + 2] = posArr[i].z;
  254. }
  255. line.geometry.addAttribute("position", new THREE.BufferAttribute(position,3));
  256. //line.geometry.setAttribute('position', new THREE.Float32BufferAttribute(new Float32Array(position), 3));
  257. line.geometry.attributes.position.needsUpdate = true;
  258. line.geometry.computeBoundingSphere();
  259. /* if(line.material instanceof THREE.LineDashedMaterial){
  260. line.computeLineDistances() //只有非buffer的geometry才有
  261. } */
  262. }
  263. ,
  264. }
  265. var convertTool = {
  266. getPos2d : function(point, camera, dom){//获取一个三维坐标对应屏幕中的二维坐标
  267. var camera = camera || player.camera;
  268. var dom = dom || player.domElement;
  269. if(!camera)return
  270. 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);
  271. var x,y;
  272. x = (pos.x + 1) / 2 * dom.clientWidth;
  273. y = (1 - (pos.y + 1) / 2) * dom.clientHeight;
  274. var inSight = x <= dom.clientWidth && x >= 0 //是否在屏幕中
  275. && y <= dom.clientHeight && y >= 0
  276. return {
  277. pos: new THREE.Vector2(x,y), // 屏幕像素坐标
  278. vector: pos, //(范围 -1 ~ 1)
  279. trueSide : pos.z<1, //trueSide为false时,即使在屏幕范围内可见,也是反方向的另一个不可以被渲染的点 参见Tag.update
  280. inSight : inSight //在屏幕范围内可见
  281. };
  282. },
  283. ifShelter: function (pos3d, pos2d, camera, floorIndex) {
  284. //检测某点在视线中是否被mesh遮挡
  285. if (!pos2d) pos2d = convertTool.getPos2d(pos3d )
  286. camera = camera || player.camera
  287. var ori = new THREE.Vector3(pos2d.x, pos2d.y, -1).unproject(camera) //找到视线原点
  288. var dir = pos3d.clone().sub(ori).normalize()
  289. var ray = new THREE.Raycaster(ori, dir); //由外向里 因为模型从内侧是可见的所以从外侧
  290. /* if(config.isEdit && publicObjectSet.editor.mainDesign.editing){
  291. var o = ray.intersectObjects(publicObjectSet.editor.mainDesign.wallMeshes);
  292. }else{ */
  293. let colliders = player.model.allFloorsVisible ? player.model.colliders : (floorIndex != void 0 ? player.model.floors.index[floorIndex] : player.model.currentFloor).collider.children
  294. //let colliders = (floorIndex == void 0 ) ? player.model.colliders : player.model.floors.index[floorIndex].collider.children
  295. var o = ray.intersectObjects(colliders);
  296. //}
  297. var len = pos3d.distanceTo(ori);
  298. if (o && o.length) {
  299. for(var i=0;i<o.length;i++){
  300. if(o[i].distance < len){ return true; }//有遮挡
  301. }
  302. }
  303. },
  304. /*
  305. 拖拽时,获取鼠标在拖拽面上的位置(需要借助另一个intersectPlane面来计算,即和相机方向一样的面,可保证铺满屏幕)
  306. 但是不一定能获取到,比如鼠标射线不朝向拖拽面时,即使获取也会是一个意外的反方向的交点。
  307. */
  308. getPosAtPlane : function(pos, info/* , mouse, camera */){ //pos:与intersectPlane的交点 见笔记
  309. var A = pos;
  310. var player = player;
  311. var mouse = player.mouse;
  312. var O = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(player.camera);
  313. if(info.y != void 0){//地面线的
  314. var y = info.y;
  315. if(player.mode == "floorplan"/* || Math.abs(O.x-pos.x)<0.0001 && Math.abs(O.z-pos.z)<0.0001) */){
  316. //intersectPlane和地面平行,无交点
  317. var x = pos.x, z = pos.z;
  318. }else{
  319. if(y<player.camera.position.y && O.y <= A.y /* || y>player.camera.position.y && O.y >= A.y */)return null; //鼠标射线向上。因为相机一定位于地面以上(地面不会抬高到相机上吧?),所以无交点。
  320. if(O.y == A.y){console.log('一样??');return;}
  321. if(A.y == y){console.log('一样2??');return;}
  322. var r = (O.y-y)/(A.y-y);
  323. var x = (r*A.x-O.x)/(r-1);
  324. var z = (r*A.z-O.z)/(r-1);
  325. }
  326. }else{//垂直的也有越过消失点以后反向变化的情况,但使用时影响不大
  327. var N = info.normalVec;
  328. var P = info.pullPos;
  329. if(N.y != 0 ){console.log('N.y != 0');return;} //仅仅支持垂直于地面的的墙壁,目前都是
  330. if(O.z==A.z){console.log('O.z==A.z?');return;}
  331. if(N.z!=0 && N.x != 0){//直接用这个通用的也可以,支持斜线的墙
  332. //console.log('N.z==0 && N.x == 0?');
  333. var c = ( N.x*(A.x-O.x) + N.y*(A.y-O.y) + N.z*(A.z-O.z));
  334. if(c == 0){console.log("分母为0?? return;");return;}
  335. 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
  336. var x = t * (A.x - O.x) + O.x;
  337. var y = t * (A.y - O.y) + O.y;
  338. var z = t * (A.z - O.z) + O.z;
  339. /*原理: 已知空间直线L:(x-a)/m=(x-b)/n=(z-c)/p和空间平面π:Ax+By+Cz+D=0;
  340. 求直线L与平面π的交点的坐标。
  341. 把直线方程改写成参数形式:设(x-a)/m=(x-b)/n=(z-c)/p=t;
  342. 则x=mt+a;y=nt+b;z=pt+c;代入平面π的方程得:
  343. A(mt+a)+B(nt+b)+C(pt+c)+D=0
  344. 由此解得t=-(Aa+Bb+Cc+D)/(Am+Bn+Cp)
  345. 再代入参数方程即得交点的坐标(x,y,z). */
  346. }else if(N.x ==0 ){ //z与pullPos相等
  347. var z = P.z;
  348. if(O.y == A.y){console.log('一样??');return;}
  349. if(A.y == y){console.log('一样2??');return;}
  350. if(A.z == z){console.log('一样3??');return;}
  351. var r = (O.z-z)/(A.z-z);
  352. var x = (r*A.x-O.x)/(r-1);
  353. var y = (r*A.y-O.y)/(r-1);
  354. }else if(N.z == 0){//x与pullPos相等
  355. var x = P.x;
  356. if(O.y == A.y){console.log('一样??');return;}
  357. if(A.y == y){console.log('一样2??');return;}
  358. if(A.x == x){console.log('一样3??');return;}
  359. var r = (O.x-x)/(A.x-x);
  360. var y = (r*A.y-O.y)/(r-1);
  361. var z = (r*A.z-O.z)/(r-1);
  362. }
  363. }
  364. return new THREE.Vector3(x,y,z);
  365. },
  366. getMouseIntersect : function(camera, meshes, mouse){//获取鼠标和meshes交点
  367. var raycaster = new THREE.Raycaster;
  368. camera.updateMatrixWorld();
  369. var origin = new THREE.Vector3(mouse.x,mouse.y,-1).unproject(camera)
  370. , end = new THREE.Vector3(mouse.x,mouse.y,1).unproject(camera);
  371. var dir = end.sub(origin).normalize()
  372. raycaster.set(origin, dir);
  373. var n = raycaster.intersectObjects(meshes);
  374. if (0 === n.length)
  375. return null;
  376. return n[0];
  377. },
  378. ifIntersectChunks : function(A,B,options={}){//获取某个线段/射线和meshes的交点
  379. var dir = B.clone().sub(A).normalize();
  380. var len = options.InfinityLen ? Infinity : A.distanceTo(B) + (options.extLen||0);
  381. var ray = new THREE.Raycaster(A.clone(), dir, 0, len);
  382. var o = ray.intersectObjects(options.model || player.model.colliders);
  383. if (o && o.length)return o;
  384. if(options.throughWidth){ //允许最小宽度,防止穿过极小的缝隙导致撞墙感
  385. var normal = math.getNormal({points:[{x:A.x, y:A.z},{x:B.x, y:B.z}]});//线段法线
  386. normal.multiplyScalar(options.throughWidth)
  387. var normalVec3 = new THREE.Vector3(normal.x, 0, normal.y);
  388. var A2 = A.clone().add(normalVec3)
  389. ray.set(A2, dir);
  390. var o2 = ray.intersectObjects(options.model || player.model.colliders);
  391. ray.set(A.clone().add(normalVec3.negate()), dir);
  392. if (o2 && o2.length)return o2;
  393. var o3 = ray.intersectObjects(options.model || player.model.colliders);
  394. if (o3 && o3.length)return o3;
  395. }
  396. return null;
  397. },
  398. getPosAtSphere : function(pos3d, toPanoPos){
  399. var dir = pos3d.clone().sub(toPanoPos);
  400. dir.normalize();//然后计算在球中
  401. dir.multiplyScalar(Constants.skyRadius);
  402. dir.add(toPanoPos);
  403. return dir;
  404. } ,
  405. getScaleForConstantSize : function(op={}){ //获得规定二维大小的mesh的scale值。可以避免因camera的projection造成的mesh视觉大小改变。 来源:tag.updateDisc
  406. var w;
  407. var i = new THREE.Vector3, o = new THREE.Vector3, l = new THREE.Vector3, c = new THREE.Vector3, h = new THREE.Vector3
  408. if(!op.resolution){
  409. let renderSize = player.sceneRenderer.renderer.getSize()
  410. op.resolution = {x:renderSize.width, y:renderSize.height}
  411. }
  412. if(!op.camera){
  413. let camera = player.cameraControls.activeControl ? player.cameraControls.activeControl.camera : player.camera
  414. let camera2 = camera.clone();
  415. camera2.matrixWorld.copy(player.camera.matrixWorld) //因为其他原因该camera的matrixWorld被还原了,而player.camera的是正确的
  416. op.camera = camera2
  417. }
  418. if(op.width2d) w = op.width2d //如果恒定二维宽度
  419. else{//否则考虑上距离,加一丢丢近大远小的效果
  420. var currentDis, nearBound, farBound
  421. if(op.camera.type == "OrthographicCamera"){
  422. currentDis = (op.camera.right - op.camera.left) / op.camera.zoom
  423. }else{
  424. currentDis = op.position.distanceTo(op.camera.position);
  425. }
  426. w = op.maxSize - ( op.maxSize - op.minSize) * THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
  427. //maxSize : mesh要表现的最大像素宽度; nearBound: 最近距离,若比nearBound近,则使用maxSize
  428. }
  429. i.copy(op.position).project(op.camera), //tag中心在屏幕上的二维坐标
  430. o.set(op.resolution.x / 2, op.resolution.y / 2, 1).multiply(i), //转化成px -w/2 到 w/2的范围
  431. l.set(w / 2, 0, 0).add(o), //加上tag宽度的一半
  432. c.set(2 / op.resolution.x, 2 / op.resolution.y, 1).multiply(l), //再转回 -1 到 1的范围
  433. h.copy(c).unproject(op.camera);//再转成三维坐标,求得tag边缘的位置
  434. var g = h.distanceTo(op.position)//就能得到tag的三维半径
  435. return g //可能NAN 当相机和position重叠时
  436. } ,
  437. updateVisible : function(object, reason, ifShow, level=0, type){//当所有加入的条件都不为false时才显示. reason='force'一般是强制、临时的
  438. if(!object.unvisibleReasons) object.unvisibleReasons = []; //如果length>0代表不可见
  439. if(!object.visibleReasons) object.visibleReasons = []; //在同级时,优先可见
  440. var update = function(){
  441. //先按从高到低的level排列
  442. object.unvisibleReasons = object.unvisibleReasons.sort((a,b)=>b.level-a.level)
  443. object.visibleReasons = object.visibleReasons.sort((a,b)=>b.level-a.level)
  444. var maxVisiLevel = object.visibleReasons[0] ? object.visibleReasons[0].level : -1
  445. var maxunVisiLevel = object.unvisibleReasons[0] ? object.unvisibleReasons[0].level : -1
  446. var shouldVisi = maxVisiLevel >= maxunVisiLevel
  447. var visiBefore = object.visible
  448. if(visiBefore != shouldVisi){
  449. object.visible = shouldVisi
  450. object.dispatchEvent({
  451. type: 'isVisible',
  452. visible: shouldVisi,
  453. reason,
  454. })
  455. }
  456. }
  457. if(ifShow){
  458. var index = object.unvisibleReasons.findIndex(e=>e.reason == reason)
  459. if(index > -1){
  460. type = 'cancel'
  461. object.unvisibleReasons.splice(index, 1);
  462. }
  463. if(type == 'add' ){
  464. if(!object.visibleReasons.some(e=>e.reason == reason)){
  465. object.visibleReasons.push({reason,level})
  466. }
  467. }
  468. }else{
  469. var index = object.visibleReasons.findIndex(e=>e.reason == reason)
  470. if(index > -1){
  471. type = 'cancel'
  472. object.visibleReasons.splice(index, 1);
  473. }
  474. if(type != 'cancel' ){
  475. if(!object.unvisibleReasons.some(e=>e.reason == reason)){
  476. object.unvisibleReasons.push({reason,level})
  477. }
  478. }
  479. }
  480. update()
  481. },
  482. getObjVisiByReason : function(object,reason){//获取在某条件下是否可见. 注: 用户在数据集选择可不可见为"datasetSelection"
  483. if(object.visible)return true
  484. else{
  485. return !object.unvisibleReasons || !object.unvisibleReasons.some(e=>e.reason == reason)
  486. }
  487. }
  488. }
  489. window.expandCommon = function(common){
  490. Object.assign(common,{
  491. intervalTool : { //延时update,防止卡顿
  492. list:[],
  493. isWaiting:function(name, func, delayTime/* , autoCycle */){
  494. let item = this.list.find(e=>e.name == name);
  495. if(!item){ //如果没有该项, 则加入循环
  496. let ifContinue = func();
  497. item = {name, func, delayTime};
  498. this.list.push(item);
  499. setTimeout(()=>{
  500. var a = this.list.indexOf(item);
  501. this.list.splice(a,1);
  502. let {func, delayTime} = item;
  503. if(item.requestUpdate || ifContinue ) this.isWaiting(name, func, delayTime); //循环
  504. },delayTime);
  505. }else {//如果有该项,说明现在请求下一次继续更新
  506. //更新属性
  507. item.func = func;
  508. item.delayTime = delayTime;
  509. item.requestUpdate = true;
  510. }
  511. },
  512. },
  513. sortByScore : function(list, request, rank) {
  514. var i = request ? common.filterAll(list, request) : list
  515. return 0 === i.length ? null : i = i.map(function(e) {
  516. let scores = rank.map(function(f){return f(e)}) //add
  517. return {
  518. item: e,
  519. scores,
  520. score: scores.reduce(function(t, i) {
  521. return t + i
  522. }, 0)
  523. }
  524. }).sort(function(e, t) {
  525. return t.score - e.score;
  526. })
  527. },
  528. getVisiblePano : function(positions = [], panos, options={}){//add
  529. var visiblePanos = [];
  530. options.posAtPanos = options.posAtPanos || {}//在不同漫游点的positions
  531. panos.forEach((pano)=>{
  532. if(!pano.isAligned())return;
  533. var A = pano.position.clone();
  534. var posB = options.posAtPanos[pano.id] || positions;
  535. var posLength = posB.length
  536. for(let i=0;i<posLength;i++){
  537. var B = posB[i];
  538. var ray = new THREE.Raycaster(A.clone(), B.clone().sub(A).normalize(), 0, A.distanceTo(B) - (options.tolerance||0) )
  539. var o = ray.intersectObjects(options.model || player.model.colliders, true);
  540. if (!o || !o.length){ //只要有一点可见,就算整体可见
  541. visiblePanos.push(pano.id);
  542. break;
  543. }
  544. }
  545. })
  546. return visiblePanos
  547. }
  548. })
  549. }
  550. //--------------------------------------
  551. //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
  552. var Manage = function(){
  553. this.weixinURL = "https://res.wx.qq.com/open/js/jweixin-1.2.0.js",
  554. this.time = "?"+new Date().getTime();
  555. this.loadAudio();
  556. // this.loadWeixin();
  557. }
  558. //动态加载js文件
  559. Manage.prototype.LoadJs = function(_files, succes){
  560. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  561. var classcodes = [];
  562. var FileArray = [];
  563. if (typeof _files === "object") {
  564. FileArray = _files;
  565. } else {
  566. /*如果文件列表是字符串,则用,切分成数组*/
  567. if (typeof _files === "string") {
  568. FileArray = _files.split(",");
  569. }
  570. }
  571. if (FileArray != null && FileArray.length > 0) {
  572. var LoadedCount = 0;
  573. for (var i = 0; i < FileArray.length; i++) {
  574. loadFile(FileArray[i], function() {
  575. LoadedCount++;
  576. if (LoadedCount == FileArray.length) {
  577. try {
  578. succes();
  579. }
  580. catch(err) {
  581. console.log("err: 您未定义回调");
  582. }
  583. }
  584. })
  585. }
  586. }
  587. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  588. function loadFile(url, success) {
  589. if (!FileIsExt(classcodes, url)) {
  590. var _ThisType = GetFileType(url);
  591. var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0,_ThisType.indexOf("?"));
  592. var fileObj = null;
  593. if (ThisType == ".js") {
  594. fileObj = document.createElement('script');
  595. fileObj.src = url;
  596. } else if (ThisType == ".css") {
  597. fileObj = document.createElement('link');
  598. fileObj.href = url;
  599. fileObj.type = "text/css";
  600. fileObj.rel = "stylesheet";
  601. } else if (ThisType == ".less") {
  602. fileObj = document.createElement('link');
  603. fileObj.href = url;
  604. fileObj.type = "text/css";
  605. fileObj.rel = "stylesheet/less";
  606. }
  607. success = success || function() {};
  608. fileObj.onload = fileObj.onreadystatechange = function() {
  609. if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
  610. success();
  611. classcodes.push(url)
  612. }
  613. }
  614. document.getElementsByTagName('head')[0].appendChild(fileObj);
  615. } else {
  616. success();
  617. }
  618. }
  619. /*获取文件类型,后缀名,小写*/
  620. function GetFileType(url) {
  621. if (url != null && url.length > 0) {
  622. return url.substr(url.lastIndexOf(".")).toLowerCase();
  623. }
  624. return "";
  625. }
  626. /*文件是否已加载*/
  627. function FileIsExt(FileArray, _url) {
  628. if (FileArray != null && FileArray.length > 0) {
  629. var len = FileArray.length;
  630. for (var i = 0; i < len; i++) {
  631. if (FileArray[i] == _url) {
  632. return true;
  633. }
  634. }
  635. }
  636. return false;
  637. }
  638. };
  639. //获取页面url后面的参数
  640. Manage.prototype.number = function(variable) {
  641. var query = window.location.search.substring(1);
  642. var vars = query.split("&");
  643. for (var i=0;i<vars.length;i++) {
  644. var pair = vars[i].split("=");
  645. if(pair[0] == variable){return pair[1];}
  646. }
  647. return(false);
  648. };
  649. Manage.prototype.loadWeixin = function() {
  650. var that = this;
  651. this.LoadJs(that.weixinURL+that.time,function(){ });
  652. }
  653. Manage.prototype.weixinShare = function() {
  654. console.log({str:"weixinShare",level:1})
  655. $.ajax({
  656. url:'https://www.4dage.com/wechat/jssdk/',
  657. type: "post",
  658. data : {
  659. 'url' : location.href.split('#')[0]
  660. },
  661. dataType:"jsonp",
  662. jsonpCallback:"success_jsonp",
  663. success:function(data, textStatus){
  664. console.log({str:"微信 success,"+data.appId, level:1})
  665. wx.config({
  666. // debug : true,
  667. appId : data.appId,
  668. timestamp : data.timestamp,
  669. nonceStr : data.nonceStr,
  670. signature : data.signature,
  671. jsApiList : [ 'checkJsApi', 'onMenuShareTimeline',
  672. 'onMenuShareAppMessage', 'onMenuShareQQ',
  673. 'onMenuShareWeibo', 'hideMenuItems',
  674. 'showMenuItems', 'hideAllNonBaseMenuItem',
  675. 'showAllNonBaseMenuItem', 'translateVoice',
  676. 'startRecord', 'stopRecord', 'onRecordEnd',
  677. 'playVoice', 'pauseVoice', 'stopVoice',
  678. 'uploadVoice', 'downloadVoice', 'chooseImage',
  679. 'previewImage', 'uploadImage', 'downloadImage',
  680. 'getNetworkType', 'openLocation', 'getLocation',
  681. 'hideOptionMenu', 'showOptionMenu', 'closeWindow',
  682. 'scanQRCode', 'chooseWXPay',
  683. 'openProductSpecificView', 'addCard', 'chooseCard',
  684. 'openCard' ]
  685. });
  686. },
  687. error:function(XMLHttpRequest,textStatus,errorThrown){
  688. console.error({str:"微信分享失败! textStatus:"+textStatus, level:1})
  689. }
  690. });
  691. var success_jsonp = function(json){
  692. console.log({str:"success_jsonp:"+json, level:1});
  693. };
  694. wx.ready(function(){
  695. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  696. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  697. //分享到朋友圈
  698. console.log({str:"微信 ready",level:1})
  699. wx.onMenuShareTimeline({
  700. title: g_weixinObj.title, // 分享标题
  701. link: g_weixinObj.lineLink, // 分享链接
  702. imgUrl: g_weixinObj.imgUrl, // 分享图标
  703. desc: g_weixinObj.desc
  704. });
  705. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  706. wx.onMenuShareAppMessage({
  707. title: g_weixinObj.title, // 分享标题
  708. desc: g_weixinObj.desc, // 分享描述
  709. link: g_weixinObj.lineLink, // 分享链接
  710. imgUrl: g_weixinObj.imgUrl, // 分享图标
  711. type: '', // 分享类型,music、video或link,不填默认为link
  712. dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空
  713. });
  714. wx.onMenuShareWeibo({
  715. title: g_weixinObj.title, // 分享标题
  716. desc: g_weixinObj.desc, // 分享描述
  717. link: g_weixinObj.lineLink, // 分享链接
  718. imgUrl: g_weixinObj.imgUrl, // 分享图标
  719. success: function () {
  720. // 用户确认分享后执行的回调函数
  721. },
  722. cancel: function () {
  723. // 用户取消分享后执行的回调函数
  724. }
  725. });
  726. wx.onMenuShareQZone({
  727. title: g_weixinObj.title, // 分享标题
  728. desc: g_weixinObj.desc, // 分享描述
  729. link: g_weixinObj.lineLink, // 分享链接
  730. imgUrl: g_weixinObj.imgUrl, // 分享图标
  731. success: function () {
  732. // 用户确认分享后执行的回调函数
  733. },
  734. cancel: function () {
  735. // 用户取消分享后执行的回调函数
  736. }
  737. });
  738. wx.onMenuShareQQ({
  739. title: g_weixinObj.title, // 分享标题
  740. desc: g_weixinObj.desc, // 分享描述
  741. link: g_weixinObj.lineLink, // 分享链接
  742. imgUrl: g_weixinObj.imgUrl, // 分享图标
  743. success: function () {
  744. // 用户确认分享后执行的回调函数
  745. },
  746. cancel: function () {
  747. // 用户取消分享后执行的回调函数
  748. }
  749. });
  750. wx.error(function(res){
  751. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  752. });
  753. });
  754. }
  755. Manage.prototype.dealURL = function(src, type){
  756. //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
  757. //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
  758. if(window.isLocal && settings.localPrefix!=void 0){//本地将线上的前缀替换
  759. var oldPrefix = 'super.4dage.com/'; //最简单的地址写一个,如果有其他完全不一样的地址就用数组逐个判断
  760. var index = src.indexOf(oldPrefix);
  761. if(index>-1){
  762. var wholeOldPrefix = src.slice(0, index+oldPrefix.length);
  763. return src.replace(wholeOldPrefix, settings.localPrefix)
  764. }else console.error("没有找到合适的本地链接")
  765. return src
  766. }else{
  767. //add https://
  768. var prefix = g_Prefix.replace('https://','').replace('http://','')
  769. if(!src.includes('http:/') && !src.includes('https:/') && src.includes(prefix)){
  770. src = 'https://'+src
  771. }
  772. return src
  773. }
  774. }
  775. Manage.prototype.removeSrcPostMark = function(url){//去除texture.load时自动加上的'?'
  776. var index = url.indexOf('?')
  777. if(index>-1){
  778. return url.slice(0, index)
  779. }else return url
  780. }
  781. Manage.prototype.showInfo = function (o) { // ({result:true, title:"发布成功"});
  782. var box = $(".resultBox");
  783. var title = o.title || o || i18n.get('保存成功');
  784. box.children().eq(0).html(title)
  785. //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000);
  786. var time = o.time || THREE.Math.clamp(title.length*130 ,1300, 5000);
  787. o.time || console.log("showtime " + time)
  788. //实际有一半的时间在渐变透明度
  789. this.showInfoTimer && clearTimeout(this.showInfoTimer)
  790. box.removeClass("animate");//如果之后不久又要showinfo一个的话,先停止前面的animate
  791. setTimeout(function () {
  792. box.css(
  793. {
  794. '-webkit-animation-duration': time + 'ms',
  795. 'animation-duration': time + 'ms'
  796. }
  797. )
  798. if(o.top){
  799. box.children().css('top', o.top + "%");
  800. }else{
  801. box.children().css('top', '' )
  802. }
  803. box.removeClass("hide");
  804. box.addClass("animate");
  805. if (o.dontInteract) {//遮挡对屏幕的操作
  806. box.css('pointer-events', 'auto')
  807. } else {
  808. box.css('pointer-events', 'none')
  809. }
  810. this.showInfoTimer = setTimeout(function () {
  811. box.removeClass("animate");
  812. box.addClass("hide");
  813. this.showInfoTimer = null;
  814. }.bind(this), time + 20)
  815. }.bind(this), 50)//这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧
  816. }//like: manage.showInfo({title:'a', top:20})
  817. //公用的函数
  818. function getQueryVariable(variable)
  819. {
  820. var query = window.location.search.substring(1);
  821. var vars = query.split("&");
  822. for (var i=0;i<vars.length;i++) {
  823. var pair = vars[i].split("=");
  824. if(pair[0] == variable){return pair[1];}
  825. }
  826. return(false);
  827. }
  828. //隐藏公司Logo
  829. function showLogo(){
  830. $("#myCompany").hide();
  831. $("#loaderCoBrandName").hide();
  832. $("#title-logo").hide();
  833. $(".title-container").css("justify-content","center")
  834. }
  835. //czj 添加随机的时间
  836. function randomTime(){
  837. return new Date()
  838. };
  839. function matcher(data){
  840. if(!data || !g_version ) return data;
  841. delete data.model.vision_version;
  842. var _data = {
  843. files: {
  844. "templates": ["images/images{{number}}/{{filename}}"]
  845. },
  846. model :{
  847. sid :window.number,
  848. camera_start:
  849. data.model.images && data.model.images.length != 0 ?
  850. {
  851. camera: {
  852. zoom: "-1",
  853. quaternion: [
  854. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  855. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  856. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  857. JSON.parse(data.model.images[0].metadata).camera_quaternion.y
  858. ]
  859. },
  860. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  861. mode: "0"
  862. }
  863. : ''
  864. },
  865. sid: window.number,
  866. hoticon: {
  867. default: "https://super.4dage.com/images/4dagePoint2.png",
  868. higt: "https://super.4dage.com/images/4dagePoint.png"
  869. },
  870. special: "false",
  871. weixinDesc: ""
  872. };
  873. $.extend(true,data,_data)
  874. return data;
  875. }
  876. function hotMatcher(data={}){
  877. //if(!data || !g_version) return data;
  878. if(g_version) {
  879. data.tourAudio = data.audio || {};
  880. }else{
  881. data.tourAudio = {}
  882. }
  883. return data;
  884. }
  885. var GifTexDeal = {
  886. animateObjects : [],
  887. animateTexs : [] ,
  888. addAnimation : function(texture, owner, info, id){
  889. /* if(this.animateObjects.find(e=>
  890. e.texture == texture && !ifSame(info, e.info)
  891. )) */
  892. var animation
  893. var tex = this.animateTexs.find(e=>e.texture == texture)
  894. if(tex){
  895. animation = tex
  896. }else{
  897. animation = {texture,info }
  898. this.animateTexs.push(animation)
  899. this.setRepeart(animation)
  900. }
  901. var object = {
  902. animation, //默认相同的texture对应的info是一样的, 对应一个animation
  903. owner,
  904. }
  905. this.animateObjects.push(object)
  906. return object
  907. },
  908. remove : function(object){
  909. var index = this.animateObjects.indexOf(object)
  910. if(index>-1){
  911. this.animateObjects.splice(index, 1)
  912. if(!this.animateObjects.find(e=>e.animation == object.animation)){
  913. let i = this.animateTexs.indexOf(object.animation)
  914. this.animateTexs.splice(i, 1)
  915. object.animation.texture.repeat.set(1,1)
  916. }
  917. this.stop(object)
  918. }
  919. },
  920. setRepeart : function(animation){
  921. animation.texture.repeat.set(1/animation.info.cellXcount, 1/animation.info.cellYcount)
  922. },
  923. start: function(object){
  924. if(!object || object.started )return;
  925. object.started = true
  926. if(object.animation.started)return;
  927. object.animation.started = true
  928. var info = object.animation.info
  929. var count = info.cellXcount * info.cellYcount - (info.voidCount || 0)
  930. if(count <= 1)return;
  931. transitions.start( (progress)=>{
  932. var index = Math.floor((count-1) * progress);
  933. var indexX = index % info.cellXcount
  934. var indexY = info.cellYcount - Math.floor(index /info.cellXcount ) - 1; //uv.offset.y是从下到上的
  935. object.animation.texture.offset.x = indexX / info.cellXcount;
  936. object.animation.texture.offset.y = indexY / info.cellYcount;
  937. //console.log(object.id + " : "+ object.texture.offset.toArray())
  938. } , info.duration * (-1), null,/* ()=>{//done (-1):循环
  939. object.started = false
  940. object.texture.offset.x = 0;
  941. object.texture.offset.y = 0;
  942. this.start(object)
  943. }, */ 0 ,null, object.id, "gif_"+object.animation.texture.id);
  944. },
  945. stop: function(object){
  946. if(!object || !object.started)return;
  947. object.started = false
  948. //只有该object对应的texture对应的所有object都停止了,才能真的停止动画:
  949. if(this.animateObjects.find(e=>e.animation == object.animation && e.started)) return;
  950. transitions.cancelById("gif_"+object.animation.texture.id);
  951. object.animation.texture.offset.set(0,0)
  952. object.animation.started = false
  953. }
  954. }
  955. var CloneObject = function(copyObj, result, isSimpleCopy, extraReplace) {
  956. //isSimpleCopy只复制最外层
  957. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  958. if(!copyObj)return copyObj //0 null undefined ''
  959. result = result || {};
  960. if (copyObj instanceof Array) {
  961. /* if (copyObj[0]instanceof Object) {
  962. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  963. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  964. }
  965. return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object
  966. return copyObj.map(e=>{
  967. if(e instanceof Object){
  968. return CloneObject(e)
  969. }else return e
  970. })
  971. }else{
  972. if(copyObj.clone instanceof Function ){ //解决一部分
  973. return copyObj.clone()
  974. }
  975. }
  976. for (var key in copyObj) {
  977. if (copyObj[key] instanceof Object && !isSimpleCopy)
  978. result[key] = CloneObject(copyObj[key]);
  979. else
  980. result[key] = copyObj[key];
  981. //如果是函数类同基本数据,即复制引用
  982. }
  983. return result;
  984. }
  985. ;
  986. var ifSame = function(object1, object2){
  987. if(object1 == object2 )return true // 0 != undefined , 0 == ''
  988. else if(!object1 || !object2) return false
  989. else if(object1.constructor != object2.constructor){
  990. return false
  991. }else if(object1 instanceof Array ) {
  992. if(object1.length != object2.length)return false;
  993. var _object2 = object2.slice(0);
  994. for(let i=0;i<object1.length;i++){
  995. var u = _object2.find(e=>ifSame(object1[i], e));
  996. if(u == void 0 && !_object2.includes(u) && !object1.includes(u))return false;
  997. else{
  998. let index = _object2.indexOf(u);
  999. _object2.splice(index,1);
  1000. }
  1001. }
  1002. return true
  1003. }else if(object1.equals instanceof Function ){//复杂数据仅支持这种,其他的可能卡住?
  1004. return object1.equals(object2)
  1005. }else if(typeof object1 == 'number' || typeof object1 == 'string'){
  1006. if(isNaN(object1) && isNaN(object2))return true
  1007. else return object1 == object2
  1008. }else if(typeof object1 == "object"){
  1009. var keys1 = Object.keys(object1)
  1010. var keys2 = Object.keys(object2)
  1011. if(!ifSame(keys1,keys2))return false;
  1012. for(let i in object1){
  1013. var same = ifSame(object1[i], object2[i]);
  1014. if(!same)return false
  1015. }
  1016. return true
  1017. }else{
  1018. console.log('isSame出现例外')
  1019. }
  1020. }
  1021. function initByTHREE(THREE){
  1022. window.bus = new THREE.EventDispatcher();//因为player一开始总是没创建好,所以加一个事件传递器
  1023. THREE.TransitionPass = function ( scene, camera ) {
  1024. this.renderScene = scene;
  1025. this.renderCamera = camera;
  1026. this.coverRenderTarget = new THREE.WebGLRenderTarget( 100, 100, {
  1027. minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter,
  1028. format: THREE.RGBAFormat
  1029. });
  1030. this.coverTex = this.coverRenderTarget.texture;
  1031. this.enabled = false;
  1032. this.oldClearColor = new THREE.Color();
  1033. this.oldClearAlpha = 1;
  1034. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  1035. this.scene = new THREE.Scene();
  1036. this.material = this.getMaskMaterial()
  1037. var copyShader = THREE.CopyShader;
  1038. this.materialCopy = new THREE.ShaderMaterial( {
  1039. uniforms: this.copyUniforms,
  1040. vertexShader: copyShader.vertexShader,
  1041. fragmentShader: copyShader.fragmentShader,
  1042. blending: THREE.NoBlending,
  1043. depthTest: false,
  1044. depthWrite: false,
  1045. transparent: true
  1046. } );
  1047. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), this.material);
  1048. this.quad.frustumCulled = false; // Avoid getting clipped
  1049. this.scene.add( this.quad );
  1050. }
  1051. THREE.TransitionPass.prototype = {//波形扩散,出下一个画面
  1052. constructor: THREE.TransitionPass,
  1053. setSize: function ( width, height ) {
  1054. this.coverRenderTarget.setSize( width, height );
  1055. },
  1056. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  1057. var oldAutoClear = renderer.autoClear;
  1058. renderer.autoClear = false;
  1059. var uniforms = this.quad.material.uniforms
  1060. uniforms.bgTex.value = readBuffer.texture; //更新
  1061. uniforms.coverTex.value = this.coverTex;
  1062. uniforms.progress.value = player.model.skybox.material.uniforms.progress.value//
  1063. uniforms.screenRatio.value = player.domElement.clientWidth / player.domElement.clientHeight;// 使波纹为圆形
  1064. uniforms.screenRatio.value *= uniforms.screenRatio.value
  1065. renderer.render( this.scene, this.camera);
  1066. renderer.autoClear = oldAutoClear;
  1067. },
  1068. start:function(sceneRenderer){
  1069. this.enabled = true
  1070. //draw coverTex
  1071. this.quad.material.uniforms.progress.value = 1;
  1072. sceneRenderer.renderer.render( sceneRenderer.scene, sceneRenderer.camera, this.coverRenderTarget, true );
  1073. console.log('start111')
  1074. },
  1075. stop:function(){
  1076. this.enabled = false
  1077. console.log('stop111')
  1078. }
  1079. ,
  1080. getMaskMaterial :function(){
  1081. return new THREE.ShaderMaterial( {
  1082. uniforms: {
  1083. coverTex: {
  1084. type: "t",
  1085. value: null
  1086. },
  1087. bgTex: {
  1088. type: "t",
  1089. value: null
  1090. },
  1091. progress:{
  1092. type: "f",
  1093. value: 0
  1094. },
  1095. screenRatio:{
  1096. type: "f",
  1097. value: 1
  1098. }
  1099. },
  1100. vertexShader: `
  1101. varying vec2 vUv;
  1102. void main()
  1103. {
  1104. vUv = uv;
  1105. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  1106. }
  1107. `,
  1108. fragmentShader: `
  1109. uniform sampler2D coverTex;
  1110. uniform sampler2D bgTex;
  1111. uniform float progress;
  1112. uniform float screenRatio;
  1113. varying vec2 vUv;
  1114. void main() {
  1115. const float maxRadius = 0.708; // sqrt(0.5^2+0.5^2)
  1116. const float minRadius = 0.0 ;
  1117. 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));
  1118. float diff = 0.292; //1.0-maxRadius;
  1119. float radiusIn = maxRadius * progress + minRadius * (1.0-progress);
  1120. float radiusOut = radiusIn + diff;
  1121. if(radius < radiusIn) {
  1122. gl_FragColor = texture2D(bgTex, vUv);
  1123. //gl_FragColor = vec4(0.0,0.0,1.0,1.0);//
  1124. }else if(radius>radiusOut){
  1125. gl_FragColor = texture2D(coverTex, vUv) ;
  1126. //gl_FragColor = vec4(1.0,1.0,0.0,1.0);//
  1127. }else{
  1128. vec4 color1 = texture2D(bgTex, vUv);
  1129. vec4 color2 = texture2D(coverTex, vUv);
  1130. float rotio = smoothstep(radiusIn ,radiusOut,radius);
  1131. gl_FragColor = mix(color1, color2, rotio);
  1132. }
  1133. }
  1134. `
  1135. } );
  1136. },
  1137. }
  1138. Object.assign(Manage.prototype, THREE.EventDispatcher.prototype)
  1139. let labels = []
  1140. class Label2D extends THREE.EventDispatcher{
  1141. constructor(o={}){
  1142. super()
  1143. this.position = o.position
  1144. this.elem = $(o.innerHTML || '<div ><a></a></div>');
  1145. $(o.domElement).append(this.elem)
  1146. this.pos2d = new THREE.Vector3
  1147. this.elem.css({position: 'absolute', 'z-index':999})
  1148. this.clickFun = o.clickFun;
  1149. this.clickFun && this.elem.on('click',this.clickFun.bind(this))
  1150. if(o.autoUpdate){
  1151. let update = (e)=>{if(e.cameraChanged) this.update()}
  1152. player.on("view.changed",update) //确保player存在
  1153. this.addEventListener('dispose', (e)=>{
  1154. player.off("view.changed",update)
  1155. })
  1156. }
  1157. this.visible = true
  1158. this.shelterByModel = o.shelterByModel
  1159. this.floorIndex = o.floorIndex
  1160. labels.push(this)
  1161. if(window.player.model){
  1162. this.init()
  1163. }else{
  1164. let f = ()=>{
  1165. window.bus.removeEventListener('playerAndModelReady',f)
  1166. this.init()
  1167. }
  1168. window.bus.addEventListener('playerAndModelReady',f)
  1169. }
  1170. }
  1171. init(){
  1172. if(this.floorIndex != void 0){
  1173. player.model.on("floor.changed",(currentFloor, mode, oldFloor)=>{
  1174. this.update(currentFloor) //注: currentFloor 这时候还没成为 model.currentFloor
  1175. })
  1176. }
  1177. }
  1178. update(currentFloor){
  1179. if(!this.position)return
  1180. if(!this.visible && this.unvisibleReasons.some(e=>e.level == 1) && !this.unvisibleReasons.some(e=>e.level>1) )return;
  1181. /*
  1182. 规定一下level共四层
  1183. level3 是notTrueSide层,权重最高。
  1184. level2 是强制可见层,如editSelected
  1185. level1 是强制不可见,如isPanorama
  1186. level0 是shelter层
  1187. 其中当visible==false时, 若导致不可见的原因是level1 代表不需要计算直接return, 否则还是要执行update 以计算更新可见性
  1188. 所以外部写的setVisible的level必须>0
  1189. */
  1190. var p = convertTool.getPos2d(this.position);
  1191. if(!p || !p.trueSide){
  1192. return this.setVisible(false, 'notTrueSide', 3, null, true)
  1193. //this.elem.css('display','none'); return;
  1194. }
  1195. this.setVisible(true, 'notTrueSide', 3, null, true)
  1196. this.setVisible(true, 'shelter', 0, null, true)
  1197. //判断label是否被模型遮挡,遮挡则消失(如果是漫游模式最好提前计算visiblePanos)
  1198. if(player.mode != 'panorama'){
  1199. currentFloor = currentFloor || player.model.currentFloor
  1200. if(!player.model.allFloorsVisible && this.floorIndex != void 0 && this.floorIndex!= currentFloor.floorIndex){
  1201. this.setVisible(false, 'shelter', 0, null, true)
  1202. //this.elem.css('display','none'); return;
  1203. if(!this.visible)return
  1204. }
  1205. if(this.shelterByModel && convertTool.ifShelter(this.position , p.vector, player.camera, this.floorIndex )){
  1206. //this.elem.css('display','none'); return;
  1207. this.setVisible(false, 'shelter', 0, null, true)
  1208. if(!this.visible)return
  1209. }
  1210. }
  1211. this.elem.css({
  1212. left: p.pos.x +'px',
  1213. top: p.pos.y +'px'
  1214. })
  1215. /* if(settings.vrEnabled){
  1216. this.elem.css({transform:'rotate('+window.screenFaceOrient+'deg)'})
  1217. }else{
  1218. this.elem.css({transform:''})
  1219. } */
  1220. //this.elem.css('display','block');
  1221. this.pos2d = p.vector;
  1222. }
  1223. setVisible(visi, reason, level=1, type, updating){
  1224. let visiOld = this.visible
  1225. convertTool.updateVisible(this, reason, visi, level, type )
  1226. updating || this.update() //再次更新可见性并计算位置
  1227. this.elem.css('display',this.visible?'block':'none');
  1228. /* if(!this.visible){
  1229. this.elem.css('display','none');
  1230. }else{
  1231. if(!visiOld){
  1232. updating || this.update()
  1233. this.elem.css('display','block');
  1234. }
  1235. } */
  1236. }
  1237. setPos(pos){
  1238. this.position = pos;
  1239. this.update()
  1240. }
  1241. dispose(){
  1242. this.elem.remove();
  1243. this._listeners = {}
  1244. this.dispatchEvent({type:'dispose'})
  1245. let index = labels.indexOf(this)
  1246. index > -1 && labels.splice(index,1)
  1247. }
  1248. }
  1249. window.Label2D = Label2D
  1250. class RoomLabel extends Label2D{
  1251. constructor(o){
  1252. if(o.position instanceof Array) o.position = new THREE.Vector3().fromArray(o.position)
  1253. o.innerHTML = `<div class="room-label" ><a><p><span>${o.title}</span></p></a></div>`
  1254. o.domElement = $(".widgets-doll-labels")[0]
  1255. o.shelterByModel = true , o.autoUpdate = true
  1256. o.clickFun = ()=>{
  1257. if(player.roomLebelClickUnabled)return
  1258. let result = common.sortByScore(player.model.floors.index[this.floorIndex].panos, [], [(pano)=>{
  1259. return -pano.position.distanceToSquared(this.position)
  1260. }]);
  1261. player.flyToPano({
  1262. pano : result && result[0] && result[0].item
  1263. })
  1264. }
  1265. super(o)
  1266. this.setTitle(o.title )
  1267. }
  1268. init(){
  1269. super.init()
  1270. //飞入后不可见
  1271. player.on("mode.changing",(oldMode, mode, pano, duration)=>{//准备飞
  1272. this.setStyle(oldMode, mode, duration)
  1273. })
  1274. this.setStyle()
  1275. }
  1276. setStyle(oldMode, mode, duration){
  1277. if(!mode) mode = player.modeTran.split('-')[1] || player.mode //要变成的mode或当前mode
  1278. if(mode == 'panorama'){
  1279. this.setVisible(false, 'isPanorama', 1)
  1280. }else if(oldMode == 'panorama'){
  1281. setTimeout(()=>{
  1282. this.setVisible(true, 'isPanorama', 1)
  1283. },duration*0.7)
  1284. }
  1285. }
  1286. setTitle(title){
  1287. this.title = title || ''
  1288. this.elem.html(`<a><p><span>${this.title}</span></p></a>`)
  1289. }
  1290. setEditSelect(state){//编辑页面用
  1291. this.editing = !!state
  1292. this.setVisible(state, 'editSelected', 2, state ? 'add':'cancel') //强制可见
  1293. }
  1294. }
  1295. window.RoomLabel = RoomLabel
  1296. class HistoryRecord extends THREE.EventDispatcher{
  1297. constructor(o){
  1298. super()
  1299. this.undoList = []
  1300. this.redoList = []
  1301. this.applyData = o.applyData //应用数据的方法
  1302. this.getData = o.getData //获取数据的方法
  1303. this.dataBefore
  1304. window.addEventListener('keydown',(e)=>{
  1305. if(e.keyCode == 90 && e.ctrlKey){//Z
  1306. this.undo()
  1307. }else if(e.keyCode == 89 && e.ctrlKey){//Y
  1308. this.redo()
  1309. }
  1310. })
  1311. }
  1312. undo(){//回退
  1313. let length = this.undoList.length
  1314. if(length>0){
  1315. let unExist
  1316. let last = this.undoList.pop();
  1317. this.applyData && (unExist = !this.applyData(last.before))
  1318. unExist || this.redoList.push(last);
  1319. unExist && this.undo()//找不到就回退下一个。
  1320. this.dispatchEvent('undo')
  1321. //console.log('undo',last)
  1322. }
  1323. }
  1324. redo(){//撤销回退
  1325. let length = this.undoList.length
  1326. let last = this.redoList.pop();
  1327. if(last){
  1328. //注意:每行的顺序不能乱
  1329. this.undoList.push(last)
  1330. this.applyData && this.applyData(last.after)
  1331. this.dispatchEvent('redo')
  1332. //console.log('redo',last)
  1333. }
  1334. }
  1335. beforeChange(o){//在变化之前(可能执行好几次直到变化完,但只有第一次有效)。 o的内容完全根据getData怎么定义
  1336. if(!this.dataBefore){
  1337. let data = this.getData(o)
  1338. data && (this.dataBefore = data)
  1339. }
  1340. }
  1341. afterChange(o){//变化结束,从beforeChange到此算一次操作。
  1342. if(this.dataBefore){
  1343. this.writeIn({before:this.dataBefore, after:this.getData(o)} ) //写入某物体变化前和变化后的状态
  1344. this.dataBefore = null
  1345. }
  1346. }
  1347. writeIn(data ){
  1348. this.redoList.length = 0; //一旦录入新的操作,就不允许undo了
  1349. this.undoList.push(data );
  1350. //console.log('新增undo', data)
  1351. }
  1352. clear(){
  1353. this.redoList.length = 0
  1354. this.undoList.length = 0
  1355. this.dataBefore = null
  1356. }
  1357. }
  1358. window.HistoryRecord = HistoryRecord
  1359. /* class VideoPlayer extends THREE.EventDispatcher{
  1360. constructor(player) {
  1361. super()
  1362. this.instances = new Map()
  1363. this.isFlv = false
  1364. }
  1365. addVideo(src) {
  1366. let video = this._createVideo(src)
  1367. this.instances.set(src, video)
  1368. return video
  1369. }
  1370. getVideo(src) {
  1371. let video = this.instances.get(src)
  1372. if (!video) {
  1373. video = this.addVideo(src)
  1374. }
  1375. return video
  1376. }
  1377. _createVideo(src) {
  1378. let video = document.createElement('video')
  1379. video.setAttribute('crossOrigin', 'anonymous')
  1380. video.setAttribute('playsinline', 'true')
  1381. video.setAttribute('x5-playsinline', 'true')
  1382. video.setAttribute('webkit-playsinline', 'true')
  1383. video.setAttribute('x5-video-player-type', 'h5')
  1384. video.setAttribute('controls', 'true')
  1385. video.setAttribute('controlslist', 'nodownload')
  1386. video.setAttribute('preload', 'meta') //注意,src赋值就会自动加载, preload="meta" 只加载元数据,提高加载速度,否则一开始卡
  1387. video.autoplay = false
  1388. video.muted = true
  1389. video.loop = true
  1390. video.style.position = 'fixed'
  1391. video.style.left = '0'
  1392. video.style.top = '0'
  1393. video.style.zIndex = '1000'
  1394. video.style.width = '200px'
  1395. video.style.display = 'none'
  1396. //document.body.appendChild(video)
  1397. //video.style.display = browser.urlHasValue('debug') ? 'block' : 'none'
  1398. video.src = src
  1399. if(this.isFlv) this.attachFlv(video)
  1400. return video
  1401. }
  1402. attachFlv(video){ 四维看看的会把视频转码成flv和mp4存在服务器, 但是大场景不会,所以安卓(如vivo)加载不了。flv必须用flvjs播放,且苹果有的支持不了
  1403. if(video.flvjsPlayer)return
  1404. let player = flvjs.createPlayer({ type: 'flv', url: video.src }) //需要是flv格式才行
  1405. player.videoElement = video
  1406. player.attachMediaElement(video)
  1407. player.on(flvjs.Events.ERROR, this._onPlayerError.bind(this))
  1408. player.load()
  1409. video.flvjsPlayer = player;
  1410. }
  1411. _onPlayerError() {
  1412. console.warn('视频加载失败')
  1413. }
  1414. changeTypeToFlv(){
  1415. this.isFlv = true
  1416. for(let [key,value] of this.instances){
  1417. this.attachFlv(value)
  1418. }
  1419. }
  1420. } */
  1421. {
  1422. let f = ()=>{
  1423. window.bus.removeEventListener('playerAndModelReady',f)
  1424. player.on("mode.changing",(currentMode, mode, pano, duration)=>{
  1425. let noLine = mode == 'floorplan';
  1426. if(noLine){
  1427. $('.widgets-doll-labels').addClass('noLine').addClass('noCorner')
  1428. }else{
  1429. $('.widgets-doll-labels').removeClass('noLine').removeClass('noCorner')
  1430. }
  1431. })
  1432. player.on("view.changed",(e)=>{
  1433. if(e.cameraChanged){
  1434. //if(needUpdateZIndex){ //如果某个label显示时需要更新index的话,加个参数
  1435. let label_ = labels.filter(e=>e.elem[0].style.display == 'block')
  1436. label_.sort((a,b)=>b.pos2d.z - a.pos2d.z)
  1437. label_.forEach((e,index)=>e.elem.css('z-index', index+1000));
  1438. //}
  1439. }
  1440. })
  1441. player.model.hotGroup.children.length ? logSth() : player.on('gotHotAndStartload',logSth);
  1442. /* {//如果是flv格式的话
  1443. window.videoPlayer = new VideoPlayer()
  1444. if(browser.detectAndroidMobile()){//安卓常常播放不了
  1445. let scriptdom = document.querySelector('#flvJs')
  1446. if(scriptdom){
  1447. scriptdom.src = 'js/lib/flv.min.js'
  1448. scriptdom.onload = ()=>{
  1449. window.videoPlayer.changeTypeToFlv()
  1450. window.bus.dispatchEvent('VideoPlayerReady' )
  1451. //Hot.startLoad()
  1452. }
  1453. }
  1454. }
  1455. } */
  1456. }
  1457. window.bus.addEventListener('playerAndModelReady',f) //player model currentPano都已有
  1458. }
  1459. window.bus.dispatchEvent({type: 'THREE_inited'})
  1460. }
  1461. //最好能知道应该播放到的currentTime
  1462. var SoundManager = {//暂不支持同时播放
  1463. currentAudio:null,//当前正在播放list中的哪一个
  1464. enableSound:true,//是否允许有声音
  1465. playHistory:[],//被打断的加入播放历史
  1466. list:[ ],//同一级别可以互相打断 //暂时不做多级别
  1467. play:function(name, src, currentTime){
  1468. var object = this.list.find(e=>e.name == name)
  1469. if(object){
  1470. if(this.currentAudio){
  1471. this.pause(this.currentAudio.name, false, true)
  1472. }
  1473. {//将当前要播放的播放历史中清除
  1474. let index = this.playHistory.indexOf(object)
  1475. if(index>-1)this.playHistory.splice(index,1);
  1476. }
  1477. this.currentAudio = object
  1478. if(src){
  1479. this.setSrc(name, src)
  1480. }
  1481. if(currentTime!=void 0){
  1482. object.audio.currentTime = currentTime
  1483. }
  1484. if(object.audio && object.src){
  1485. object.audio.load(); // iOS 9 还需要额外的 load 一下, 否则直接 play 无效 *///https://www.cnblogs.com/interdrp/p/4211883.html 部分资料
  1486. object.audio.play();
  1487. object.audio.paused || object.callback && object.callback(true)
  1488. Log(name + ' 播放 ' )
  1489. }
  1490. }
  1491. },
  1492. pause:function(name, autoReplayLast, isInterrupt){//需要能自动恢复上一个被打算的音频。恢复前判断是否还需要播放
  1493. var object = this.list.find(e=>e.name == name)
  1494. if(object && this.currentAudio == object){
  1495. this.currentAudio = null
  1496. if(object.audio){
  1497. object.audio.pause()
  1498. object.callback && object.callback(false)
  1499. object.audio.src && Log(name + ' 中断音频 '+ "("+common.getFileNameFromUrl(object.audio.src)+')' )
  1500. }
  1501. if(isInterrupt){//一般主动调用不需要加这个
  1502. this.playHistory.push(object)//如果是被中断的,加入播放历史,等待恢复播放
  1503. }
  1504. if(autoReplayLast){ //播放之前的音频。它们是被打断过的。
  1505. while(this.playHistory.length){
  1506. var last = this.playHistory.pop();
  1507. if(last.src && last.canplay(last.audio)){
  1508. this.play(last.name )
  1509. }
  1510. }
  1511. }
  1512. }
  1513. },
  1514. setSrc : function(name, src){//不能直接给audio赋src!一定要用这个函数!因为我要拿这里的src来判断有无src,因为貌似audio的src会自动变,''时会变成html的链接
  1515. var object = this.list.find(e=>e.name == name)
  1516. object.src = src
  1517. object.audio.src = src
  1518. Log(`${object.name} 设置src: ${src}`)
  1519. },
  1520. createAudio:function(object={}){//name, level, canplay
  1521. if(!object.fake){
  1522. object.audio = new Audio();
  1523. object.audio.loop = !!object.loop;
  1524. //object.audio.autoplay = true;
  1525. object.audio.addEventListener('ended', ()=>{
  1526. if(object.loop){//循环
  1527. Log(`${object.name} 播放完毕,重新播放`)
  1528. object.audio.play()
  1529. }else{
  1530. this.pause(object.name, true);//停止后的后续处理
  1531. }
  1532. });
  1533. object.audio.oncanplaythrough = ()=>{
  1534. Log(`${object.name} canplaythrough `)
  1535. }
  1536. }
  1537. this.list.push(object)
  1538. },
  1539. initAutoPlay:function(){ //处理设备自动播放限制
  1540. let play = function(){
  1541. if (this.currentAudio && this.currentAudio.audio && this.currentAudio.src && this.currentAudio.audio.paused ) {
  1542. this.currentAudio.audio.play() //一般触屏了都会播放成功,就不识别paused了
  1543. this.currentAudio.callback && this.currentAudio.callback(true)
  1544. Log(`${this.currentAudio.name} 自动播放成功`) //即使设置src在这之后好像也能成功播放
  1545. }else{
  1546. }
  1547. document.removeEventListener("touchstart",play);
  1548. document.removeEventListener("click",play);
  1549. $('#player')[0].removeEventListener("touchstart", play);
  1550. }.bind(this);
  1551. document.addEventListener("WeixinJSBridgeReady", play, false);
  1552. document.addEventListener("touchstart", play);//ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
  1553. document.addEventListener("click", play);
  1554. $('#player')[0].addEventListener("touchstart", play);
  1555. }
  1556. }
  1557. function Log(value, color, fontSize){
  1558. color = color || '#13f'
  1559. fontSize = fontSize || 14
  1560. console.warn(`%c${value}`, `color:${color};font-size:${fontSize}px`)
  1561. }
  1562. Manage.prototype.loadAudio = function() { //相关:g_tourAudio \ g_playAudio
  1563. //热点页面因为挡住了界面,所以暂时不存在别的音频阻止热点音频的可能
  1564. //box视频都静音,所以暂时不考虑
  1565. SoundManager.createAudio({
  1566. name:'bgm',
  1567. level:0,
  1568. src:'',
  1569. loop:true,
  1570. canplay:(audio)=>{
  1571. return this.bgmShouldPlay
  1572. },
  1573. callback:(state)=>{//play或pause时随之触发的函数(即使还没开始播放)
  1574. if(state){
  1575. $("#volume a img").attr("src", "./images/Volume btn_off.png")
  1576. $("#volume").attr("title", "关闭声音");
  1577. }else{
  1578. $("#volume a img").attr("src", "./images/Volume btn_on.png")
  1579. $("#volume").attr("title", "打开声音");
  1580. }
  1581. }
  1582. })
  1583. SoundManager.createAudio({
  1584. name:'tour',
  1585. level:0,
  1586. src:'',
  1587. loop:false,
  1588. canplay:(audio)=>{
  1589. return player.director && player.director.tourIsPlaying && player.director.getAudio()
  1590. }
  1591. })
  1592. SoundManager.createAudio({
  1593. name:'hot',
  1594. fake:true,//实际上没有audio. 只是为了来停止和续播其他音频
  1595. level:1,
  1596. src:'',
  1597. loop:false,
  1598. canplay:(audio)=>{
  1599. }
  1600. })
  1601. $("#volume").find("a").on("click", ()=> {
  1602. if($("#volume img")[0].src.indexOf("btn_on.png")>-1)
  1603. {
  1604. this.switchBgmState(true);
  1605. }
  1606. else if($("#volume img")[0].src.indexOf("btn_off.png")>-1)
  1607. {
  1608. this.switchBgmState(false);
  1609. }
  1610. })
  1611. this.switchBgmState(true);//初始设置允许播放bgm
  1612. SoundManager.initAutoPlay()
  1613. }
  1614. Manage.prototype.switchBgmState = function(state){//按钮的状态完全代表是否应该播放bgm,即使还没加载完
  1615. this.bgmShouldPlay = state
  1616. if(state){
  1617. SoundManager.play('bgm')
  1618. }else{
  1619. SoundManager.pause('bgm')
  1620. }
  1621. this.dispatchEvent && this.dispatchEvent({type:'switchBgmState'})
  1622. /* if(!g_bgAudio || !g_bgAudio.src) return;
  1623. var played = function(){
  1624. console.log('begin play bgm');
  1625. g_play = 1;
  1626. g_playAudio = g_bgAudio;
  1627. g_tourAudio && g_tourAudio.pause()
  1628. }
  1629. var paused = function(){
  1630. g_play = 0;
  1631. g_playAudio == g_bgAudio && (g_playAudio = null)
  1632. }
  1633. if(state ){
  1634. g_bgAudio.play();
  1635. if(g_bgAudio.paused){
  1636. paused()
  1637. }else{
  1638. played()
  1639. return true
  1640. }
  1641. }else{
  1642. g_bgAudio.pause();
  1643. paused()
  1644. }
  1645. g_bgAudio.pauseByHot = false
  1646. g_bgAudio.pauseByTour = false */
  1647. }
  1648. var manage = new Manage();
  1649. //处理cursor优先级
  1650. var CursorDeal = {
  1651. priorityEvent : [//在前面的优先级高
  1652. {"noIntersect":'not-allowed'},
  1653. {"addHot":'cell'},
  1654. {"hoverFootIcon":'pointer'},
  1655. {"hoverHot":'pointer'},
  1656. {"addLabel":'cell'},
  1657. {"moveLabel":'grab'},
  1658. ],
  1659. domElements :[$('#player')[0]],
  1660. list:[], //当前存在的cursor状态
  1661. currentCursorIndex:null,
  1662. /* init : function(viewer){
  1663. this.priorityEvent.forEach(e=>{//刚开始Potree.resourcePath没值,现在换
  1664. for(let i in e){
  1665. e[i] = Common.replaceAll(e[i],'{Potree.resourcePath}',Potree.resourcePath)
  1666. }
  1667. })
  1668. this.domElements = [viewer.renderArea, viewer.mapViewer.renderArea];
  1669. viewer.addEventListener("CursorChange",(e)=>{
  1670. if(e.action == 'add'){
  1671. this.add(e.name)
  1672. }else{
  1673. this.remove(e.name)
  1674. }
  1675. })
  1676. }, */
  1677. add : function(name){
  1678. var priorityItem = this.priorityEvent.find(e=>e[name])
  1679. if(!priorityItem){
  1680. console.error('CursorDeal 未定义优先级 name:'+ name);
  1681. return
  1682. }
  1683. if(!this.list.includes(name)){
  1684. this.judge({addItem: priorityItem, name})
  1685. this.list.push(name)
  1686. }
  1687. },
  1688. remove : function(name){
  1689. var index = this.list.indexOf(name);
  1690. if(index > -1){
  1691. this.list.splice(index, 1)
  1692. this.judge()
  1693. }
  1694. },
  1695. judge:function(o={}){
  1696. //console.log(o,this.list)
  1697. if(o.addItem){
  1698. var addIndex = this.priorityEvent.indexOf(o.addItem)
  1699. if(addIndex < this.currentCursorIndex || this.currentCursorIndex == void 0){
  1700. this.domElements.forEach(e=>e.style.cursor = o.addItem[o.name] )
  1701. this.currentCursorIndex = addIndex
  1702. }
  1703. }else{
  1704. var levelMax = {index:Infinity, cursor:null }
  1705. this.list.forEach(name=>{
  1706. var priorityItem = this.priorityEvent.find(e=>e[name])
  1707. var index = this.priorityEvent.indexOf(priorityItem)
  1708. if(index < levelMax.index){
  1709. levelMax.index = index;
  1710. levelMax.cursor = priorityItem[name]
  1711. }
  1712. })
  1713. this.currentCursorIndex = levelMax.index
  1714. this.domElements.forEach(e=>e.style.cursor = levelMax.cursor || '')
  1715. }
  1716. }
  1717. }
  1718. function logSth(){
  1719. let hotCount = player.model.hotGroup.children.length
  1720. let videoCount = player.model.hotGroup.children.filter(e=>e.texType == 'video').length
  1721. let photoCount = player.model.hotGroup.children.filter(e=>e.texType == 'photo').length
  1722. let shineCount = player.model.hotGroup.children.filter(e=>e.texType == 'shine').length
  1723. let aniCount = player.model.hotGroup.children.filter(e=>e.info.animateInfo).length
  1724. let objCount = player.model.hotGroup.children.filter(e=>e.objObject).length
  1725. let chunkLen = player.model.chunks.length
  1726. let vertexC = player.model.chunks.reduce(function(total, chunk ){return total+chunk.geometry.attributes.position.count}, 0)
  1727. let panoCount = player.model.panos.list.length
  1728. Log(`共有chunk个数 ${chunkLen} ( 顶点数 ${vertexC} )
  1729. 热点个数 ${hotCount} ( vedio ${videoCount} 个,photo ${photoCount} 个,shine ${shineCount}个。 gif ${aniCount} 个,obj ${objCount} 个
  1730. 漫游点数 ${panoCount} 个)`, '#FF4399', 14)
  1731. }
  1732. window.sceneFrom = number.slice(0,3) == 'KJ-' ? 'kankan' : '' //看看or看见转来的
  1733. //兼容一代的場景
  1734. //請求地址統一管理
  1735. var g_onePregix = "https://bigscene.4dage.com/" //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
  1736. var g_version = manage.number("version");
  1737. g_version === "one" ? g_Prefix = g_onePregix : '';