manage.js 34 KB

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