manage.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804
  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. getNormal: function(line2d){//获取二维法向量 方向向内
  401. var x,y;//要求的向量
  402. //line2d的向量
  403. var x1 = line2d.points[1].x - line2d.points[0].x;
  404. var y1 = line2d.points[1].y - line2d.points[0].y;
  405. //假设法向量的x或y固定为1或-1
  406. if(y1 != 0){
  407. x = 1;
  408. y = - (x1 * x) / y1;
  409. }else if(x1 != 0){//y如果为0,正常情况x不会是0
  410. y = 1;
  411. x = - (y1 * y) / x1;
  412. }else{
  413. console.log("两个点一样");
  414. return null;
  415. }
  416. //判断方向里或者外:
  417. var vNormal = new THREE.Vector3(x, 0, y);
  418. var vLine = new THREE.Vector3(x1, 0, y1);
  419. var vDir = vNormal.cross(vLine);
  420. if(vDir.y>0){
  421. x *= -1;
  422. y *= -1;
  423. }
  424. return new THREE.Vector2(x, y).normalize();
  425. },
  426. getPosAtSphere: function(pos3d, toPanoPos) {
  427. var dir = pos3d.clone().sub(toPanoPos);
  428. dir.normalize(); //然后计算在球中
  429. dir.multiplyScalar(Constants.skyRadius);
  430. dir.add(toPanoPos);
  431. return dir;
  432. },
  433. getScaleForConstantSize: function(op = {}) {
  434. //获得规定二维大小的mesh的scale值。可以避免因camera的projection造成的mesh视觉大小改变。 来源:tag.updateDisc
  435. var w;
  436. var i = new THREE.Vector3(),
  437. o = new THREE.Vector3(),
  438. l = new THREE.Vector3(),
  439. c = new THREE.Vector3(),
  440. h = new THREE.Vector3();
  441. if (op.width2d) w = op.width2d;
  442. //如果恒定二维宽度
  443. else {
  444. //否则考虑上距离,加一丢丢近大远小的效果
  445. var currentDis, nearBound, farBound;
  446. if (op.camera.type == "OrthographicCamera") {
  447. currentDis = (op.camera.right - op.camera.left) / op.camera.zoom;
  448. } else {
  449. currentDis = op.position.distanceTo(op.camera.position);
  450. }
  451. w = op.maxSize - (op.maxSize - op.minSize) * THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
  452. //maxSize : mesh要表现的最大像素宽度; nearBound: 最近距离,若比nearBound近,则使用maxSize
  453. }
  454. i.copy(op.position).project(op.camera), //tag中心在屏幕上的二维坐标
  455. o.set(op.resolution.x / 2, op.resolution.y / 2, 1).multiply(i), //转化成px -w/2 到 w/2的范围
  456. l.set(w / 2, 0, 0).add(o), //加上tag宽度的一半
  457. c.set(2 / op.resolution.x, 2 / op.resolution.y, 1).multiply(l), //再转回 -1 到 1的范围
  458. h.copy(c).unproject(op.camera); //再转成三维坐标,求得tag边缘的位置
  459. var g = h.distanceTo(op.position); //就能得到tag的三维半径
  460. return g; //可能NAN 当相机和position重叠时
  461. },
  462. updateVisible: function(object, reason, ifShow, level = 0, type) {
  463. //当所有加入的条件都不为false时才显示. reason='force'一般是强制、临时的
  464. if (!object.unvisibleReasons) object.unvisibleReasons = []; //如果length>0代表不可见
  465. if (!object.visibleReasons) object.visibleReasons = []; //在同级时,优先可见
  466. var update = function() {
  467. //先按从高到低的level排列
  468. object.unvisibleReasons = object.unvisibleReasons.sort((a, b) => b.level - a.level);
  469. object.visibleReasons = object.visibleReasons.sort((a, b) => b.level - a.level);
  470. var maxVisiLevel = object.visibleReasons[0] ? object.visibleReasons[0].level : -1;
  471. var maxunVisiLevel = object.unvisibleReasons[0] ? object.unvisibleReasons[0].level : -1;
  472. var shouldVisi = maxVisiLevel >= maxunVisiLevel;
  473. var visiBefore = object.visible;
  474. if (visiBefore != shouldVisi) {
  475. object.visible = shouldVisi;
  476. object.dispatchEvent({
  477. type: "isVisible",
  478. visible: shouldVisi,
  479. reason,
  480. });
  481. }
  482. };
  483. if (ifShow) {
  484. var index = object.unvisibleReasons.findIndex((e) => e.reason == reason);
  485. if (index > -1) {
  486. type = "cancel";
  487. object.unvisibleReasons.splice(index, 1);
  488. }
  489. if (type == "add") {
  490. if (!object.visibleReasons.some((e) => e.reason == reason)) {
  491. object.visibleReasons.push({ reason, level });
  492. }
  493. }
  494. } else {
  495. var index = object.visibleReasons.findIndex((e) => e.reason == reason);
  496. if (index > -1) {
  497. type = "cancel";
  498. object.visibleReasons.splice(index, 1);
  499. }
  500. if (type != "cancel") {
  501. if (!object.unvisibleReasons.some((e) => e.reason == reason)) {
  502. object.unvisibleReasons.push({ reason, level });
  503. }
  504. }
  505. }
  506. update();
  507. },
  508. getObjVisiByReason: function(object, reason) {
  509. //获取在某条件下是否可见. 注: 用户在数据集选择可不可见为"datasetSelection"
  510. if (object.visible) return true;
  511. else {
  512. return !object.unvisibleReasons || !object.unvisibleReasons.some((e) => e.reason == reason);
  513. }
  514. },
  515. };
  516. //--------------------------------------
  517. //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
  518. var Manage = function() {
  519. (this.weixinURL = "https://res.wx.qq.com/open/js/jweixin-1.2.0.js"), (this.time = "?" + new Date().getTime());
  520. this.loadAudio();
  521. // this.loadWeixin();
  522. };
  523. //动态加载js文件
  524. Manage.prototype.LoadJs = function(_files, succes) {
  525. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  526. var classcodes = [];
  527. var FileArray = [];
  528. if (typeof _files === "object") {
  529. FileArray = _files;
  530. } else {
  531. /*如果文件列表是字符串,则用,切分成数组*/
  532. if (typeof _files === "string") {
  533. FileArray = _files.split(",");
  534. }
  535. }
  536. if (FileArray != null && FileArray.length > 0) {
  537. var LoadedCount = 0;
  538. for (var i = 0; i < FileArray.length; i++) {
  539. loadFile(FileArray[i], function() {
  540. LoadedCount++;
  541. if (LoadedCount == FileArray.length) {
  542. try {
  543. succes();
  544. } catch (err) {
  545. console.log("err: 您未定义回调");
  546. }
  547. }
  548. });
  549. }
  550. }
  551. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  552. function loadFile(url, success) {
  553. if (!FileIsExt(classcodes, url)) {
  554. var _ThisType = GetFileType(url);
  555. var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0, _ThisType.indexOf("?"));
  556. var fileObj = null;
  557. if (ThisType == ".js") {
  558. fileObj = document.createElement("script");
  559. fileObj.src = url;
  560. } else if (ThisType == ".css") {
  561. fileObj = document.createElement("link");
  562. fileObj.href = url;
  563. fileObj.type = "text/css";
  564. fileObj.rel = "stylesheet";
  565. } else if (ThisType == ".less") {
  566. fileObj = document.createElement("link");
  567. fileObj.href = url;
  568. fileObj.type = "text/css";
  569. fileObj.rel = "stylesheet/less";
  570. }
  571. success = success || function() {};
  572. fileObj.onload = fileObj.onreadystatechange = function() {
  573. if (!this.readyState || "loaded" === this.readyState || "complete" === this.readyState) {
  574. success();
  575. classcodes.push(url);
  576. }
  577. };
  578. document.getElementsByTagName("head")[0].appendChild(fileObj);
  579. } else {
  580. success();
  581. }
  582. }
  583. /*获取文件类型,后缀名,小写*/
  584. function GetFileType(url) {
  585. if (url != null && url.length > 0) {
  586. return url.substr(url.lastIndexOf(".")).toLowerCase();
  587. }
  588. return "";
  589. }
  590. /*文件是否已加载*/
  591. function FileIsExt(FileArray, _url) {
  592. if (FileArray != null && FileArray.length > 0) {
  593. var len = FileArray.length;
  594. for (var i = 0; i < len; i++) {
  595. if (FileArray[i] == _url) {
  596. return true;
  597. }
  598. }
  599. }
  600. return false;
  601. }
  602. };
  603. //获取页面url后面的参数
  604. Manage.prototype.number = function(variable) {
  605. var query = window.location.search.substring(1);
  606. var vars = query.split("&");
  607. for (var i = 0; i < vars.length; i++) {
  608. var pair = vars[i].split("=");
  609. if (pair[0] == variable) {
  610. return pair[1];
  611. }
  612. }
  613. return false;
  614. };
  615. Manage.prototype.loadWeixin = function() {
  616. var that = this;
  617. this.LoadJs(that.weixinURL + that.time, function() {});
  618. };
  619. Manage.prototype.weixinShare = function() {
  620. console.log("weixinShare");
  621. $.ajax({
  622. url: "https://www.4dage.com/wechat/jssdk/",
  623. type: "post",
  624. data: {
  625. url: location.href.split("#")[0],
  626. },
  627. dataType: "jsonp",
  628. jsonpCallback: "success_jsonp",
  629. success: function(data, textStatus) {
  630. console.log("weixinShare success");
  631. console.log(data.appId);
  632. wx.config({
  633. // debug : true,
  634. appId: data.appId,
  635. timestamp: data.timestamp,
  636. nonceStr: data.nonceStr,
  637. signature: data.signature,
  638. jsApiList: [
  639. "checkJsApi",
  640. "onMenuShareTimeline",
  641. "onMenuShareAppMessage",
  642. "onMenuShareQQ",
  643. "onMenuShareWeibo",
  644. "hideMenuItems",
  645. "showMenuItems",
  646. "hideAllNonBaseMenuItem",
  647. "showAllNonBaseMenuItem",
  648. "translateVoice",
  649. "startRecord",
  650. "stopRecord",
  651. "onRecordEnd",
  652. "playVoice",
  653. "pauseVoice",
  654. "stopVoice",
  655. "uploadVoice",
  656. "downloadVoice",
  657. "chooseImage",
  658. "previewImage",
  659. "uploadImage",
  660. "downloadImage",
  661. "getNetworkType",
  662. "openLocation",
  663. "getLocation",
  664. "hideOptionMenu",
  665. "showOptionMenu",
  666. "closeWindow",
  667. "scanQRCode",
  668. "chooseWXPay",
  669. "openProductSpecificView",
  670. "addCard",
  671. "chooseCard",
  672. "openCard",
  673. ],
  674. });
  675. },
  676. error: function(XMLHttpRequest, textStatus, errorThrown) {
  677. console.log("jsonp.error:" + textStatus);
  678. },
  679. });
  680. var success_jsonp = function(json) {
  681. console.log(json);
  682. };
  683. wx.ready(function() {
  684. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  685. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  686. //分享到朋友圈
  687. console.log(g_weixinObj);
  688. wx.onMenuShareTimeline({
  689. title: g_weixinObj.title, // 分享标题
  690. link: g_weixinObj.lineLink, // 分享链接
  691. imgUrl: g_weixinObj.imgUrl, // 分享图标
  692. desc: g_weixinObj.desc,
  693. });
  694. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  695. wx.onMenuShareAppMessage({
  696. title: g_weixinObj.title, // 分享标题
  697. desc: g_weixinObj.desc, // 分享描述
  698. link: g_weixinObj.lineLink, // 分享链接
  699. imgUrl: g_weixinObj.imgUrl, // 分享图标
  700. type: "", // 分享类型,music、video或link,不填默认为link
  701. dataUrl: "", // 如果type是music或video,则要提供数据链接,默认为空
  702. });
  703. wx.onMenuShareWeibo({
  704. title: g_weixinObj.title, // 分享标题
  705. desc: g_weixinObj.desc, // 分享描述
  706. link: g_weixinObj.lineLink, // 分享链接
  707. imgUrl: g_weixinObj.imgUrl, // 分享图标
  708. success: function() {
  709. // 用户确认分享后执行的回调函数
  710. },
  711. cancel: function() {
  712. // 用户取消分享后执行的回调函数
  713. },
  714. });
  715. wx.onMenuShareQZone({
  716. title: g_weixinObj.title, // 分享标题
  717. desc: g_weixinObj.desc, // 分享描述
  718. link: g_weixinObj.lineLink, // 分享链接
  719. imgUrl: g_weixinObj.imgUrl, // 分享图标
  720. success: function() {
  721. // 用户确认分享后执行的回调函数
  722. },
  723. cancel: function() {
  724. // 用户取消分享后执行的回调函数
  725. },
  726. });
  727. wx.onMenuShareQQ({
  728. title: g_weixinObj.title, // 分享标题
  729. desc: g_weixinObj.desc, // 分享描述
  730. link: g_weixinObj.lineLink, // 分享链接
  731. imgUrl: g_weixinObj.imgUrl, // 分享图标
  732. success: function() {
  733. // 用户确认分享后执行的回调函数
  734. },
  735. cancel: function() {
  736. // 用户取消分享后执行的回调函数
  737. },
  738. });
  739. wx.error(function(res) {
  740. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  741. });
  742. });
  743. };
  744. Manage.prototype.dealURL = function(src, type) {
  745. //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
  746. //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
  747. if (window.isLocal && settings.localPrefix != void 0) {
  748. //本地将线上的前缀替换
  749. var oldPrefix = "super.4dage.com/"; //最简单的地址写一个,如果有其他完全不一样的地址就用数组逐个判断
  750. var index = src.indexOf(oldPrefix);
  751. if (index > -1) {
  752. var wholeOldPrefix = src.slice(0, index + oldPrefix.length);
  753. return src.replace(wholeOldPrefix, settings.localPrefix);
  754. }
  755. console.error("没有找到合适的本地链接");
  756. return src;
  757. } else {
  758. //add https://
  759. var prefix = g_Prefix.replace("https://", "").replace("http://", "");
  760. if (!src.includes("http:/") && !src.includes("https:/") && src.includes(prefix)) {
  761. src = "https://" + src;
  762. }
  763. return src;
  764. }
  765. };
  766. Manage.prototype.removeSrcPostMark = function(url) {
  767. //去除texture.load时自动加上的'?'
  768. var index = url.indexOf("?");
  769. if (index > -1) {
  770. return url.slice(0, index);
  771. } else return url;
  772. };
  773. Manage.prototype.showInfo = function(o) {
  774. // ({result:true, title:"发布成功"});
  775. var box = $(".resultBox");
  776. var title = o.title || o || i18n.get("保存成功");
  777. box
  778. .children()
  779. .eq(0)
  780. .html(title);
  781. //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000);
  782. var time = o.time || THREE.Math.clamp(title.length * 130, 1300, 5000);
  783. o.time || console.log("showtime " + time);
  784. //实际有一半的时间在渐变透明度
  785. this.showInfoTimer && clearTimeout(this.showInfoTimer);
  786. box.removeClass("animate"); //如果之后不久又要showinfo一个的话,先停止前面的animate
  787. setTimeout(
  788. function() {
  789. box.css({
  790. "-webkit-animation-duration": time + "ms",
  791. "animation-duration": time + "ms",
  792. });
  793. if (o.top) {
  794. box.children().css("top", o.top + "%");
  795. } else {
  796. box.children().css("top", "");
  797. }
  798. box.removeClass("hide");
  799. box.addClass("animate");
  800. if (o.dontInteract) {
  801. //遮挡对屏幕的操作
  802. box.css("pointer-events", "auto");
  803. } else {
  804. box.css("pointer-events", "none");
  805. }
  806. this.showInfoTimer = setTimeout(
  807. function() {
  808. box.removeClass("animate");
  809. box.addClass("hide");
  810. this.showInfoTimer = null;
  811. }.bind(this),
  812. time + 20
  813. );
  814. }.bind(this),
  815. 50
  816. ); //这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧
  817. }; //like: manage.showInfo({title:'a', top:20})
  818. //公用的函数
  819. function getQueryVariable(variable) {
  820. var query = window.location.search.substring(1);
  821. var vars = query.split("&");
  822. for (var i = 0; i < vars.length; i++) {
  823. var pair = vars[i].split("=");
  824. if (pair[0] == variable) {
  825. return pair[1];
  826. }
  827. }
  828. return false;
  829. }
  830. //隐藏公司Logo
  831. function showLogo() {
  832. $("#myCompany").hide();
  833. $("#loaderCoBrandName").hide();
  834. $("#title-logo").hide();
  835. $(".title-container").css("justify-content", "center");
  836. }
  837. //czj 添加随机的时间
  838. function randomTime() {
  839. return new Date();
  840. }
  841. function matcher(data) {
  842. if (!data || !g_version) return data;
  843. delete data.model.vision_version;
  844. var _data = {
  845. files: {
  846. templates: ["images/images{{number}}/{{filename}}"],
  847. },
  848. model: {
  849. sid: window.number,
  850. camera_start:
  851. data.model.images && data.model.images.length != 0
  852. ? {
  853. camera: {
  854. zoom: "-1",
  855. quaternion: [
  856. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  857. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  858. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  859. JSON.parse(data.model.images[0].metadata).camera_quaternion.y,
  860. ],
  861. },
  862. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  863. mode: "0",
  864. }
  865. : "",
  866. },
  867. sid: window.number,
  868. hoticon: {
  869. default: "https://super.4dage.com/images/4dagePoint2.png",
  870. higt: "https://super.4dage.com/images/4dagePoint.png",
  871. },
  872. special: "false",
  873. weixinDesc: "",
  874. };
  875. $.extend(true, data, _data);
  876. return data;
  877. }
  878. function hotMatcher(data = {}) {
  879. //if(!data || !g_version) return data;
  880. if (g_version) {
  881. data.tourAudio = data.audio || {};
  882. } else {
  883. data.tourAudio = {};
  884. }
  885. return data;
  886. }
  887. var GifTexDeal = {
  888. animateObjects: [],
  889. animateTexs: [],
  890. addAnimation: function(texture, owner, info, id) {
  891. /* if(this.animateObjects.find(e=>
  892. e.texture == texture && !ifSame(info, e.info)
  893. )) */
  894. var animation;
  895. var tex = this.animateTexs.find((e) => e.texture == texture);
  896. if (tex) {
  897. animation = tex;
  898. } else {
  899. animation = { texture, info };
  900. this.animateTexs.push(animation);
  901. this.setRepeart(animation);
  902. }
  903. var object = {
  904. animation, //默认相同的texture对应的info是一样的, 对应一个animation
  905. owner,
  906. };
  907. this.animateObjects.push(object);
  908. return object;
  909. },
  910. remove: function(object) {
  911. var index = this.animateObjects.indexOf(object);
  912. if (index > -1) {
  913. this.animateObjects.splice(index, 1);
  914. if (!this.animateObjects.find((e) => e.animation == object.animation)) {
  915. let i = this.animateTexs.indexOf(object.animation);
  916. this.animateTexs.splice(i, 1);
  917. object.animation.texture.repeat.set(1, 1);
  918. }
  919. this.stop(object);
  920. }
  921. },
  922. setRepeart: function(animation) {
  923. animation.texture.repeat.set(1 / animation.info.cellXcount, 1 / animation.info.cellYcount);
  924. },
  925. start: function(object) {
  926. if (!object || object.started) return;
  927. object.started = true;
  928. if (object.animation.started) return;
  929. object.animation.started = true;
  930. var info = object.animation.info;
  931. var count = info.cellXcount * info.cellYcount - (info.voidCount || 0);
  932. if (count <= 1) return;
  933. transitions.start(
  934. (progress) => {
  935. var index = Math.floor(count * progress);
  936. var indexX = index % info.cellXcount;
  937. var indexY = info.cellYcount - Math.floor(index / info.cellXcount) - 1; //uv.offset.y是从下到上的
  938. object.animation.texture.offset.x = indexX / info.cellXcount;
  939. object.animation.texture.offset.y = indexY / info.cellYcount;
  940. //console.log(object.id + " : "+ object.texture.offset.toArray())
  941. },
  942. info.duration * -1,
  943. null,
  944. /* ()=>{//done (-1):循环
  945. object.started = false
  946. object.texture.offset.x = 0;
  947. object.texture.offset.y = 0;
  948. this.start(object)
  949. }, */ 0,
  950. null,
  951. object.id,
  952. "gif_" + object.animation.texture.id
  953. );
  954. },
  955. stop: function(object) {
  956. if (!object || !object.started) return;
  957. object.started = false;
  958. //只有该object对应的texture对应的所有object都停止了,才能真的停止动画:
  959. if (this.animateObjects.find((e) => e.animation == object.animation && e.started)) return;
  960. transitions.cancelById("gif_" + object.animation.texture.id);
  961. object.animation.texture.offset.set(0, 0);
  962. object.animation.started = false;
  963. },
  964. };
  965. var CloneObject = function(copyObj, result, isSimpleCopy, extraReplace) {
  966. //isSimpleCopy只复制最外层
  967. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  968. if (!copyObj) return copyObj; //0 null undefined ''
  969. result = result || {};
  970. if (copyObj instanceof Array) {
  971. /* if (copyObj[0]instanceof Object) {
  972. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  973. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  974. }
  975. return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object
  976. return copyObj.map((e) => {
  977. if (e instanceof Object) {
  978. return CloneObject(e);
  979. } else return e;
  980. });
  981. } else {
  982. if (copyObj.clone instanceof Function) {
  983. //解决一部分
  984. return copyObj.clone();
  985. }
  986. }
  987. for (var key in copyObj) {
  988. if (copyObj[key] instanceof Object && !isSimpleCopy) result[key] = CloneObject(copyObj[key]);
  989. else result[key] = copyObj[key];
  990. //如果是函数类同基本数据,即复制引用
  991. }
  992. return result;
  993. };
  994. var ifSame = function(object1, object2) {
  995. if (object1 == object2) return true;
  996. // 0 != undefined , 0 == ''
  997. else if (!object1 || !object2) return false;
  998. else if (object1.constructor != object2.constructor) {
  999. return false;
  1000. } else if (object1 instanceof Array) {
  1001. if (object1.length != object2.length) return false;
  1002. var _object2 = object2.slice(0);
  1003. for (let i = 0; i < object1.length; i++) {
  1004. var u = _object2.find((e) => ifSame(object1[i], e));
  1005. if (u == void 0 && !_object2.includes(u) && !object1.includes(u)) return false;
  1006. else {
  1007. let index = _object2.indexOf(u);
  1008. _object2.splice(index, 1);
  1009. }
  1010. }
  1011. return true;
  1012. } else if (object1.equals instanceof Function) {
  1013. //复杂数据仅支持这种,其他的可能卡住?
  1014. return object1.equals(object2);
  1015. } else if (typeof object1 == "number" || typeof object1 == "string") {
  1016. if (isNaN(object1) && isNaN(object2)) return true;
  1017. else return object1 == object2;
  1018. } else if (typeof object1 == "object") {
  1019. var keys1 = Object.keys(object1);
  1020. var keys2 = Object.keys(object2);
  1021. if (!ifSame(keys1, keys2)) return false;
  1022. for (let i in object1) {
  1023. var same = ifSame(object1[i], object2[i]);
  1024. if (!same) return false;
  1025. }
  1026. return true;
  1027. } else {
  1028. console.log("isSame出现例外");
  1029. }
  1030. };
  1031. function initByTHREE(THREE) {
  1032. window.bus = new THREE.EventDispatcher(); //因为player一开始总是没创建好,所以加一个事件传递器
  1033. THREE.TransitionPass = function(scene, camera) {
  1034. this.renderScene = scene;
  1035. this.renderCamera = camera;
  1036. this.coverRenderTarget = new THREE.WebGLRenderTarget(100, 100, {
  1037. minFilter: THREE.LinearFilter,
  1038. magFilter: THREE.LinearFilter,
  1039. format: THREE.RGBAFormat,
  1040. });
  1041. this.coverTex = this.coverRenderTarget.texture;
  1042. this.enabled = false;
  1043. this.oldClearColor = new THREE.Color();
  1044. this.oldClearAlpha = 1;
  1045. this.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
  1046. this.scene = new THREE.Scene();
  1047. this.material = this.getMaskMaterial();
  1048. var copyShader = THREE.CopyShader;
  1049. this.materialCopy = new THREE.ShaderMaterial({
  1050. uniforms: this.copyUniforms,
  1051. vertexShader: copyShader.vertexShader,
  1052. fragmentShader: copyShader.fragmentShader,
  1053. blending: THREE.NoBlending,
  1054. depthTest: false,
  1055. depthWrite: false,
  1056. transparent: true,
  1057. });
  1058. this.quad = new THREE.Mesh(new THREE.PlaneBufferGeometry(2, 2), this.material);
  1059. this.quad.frustumCulled = false; // Avoid getting clipped
  1060. this.scene.add(this.quad);
  1061. };
  1062. THREE.TransitionPass.prototype = {
  1063. //波形扩散,出下一个画面
  1064. constructor: THREE.TransitionPass,
  1065. setSize: function(width, height) {
  1066. this.coverRenderTarget.setSize(width, height);
  1067. },
  1068. render: function(renderer, writeBuffer, readBuffer, delta, maskActive) {
  1069. var oldAutoClear = renderer.autoClear;
  1070. renderer.autoClear = false;
  1071. var uniforms = this.quad.material.uniforms;
  1072. uniforms.bgTex.value = readBuffer.texture; //更新
  1073. uniforms.coverTex.value = this.coverTex;
  1074. uniforms.progress.value = player.model.skybox.material.uniforms.progress.value; //
  1075. uniforms.screenRatio.value = player.domElement.clientWidth / player.domElement.clientHeight; // 使波纹为圆形
  1076. uniforms.screenRatio.value *= uniforms.screenRatio.value;
  1077. renderer.render(this.scene, this.camera);
  1078. renderer.autoClear = oldAutoClear;
  1079. },
  1080. start: function(sceneRenderer) {
  1081. this.enabled = true;
  1082. //draw coverTex
  1083. this.quad.material.uniforms.progress.value = 1;
  1084. sceneRenderer.renderer.render(sceneRenderer.scene, sceneRenderer.camera, this.coverRenderTarget, true);
  1085. console.log("start111");
  1086. },
  1087. stop: function() {
  1088. this.enabled = false;
  1089. console.log("stop111");
  1090. },
  1091. getMaskMaterial: function() {
  1092. return new THREE.ShaderMaterial({
  1093. uniforms: {
  1094. coverTex: {
  1095. type: "t",
  1096. value: null,
  1097. },
  1098. bgTex: {
  1099. type: "t",
  1100. value: null,
  1101. },
  1102. progress: {
  1103. type: "f",
  1104. value: 0,
  1105. },
  1106. screenRatio: {
  1107. type: "f",
  1108. value: 1,
  1109. },
  1110. },
  1111. vertexShader: `
  1112. varying vec2 vUv;
  1113. void main()
  1114. {
  1115. vUv = uv;
  1116. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  1117. }
  1118. `,
  1119. fragmentShader: `
  1120. uniform sampler2D coverTex;
  1121. uniform sampler2D bgTex;
  1122. uniform float progress;
  1123. uniform float screenRatio;
  1124. varying vec2 vUv;
  1125. void main() {
  1126. const float maxRadius = 0.708; // sqrt(0.5^2+0.5^2)
  1127. const float minRadius = 0.0 ;
  1128. 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));
  1129. float diff = 0.292; //1.0-maxRadius;
  1130. float radiusIn = maxRadius * progress + minRadius * (1.0-progress);
  1131. float radiusOut = radiusIn + diff;
  1132. if(radius < radiusIn) {
  1133. gl_FragColor = texture2D(bgTex, vUv);
  1134. //gl_FragColor = vec4(0.0,0.0,1.0,1.0);//
  1135. }else if(radius>radiusOut){
  1136. gl_FragColor = texture2D(coverTex, vUv) ;
  1137. //gl_FragColor = vec4(1.0,1.0,0.0,1.0);//
  1138. }else{
  1139. vec4 color1 = texture2D(bgTex, vUv);
  1140. vec4 color2 = texture2D(coverTex, vUv);
  1141. float rotio = smoothstep(radiusIn ,radiusOut,radius);
  1142. gl_FragColor = mix(color1, color2, rotio);
  1143. }
  1144. }
  1145. `,
  1146. });
  1147. },
  1148. };
  1149. let labels = [];
  1150. class Label2D extends THREE.EventDispatcher {
  1151. constructor(o = {}) {
  1152. super();
  1153. this.position = o.position;
  1154. this.elem = $(o.innerHTML || "<div ><a></a></div>");
  1155. $(o.domElement).append(this.elem);
  1156. this.pos2d = new THREE.Vector3();
  1157. this.elem.css({ position: "absolute", "z-index": 999 });
  1158. this.clickFun = o.clickFun;
  1159. this.clickFun && this.elem.on("click", this.clickFun.bind(this));
  1160. if (o.autoUpdate) {
  1161. let update = (e) => {
  1162. if (e.cameraChanged) this.update();
  1163. };
  1164. player.on("view.changed", update); //确保player存在
  1165. this.addEventListener("dispose", (e) => {
  1166. player.off("view.changed", update);
  1167. });
  1168. }
  1169. this.visible = true;
  1170. this.shelterByModel = o.shelterByModel;
  1171. this.floorIndex = o.floorIndex;
  1172. labels.push(this);
  1173. if (window.player.model) {
  1174. this.init();
  1175. } else {
  1176. window.bus.addEventListener("playerAndModelReady", this.init.bind(this));
  1177. }
  1178. }
  1179. init() {
  1180. if (this.floorIndex != void 0) {
  1181. player.model.on("floor.changed", (currentFloor, mode, oldFloor) => {
  1182. this.update(currentFloor); //注: currentFloor 这时候还没成为 model.currentFloor
  1183. });
  1184. }
  1185. }
  1186. update(currentFloor) {
  1187. if (!this.position || !this.visible) return;
  1188. var p = convertTool.getPos2d(this.position);
  1189. if (!p || !p.trueSide) {
  1190. this.elem.css("display", "none");
  1191. return;
  1192. }
  1193. //判断label是否被模型遮挡,遮挡则消失(如果是漫游模式最好提前计算visiblePanos)
  1194. if (player.mode != "panorama") {
  1195. currentFloor = currentFloor || player.model.currentFloor;
  1196. if (!player.model.allFloorsVisible && this.floorIndex != void 0 && this.floorIndex != currentFloor.floorIndex) {
  1197. this.elem.css("display", "none");
  1198. return;
  1199. }
  1200. if (this.shelterByModel && convertTool.ifShelter(this.position, this.floorIndex)) {
  1201. this.elem.css("display", "none");
  1202. return;
  1203. }
  1204. }
  1205. this.elem.css({
  1206. left: p.pos.x + "px",
  1207. top: p.pos.y + "px",
  1208. });
  1209. /* if(settings.vrEnabled){
  1210. this.elem.css({transform:'rotate('+window.screenFaceOrient+'deg)'})
  1211. }else{
  1212. this.elem.css({transform:''})
  1213. } */
  1214. this.elem.css("display", "block");
  1215. this.pos2d = p.vector;
  1216. }
  1217. setVisible(visi, reason, level = 0, type) {
  1218. convertTool.updateVisible(this, reason, visi, level, type);
  1219. if (!this.visible) {
  1220. this.elem.css("display", "none");
  1221. } else {
  1222. this.update();
  1223. }
  1224. }
  1225. setPos(pos) {
  1226. this.position = pos;
  1227. this.update();
  1228. }
  1229. dispose() {
  1230. this.elem.remove();
  1231. this._listeners = {};
  1232. this.dispatchEvent({ type: "dispose" });
  1233. let index = labels.indexOf(this);
  1234. index > -1 && labels.splice(index, 1);
  1235. }
  1236. }
  1237. window.Label2D = Label2D;
  1238. class RoomLabel extends Label2D {
  1239. constructor(o) {
  1240. if (o.position instanceof Array) o.position = new THREE.Vector3().fromArray(o.position);
  1241. o.innerHTML = `<div class="room-label" ><a><p><span>${o.title}</span></p></a></div>`;
  1242. o.domElement = $(".widgets-doll-labels")[0];
  1243. (o.shelterByModel = true), (o.autoUpdate = true);
  1244. o.clickFun = () => {
  1245. if (player.roomLebelClickUnabled) return;
  1246. let result = common.sortByScore(
  1247. player.model.floors.index[this.floorIndex].panos,
  1248. [],
  1249. [
  1250. (pano) => {
  1251. return -pano.position.distanceToSquared(this.position);
  1252. },
  1253. ]
  1254. );
  1255. player.flyToPano({
  1256. pano: result && result[0] && result[0].item,
  1257. });
  1258. };
  1259. super(o);
  1260. this.setTitle(o.title);
  1261. }
  1262. init() {
  1263. super.init();
  1264. //飞入后不可见
  1265. player.on("mode.changing", (currentMode, mode, pano, duration) => {
  1266. //准备飞
  1267. this.setStyle(currentMode, mode, duration);
  1268. });
  1269. this.setStyle();
  1270. }
  1271. setStyle(currentMode, mode, duration) {
  1272. if (!mode) mode = player.mode;
  1273. if (mode == "panorama") {
  1274. this.setVisible(false, "isPanorama");
  1275. } else if (currentMode == "panorama") {
  1276. setTimeout(() => {
  1277. this.setVisible(true, "isPanorama");
  1278. }, duration * 0.7);
  1279. }
  1280. }
  1281. setTitle(title) {
  1282. this.title = title || "";
  1283. this.elem.html(`<a><p><span>${this.title}</span></p></a>`);
  1284. }
  1285. setEditSelect(state) {
  1286. //编辑页面用
  1287. this.editing = !!state;
  1288. this.setVisible(state, "editSelected", 1, state ? "add" : "cancel"); //强制可见
  1289. }
  1290. }
  1291. window.RoomLabel = RoomLabel;
  1292. window.bus.addEventListener("playerAndModelReady", () => {
  1293. player.on("mode.changing", (currentMode, mode, pano, duration) => {
  1294. let noLine = mode == "floorplan";
  1295. if (noLine) {
  1296. $(".widgets-doll-labels")
  1297. .addClass("noLine")
  1298. .addClass("noCorner");
  1299. } else {
  1300. $(".widgets-doll-labels")
  1301. .removeClass("noLine")
  1302. .removeClass("noCorner");
  1303. }
  1304. });
  1305. player.on("view.changed", (e) => {
  1306. if (e.cameraChanged) {
  1307. //if(needUpdateZIndex){ //如果某个label显示时需要更新index的话,加个参数
  1308. let label_ = labels.filter((e) => e.elem[0].style.display == "block");
  1309. label_.sort((a, b) => b.pos2d.z - a.pos2d.z);
  1310. label_.forEach((e, index) => e.elem.css("z-index", index + 1000));
  1311. //}
  1312. }
  1313. });
  1314. });
  1315. }
  1316. //最好能知道应该播放到的currentTime
  1317. var SoundManager = {
  1318. //暂不支持同时播放
  1319. currentAudio: null, //当前正在播放list中的哪一个
  1320. enableSound: true, //是否允许有声音
  1321. playHistory: [], //被打断的加入播放历史
  1322. list: [], //同一级别可以互相打断 //暂时不做多级别
  1323. play: function(name, src, currentTime) {
  1324. var object = this.list.find((e) => e.name == name);
  1325. if (object) {
  1326. if (this.currentAudio) {
  1327. this.pause(this.currentAudio.name, false, true);
  1328. }
  1329. {
  1330. //将当前要播放的播放历史中清除
  1331. let index = this.playHistory.indexOf(object);
  1332. if (index > -1) this.playHistory.splice(index, 1);
  1333. }
  1334. this.currentAudio = object;
  1335. if (src) {
  1336. this.setSrc(name, src);
  1337. }
  1338. if (currentTime != void 0) {
  1339. object.audio.currentTime = currentTime;
  1340. }
  1341. if (object.audio && object.src) {
  1342. object.audio.load(); // iOS 9 还需要额外的 load 一下, 否则直接 play 无效 *///https://www.cnblogs.com/interdrp/p/4211883.html 部分资料
  1343. object.audio.play();
  1344. object.callback && object.callback(true);
  1345. Log(name + " 播放 ");
  1346. }
  1347. }
  1348. },
  1349. pause: function(name, autoReplayLast, isInterrupt) {
  1350. //需要能自动恢复上一个被打算的音频。恢复前判断是否还需要播放
  1351. var object = this.list.find((e) => e.name == name);
  1352. if (object) {
  1353. this.currentAudio = null;
  1354. if (object.audio) {
  1355. object.audio.pause();
  1356. object.callback && object.callback(false);
  1357. object.audio.src && Log(name + " 中断音频 " + "(" + common.getFileNameFromUrl(object.audio.src) + ")");
  1358. }
  1359. if (isInterrupt) {
  1360. //一般主动调用不需要加这个
  1361. this.playHistory.push(object); //如果是被中断的,加入播放历史,等待恢复播放
  1362. }
  1363. if (autoReplayLast) {
  1364. //播放之前的音频。它们是被打断过的。
  1365. while (this.playHistory.length) {
  1366. var last = this.playHistory.pop();
  1367. if (last.src && last.canplay(last.audio)) {
  1368. this.play(last.name);
  1369. }
  1370. }
  1371. }
  1372. }
  1373. },
  1374. setSrc: function(name, src) {
  1375. //不能直接给audio赋src!一定要用这个函数!因为我要拿这里的src来判断有无src,因为貌似audio的src会自动变,''时会变成html的链接
  1376. var object = this.list.find((e) => e.name == name);
  1377. object.src = src;
  1378. object.audio.src = src;
  1379. Log(`${object.name} 设置src: ${src}`);
  1380. },
  1381. createAudio: function(object = {}) {
  1382. //name, level, canplay
  1383. if (!object.fake) {
  1384. object.audio = new Audio();
  1385. object.audio.loop = !!object.loop;
  1386. //object.audio.autoplay = true;
  1387. object.audio.addEventListener("ended", () => {
  1388. if (object.loop) {
  1389. //循环
  1390. Log(`${object.name} 播放完毕,重新播放`);
  1391. object.audio.play();
  1392. } else {
  1393. this.pause(object.name, true); //停止后的后续处理
  1394. }
  1395. });
  1396. object.audio.oncanplaythrough = () => {
  1397. Log(`${object.name} canplaythrough `);
  1398. };
  1399. }
  1400. this.list.push(object);
  1401. },
  1402. initAutoPlay: function() {
  1403. //处理设备自动播放限制
  1404. let play = function() {
  1405. if (this.currentAudio && this.currentAudio.audio && this.currentAudio.src) {
  1406. this.currentAudio.audio.play();
  1407. Log(`${this.currentAudio.name} 自动播放成功`); //即使设置src在这之后好像也能成功播放
  1408. } else {
  1409. }
  1410. document.removeEventListener("touchstart", play);
  1411. document.removeEventListener("click", play);
  1412. $("#player")[0] && $("#player")[0].removeEventListener("touchstart", play);
  1413. }.bind(this);
  1414. document.addEventListener("WeixinJSBridgeReady", play, false);
  1415. document.addEventListener("touchstart", play); //ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
  1416. document.addEventListener("click", play);
  1417. $("#player")[0] && $("#player")[0].addEventListener("touchstart", play);
  1418. },
  1419. };
  1420. function Log(value, color, fontSize) {
  1421. color = color || "#13f";
  1422. fontSize = fontSize || 14;
  1423. console.warn(`%c${value}`, `color:${color};font-size:${fontSize}px`);
  1424. }
  1425. Manage.prototype.loadAudio = function() {
  1426. //相关:g_tourAudio \ g_playAudio
  1427. //热点页面因为挡住了界面,所以暂时不存在别的音频阻止热点音频的可能
  1428. //box视频都静音,所以暂时不考虑
  1429. SoundManager.createAudio({
  1430. name: "bgm",
  1431. level: 0,
  1432. src: "",
  1433. loop: true,
  1434. canplay: (audio) => {
  1435. return this.bgmShouldPlay;
  1436. },
  1437. callback: (state) => {
  1438. //play或pause时随之触发的函数(即使还没开始播放)
  1439. if (state) {
  1440. $("#volume a img").attr("src", "./images/Volume btn_off.png");
  1441. $("#volume").attr("title", "关闭声音");
  1442. } else {
  1443. $("#volume a img").attr("src", "./images/Volume btn_on.png");
  1444. $("#volume").attr("title", "打开声音");
  1445. }
  1446. },
  1447. });
  1448. SoundManager.createAudio({
  1449. name: "tour",
  1450. level: 0,
  1451. src: "",
  1452. loop: false,
  1453. canplay: (audio) => {
  1454. return player.director && player.director.tourIsPlaying && player.director.getAudio();
  1455. },
  1456. });
  1457. SoundManager.createAudio({
  1458. name: "hot",
  1459. fake: true, //实际上没有audio. 只是为了来停止和续播其他音频
  1460. level: 1,
  1461. src: "",
  1462. loop: false,
  1463. canplay: (audio) => {},
  1464. });
  1465. $("#volume")
  1466. .find("a")
  1467. .on("click", () => {
  1468. if ($("#volume img")[0].src.indexOf("btn_on.png") > -1) {
  1469. this.switchBgmState(true);
  1470. } else if ($("#volume img")[0].src.indexOf("btn_off.png") > -1) {
  1471. this.switchBgmState(false);
  1472. }
  1473. });
  1474. this.switchBgmState(true); //初始设置允许播放bgm
  1475. SoundManager.initAutoPlay();
  1476. };
  1477. Manage.prototype.switchBgmState = function(state) {
  1478. //按钮的状态完全代表是否应该播放bgm,即使还没加载完
  1479. this.bgmShouldPlay = state;
  1480. if (state) {
  1481. SoundManager.play("bgm");
  1482. } else {
  1483. SoundManager.pause("bgm");
  1484. }
  1485. /* if(!g_bgAudio || !g_bgAudio.src) return;
  1486. var played = function(){
  1487. console.log('begin play bgm');
  1488. g_play = 1;
  1489. g_playAudio = g_bgAudio;
  1490. g_tourAudio && g_tourAudio.pause()
  1491. }
  1492. var paused = function(){
  1493. g_play = 0;
  1494. g_playAudio == g_bgAudio && (g_playAudio = null)
  1495. }
  1496. if(state ){
  1497. g_bgAudio.play();
  1498. if(g_bgAudio.paused){
  1499. paused()
  1500. }else{
  1501. played()
  1502. return true
  1503. }
  1504. }else{
  1505. g_bgAudio.pause();
  1506. paused()
  1507. }
  1508. g_bgAudio.pauseByHot = false
  1509. g_bgAudio.pauseByTour = false */
  1510. };
  1511. var manage = new Manage();
  1512. //处理cursor优先级
  1513. var CursorDeal = {
  1514. priorityEvent: [
  1515. //在前面的优先级高
  1516. { noIntersect: "not-allowed" },
  1517. { addHot: "cell" },
  1518. { hoverFootIcon: "pointer" },
  1519. { hoverHot: "pointer" },
  1520. { addLabel: "cell" },
  1521. { moveLabel: "grab" },
  1522. ],
  1523. domElements: [$("#player")[0] && $("#player")[0]],
  1524. list: [], //当前存在的cursor状态
  1525. currentCursorIndex: null,
  1526. /* init : function(viewer){
  1527. this.priorityEvent.forEach(e=>{//刚开始Potree.resourcePath没值,现在换
  1528. for(let i in e){
  1529. e[i] = Common.replaceAll(e[i],'{Potree.resourcePath}',Potree.resourcePath)
  1530. }
  1531. })
  1532. this.domElements = [viewer.renderArea, viewer.mapViewer.renderArea];
  1533. viewer.addEventListener("CursorChange",(e)=>{
  1534. if(e.action == 'add'){
  1535. this.add(e.name)
  1536. }else{
  1537. this.remove(e.name)
  1538. }
  1539. })
  1540. }, */
  1541. add: function(name) {
  1542. var priorityItem = this.priorityEvent.find((e) => e[name]);
  1543. if (!priorityItem) {
  1544. console.error("CursorDeal 未定义优先级 name:" + name);
  1545. return;
  1546. }
  1547. if (!this.list.includes(name)) {
  1548. this.judge({ addItem: priorityItem, name });
  1549. this.list.push(name);
  1550. }
  1551. },
  1552. remove: function(name) {
  1553. var index = this.list.indexOf(name);
  1554. if (index > -1) {
  1555. this.list.splice(index, 1);
  1556. this.judge();
  1557. }
  1558. },
  1559. judge: function(o = {}) {
  1560. //console.log(o,this.list)
  1561. if (o.addItem) {
  1562. var addIndex = this.priorityEvent.indexOf(o.addItem);
  1563. if (addIndex < this.currentCursorIndex || this.currentCursorIndex == void 0) {
  1564. this.domElements.forEach((e) => (e.style.cursor = o.addItem[o.name]));
  1565. this.currentCursorIndex = addIndex;
  1566. }
  1567. } else {
  1568. var levelMax = { index: Infinity, cursor: null };
  1569. this.list.forEach((name) => {
  1570. var priorityItem = this.priorityEvent.find((e) => e[name]);
  1571. var index = this.priorityEvent.indexOf(priorityItem);
  1572. if (index < levelMax.index) {
  1573. levelMax.index = index;
  1574. levelMax.cursor = priorityItem[name];
  1575. }
  1576. });
  1577. this.currentCursorIndex = levelMax.index;
  1578. this.domElements.forEach((e) => (e.style.cursor = levelMax.cursor || ""));
  1579. }
  1580. },
  1581. };
  1582. //兼容一代的場景
  1583. //請求地址統一管理
  1584. var g_onePregix = "https://bigscene.4dage.com/"; //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
  1585. var g_version = manage.number("version");
  1586. g_version === "one" ? (g_Prefix = g_onePregix) : "";