manage.js 63 KB

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