manage.js 60 KB

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