manage.js 40 KB

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