manage.js 72 KB

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