manage.js 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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":"https://super.4dage.com/images/4dagePoint2.png",
  19. "point2":"https://super.4dage.com/images/4dagePoint.png"
  20. };
  21. var g_saveHot=false;
  22. var g_TextColor=0x7777ff;
  23. var g_Text=null;
  24. var g_TextPlaneMesh=[];
  25. var g_TextIconMesh=[];
  26. var g_TextIcon="./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. if(window.isLocal && settings.localPrefix!=void 0){//本地将线上的前缀替换
  373. var oldPrefix = 'super.4dage.com/'; //最简单的地址写一个,如果有其他完全不一样的地址就用数组逐个判断
  374. var index = src.indexOf(oldPrefix);
  375. if(index>-1){
  376. var wholeOldPrefix = src.slice(0, index+oldPrefix.length);
  377. return src.replace(wholeOldPrefix, settings.localPrefix)
  378. }
  379. // console.error("没有找到合适的本地链接")
  380. return src
  381. }else{
  382. //add https://
  383. var prefix = g_Prefix.replace('https://','').replace('http://','')
  384. if(!src.includes('http:/') && !src.includes('https:/') && src.includes(prefix)){
  385. src = 'https://'+src
  386. }
  387. return src
  388. }
  389. }
  390. Manage.prototype.removeSrcPostMark = function(url){//去除texture.load时自动加上的'?'
  391. var index = url.indexOf('?')
  392. if(index>-1){
  393. return url.slice(0, index)
  394. }else return url
  395. }
  396. Manage.prototype.showInfo = function (o) { // ({result:true, title:"发布成功"});
  397. var box = $(".resultBox");
  398. var title = o.title || o || i18n.get('保存成功');
  399. box.children().eq(0).html(title)
  400. //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000);
  401. var time = o.time || THREE.Math.clamp(title.length*130 ,1300, 5000);
  402. o.time || console.log("showtime " + time)
  403. //实际有一半的时间在渐变透明度
  404. this.showInfoTimer && clearTimeout(this.showInfoTimer)
  405. box.removeClass("animate");//如果之后不久又要showinfo一个的话,先停止前面的animate
  406. setTimeout(function () {
  407. box.css(
  408. {
  409. '-webkit-animation-duration': time + 'ms',
  410. 'animation-duration': time + 'ms'
  411. }
  412. )
  413. if(o.top){
  414. box.children().css('top', o.top + "%");
  415. }else{
  416. box.children().css('top', '' )
  417. }
  418. box.removeClass("hide");
  419. box.addClass("animate");
  420. if (o.dontInteract) {//遮挡对屏幕的操作
  421. box.css('pointer-events', 'auto')
  422. } else {
  423. box.css('pointer-events', 'none')
  424. }
  425. this.showInfoTimer = setTimeout(function () {
  426. box.removeClass("animate");
  427. box.addClass("hide");
  428. this.showInfoTimer = null;
  429. }.bind(this), time + 20)
  430. }.bind(this), 50)//这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧
  431. }//like: manage.showInfo({title:'a', top:20})
  432. //公用的函数
  433. function getQueryVariable(variable)
  434. {
  435. var query = window.location.search.substring(1);
  436. var vars = query.split("&");
  437. for (var i=0;i<vars.length;i++) {
  438. var pair = vars[i].split("=");
  439. if(pair[0] == variable){return pair[1];}
  440. }
  441. return(false);
  442. }
  443. //隐藏公司Logo
  444. function showLogo(){
  445. $("#myCompany").hide();
  446. $("#loaderCoBrandName").hide();
  447. $("#title-logo").hide();
  448. $(".title-container").css("justify-content","center")
  449. }
  450. //czj 添加随机的时间
  451. function randomTime(){
  452. return new Date()
  453. };
  454. function matcher(data){
  455. if(!data || !g_version ) return data;
  456. delete data.model.vision_version;
  457. var _data = {
  458. files: {
  459. "templates": ["images/images{{number}}/{{filename}}"]
  460. },
  461. model :{
  462. sid :window.number,
  463. camera_start:
  464. data.model.images && data.model.images.length != 0 ?
  465. {
  466. camera: {
  467. zoom: "-1",
  468. quaternion: [
  469. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  470. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  471. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  472. JSON.parse(data.model.images[0].metadata).camera_quaternion.y
  473. ]
  474. },
  475. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  476. mode: "0"
  477. }
  478. : ''
  479. },
  480. sid: window.number,
  481. hoticon: {
  482. default: "https://super.4dage.com/images/4dagePoint2.png",
  483. higt: "https://super.4dage.com/images/4dagePoint.png"
  484. },
  485. special: "false",
  486. weixinDesc: ""
  487. };
  488. $.extend(true,data,_data)
  489. return data;
  490. }
  491. function hotMatcher(data={}){
  492. //if(!data || !g_version) return data;
  493. if(g_version) {
  494. data.tourAudio = data.audio || {};
  495. }else{
  496. data.tourAudio = {}
  497. }
  498. return data;
  499. }
  500. var GifTexDeal = {
  501. animateObjects : [],
  502. animateTexs : [] ,
  503. addAnimation : function(texture, owner, info, id){
  504. /* if(this.animateObjects.find(e=>
  505. e.texture == texture && !ifSame(info, e.info)
  506. )) */
  507. var animation
  508. var tex = this.animateTexs.find(e=>e.texture == texture)
  509. if(tex){
  510. animation = tex
  511. }else{
  512. animation = {texture,info }
  513. this.animateTexs.push(animation)
  514. this.setRepeart(animation)
  515. }
  516. var object = {
  517. animation, //默认相同的texture对应的info是一样的, 对应一个animation
  518. owner,
  519. }
  520. this.animateObjects.push(object)
  521. return object
  522. },
  523. remove : function(object){
  524. var index = this.animateObjects.indexOf(object)
  525. if(index>-1){
  526. this.animateObjects.splice(index, 1)
  527. if(!this.animateObjects.find(e=>e.animation == object.animation)){
  528. let i = this.animateTexs.indexOf(object.animation)
  529. this.animateTexs.splice(i, 1)
  530. object.animation.texture.repeat.set(1,1)
  531. }
  532. this.stop(object)
  533. }
  534. },
  535. setRepeart : function(animation){
  536. animation.texture.repeat.set(1/animation.info.cellXcount, 1/animation.info.cellYcount)
  537. },
  538. start: function(object){
  539. if(!object || object.started )return;
  540. object.started = true
  541. if(object.animation.started)return;
  542. object.animation.started = true
  543. var info = object.animation.info
  544. var count = info.cellXcount * info.cellYcount - (info.voidCount || 0)
  545. if(count <= 1)return;
  546. transitions.start( (progress)=>{
  547. var index = Math.floor(count * progress);
  548. var indexX = index % info.cellXcount
  549. var indexY = info.cellYcount - Math.floor(index /info.cellXcount ) - 1; //uv.offset.y是从下到上的
  550. object.animation.texture.offset.x = indexX / info.cellXcount;
  551. object.animation.texture.offset.y = indexY / info.cellYcount;
  552. //console.log(object.id + " : "+ object.texture.offset.toArray())
  553. } , info.duration * (-1), null,/* ()=>{//done (-1):循环
  554. object.started = false
  555. object.texture.offset.x = 0;
  556. object.texture.offset.y = 0;
  557. this.start(object)
  558. }, */ 0 ,null, object.id, "gif_"+object.animation.texture.id);
  559. },
  560. stop: function(object){
  561. if(!object || !object.started)return;
  562. object.started = false
  563. //只有该object对应的texture对应的所有object都停止了,才能真的停止动画:
  564. if(this.animateObjects.find(e=>e.animation == object.animation && e.started)) return;
  565. transitions.cancelById("gif_"+object.animation.texture.id);
  566. object.animation.texture.offset.set(0,0)
  567. object.animation.started = false
  568. }
  569. }
  570. var CloneObject = function(copyObj, result, isSimpleCopy, extraReplace) {
  571. //isSimpleCopy只复制最外层
  572. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  573. if(!copyObj)return copyObj //0 null undefined ''
  574. result = result || {};
  575. if (copyObj instanceof Array) {
  576. /* if (copyObj[0]instanceof Object) {
  577. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  578. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  579. }
  580. return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object
  581. return copyObj.map(e=>{
  582. if(e instanceof Object){
  583. return CloneObject(e)
  584. }else return e
  585. })
  586. }else{
  587. if(copyObj.clone instanceof Function ){ //解决一部分
  588. return copyObj.clone()
  589. }
  590. }
  591. for (var key in copyObj) {
  592. if (copyObj[key] instanceof Object && !isSimpleCopy)
  593. result[key] = CloneObject(copyObj[key]);
  594. else
  595. result[key] = copyObj[key];
  596. //如果是函数类同基本数据,即复制引用
  597. }
  598. return result;
  599. }
  600. ;
  601. var ifSame = function(object1, object2){
  602. if(object1 == object2 )return true // 0 != undefined , 0 == ''
  603. else if(!object1 || !object2) return false
  604. else if(object1.constructor != object2.constructor){
  605. return false
  606. }else if(object1 instanceof Array ) {
  607. if(object1.length != object2.length)return false;
  608. var _object2 = object2.slice(0);
  609. for(let i=0;i<object1.length;i++){
  610. var u = _object2.find(e=>ifSame(object1[i], e));
  611. if(u == void 0 && !_object2.includes(u) && !object1.includes(u))return false;
  612. else{
  613. let index = _object2.indexOf(u);
  614. _object2.splice(index,1);
  615. }
  616. }
  617. return true
  618. }else if(object1.equals instanceof Function ){//复杂数据仅支持这种,其他的可能卡住?
  619. return object1.equals(object2)
  620. }else if(typeof object1 == 'number' || typeof object1 == 'string'){
  621. if(isNaN(object1) && isNaN(object2))return true
  622. else return object1 == object2
  623. }else if(typeof object1 == "object"){
  624. var keys1 = Object.keys(object1)
  625. var keys2 = Object.keys(object2)
  626. if(!ifSame(keys1,keys2))return false;
  627. for(let i in object1){
  628. var same = ifSame(object1[i], object2[i]);
  629. if(!same)return false
  630. }
  631. return true
  632. }else{
  633. console.log('isSame出现例外')
  634. }
  635. }
  636. /* var SoundManager = {//暂不支持同时播放
  637. currentAudio:null,//当前正在播放list中的哪一个
  638. list:[
  639. {
  640. name:"bg",
  641. level : 0,//越大优先级越高
  642. canBeInterrupted : true ,
  643. },
  644. {
  645. name:"boxVideo",
  646. level : 1,
  647. canBeInterrupted : true,
  648. checkIfNeedPlay:function(){
  649. }
  650. },
  651. {
  652. name:"hot",
  653. level : 2,
  654. canBeInterrupted : true
  655. },
  656. {
  657. name:"tour",
  658. level : 3,
  659. canBeInterrupted : true
  660. },
  661. ],
  662. switchPlay:function(){
  663. },
  664. register:function(){
  665. }
  666. }
  667. */
  668. //最好能知道应该播放到的currentTime
  669. var SoundManager = {//暂不支持同时播放
  670. currentAudio:null,//当前正在播放list中的哪一个
  671. enableSound:true,//是否允许有声音
  672. playHistory:[],//被打断的加入播放历史
  673. list:[ ],//同一级别可以互相打断 //暂时不做多级别
  674. play:function(name, src, currentTime){
  675. var object = this.list.find(e=>e.name == name)
  676. if(object){
  677. if(this.currentAudio){
  678. this.pause(this.currentAudio.name, false, true)
  679. }
  680. {//将当前要播放的播放历史中清除
  681. let index = this.playHistory.indexOf(object)
  682. if(index>-1)this.playHistory.splice(index,1);
  683. }
  684. this.currentAudio = object
  685. if(src){
  686. this.setSrc(name, src)
  687. }
  688. if(currentTime!=void 0){
  689. object.audio.currentTime = currentTime
  690. }
  691. if(object.audio){
  692. object.audio.load(); // iOS 9 还需要额外的 load 一下, 否则直接 play 无效 *///https://www.cnblogs.com/interdrp/p/4211883.html 部分资料
  693. object.audio.play();
  694. object.callback && object.callback(true)
  695. }
  696. Log(name + ' 播放 ' )
  697. }
  698. },
  699. pause:function(name, autoReplayLast, isInterrupt){//需要能自动恢复上一个被打算的音频。恢复前判断是否还需要播放
  700. var object = this.list.find(e=>e.name == name)
  701. if(object){
  702. this.currentAudio = null
  703. if(object.audio){
  704. object.audio.pause()
  705. object.callback && object.callback(false)
  706. Log(name + ' 中断音频 '+ "("+common.getFileNameFromUrl(object.audio.src)+')' )
  707. }
  708. if(isInterrupt){//一般主动调用不需要加这个
  709. this.playHistory.push(object)//如果是被中断的,加入播放历史,等待恢复播放
  710. }
  711. if(autoReplayLast){ //播放之前的音频。它们是被打断过的。
  712. while(this.playHistory.length){
  713. var last = this.playHistory.pop();
  714. if(last.src && last.canplay(last.audio)){
  715. this.play(last.name )
  716. }
  717. }
  718. }
  719. }
  720. },
  721. setSrc : function(name, src){//不能直接给audio赋src!一定要用这个函数!因为我要拿这里的src来判断有无src,因为貌似audio的src会自动变,''时会变成html的链接
  722. var object = this.list.find(e=>e.name == name)
  723. object.src = src
  724. object.audio.src = src
  725. Log(`${object.name} 设置src: ${src}`)
  726. },
  727. createAudio:function(object={}){//name, level, canplay
  728. if(!object.fake){
  729. object.audio = new Audio();
  730. object.audio.loop = !!object.loop;
  731. //object.audio.autoplay = true;
  732. object.audio.addEventListener('ended', ()=>{
  733. if(object.loop){//循环
  734. Log(`${object.name} 播放完毕,重新播放`)
  735. object.audio.play()
  736. }else{
  737. this.pause(object.name, true);//停止后的后续处理
  738. }
  739. });
  740. object.audio.oncanplaythrough = ()=>{
  741. Log(`${object.name} canplaythrough `)
  742. }
  743. }
  744. this.list.push(object)
  745. },
  746. initAutoPlay:function(){ //处理设备自动播放限制
  747. let play = function(){
  748. if(this.currentAudio && this.currentAudio.audio){
  749. this.currentAudio.audio.play()
  750. Log(`${this.currentAudio.name} 自动播放成功`) //即使设置src在这之后好像也能成功播放
  751. }else{
  752. }
  753. document.removeEventListener("touchstart",play);
  754. document.removeEventListener("click",play);
  755. $('#player')[0].removeEventListener("touchstart", play);
  756. }.bind(this);
  757. document.addEventListener("WeixinJSBridgeReady", play, false);
  758. document.addEventListener("touchstart", play);//ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
  759. document.addEventListener("click", play);
  760. $('#player')[0].addEventListener("touchstart", play);
  761. }
  762. }
  763. function Log(value, color, fontSize){
  764. color = color || '#13f'
  765. fontSize = fontSize || 14
  766. console.warn(`%c${value}`, `color:${color};font-size:${fontSize}px`)
  767. }
  768. Manage.prototype.loadAudio = function() { //相关:g_tourAudio \ g_playAudio
  769. //热点页面因为挡住了界面,所以暂时不存在别的音频阻止热点音频的可能
  770. //box视频都静音,所以暂时不考虑
  771. SoundManager.createAudio({
  772. name:'bgm',
  773. level:0,
  774. src:'',
  775. loop:true,
  776. canplay:(audio)=>{
  777. return this.bgmShouldPlay
  778. },
  779. callback:(state)=>{//play或pause时随之触发的函数(即使还没开始播放)
  780. if(state){
  781. $("#volume a img").attr("src", "./images/Volume btn_off.png")
  782. $("#volume").attr("title", "关闭声音");
  783. }else{
  784. $("#volume a img").attr("src", "./images/Volume btn_on.png")
  785. $("#volume").attr("title", "打开声音");
  786. }
  787. }
  788. })
  789. SoundManager.createAudio({
  790. name:'tour',
  791. level:0,
  792. src:'',
  793. loop:false,
  794. canplay:(audio)=>{
  795. return player.director && player.director.tourIsPlaying && player.director.getAudio()
  796. }
  797. })
  798. SoundManager.createAudio({
  799. name:'hot',
  800. fake:true,//实际上没有audio. 只是为了来停止和续播其他音频
  801. level:1,
  802. src:'',
  803. loop:false,
  804. canplay:(audio)=>{
  805. }
  806. })
  807. $("#volume").find("a").on("click", ()=> {
  808. if($("#volume img")[0].src.indexOf("btn_on.png")>-1)
  809. {
  810. this.switchBgmState(true);
  811. }
  812. else if($("#volume img")[0].src.indexOf("btn_off.png")>-1)
  813. {
  814. this.switchBgmState(false);
  815. }
  816. })
  817. this.switchBgmState(true);//初始设置允许播放bgm
  818. SoundManager.initAutoPlay()
  819. }
  820. Manage.prototype.switchBgmState = function(state){//按钮的状态完全代表是否应该播放bgm,即使还没加载完
  821. this.bgmShouldPlay = state
  822. if(state){
  823. SoundManager.play('bgm')
  824. }else{
  825. SoundManager.pause('bgm')
  826. }
  827. /* if(!g_bgAudio || !g_bgAudio.src) return;
  828. var played = function(){
  829. console.log('begin play bgm');
  830. g_play = 1;
  831. g_playAudio = g_bgAudio;
  832. g_tourAudio && g_tourAudio.pause()
  833. }
  834. var paused = function(){
  835. g_play = 0;
  836. g_playAudio == g_bgAudio && (g_playAudio = null)
  837. }
  838. if(state ){
  839. g_bgAudio.play();
  840. if(g_bgAudio.paused){
  841. paused()
  842. }else{
  843. played()
  844. return true
  845. }
  846. }else{
  847. g_bgAudio.pause();
  848. paused()
  849. }
  850. g_bgAudio.pauseByHot = false
  851. g_bgAudio.pauseByTour = false */
  852. }
  853. var manage = new Manage();
  854. //兼容一代的場景
  855. //請求地址統一管理
  856. var g_onePregix = "https://bigscene.4dage.com/" //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
  857. var g_version = manage.number("version");
  858. g_version === "one" ? g_Prefix = g_onePregix : '';