manage.js 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  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.245:8003/";
  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":"static/images/4dagePoint2.png",
  19. "point2":"static/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. }
  280. //动态加载js文件
  281. Manage.prototype.LoadJs = function(_files, succes){
  282. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  283. var classcodes = [];
  284. var FileArray = [];
  285. if (typeof _files === "object") {
  286. FileArray = _files;
  287. } else {
  288. /*如果文件列表是字符串,则用,切分成数组*/
  289. if (typeof _files === "string") {
  290. FileArray = _files.split(",");
  291. }
  292. }
  293. if (FileArray != null && FileArray.length > 0) {
  294. var LoadedCount = 0;
  295. for (var i = 0; i < FileArray.length; i++) {
  296. loadFile(FileArray[i], function() {
  297. LoadedCount++;
  298. if (LoadedCount == FileArray.length) {
  299. try {
  300. succes();
  301. }
  302. catch(err) {
  303. console.log("err: 您未定义回调");
  304. }
  305. }
  306. })
  307. }
  308. }
  309. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  310. function loadFile(url, success) {
  311. if (!FileIsExt(classcodes, url)) {
  312. var _ThisType = GetFileType(url);
  313. var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0,_ThisType.indexOf("?"));
  314. var fileObj = null;
  315. if (ThisType == ".js") {
  316. fileObj = document.createElement('script');
  317. fileObj.src = url;
  318. } else if (ThisType == ".css") {
  319. fileObj = document.createElement('link');
  320. fileObj.href = url;
  321. fileObj.type = "text/css";
  322. fileObj.rel = "stylesheet";
  323. } else if (ThisType == ".less") {
  324. fileObj = document.createElement('link');
  325. fileObj.href = url;
  326. fileObj.type = "text/css";
  327. fileObj.rel = "stylesheet/less";
  328. }
  329. success = success || function() {};
  330. fileObj.onload = fileObj.onreadystatechange = function() {
  331. if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
  332. success();
  333. classcodes.push(url)
  334. }
  335. }
  336. document.getElementsByTagName('head')[0].appendChild(fileObj);
  337. } else {
  338. success();
  339. }
  340. }
  341. /*获取文件类型,后缀名,小写*/
  342. function GetFileType(url) {
  343. if (url != null && url.length > 0) {
  344. return url.substr(url.lastIndexOf(".")).toLowerCase();
  345. }
  346. return "";
  347. }
  348. /*文件是否已加载*/
  349. function FileIsExt(FileArray, _url) {
  350. if (FileArray != null && FileArray.length > 0) {
  351. var len = FileArray.length;
  352. for (var i = 0; i < len; i++) {
  353. if (FileArray[i] == _url) {
  354. return true;
  355. }
  356. }
  357. }
  358. return false;
  359. }
  360. };
  361. //获取页面url后面的参数
  362. Manage.prototype.number = function(variable) {
  363. var query = window.location.search.substring(1);
  364. var vars = query.split("&");
  365. for (var i=0;i<vars.length;i++) {
  366. var pair = vars[i].split("=");
  367. if(pair[0] == variable){return pair[1];}
  368. }
  369. return(false);
  370. };
  371. Manage.prototype.dealURL = function(src, type){
  372. //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
  373. //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
  374. if(window.isLocal && settings.localPrefix!=void 0){//本地将线上的前缀替换
  375. var oldPrefix = 'super.4dage.com/'; //最简单的地址写一个,如果有其他完全不一样的地址就用数组逐个判断
  376. var index = src.indexOf(oldPrefix);
  377. if(index>-1){
  378. var wholeOldPrefix = src.slice(0, index+oldPrefix.length);
  379. return src.replace(wholeOldPrefix, settings.localPrefix)
  380. }
  381. console.error("没有找到合适的本地链接")
  382. return src
  383. }else{
  384. //add https://
  385. var prefix = g_Prefix.replace('https://','').replace('http://','')
  386. if(!src.includes('http:/') && !src.includes('https:/') && src.includes(prefix)){
  387. src = 'https://'+src
  388. }
  389. return src
  390. }
  391. }
  392. Manage.prototype.removeSrcPostMark = function(url){//去除texture.load时自动加上的'?'
  393. var index = url.indexOf('?')
  394. if(index>-1){
  395. return url.slice(0, index)
  396. }else return url
  397. }
  398. Manage.prototype.showInfo = function (o) { // ({result:true, title:"发布成功"});
  399. var box = $(".resultBox");
  400. var title = o.title || o || i18n.get('保存成功');
  401. box.children().eq(0).html(title)
  402. //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000);
  403. var time = o.time || THREE.Math.clamp(title.length*130 ,1300, 5000);
  404. o.time || console.log("showtime " + time)
  405. //实际有一半的时间在渐变透明度
  406. this.showInfoTimer && clearTimeout(this.showInfoTimer)
  407. box.removeClass("animate");//如果之后不久又要showinfo一个的话,先停止前面的animate
  408. setTimeout(function () {
  409. box.css(
  410. {
  411. '-webkit-animation-duration': time + 'ms',
  412. 'animation-duration': time + 'ms'
  413. }
  414. )
  415. if(o.top){
  416. box.children().css('top', o.top + "%");
  417. }else{
  418. box.children().css('top', '' )
  419. }
  420. box.removeClass("hide");
  421. box.addClass("animate");
  422. if (o.dontInteract) {//遮挡对屏幕的操作
  423. box.css('pointer-events', 'auto')
  424. } else {
  425. box.css('pointer-events', 'none')
  426. }
  427. this.showInfoTimer = setTimeout(function () {
  428. box.removeClass("animate");
  429. box.addClass("hide");
  430. this.showInfoTimer = null;
  431. }.bind(this), time + 20)
  432. }.bind(this), 50)//这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧
  433. }//like: manage.showInfo({title:'a', top:20})
  434. //公用的函数
  435. function getQueryVariable(variable)
  436. {
  437. var query = window.location.search.substring(1);
  438. var vars = query.split("&");
  439. for (var i=0;i<vars.length;i++) {
  440. var pair = vars[i].split("=");
  441. if(pair[0] == variable){return pair[1];}
  442. }
  443. return(false);
  444. }
  445. //隐藏公司Logo
  446. function showLogo(){
  447. $("#myCompany").hide();
  448. $("#loaderCoBrandName").hide();
  449. $("#title-logo").hide();
  450. $(".title-container").css("justify-content","center")
  451. }
  452. //czj 添加随机的时间
  453. function randomTime(){
  454. return new Date()
  455. }
  456. function matcher(data){
  457. if(!data || !g_version ) return data;
  458. delete data.model.vision_version;
  459. var _data = {
  460. files: {
  461. "templates": ["images/images{{number}}/{{filename}}"]
  462. },
  463. model :{
  464. sid :window.number,
  465. camera_start:
  466. data.model.images && data.model.images.length != 0 ?
  467. {
  468. camera: {
  469. zoom: "-1",
  470. quaternion: [
  471. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  472. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  473. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  474. JSON.parse(data.model.images[0].metadata).camera_quaternion.y
  475. ]
  476. },
  477. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  478. mode: "0"
  479. }
  480. : ''
  481. },
  482. sid: window.number,
  483. hoticon: {
  484. default: "https://super.4dage.com/images/4dagePoint2.png",
  485. higt: "https://super.4dage.com/images/4dagePoint.png"
  486. },
  487. special: "false",
  488. weixinDesc: ""
  489. };
  490. $.extend(true,data,_data)
  491. return data;
  492. }
  493. function hotMatcher(data={}){
  494. //if(!data || !g_version) return data;
  495. if(g_version) {
  496. data.tourAudio = data.audio || {};
  497. }else{
  498. data.tourAudio = {}
  499. }
  500. return data;
  501. }
  502. var GifTexDeal = {
  503. animateObjects : [],
  504. animateTexs : [] ,
  505. addAnimation : function(texture, owner, info, id){
  506. /* if(this.animateObjects.find(e=>
  507. e.texture == texture && !ifSame(info, e.info)
  508. )) */
  509. var animation
  510. var tex = this.animateTexs.find(e=>e.texture == texture)
  511. if(tex){
  512. animation = tex
  513. }else{
  514. animation = {texture,info }
  515. this.animateTexs.push(animation)
  516. this.setRepeart(animation)
  517. }
  518. var object = {
  519. animation, //默认相同的texture对应的info是一样的, 对应一个animation
  520. owner,
  521. }
  522. this.animateObjects.push(object)
  523. return object
  524. },
  525. remove : function(object){
  526. var index = this.animateObjects.indexOf(object)
  527. if(index>-1){
  528. this.animateObjects.splice(index, 1)
  529. if(!this.animateObjects.find(e=>e.animation == object.animation)){
  530. let i = this.animateTexs.indexOf(object.animation)
  531. this.animateTexs.splice(i, 1)
  532. object.animation.texture.repeat.set(1,1)
  533. }
  534. this.stop(object)
  535. }
  536. },
  537. setRepeart : function(animation){
  538. animation.texture.repeat.set(1/animation.info.cellXcount, 1/animation.info.cellYcount)
  539. },
  540. start: function(object){
  541. if(!object || object.started )return;
  542. object.started = true
  543. if(object.animation.started)return;
  544. object.animation.started = true
  545. var info = object.animation.info
  546. var count = info.cellXcount * info.cellYcount - (info.voidCount || 0)
  547. if(count <= 1)return;
  548. transitions.start( (progress)=>{
  549. var index = Math.floor(count * progress);
  550. var indexX = index % info.cellXcount
  551. var indexY = info.cellYcount - Math.floor(index /info.cellXcount ) - 1; //uv.offset.y是从下到上的
  552. object.animation.texture.offset.x = indexX / info.cellXcount;
  553. object.animation.texture.offset.y = indexY / info.cellYcount;
  554. //console.log(object.id + " : "+ object.texture.offset.toArray())
  555. } , info.duration * (-1), null,/* ()=>{//done (-1):循环
  556. object.started = false
  557. object.texture.offset.x = 0;
  558. object.texture.offset.y = 0;
  559. this.start(object)
  560. }, */ 0 ,null, object.id, "gif_"+object.animation.texture.id);
  561. },
  562. stop: function(object){
  563. if(!object || !object.started)return;
  564. object.started = false
  565. //只有该object对应的texture对应的所有object都停止了,才能真的停止动画:
  566. if(this.animateObjects.find(e=>e.animation == object.animation && e.started)) return;
  567. transitions.cancelById("gif_"+object.animation.texture.id);
  568. object.animation.texture.offset.set(0,0)
  569. object.animation.started = false
  570. }
  571. }
  572. var CloneObject = function(copyObj, result, isSimpleCopy, extraReplace) {
  573. //isSimpleCopy只复制最外层
  574. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  575. if(!copyObj)return copyObj //0 null undefined ''
  576. result = result || {};
  577. if (copyObj instanceof Array) {
  578. /* if (copyObj[0]instanceof Object) {
  579. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  580. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  581. }
  582. return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object
  583. return copyObj.map(e=>{
  584. if(e instanceof Object){
  585. return CloneObject(e)
  586. }else return e
  587. })
  588. }else{
  589. if(copyObj.clone instanceof Function ){ //解决一部分
  590. return copyObj.clone()
  591. }
  592. }
  593. for (var key in copyObj) {
  594. if (copyObj[key] instanceof Object && !isSimpleCopy)
  595. result[key] = CloneObject(copyObj[key]);
  596. else
  597. result[key] = copyObj[key];
  598. //如果是函数类同基本数据,即复制引用
  599. }
  600. return result;
  601. }
  602. ;
  603. var ifSame = function(object1, object2){
  604. if(object1 == object2 )return true // 0 != undefined , 0 == ''
  605. else if(!object1 || !object2) return false
  606. else if(object1.constructor != object2.constructor){
  607. return false
  608. }else if(object1 instanceof Array ) {
  609. if(object1.length != object2.length)return false;
  610. var _object2 = object2.slice(0);
  611. for(let i=0;i<object1.length;i++){
  612. var u = _object2.find(e=>ifSame(object1[i], e));
  613. if(u == void 0 && !_object2.includes(u) && !object1.includes(u))return false;
  614. else{
  615. let index = _object2.indexOf(u);
  616. _object2.splice(index,1);
  617. }
  618. }
  619. return true
  620. }else if(object1.equals instanceof Function ){//复杂数据仅支持这种,其他的可能卡住?
  621. return object1.equals(object2)
  622. }else if(typeof object1 == 'number' || typeof object1 == 'string'){
  623. if(isNaN(object1) && isNaN(object2))return true
  624. else return object1 == object2
  625. }else if(typeof object1 == "object"){
  626. var keys1 = Object.keys(object1)
  627. var keys2 = Object.keys(object2)
  628. if(!ifSame(keys1,keys2))return false;
  629. for(let i in object1){
  630. var same = ifSame(object1[i], object2[i]);
  631. if(!same)return false
  632. }
  633. return true
  634. }else{
  635. console.log('isSame出现例外')
  636. }
  637. }
  638. /* var SoundManager = {//暂不支持同时播放
  639. currentAudio:null,//当前正在播放list中的哪一个
  640. list:[
  641. {
  642. name:"bg",
  643. level : 0,//越大优先级越高
  644. canBeInterrupted : true ,
  645. },
  646. {
  647. name:"boxVideo",
  648. level : 1,
  649. canBeInterrupted : true,
  650. checkIfNeedPlay:function(){
  651. }
  652. },
  653. {
  654. name:"hot",
  655. level : 2,
  656. canBeInterrupted : true
  657. },
  658. {
  659. name:"tour",
  660. level : 3,
  661. canBeInterrupted : true
  662. },
  663. ],
  664. switchPlay:function(){
  665. },
  666. register:function(){
  667. }
  668. }
  669. */
  670. //最好能知道应该播放到的currentTime
  671. var SoundManager = {//暂不支持同时播放
  672. currentAudio:null,//当前正在播放list中的哪一个
  673. enableSound:true,//是否允许有声音
  674. playHistory:[],//被打断的加入播放历史
  675. list:[ ],//同一级别可以互相打断 //暂时不做多级别
  676. play:function(name, src, currentTime){
  677. var object = this.list.find(e=>e.name == name)
  678. if(object){
  679. if(this.currentAudio){
  680. this.pause(this.currentAudio.name, false, true)
  681. }
  682. {//将当前要播放的播放历史中清除
  683. let index = this.playHistory.indexOf(object)
  684. if(index>-1)this.playHistory.splice(index,1);
  685. }
  686. this.currentAudio = object
  687. if(src){
  688. this.setSrc(name, src)
  689. }
  690. if(currentTime!=void 0){
  691. object.audio.currentTime = currentTime
  692. }
  693. if(object.audio){
  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. if(state){
  782. $("#volume a img").attr("src", "./static/images/Volume btn_off.png")
  783. $("#volume").attr("title", "关闭声音");
  784. }else{
  785. $("#volume a img").attr("src", "./static/images/Volume btn_on.png")
  786. $("#volume").attr("title", "打开声音");
  787. }
  788. }
  789. })
  790. SoundManager.createAudio({
  791. name:'tour',
  792. level:0,
  793. src:'',
  794. loop:false,
  795. canplay:(audio)=>{
  796. return player.director && player.director.tourIsPlaying && player.director.getAudio()
  797. }
  798. })
  799. SoundManager.createAudio({
  800. name:'hot',
  801. fake:true,//实际上没有audio. 只是为了来停止和续播其他音频
  802. level:1,
  803. src:'',
  804. loop:false,
  805. canplay:(audio)=>{
  806. }
  807. })
  808. $("#volume").find("a").on("click", ()=> {
  809. if($("#volume img")[0].src.indexOf("btn_on.png")>-1)
  810. {
  811. this.switchBgmState(true);
  812. }
  813. else if($("#volume img")[0].src.indexOf("btn_off.png")>-1)
  814. {
  815. this.switchBgmState(false);
  816. }
  817. })
  818. this.switchBgmState(true);//初始设置允许播放bgm
  819. SoundManager.initAutoPlay()
  820. }
  821. Manage.prototype.switchBgmState = function(state){//按钮的状态完全代表是否应该播放bgm,即使还没加载完
  822. this.bgmShouldPlay = state
  823. if(state){
  824. SoundManager.play('bgm')
  825. }else{
  826. SoundManager.pause('bgm')
  827. }
  828. /* if(!g_bgAudio || !g_bgAudio.src) return;
  829. var played = function(){
  830. console.log('begin play bgm');
  831. g_play = 1;
  832. g_playAudio = g_bgAudio;
  833. g_tourAudio && g_tourAudio.pause()
  834. }
  835. var paused = function(){
  836. g_play = 0;
  837. g_playAudio == g_bgAudio && (g_playAudio = null)
  838. }
  839. if(state ){
  840. g_bgAudio.play();
  841. if(g_bgAudio.paused){
  842. paused()
  843. }else{
  844. played()
  845. return true
  846. }
  847. }else{
  848. g_bgAudio.pause();
  849. paused()
  850. }
  851. g_bgAudio.pauseByHot = false
  852. g_bgAudio.pauseByTour = false */
  853. }
  854. var manage = new Manage();
  855. //兼容一代的場景
  856. //請求地址統一管理
  857. var g_onePregix = "https://bigscene.4dage.com/" //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
  858. var g_version = manage.number("version");
  859. g_version === "one" ? g_Prefix = g_onePregix : '';