manage.js 73 KB

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