manage.js 61 KB

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