manage.js 56 KB

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