manage.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  1. var g_ProjectName=window.location.pathname.substring(window.location.pathname.indexOf("/")+1,window.location.pathname.lastIndexOf("/"));
  2. // var g_Prefix="http://192.168.0.109:8004/";
  3. var g_Prefix=window.location.origin+'/';
  4. window.isLocal = true
  5. var g_index=null;
  6. var g_modeldata=null;
  7. var g_weixinTitle=null;
  8. var g_Hots=null;
  9. var g_HotMeshes=[];
  10. var g_HotMeshSize = {
  11. g_HotMeshWidth: 0.3,
  12. g_HotMeshHeight:0.3
  13. };
  14. //add表示添加,delete表示删除
  15. var g_HotStatus=null;
  16. var g_newHot = [];//存储新加热点
  17. var g_HotImage= {
  18. "point":"https://super.4dage.com/images/4dagePoint2.png",
  19. "point2":"https://super.4dage.com/images/4dagePoint.png"
  20. };
  21. var g_saveHot=false;
  22. var g_TextColor=0x7777ff;
  23. var g_Text=null;
  24. var g_TextPlaneMesh=[];
  25. var g_TextIconMesh=[];
  26. var g_TextIcon="./static/images/text.png";
  27. var g_SelectTextIndex=null;
  28. var g_TextShow=null;
  29. var g_audioPlay=false;
  30. var g_background=null;
  31. var g_roof=null;
  32. var g_data2 = null;//加载的data2.js的内容
  33. var g_bgAudio=null;//背景音乐
  34. var g_tourAudio=null;//导览音乐
  35. var g_play = 1;//表示播放图标状态
  36. var g_playAudio = null;//当前在播放或当继续播放时应该播放的,是g_bgAudio或g_tourAudio
  37. var g_currentHot = null;//当前打开的热点
  38. //var g_Texture=null;
  39. //var g_ChunknameTexture={}; //chunkname和贴图名称对应
  40. var g_NormalTexture=false;
  41. var g_SpecularTexture=false;
  42. var g_DirectionalLight=null;
  43. var g_snapShotWidth = 200; //截图下载图片的大小
  44. var g_snapShotHeight = 140;
  45. //微信分享
  46. var g_weixinObj = {
  47. "title": document.querySelector("head title").innerHTML,
  48. "lineLink" : window.location.href,
  49. "imgUrl" : "https://www.4dmodel.com/SuperPanoramic/images/weixintitle.jpg",
  50. "desc" : "四维时代提供技术支持",
  51. }
  52. var settings = {
  53. hotClickEvent:{
  54. video:{
  55. playAndPause:true,
  56. examine:false,
  57. openHot:false
  58. },
  59. photo:{
  60. examine:false,
  61. openHot:false
  62. },
  63. shine:{
  64. examine:true,
  65. openHot:true
  66. }
  67. },
  68. //默认的:
  69. teleportTime: 1500,//瞬间过渡的时间
  70. /* flytimeDistanceMultiplier:150,
  71. flyTime:750, */
  72. tourRotTime:2, //默认停留2秒
  73. //dontExamHot:true
  74. transparentBg: false,
  75. bgImg: null,
  76. localPrefix:'/'
  77. }
  78. if(window.number == '725'||window.number == '724'){
  79. settings.mobileNavHigh = true
  80. }
  81. //共用函数:
  82. window.common = null;
  83. window.MathLight = null;
  84. window.math = null
  85. window.easing = null
  86. window.lerp = null
  87. window.transitions = null
  88. window.browser = null
  89. window.momentTourBlackNewType = 0//= number == 'TEST'//true
  90. var dealMap = (map)=>{//使不resize when image is not power of two
  91. map.wrapS = map.wrapT = THREE.ClampToEdgeWrapping;
  92. map.minFilter = THREE.LinearFilter;
  93. map.magFilter = THREE.LinearFilter;
  94. map.generateMipmaps = true;
  95. }
  96. var dom = {
  97. getOffset: function(type, element, parent) {
  98. left = (type == "left") ? element.offsetLeft : element.offsetTop;
  99. if (!parent) parent = $("body")[0];
  100. while (element = element.offsetParent) {
  101. if (element == parent) break;
  102. left += (type == "left") ? element.offsetLeft : element.offsetTop;
  103. }
  104. return left;
  105. }
  106. };
  107. var getTransformSid = function(){
  108. var name
  109. if(player.mode == 'panorama'){
  110. name = player.currentPano ? player.currentPano.id : 'outside'
  111. }else{
  112. name = 'outside'
  113. }
  114. return name
  115. }
  116. var convertTool = {
  117. getPos2d : function(point, camera, dom){//获取一个三维坐标对应屏幕中的二维坐标
  118. var camera = camera || player.camera;
  119. var dom = dom || player.domElement;
  120. 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);
  121. var x,y;
  122. x = (pos.x + 1) / 2 * dom.clientWidth;
  123. y = (1 - (pos.y + 1) / 2) * dom.clientHeight;
  124. var inSight = x <= dom.clientWidth && x >= 0 //是否在屏幕中
  125. && y <= dom.clientHeight && y >= 0
  126. return {
  127. pos: new THREE.Vector2(x,y), // 屏幕像素坐标
  128. vector: pos, //(范围 -1 ~ 1)
  129. trueSide : pos.z<1, //trueSide为false时,即使在屏幕范围内可见,也是反方向的另一个不可以被渲染的点 参见Tag.update
  130. inSight : inSight //在屏幕范围内可见
  131. };
  132. },
  133. ifShelter: function(pos3d){//检测某点在视线中是否被mesh遮挡
  134. var ori = player.position
  135. var dir = pos3d.clone().sub(ori).normalize()
  136. var ray = new THREE.Raycaster(ori, dir) //由外向里 因为模型从内侧是可见的所以从外侧
  137. /* if(config.isEdit && publicObjectSet.editor.mainDesign.editing){
  138. var o = ray.intersectObjects(publicObjectSet.editor.mainDesign.wallMeshes);
  139. }else{ */
  140. var o = ray.intersectObjects(player.model.colliders);
  141. //}
  142. var len = pos3d.distanceTo(ori);
  143. if (o && o.length) {
  144. for(var i=0;i<o.length;i++){
  145. if(o[i].distance < len){ return true; }//有遮挡
  146. }
  147. }
  148. },
  149. /*
  150. 拖拽时,获取鼠标在拖拽面上的位置(需要借助另一个intersectPlane面来计算,即和相机方向一样的面,可保证铺满屏幕)
  151. 但是不一定能获取到,比如鼠标射线不朝向拖拽面时,即使获取也会是一个意外的反方向的交点。
  152. */
  153. getPosAtPlane : function(pos, info/* , mouse, camera */){ //pos:与intersectPlane的交点 见笔记
  154. var A = pos;
  155. var player = player;
  156. var mouse = player.mouse;
  157. var O = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(player.camera);
  158. if(info.y != void 0){//地面线的
  159. var y = info.y;
  160. if(player.mode == "floorplan"/* || Math.abs(O.x-pos.x)<0.0001 && Math.abs(O.z-pos.z)<0.0001) */){
  161. //intersectPlane和地面平行,无交点
  162. var x = pos.x, z = pos.z;
  163. }else{
  164. if(y<player.camera.position.y && O.y <= A.y /* || y>player.camera.position.y && O.y >= A.y */)return null; //鼠标射线向上。因为相机一定位于地面以上(地面不会抬高到相机上吧?),所以无交点。
  165. if(O.y == A.y){console.log('一样??');return;}
  166. if(A.y == y){console.log('一样2??');return;}
  167. var r = (O.y-y)/(A.y-y);
  168. var x = (r*A.x-O.x)/(r-1);
  169. var z = (r*A.z-O.z)/(r-1);
  170. }
  171. }else{//垂直的也有越过消失点以后反向变化的情况,但使用时影响不大
  172. var N = info.normalVec;
  173. var P = info.pullPos;
  174. if(N.y != 0 ){console.log('N.y != 0');return;} //仅仅支持垂直于地面的的墙壁,目前都是
  175. if(O.z==A.z){console.log('O.z==A.z?');return;}
  176. if(N.z!=0 && N.x != 0){//直接用这个通用的也可以,支持斜线的墙
  177. //console.log('N.z==0 && N.x == 0?');
  178. var c = ( N.x*(A.x-O.x) + N.y*(A.y-O.y) + N.z*(A.z-O.z));
  179. if(c == 0){console.log("分母为0?? return;");return;}
  180. 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
  181. var x = t * (A.x - O.x) + O.x;
  182. var y = t * (A.y - O.y) + O.y;
  183. var z = t * (A.z - O.z) + O.z;
  184. /*原理: 已知空间直线L:(x-a)/m=(x-b)/n=(z-c)/p和空间平面π:Ax+By+Cz+D=0;
  185. 求直线L与平面π的交点的坐标。
  186. 把直线方程改写成参数形式:设(x-a)/m=(x-b)/n=(z-c)/p=t;
  187. 则x=mt+a;y=nt+b;z=pt+c;代入平面π的方程得:
  188. A(mt+a)+B(nt+b)+C(pt+c)+D=0
  189. 由此解得t=-(Aa+Bb+Cc+D)/(Am+Bn+Cp)
  190. 再代入参数方程即得交点的坐标(x,y,z). */
  191. }else if(N.x ==0 ){ //z与pullPos相等
  192. var z = P.z;
  193. if(O.y == A.y){console.log('一样??');return;}
  194. if(A.y == y){console.log('一样2??');return;}
  195. if(A.z == z){console.log('一样3??');return;}
  196. var r = (O.z-z)/(A.z-z);
  197. var x = (r*A.x-O.x)/(r-1);
  198. var y = (r*A.y-O.y)/(r-1);
  199. }else if(N.z == 0){//x与pullPos相等
  200. var x = P.x;
  201. if(O.y == A.y){console.log('一样??');return;}
  202. if(A.y == y){console.log('一样2??');return;}
  203. if(A.x == x){console.log('一样3??');return;}
  204. var r = (O.x-x)/(A.x-x);
  205. var y = (r*A.y-O.y)/(r-1);
  206. var z = (r*A.z-O.z)/(r-1);
  207. }
  208. }
  209. return new THREE.Vector3(x,y,z);
  210. },
  211. getMouseIntersect : function(camera, meshes, mouse){//获取鼠标和meshes交点
  212. var raycaster = new THREE.Raycaster;
  213. camera.updateMatrixWorld();
  214. var origin = new THREE.Vector3(mouse.x,mouse.y,-1).unproject(camera)
  215. , end = new THREE.Vector3(mouse.x,mouse.y,1).unproject(camera);
  216. var dir = end.sub(origin).normalize()
  217. raycaster.set(origin, dir);
  218. var n = raycaster.intersectObjects(meshes);
  219. if (0 === n.length)
  220. return null;
  221. return n[0];
  222. },
  223. ifIntersectChunks : function(A,B,options={}){//获取某个线段/射线和meshes的交点
  224. var dir = B.clone().sub(A).normalize();
  225. var len = options.InfinityLen ? Infinity : A.distanceTo(B) + (options.extLen||0);
  226. var ray = new THREE.Raycaster(A.clone(), dir, 0, len);
  227. var o = ray.intersectObjects(options.model || player.model.colliders);
  228. if (o && o.length)return o;
  229. if(options.throughWidth){ //允许最小宽度,防止穿过极小的缝隙导致撞墙感
  230. var normal = math.getNormal({points:[{x:A.x, y:A.z},{x:B.x, y:B.z}]});//线段法线
  231. normal.multiplyScalar(options.throughWidth)
  232. var normalVec3 = new THREE.Vector3(normal.x, 0, normal.y);
  233. var A2 = A.clone().add(normalVec3)
  234. ray.set(A2, dir);
  235. var o2 = ray.intersectObjects(options.model || player.model.colliders);
  236. ray.set(A.clone().add(normalVec3.negate()), dir);
  237. if (o2 && o2.length)return o2;
  238. var o3 = ray.intersectObjects(options.model || player.model.colliders);
  239. if (o3 && o3.length)return o3;
  240. }
  241. return null;
  242. },
  243. getPosAtSphere : function(pos3d, toPanoPos){
  244. var dir = pos3d.clone().sub(toPanoPos);
  245. dir.normalize();//然后计算在球中
  246. dir.multiplyScalar(Constants.skyRadius);
  247. dir.add(toPanoPos);
  248. return dir;
  249. } ,
  250. getScaleForConstantSize : function(op={}){ //获得规定二维大小的mesh的scale值。可以避免因camera的projection造成的mesh视觉大小改变。 来源:tag.updateDisc
  251. var w;
  252. var i = new THREE.Vector3, o = new THREE.Vector3, l = new THREE.Vector3, c = new THREE.Vector3, h = new THREE.Vector3
  253. if(op.width2d) w = op.width2d //如果恒定二维宽度
  254. else{//否则考虑上距离,加一丢丢近大远小的效果
  255. var currentDis, nearBound, farBound
  256. if(op.camera.type == "OrthographicCamera"){
  257. currentDis = (op.camera.right - op.camera.left) / op.camera.zoom
  258. }else{
  259. currentDis = op.position.distanceTo(op.camera.position);
  260. }
  261. w = op.maxSize - ( op.maxSize - op.minSize) * THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
  262. //maxSize : mesh要表现的最大像素宽度; nearBound: 最近距离,若比nearBound近,则使用maxSize
  263. }
  264. i.copy(op.position).project(op.camera), //tag中心在屏幕上的二维坐标
  265. o.set(op.resolution.x / 2, op.resolution.y / 2, 1).multiply(i), //转化成px -w/2 到 w/2的范围
  266. l.set(w / 2, 0, 0).add(o), //加上tag宽度的一半
  267. c.set(2 / op.resolution.x, 2 / op.resolution.y, 1).multiply(l), //再转回 -1 到 1的范围
  268. h.copy(c).unproject(op.camera);//再转成三维坐标,求得tag边缘的位置
  269. var g = h.distanceTo(op.position)//就能得到tag的三维半径
  270. return g //可能NAN 当相机和position重叠时
  271. }
  272. }
  273. //--------------------------------------
  274. //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
  275. var Manage = function(){
  276. this.weixinURL = "https://res.wx.qq.com/open/js/jweixin-1.2.0.js",
  277. this.time = "?"+new Date().getTime();
  278. this.loadAudio();
  279. // this.loadWeixin();
  280. }
  281. //动态加载js文件
  282. Manage.prototype.LoadJs = function(_files, succes){
  283. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  284. var classcodes = [];
  285. var FileArray = [];
  286. if (typeof _files === "object") {
  287. FileArray = _files;
  288. } else {
  289. /*如果文件列表是字符串,则用,切分成数组*/
  290. if (typeof _files === "string") {
  291. FileArray = _files.split(",");
  292. }
  293. }
  294. if (FileArray != null && FileArray.length > 0) {
  295. var LoadedCount = 0;
  296. for (var i = 0; i < FileArray.length; i++) {
  297. loadFile(FileArray[i], function() {
  298. LoadedCount++;
  299. if (LoadedCount == FileArray.length) {
  300. try {
  301. succes();
  302. }
  303. catch(err) {
  304. console.log("err: 您未定义回调");
  305. }
  306. }
  307. })
  308. }
  309. }
  310. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  311. function loadFile(url, success) {
  312. if (!FileIsExt(classcodes, url)) {
  313. var _ThisType = GetFileType(url);
  314. var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0,_ThisType.indexOf("?"));
  315. var fileObj = null;
  316. if (ThisType == ".js") {
  317. fileObj = document.createElement('script');
  318. fileObj.src = url;
  319. } else if (ThisType == ".css") {
  320. fileObj = document.createElement('link');
  321. fileObj.href = url;
  322. fileObj.type = "text/css";
  323. fileObj.rel = "stylesheet";
  324. } else if (ThisType == ".less") {
  325. fileObj = document.createElement('link');
  326. fileObj.href = url;
  327. fileObj.type = "text/css";
  328. fileObj.rel = "stylesheet/less";
  329. }
  330. success = success || function() {};
  331. fileObj.onload = fileObj.onreadystatechange = function() {
  332. if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
  333. success();
  334. classcodes.push(url)
  335. }
  336. }
  337. document.getElementsByTagName('head')[0].appendChild(fileObj);
  338. } else {
  339. success();
  340. }
  341. }
  342. /*获取文件类型,后缀名,小写*/
  343. function GetFileType(url) {
  344. if (url != null && url.length > 0) {
  345. return url.substr(url.lastIndexOf(".")).toLowerCase();
  346. }
  347. return "";
  348. }
  349. /*文件是否已加载*/
  350. function FileIsExt(FileArray, _url) {
  351. if (FileArray != null && FileArray.length > 0) {
  352. var len = FileArray.length;
  353. for (var i = 0; i < len; i++) {
  354. if (FileArray[i] == _url) {
  355. return true;
  356. }
  357. }
  358. }
  359. return false;
  360. }
  361. };
  362. //获取页面url后面的参数
  363. Manage.prototype.number = function(variable) {
  364. var query = window.location.search.substring(1);
  365. var vars = query.split("&");
  366. for (var i=0;i<vars.length;i++) {
  367. var pair = vars[i].split("=");
  368. if(pair[0] == variable){return pair[1];}
  369. }
  370. return(false);
  371. };
  372. Manage.prototype.loadWeixin = function() {
  373. var that = this;
  374. this.LoadJs(that.weixinURL+that.time,function(){ });
  375. }
  376. Manage.prototype.weixinShare = function() {
  377. console.log("weixinShare")
  378. $.ajax({
  379. url:'https://www.4dage.com/wechat/jssdk/',
  380. type: "post",
  381. data : {
  382. 'url' : location.href.split('#')[0]
  383. },
  384. dataType:"jsonp",
  385. jsonpCallback:"success_jsonp",
  386. success:function(data,textStatus){
  387. console.log("weixinShare success")
  388. console.log(data.appId)
  389. wx.config({
  390. // debug : true,
  391. appId : data.appId,
  392. timestamp : data.timestamp,
  393. nonceStr : data.nonceStr,
  394. signature : data.signature,
  395. jsApiList : [ 'checkJsApi', 'onMenuShareTimeline',
  396. 'onMenuShareAppMessage', 'onMenuShareQQ',
  397. 'onMenuShareWeibo', 'hideMenuItems',
  398. 'showMenuItems', 'hideAllNonBaseMenuItem',
  399. 'showAllNonBaseMenuItem', 'translateVoice',
  400. 'startRecord', 'stopRecord', 'onRecordEnd',
  401. 'playVoice', 'pauseVoice', 'stopVoice',
  402. 'uploadVoice', 'downloadVoice', 'chooseImage',
  403. 'previewImage', 'uploadImage', 'downloadImage',
  404. 'getNetworkType', 'openLocation', 'getLocation',
  405. 'hideOptionMenu', 'showOptionMenu', 'closeWindow',
  406. 'scanQRCode', 'chooseWXPay',
  407. 'openProductSpecificView', 'addCard', 'chooseCard',
  408. 'openCard' ]
  409. });
  410. },
  411. error:function(XMLHttpRequest,textStatus,errorThrown){
  412. console.log("jsonp.error:"+textStatus);
  413. }
  414. });
  415. var success_jsonp = function(json){
  416. console.log(json);
  417. };
  418. wx.ready(function(){
  419. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  420. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  421. //分享到朋友圈
  422. console.log(g_weixinObj)
  423. wx.onMenuShareTimeline({
  424. title: g_weixinObj.title, // 分享标题
  425. link: g_weixinObj.lineLink, // 分享链接
  426. imgUrl: g_weixinObj.imgUrl, // 分享图标
  427. desc: g_weixinObj.desc
  428. });
  429. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  430. wx.onMenuShareAppMessage({
  431. title: g_weixinObj.title, // 分享标题
  432. desc: g_weixinObj.desc, // 分享描述
  433. link: g_weixinObj.lineLink, // 分享链接
  434. imgUrl: g_weixinObj.imgUrl, // 分享图标
  435. type: '', // 分享类型,music、video或link,不填默认为link
  436. dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空
  437. });
  438. wx.onMenuShareWeibo({
  439. title: g_weixinObj.title, // 分享标题
  440. desc: g_weixinObj.desc, // 分享描述
  441. link: g_weixinObj.lineLink, // 分享链接
  442. imgUrl: g_weixinObj.imgUrl, // 分享图标
  443. success: function () {
  444. // 用户确认分享后执行的回调函数
  445. },
  446. cancel: function () {
  447. // 用户取消分享后执行的回调函数
  448. }
  449. });
  450. wx.onMenuShareQZone({
  451. title: g_weixinObj.title, // 分享标题
  452. desc: g_weixinObj.desc, // 分享描述
  453. link: g_weixinObj.lineLink, // 分享链接
  454. imgUrl: g_weixinObj.imgUrl, // 分享图标
  455. success: function () {
  456. // 用户确认分享后执行的回调函数
  457. },
  458. cancel: function () {
  459. // 用户取消分享后执行的回调函数
  460. }
  461. });
  462. wx.onMenuShareQQ({
  463. title: g_weixinObj.title, // 分享标题
  464. desc: g_weixinObj.desc, // 分享描述
  465. link: g_weixinObj.lineLink, // 分享链接
  466. imgUrl: g_weixinObj.imgUrl, // 分享图标
  467. success: function () {
  468. // 用户确认分享后执行的回调函数
  469. },
  470. cancel: function () {
  471. // 用户取消分享后执行的回调函数
  472. }
  473. });
  474. wx.error(function(res){
  475. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  476. });
  477. });
  478. }
  479. Manage.prototype.dealURL = function(src, type){
  480. //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
  481. //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
  482. if(window.isLocal && settings.localPrefix!=void 0){//本地将线上的前缀替换
  483. var oldPrefix = 'super.4dage.com/'; //最简单的地址写一个,如果有其他完全不一样的地址就用数组逐个判断
  484. var index = src.indexOf(oldPrefix);
  485. if(index>-1){
  486. var wholeOldPrefix = src.slice(0, index+oldPrefix.length);
  487. return src.replace(wholeOldPrefix, settings.localPrefix)
  488. }
  489. // console.error("没有找到合适的本地链接")
  490. return src
  491. }else{
  492. //add https://
  493. var prefix = g_Prefix.replace('https://','').replace('http://','')
  494. if(!src.includes('http:/') && !src.includes('https:/') && src.includes(prefix)){
  495. src = 'https://'+src
  496. }
  497. return src
  498. }
  499. }
  500. Manage.prototype.removeSrcPostMark = function(url){//去除texture.load时自动加上的'?'
  501. var index = url.indexOf('?')
  502. if(index>-1){
  503. return url.slice(0, index)
  504. }else return url
  505. }
  506. Manage.prototype.showInfo = function (o) { // ({result:true, title:"发布成功"});
  507. var box = $(".resultBox");
  508. var title = o.title || o || i18n.get('保存成功');
  509. box.children().eq(0).html(title)
  510. //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000);
  511. var time = o.time || THREE.Math.clamp(title.length*130 ,1300, 5000);
  512. o.time || console.log("showtime " + time)
  513. //实际有一半的时间在渐变透明度
  514. this.showInfoTimer && clearTimeout(this.showInfoTimer)
  515. box.removeClass("animate");//如果之后不久又要showinfo一个的话,先停止前面的animate
  516. setTimeout(function () {
  517. box.css(
  518. {
  519. '-webkit-animation-duration': time + 'ms',
  520. 'animation-duration': time + 'ms'
  521. }
  522. )
  523. if(o.top){
  524. box.children().css('top', o.top + "%");
  525. }else{
  526. box.children().css('top', '' )
  527. }
  528. box.removeClass("hide");
  529. box.addClass("animate");
  530. if (o.dontInteract) {//遮挡对屏幕的操作
  531. box.css('pointer-events', 'auto')
  532. } else {
  533. box.css('pointer-events', 'none')
  534. }
  535. this.showInfoTimer = setTimeout(function () {
  536. box.removeClass("animate");
  537. box.addClass("hide");
  538. this.showInfoTimer = null;
  539. }.bind(this), time + 20)
  540. }.bind(this), 50)//这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧
  541. }//like: manage.showInfo({title:'a', top:20})
  542. //公用的函数
  543. function getQueryVariable(variable)
  544. {
  545. var query = window.location.search.substring(1);
  546. var vars = query.split("&");
  547. for (var i=0;i<vars.length;i++) {
  548. var pair = vars[i].split("=");
  549. if(pair[0] == variable){return pair[1];}
  550. }
  551. return(false);
  552. }
  553. //隐藏公司Logo
  554. function showLogo(){
  555. $("#myCompany").hide();
  556. $("#loaderCoBrandName").hide();
  557. $("#title-logo").hide();
  558. $(".title-container").css("justify-content","center")
  559. }
  560. //czj 添加随机的时间
  561. function randomTime(){
  562. return new Date()
  563. };
  564. function matcher(data){
  565. if(!data || !g_version ) return data;
  566. delete data.model.vision_version;
  567. var _data = {
  568. files: {
  569. "templates": ["images/images{{number}}/{{filename}}"]
  570. },
  571. model :{
  572. sid :window.number,
  573. camera_start:
  574. data.model.images && data.model.images.length != 0 ?
  575. {
  576. camera: {
  577. zoom: "-1",
  578. quaternion: [
  579. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  580. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  581. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  582. JSON.parse(data.model.images[0].metadata).camera_quaternion.y
  583. ]
  584. },
  585. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  586. mode: "0"
  587. }
  588. : ''
  589. },
  590. sid: window.number,
  591. hoticon: {
  592. default: "https://super.4dage.com/images/4dagePoint2.png",
  593. higt: "https://super.4dage.com/images/4dagePoint.png"
  594. },
  595. special: "false",
  596. weixinDesc: ""
  597. };
  598. $.extend(true,data,_data)
  599. return data;
  600. }
  601. function hotMatcher(data={}){
  602. //if(!data || !g_version) return data;
  603. if(g_version) {
  604. data.tourAudio = data.audio || {};
  605. }else{
  606. data.tourAudio = {}
  607. }
  608. return data;
  609. }
  610. var GifTexDeal = {
  611. animateObjects : [],
  612. animateTexs : [] ,
  613. addAnimation : function(texture, owner, info, id){
  614. /* if(this.animateObjects.find(e=>
  615. e.texture == texture && !ifSame(info, e.info)
  616. )) */
  617. var animation
  618. var tex = this.animateTexs.find(e=>e.texture == texture)
  619. if(tex){
  620. animation = tex
  621. }else{
  622. animation = {texture,info }
  623. this.animateTexs.push(animation)
  624. this.setRepeart(animation)
  625. }
  626. var object = {
  627. animation, //默认相同的texture对应的info是一样的, 对应一个animation
  628. owner,
  629. }
  630. this.animateObjects.push(object)
  631. return object
  632. },
  633. remove : function(object){
  634. var index = this.animateObjects.indexOf(object)
  635. if(index>-1){
  636. this.animateObjects.splice(index, 1)
  637. if(!this.animateObjects.find(e=>e.animation == object.animation)){
  638. let i = this.animateTexs.indexOf(object.animation)
  639. this.animateTexs.splice(i, 1)
  640. object.animation.texture.repeat.set(1,1)
  641. }
  642. this.stop(object)
  643. }
  644. },
  645. setRepeart : function(animation){
  646. animation.texture.repeat.set(1/animation.info.cellXcount, 1/animation.info.cellYcount)
  647. },
  648. start: function(object){
  649. if(!object || object.started )return;
  650. object.started = true
  651. if(object.animation.started)return;
  652. object.animation.started = true
  653. var info = object.animation.info
  654. var count = info.cellXcount * info.cellYcount - (info.voidCount || 0)
  655. if(count <= 1)return;
  656. transitions.start( (progress)=>{
  657. var index = Math.floor(count * progress);
  658. var indexX = index % info.cellXcount
  659. var indexY = info.cellYcount - Math.floor(index /info.cellXcount ) - 1; //uv.offset.y是从下到上的
  660. object.animation.texture.offset.x = indexX / info.cellXcount;
  661. object.animation.texture.offset.y = indexY / info.cellYcount;
  662. //console.log(object.id + " : "+ object.texture.offset.toArray())
  663. } , info.duration * (-1), null,/* ()=>{//done (-1):循环
  664. object.started = false
  665. object.texture.offset.x = 0;
  666. object.texture.offset.y = 0;
  667. this.start(object)
  668. }, */ 0 ,null, object.id, "gif_"+object.animation.texture.id);
  669. },
  670. stop: function(object){
  671. if(!object || !object.started)return;
  672. object.started = false
  673. //只有该object对应的texture对应的所有object都停止了,才能真的停止动画:
  674. if(this.animateObjects.find(e=>e.animation == object.animation && e.started)) return;
  675. transitions.cancelById("gif_"+object.animation.texture.id);
  676. object.animation.texture.offset.set(0,0)
  677. object.animation.started = false
  678. }
  679. }
  680. var CloneObject = function(copyObj, result, isSimpleCopy, extraReplace) {
  681. //isSimpleCopy只复制最外层
  682. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  683. if(!copyObj)return copyObj //0 null undefined ''
  684. result = result || {};
  685. if (copyObj instanceof Array) {
  686. /* if (copyObj[0]instanceof Object) {
  687. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  688. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  689. }
  690. return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object
  691. return copyObj.map(e=>{
  692. if(e instanceof Object){
  693. return CloneObject(e)
  694. }else return e
  695. })
  696. }else{
  697. if(copyObj.clone instanceof Function ){ //解决一部分
  698. return copyObj.clone()
  699. }
  700. }
  701. for (var key in copyObj) {
  702. if (copyObj[key] instanceof Object && !isSimpleCopy)
  703. result[key] = CloneObject(copyObj[key]);
  704. else
  705. result[key] = copyObj[key];
  706. //如果是函数类同基本数据,即复制引用
  707. }
  708. return result;
  709. }
  710. ;
  711. var ifSame = function(object1, object2){
  712. if(object1 == object2 )return true // 0 != undefined , 0 == ''
  713. else if(!object1 || !object2) return false
  714. else if(object1.constructor != object2.constructor){
  715. return false
  716. }else if(object1 instanceof Array ) {
  717. if(object1.length != object2.length)return false;
  718. var _object2 = object2.slice(0);
  719. for(let i=0;i<object1.length;i++){
  720. var u = _object2.find(e=>ifSame(object1[i], e));
  721. if(u == void 0 && !_object2.includes(u) && !object1.includes(u))return false;
  722. else{
  723. let index = _object2.indexOf(u);
  724. _object2.splice(index,1);
  725. }
  726. }
  727. return true
  728. }else if(object1.equals instanceof Function ){//复杂数据仅支持这种,其他的可能卡住?
  729. return object1.equals(object2)
  730. }else if(typeof object1 == 'number' || typeof object1 == 'string'){
  731. if(isNaN(object1) && isNaN(object2))return true
  732. else return object1 == object2
  733. }else if(typeof object1 == "object"){
  734. var keys1 = Object.keys(object1)
  735. var keys2 = Object.keys(object2)
  736. if(!ifSame(keys1,keys2))return false;
  737. for(let i in object1){
  738. var same = ifSame(object1[i], object2[i]);
  739. if(!same)return false
  740. }
  741. return true
  742. }else{
  743. console.log('isSame出现例外')
  744. }
  745. }
  746. /* var SoundManager = {//暂不支持同时播放
  747. currentAudio:null,//当前正在播放list中的哪一个
  748. list:[
  749. {
  750. name:"bg",
  751. level : 0,//越大优先级越高
  752. canBeInterrupted : true ,
  753. },
  754. {
  755. name:"boxVideo",
  756. level : 1,
  757. canBeInterrupted : true,
  758. checkIfNeedPlay:function(){
  759. }
  760. },
  761. {
  762. name:"hot",
  763. level : 2,
  764. canBeInterrupted : true
  765. },
  766. {
  767. name:"tour",
  768. level : 3,
  769. canBeInterrupted : true
  770. },
  771. ],
  772. switchPlay:function(){
  773. },
  774. register:function(){
  775. }
  776. }
  777. */
  778. //最好能知道应该播放到的currentTime
  779. var SoundManager = {//暂不支持同时播放
  780. currentAudio:null,//当前正在播放list中的哪一个
  781. enableSound:true,//是否允许有声音
  782. playHistory:[],//被打断的加入播放历史
  783. list:[ ],//同一级别可以互相打断 //暂时不做多级别
  784. play:function(name, src, currentTime){
  785. var object = this.list.find(e=>e.name == name)
  786. if(object){
  787. if(this.currentAudio){
  788. this.pause(this.currentAudio.name, false, true)
  789. }
  790. {//将当前要播放的播放历史中清除
  791. let index = this.playHistory.indexOf(object)
  792. if(index>-1)this.playHistory.splice(index,1);
  793. }
  794. this.currentAudio = object
  795. if(src){
  796. this.setSrc(name, src)
  797. }
  798. if(currentTime!=void 0){
  799. object.audio.currentTime = currentTime
  800. }
  801. if(object.audio){
  802. console.log(window.ISMUTED,1111111);
  803. object.audio.muted = window.ISMUTED
  804. object.audio.load(); // iOS 9 还需要额外的 load 一下, 否则直接 play 无效 *///https://www.cnblogs.com/interdrp/p/4211883.html 部分资料
  805. object.audio.play();
  806. object.callback && object.callback(true)
  807. }
  808. console.log(this.currentAudio);
  809. Log(name + ' 播放 ' )
  810. }
  811. },
  812. pause:function(name, autoReplayLast, isInterrupt){//需要能自动恢复上一个被打算的音频。恢复前判断是否还需要播放
  813. var object = this.list.find(e=>e.name == name)
  814. if(object){
  815. this.currentAudio = null
  816. if(object.audio){
  817. object.audio.pause()
  818. object.callback && object.callback(false)
  819. Log(name + ' 中断音频 '+ "("+common.getFileNameFromUrl(object.audio.src)+')' )
  820. }
  821. if(isInterrupt){//一般主动调用不需要加这个
  822. this.playHistory.push(object)//如果是被中断的,加入播放历史,等待恢复播放
  823. }
  824. if(autoReplayLast){ //播放之前的音频。它们是被打断过的。
  825. while(this.playHistory.length){
  826. var last = this.playHistory.pop();
  827. if(last.src && last.canplay(last.audio)){
  828. this.play(last.name )
  829. }
  830. }
  831. }
  832. }
  833. },
  834. setSrc : function(name, src){//不能直接给audio赋src!一定要用这个函数!因为我要拿这里的src来判断有无src,因为貌似audio的src会自动变,''时会变成html的链接
  835. var object = this.list.find(e=>e.name == name)
  836. object.src = src
  837. object.audio.src = src
  838. Log(`${object.name} 设置src: ${src}`)
  839. },
  840. createAudio:function(object={}){//name, level, canplay
  841. if(!object.fake){
  842. object.audio = new Audio();
  843. object.audio.loop = !!object.loop;
  844. //object.audio.autoplay = true;
  845. object.audio.addEventListener('ended', ()=>{
  846. if(object.loop){//循环
  847. Log(`${object.name} 播放完毕,重新播放`)
  848. object.audio.play()
  849. }else{
  850. this.pause(object.name, true);//停止后的后续处理
  851. }
  852. });
  853. object.audio.oncanplaythrough = ()=>{
  854. Log(`${object.name} canplaythrough `)
  855. }
  856. }
  857. this.list.push(object)
  858. },
  859. initAutoPlay:function(){ //处理设备自动播放限制
  860. let play = function(){
  861. if(this.currentAudio && this.currentAudio.audio){
  862. this.currentAudio.audio.play()
  863. Log(`${this.currentAudio.name} 自动播放成功`) //即使设置src在这之后好像也能成功播放
  864. }else{
  865. }
  866. document.removeEventListener("touchstart",play);
  867. document.removeEventListener("click",play);
  868. $('#player')[0] && $('#player')[0].removeEventListener("touchstart", play);
  869. }.bind(this);
  870. document.addEventListener("WeixinJSBridgeReady", play, false);
  871. document.addEventListener("touchstart", play);//ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
  872. document.addEventListener("click", play);
  873. $('#player')[0] && $('#player')[0].addEventListener("touchstart", play);
  874. }
  875. }
  876. function Log(value, color, fontSize){
  877. color = color || '#13f'
  878. fontSize = fontSize || 14
  879. console.warn(`%c${value}`, `color:${color};font-size:${fontSize}px`)
  880. }
  881. Manage.prototype.loadAudio = function() { //相关:g_tourAudio \ g_playAudio
  882. //热点页面因为挡住了界面,所以暂时不存在别的音频阻止热点音频的可能
  883. //box视频都静音,所以暂时不考虑
  884. SoundManager.createAudio({
  885. name:'bgm',
  886. level:0,
  887. src:'',
  888. loop:true,
  889. canplay:(audio)=>{
  890. return this.bgmShouldPlay
  891. },
  892. callback:(state)=>{//play或pause时随之触发的函数(即使还没开始播放)
  893. if(state){
  894. $("#volume a img").attr("src", "./static/images/Volume btn_off.png")
  895. $("#volume").attr("title", "关闭声音");
  896. }else{
  897. $("#volume a img").attr("src", "./static/images/Volume btn_on.png")
  898. $("#volume").attr("title", "打开声音");
  899. }
  900. }
  901. })
  902. SoundManager.createAudio({
  903. name:'tour',
  904. level:0,
  905. src:'',
  906. loop:false,
  907. canplay:(audio)=>{
  908. return player.director && player.director.tourIsPlaying && player.director.getAudio()
  909. }
  910. })
  911. SoundManager.createAudio({
  912. name:'hot',
  913. fake:true,//实际上没有audio. 只是为了来停止和续播其他音频
  914. level:1,
  915. src:'',
  916. loop:false,
  917. canplay:(audio)=>{
  918. }
  919. })
  920. $("#volume").find("a").on("click", ()=> {
  921. if($("#volume img")[0].src.indexOf("btn_on.png")>-1)
  922. {
  923. this.switchBgmState(true);
  924. }
  925. else if($("#volume img")[0].src.indexOf("btn_off.png")>-1)
  926. {
  927. this.switchBgmState(false);
  928. }
  929. })
  930. this.switchBgmState(true);//初始设置允许播放bgm
  931. SoundManager.initAutoPlay()
  932. }
  933. Manage.prototype.switchBgmState = function(state){//按钮的状态完全代表是否应该播放bgm,即使还没加载完
  934. this.bgmShouldPlay = state
  935. if(state){
  936. SoundManager.play('bgm')
  937. }else{
  938. SoundManager.pause('bgm')
  939. }
  940. /* if(!g_bgAudio || !g_bgAudio.src) return;
  941. var played = function(){
  942. console.log('begin play bgm');
  943. g_play = 1;
  944. g_playAudio = g_bgAudio;
  945. g_tourAudio && g_tourAudio.pause()
  946. }
  947. var paused = function(){
  948. g_play = 0;
  949. g_playAudio == g_bgAudio && (g_playAudio = null)
  950. }
  951. if(state ){
  952. g_bgAudio.play();
  953. if(g_bgAudio.paused){
  954. paused()
  955. }else{
  956. played()
  957. return true
  958. }
  959. }else{
  960. g_bgAudio.pause();
  961. paused()
  962. }
  963. g_bgAudio.pauseByHot = false
  964. g_bgAudio.pauseByTour = false */
  965. }
  966. var manage = new Manage();
  967. //兼容一代的場景
  968. //請求地址統一管理
  969. var g_onePregix = "https://bigscene.4dage.com/" //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
  970. var g_version = manage.number("version");
  971. g_version === "one" ? g_Prefix = g_onePregix : '';