manage.js 72 KB

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