manage.js 55 KB

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