manage.js 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808
  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. // http://wangzhan.cctv.com/wlwm2022/test/data/1248
  4. // var g_Prefix = "https://wangzhan.cctv.com/wlwm2022/test/";
  5. // var g_Prefix=window.location.href.substring(0,window.location.href.indexOf("/index.html")+1);
  6. var s = window.location.href.split("/");
  7. s.pop();
  8. //var g_Prefix = s.join('/');
  9. var g_index = null;
  10. var g_modeldata = null;
  11. var g_weixinTitle = null;
  12. var g_Hots = null;
  13. var g_HotMeshes = [];
  14. var g_HotMeshSize = {
  15. g_HotMeshWidth: 0.3,
  16. g_HotMeshHeight: 0.3,
  17. };
  18. //add表示添加,delete表示删除
  19. var g_HotStatus = null;
  20. var g_newHot = []; //存储新加热点
  21. var g_HotImage = {
  22. point: "https://super.4dage.com/images/4dagePoint2.png",
  23. point2: "https://super.4dage.com/images/4dagePoint.png",
  24. };
  25. var g_saveHot = false;
  26. var g_TextColor = 0x7777ff;
  27. var g_Text = null;
  28. var g_TextPlaneMesh = [];
  29. var g_TextIconMesh = [];
  30. var g_TextIcon = "./images/text.png";
  31. var g_SelectTextIndex = null;
  32. var g_TextShow = null;
  33. var g_audioPlay = false;
  34. var g_background = null;
  35. var g_roof = null;
  36. var g_data2 = null; //加载的data2.js的内容
  37. var g_bgAudio = null; //背景音乐
  38. var g_tourAudio = null; //导览音乐
  39. var g_play = 1; //表示播放图标状态
  40. var g_playAudio = null; //当前在播放或当继续播放时应该播放的,是g_bgAudio或g_tourAudio
  41. var g_currentHot = null; //当前打开的热点
  42. //var g_Texture=null;
  43. //var g_ChunknameTexture={}; //chunkname和贴图名称对应
  44. var g_NormalTexture = false;
  45. var g_SpecularTexture = false;
  46. var g_DirectionalLight = null;
  47. var g_snapShotWidth = 200; //截图下载图片的大小
  48. var g_snapShotHeight = 140;
  49. //微信分享
  50. var g_weixinObj = {
  51. title: document.querySelector("head title").innerHTML,
  52. lineLink: window.location.href,
  53. imgUrl: "https://www.4dmodel.com/SuperPanoramic/images/weixintitle.jpg",
  54. desc: "四维时代提供技术支持",
  55. };
  56. var settings = {
  57. hotClickEvent: {
  58. video: {
  59. playAndPause: true,
  60. examine: false,
  61. openHot: false,
  62. },
  63. photo: {
  64. examine: false,
  65. openHot: false,
  66. },
  67. shine: {
  68. examine: true,
  69. openHot: true,
  70. },
  71. },
  72. hotClickActions: ["playAndPause", "examine", "openHot", "fastTran"],
  73. //默认的:
  74. teleportTime: 1500, //瞬间过渡的时间
  75. /* flytimeDistanceMultiplier:150,
  76. flyTime:750, */
  77. tourRotTime: 2, //默认停留2秒
  78. hotFastTran:true,
  79. dontExamHot:true,
  80. transparentBg: true,
  81. bgImg: './static/images/bg.jpg',
  82. mobileBgImg: './static/images/mobile_bg.png',
  83. bgColor: '#0f3574',
  84. };
  85. if (window.number == "725" || window.number == "724") {
  86. settings.mobileNavHigh = true;
  87. }
  88. //共用函数:
  89. window.common = null;
  90. window.MathLight = null;
  91. window.math = null;
  92. window.easing = null;
  93. window.lerp = null;
  94. window.transitions = null;
  95. window.browser = null;
  96. function watch(object, propName, initialValue) {
  97. //监听某个属性的变化
  98. let v = initialValue;
  99. Object.defineProperty(object, propName, {
  100. get: function() {
  101. return v;
  102. },
  103. set: function(e) {
  104. console.log("watch:", propName, e);
  105. v = e;
  106. },
  107. });
  108. }
  109. var toPrecision = function(e, t) {
  110. function i(e, t) {
  111. var i = Math.pow(10, t);
  112. return Math.round(e * i) / i;
  113. }
  114. if (e instanceof Array) {
  115. for (var n = 0; n < e.length; n++) e[n] = i(e[n], t);
  116. return e;
  117. }
  118. return i(e, t);
  119. };
  120. var dealMap = (map) => {
  121. //使不resize when image is not power of two
  122. map.wrapS = map.wrapT = THREE.ClampToEdgeWrapping;
  123. map.minFilter = THREE.LinearFilter;
  124. map.magFilter = THREE.LinearFilter;
  125. map.generateMipmaps = true;
  126. };
  127. var dom = {
  128. getOffset: function(type, element, parent) {
  129. left = type == "left" ? element.offsetLeft : element.offsetTop;
  130. if (!parent) parent = $("body")[0];
  131. while ((element = element.offsetParent)) {
  132. if (element == parent) break;
  133. left += type == "left" ? element.offsetLeft : element.offsetTop;
  134. }
  135. return left;
  136. },
  137. };
  138. var getTransformSid = function() {
  139. var name;
  140. if (player.mode == "panorama") {
  141. name = player.currentPano ? player.currentPano.id : "outside";
  142. } else {
  143. name = "outside";
  144. }
  145. return name;
  146. };
  147. var LineDraw = {
  148. /* createLine: function(posArr, o) {
  149. var e = new THREE.BufferGeometry
  150. , p = new Float32Array(6);
  151. e.addAttribute("position", new THREE.BufferAttribute(p,3));
  152. //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
  153. var p = e.attributes.position.array;
  154. for (var i = 0; i < 2; i++) {
  155. p[i * 3] = posArr[i].x;
  156. p[i * 3 + 1] = posArr[i].y;
  157. p[i * 3 + 2] = posArr[i].z;
  158. }
  159. var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
  160. linewidth: o.width || 1,
  161. //windows无效。 似乎mac/ios上粗细有效 ?
  162. color: o.color || defaultColor,
  163. transparent: o.dontAlwaysSeen ? false : true,
  164. depthTest: o.dontAlwaysSeen ? true : false
  165. })
  166. var line = new THREE.Line(e,mat);
  167. line.renderOrder = o.renderOrder || 4
  168. //同tagStem; //如果不加高,可能会部分被model遮住
  169. return line;
  170. } */
  171. createLine: function(posArr, o = {}) {
  172. //多段普通线 (第二个点和第三个点之间是没有线段的, 所以不用在意线段顺序)
  173. var mat;
  174. if (o.mat) {
  175. mat = o.mat;
  176. } else {
  177. let prop = {
  178. lineWidth: o.lineWidth || 1,
  179. //windows无效。 似乎mac/ios上粗细有效 ?
  180. color: o.color || defaultColor,
  181. transparent: o.dontAlwaysSeen ? false : true,
  182. depthTest: o.dontAlwaysSeen ? true : false,
  183. opacity: o.opacity != void 0 ? o.opacity : 1,
  184. };
  185. if (o.deshed) {
  186. (prop.dashSize = o.dashSize || 0.1), (prop.gapSize = o.gapSize || 0.1);
  187. }
  188. mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"](prop);
  189. }
  190. var line = new THREE.LineSegments(new THREE.BufferGeometry(), mat);
  191. line.renderOrder = o.renderOrder || 4;
  192. this.moveLine(line, posArr);
  193. return line;
  194. },
  195. moveLine: function(line, posArr) {
  196. if (posArr.length == 0) return;
  197. let position = new Float32Array(posArr.length * 3); //[]
  198. for (var i = 0; i < 2; i++) {
  199. position[i * 3] = posArr[i].x;
  200. position[i * 3 + 1] = posArr[i].y;
  201. position[i * 3 + 2] = posArr[i].z;
  202. }
  203. line.geometry.addAttribute("position", new THREE.BufferAttribute(position, 3));
  204. //line.geometry.setAttribute('position', new THREE.Float32BufferAttribute(new Float32Array(position), 3));
  205. line.geometry.attributes.position.needsUpdate = true;
  206. line.geometry.computeBoundingSphere();
  207. /* if(line.material instanceof THREE.LineDashedMaterial){
  208. line.computeLineDistances() //只有非buffer的geometry才有
  209. } */
  210. },
  211. };
  212. var convertTool = {
  213. getPos2d: function(point, camera, dom) {
  214. //获取一个三维坐标对应屏幕中的二维坐标
  215. var camera = camera || player.camera;
  216. var dom = dom || player.domElement;
  217. if (!camera) return;
  218. 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);
  219. var x, y;
  220. x = ((pos.x + 1) / 2) * dom.clientWidth;
  221. y = (1 - (pos.y + 1) / 2) * dom.clientHeight;
  222. var inSight =
  223. x <= dom.clientWidth &&
  224. x >= 0 && //是否在屏幕中
  225. y <= dom.clientHeight &&
  226. y >= 0;
  227. return {
  228. pos: new THREE.Vector2(x, y), // 屏幕像素坐标
  229. vector: pos, //(范围 -1 ~ 1)
  230. trueSide: pos.z < 1, //trueSide为false时,即使在屏幕范围内可见,也是反方向的另一个不可以被渲染的点 参见Tag.update
  231. inSight: inSight, //在屏幕范围内可见
  232. };
  233. },
  234. ifShelter: function(pos3d, floorIndex) {
  235. //检测某点在视线中是否被mesh遮挡
  236. var ori = player.position;
  237. var dir = pos3d
  238. .clone()
  239. .sub(ori)
  240. .normalize();
  241. var ray = new THREE.Raycaster(ori, dir); //由外向里 因为模型从内侧是可见的所以从外侧
  242. /* if(config.isEdit && publicObjectSet.editor.mainDesign.editing){
  243. var o = ray.intersectObjects(publicObjectSet.editor.mainDesign.wallMeshes);
  244. }else{ */
  245. let colliders = player.model.allFloorsVisible
  246. ? player.model.colliders
  247. : (floorIndex != void 0 ? player.model.floors.index[floorIndex] : player.model.currentFloor).collider.children;
  248. //let colliders = (floorIndex == void 0 ) ? player.model.colliders : player.model.floors.index[floorIndex].collider.children
  249. var o = ray.intersectObjects(colliders);
  250. //}
  251. var len = pos3d.distanceTo(ori);
  252. if (o && o.length) {
  253. for (var i = 0; i < o.length; i++) {
  254. if (o[i].distance < len) {
  255. return true;
  256. } //有遮挡
  257. }
  258. }
  259. },
  260. /*
  261. 拖拽时,获取鼠标在拖拽面上的位置(需要借助另一个intersectPlane面来计算,即和相机方向一样的面,可保证铺满屏幕)
  262. 但是不一定能获取到,比如鼠标射线不朝向拖拽面时,即使获取也会是一个意外的反方向的交点。
  263. */
  264. getPosAtPlane: function(pos, info /* , mouse, camera */) {
  265. //pos:与intersectPlane的交点 见笔记
  266. var A = pos;
  267. var player = player;
  268. var mouse = player.mouse;
  269. var O = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(player.camera);
  270. if (info.y != void 0) {
  271. //地面线的
  272. var y = info.y;
  273. if (player.mode == "floorplan" /* || Math.abs(O.x-pos.x)<0.0001 && Math.abs(O.z-pos.z)<0.0001) */) {
  274. //intersectPlane和地面平行,无交点
  275. var x = pos.x,
  276. z = pos.z;
  277. } else {
  278. if (y < player.camera.position.y && O.y <= A.y /* || y>player.camera.position.y && O.y >= A.y */) return null; //鼠标射线向上。因为相机一定位于地面以上(地面不会抬高到相机上吧?),所以无交点。
  279. if (O.y == A.y) {
  280. console.log("一样??");
  281. return;
  282. }
  283. if (A.y == y) {
  284. console.log("一样2??");
  285. return;
  286. }
  287. var r = (O.y - y) / (A.y - y);
  288. var x = (r * A.x - O.x) / (r - 1);
  289. var z = (r * A.z - O.z) / (r - 1);
  290. }
  291. } else {
  292. //垂直的也有越过消失点以后反向变化的情况,但使用时影响不大
  293. var N = info.normalVec;
  294. var P = info.pullPos;
  295. if (N.y != 0) {
  296. console.log("N.y != 0");
  297. return;
  298. } //仅仅支持垂直于地面的的墙壁,目前都是
  299. if (O.z == A.z) {
  300. console.log("O.z==A.z?");
  301. return;
  302. }
  303. if (N.z != 0 && N.x != 0) {
  304. //直接用这个通用的也可以,支持斜线的墙
  305. //console.log('N.z==0 && N.x == 0?');
  306. var c = N.x * (A.x - O.x) + N.y * (A.y - O.y) + N.z * (A.z - O.z);
  307. if (c == 0) {
  308. console.log("分母为0?? return;");
  309. return;
  310. }
  311. 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;
  312. var x = t * (A.x - O.x) + O.x;
  313. var y = t * (A.y - O.y) + O.y;
  314. var z = t * (A.z - O.z) + O.z;
  315. /*原理: 已知空间直线L:(x-a)/m=(x-b)/n=(z-c)/p和空间平面π:Ax+By+Cz+D=0;
  316. 求直线L与平面π的交点的坐标。
  317. 把直线方程改写成参数形式:设(x-a)/m=(x-b)/n=(z-c)/p=t;
  318. 则x=mt+a;y=nt+b;z=pt+c;代入平面π的方程得:
  319. A(mt+a)+B(nt+b)+C(pt+c)+D=0
  320. 由此解得t=-(Aa+Bb+Cc+D)/(Am+Bn+Cp)
  321. 再代入参数方程即得交点的坐标(x,y,z). */
  322. } else if (N.x == 0) {
  323. //z与pullPos相等
  324. var z = P.z;
  325. if (O.y == A.y) {
  326. console.log("一样??");
  327. return;
  328. }
  329. if (A.y == y) {
  330. console.log("一样2??");
  331. return;
  332. }
  333. if (A.z == z) {
  334. console.log("一样3??");
  335. return;
  336. }
  337. var r = (O.z - z) / (A.z - z);
  338. var x = (r * A.x - O.x) / (r - 1);
  339. var y = (r * A.y - O.y) / (r - 1);
  340. } else if (N.z == 0) {
  341. //x与pullPos相等
  342. var x = P.x;
  343. if (O.y == A.y) {
  344. console.log("一样??");
  345. return;
  346. }
  347. if (A.y == y) {
  348. console.log("一样2??");
  349. return;
  350. }
  351. if (A.x == x) {
  352. console.log("一样3??");
  353. return;
  354. }
  355. var r = (O.x - x) / (A.x - x);
  356. var y = (r * A.y - O.y) / (r - 1);
  357. var z = (r * A.z - O.z) / (r - 1);
  358. }
  359. }
  360. return new THREE.Vector3(x, y, z);
  361. },
  362. getMouseIntersect: function(camera, meshes, mouse) {
  363. //获取鼠标和meshes交点
  364. var raycaster = new THREE.Raycaster();
  365. camera.updateMatrixWorld();
  366. var origin = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(camera),
  367. end = new THREE.Vector3(mouse.x, mouse.y, 1).unproject(camera);
  368. var dir = end.sub(origin).normalize();
  369. raycaster.set(origin, dir);
  370. var n = raycaster.intersectObjects(meshes);
  371. if (0 === n.length) return null;
  372. return n[0];
  373. },
  374. ifIntersectChunks: function(A, B, options = {}) {
  375. //获取某个线段/射线和meshes的交点
  376. var dir = B.clone()
  377. .sub(A)
  378. .normalize();
  379. var len = options.InfinityLen ? Infinity : A.distanceTo(B) + (options.extLen || 0);
  380. var ray = new THREE.Raycaster(A.clone(), dir, 0, len);
  381. var o = ray.intersectObjects(options.model || player.model.colliders);
  382. if (o && o.length) return o;
  383. if (options.throughWidth) {
  384. //允许最小宽度,防止穿过极小的缝隙导致撞墙感
  385. var normal = math.getNormal({
  386. points: [
  387. { x: A.x, y: A.z },
  388. { x: B.x, y: B.z },
  389. ],
  390. }); //线段法线
  391. normal.multiplyScalar(options.throughWidth);
  392. var normalVec3 = new THREE.Vector3(normal.x, 0, normal.y);
  393. var A2 = A.clone().add(normalVec3);
  394. ray.set(A2, dir);
  395. var o2 = ray.intersectObjects(options.model || player.model.colliders);
  396. ray.set(A.clone().add(normalVec3.negate()), dir);
  397. if (o2 && o2.length) return o2;
  398. var o3 = ray.intersectObjects(options.model || player.model.colliders);
  399. if (o3 && o3.length) return o3;
  400. }
  401. return null;
  402. },
  403. getNormal: function(line2d){//获取二维法向量 方向向内
  404. var x,y;//要求的向量
  405. //line2d的向量
  406. var x1 = line2d.points[1].x - line2d.points[0].x;
  407. var y1 = line2d.points[1].y - line2d.points[0].y;
  408. //假设法向量的x或y固定为1或-1
  409. if(y1 != 0){
  410. x = 1;
  411. y = - (x1 * x) / y1;
  412. }else if(x1 != 0){//y如果为0,正常情况x不会是0
  413. y = 1;
  414. x = - (y1 * y) / x1;
  415. }else{
  416. console.log("两个点一样");
  417. return null;
  418. }
  419. //判断方向里或者外:
  420. var vNormal = new THREE.Vector3(x, 0, y);
  421. var vLine = new THREE.Vector3(x1, 0, y1);
  422. var vDir = vNormal.cross(vLine);
  423. if(vDir.y>0){
  424. x *= -1;
  425. y *= -1;
  426. }
  427. return new THREE.Vector2(x, y).normalize();
  428. },
  429. getPosAtSphere: function(pos3d, toPanoPos) {
  430. var dir = pos3d.clone().sub(toPanoPos);
  431. dir.normalize(); //然后计算在球中
  432. dir.multiplyScalar(Constants.skyRadius);
  433. dir.add(toPanoPos);
  434. return dir;
  435. },
  436. getScaleForConstantSize: function(op = {}) {
  437. //获得规定二维大小的mesh的scale值。可以避免因camera的projection造成的mesh视觉大小改变。 来源:tag.updateDisc
  438. var w;
  439. var i = new THREE.Vector3(),
  440. o = new THREE.Vector3(),
  441. l = new THREE.Vector3(),
  442. c = new THREE.Vector3(),
  443. h = new THREE.Vector3();
  444. if (op.width2d) w = op.width2d;
  445. //如果恒定二维宽度
  446. else {
  447. //否则考虑上距离,加一丢丢近大远小的效果
  448. var currentDis, nearBound, farBound;
  449. if (op.camera.type == "OrthographicCamera") {
  450. currentDis = (op.camera.right - op.camera.left) / op.camera.zoom;
  451. } else {
  452. currentDis = op.position.distanceTo(op.camera.position);
  453. }
  454. w = op.maxSize - (op.maxSize - op.minSize) * THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
  455. //maxSize : mesh要表现的最大像素宽度; nearBound: 最近距离,若比nearBound近,则使用maxSize
  456. }
  457. i.copy(op.position).project(op.camera), //tag中心在屏幕上的二维坐标
  458. o.set(op.resolution.x / 2, op.resolution.y / 2, 1).multiply(i), //转化成px -w/2 到 w/2的范围
  459. l.set(w / 2, 0, 0).add(o), //加上tag宽度的一半
  460. c.set(2 / op.resolution.x, 2 / op.resolution.y, 1).multiply(l), //再转回 -1 到 1的范围
  461. h.copy(c).unproject(op.camera); //再转成三维坐标,求得tag边缘的位置
  462. var g = h.distanceTo(op.position); //就能得到tag的三维半径
  463. return g; //可能NAN 当相机和position重叠时
  464. },
  465. updateVisible: function(object, reason, ifShow, level = 0, type) {
  466. //当所有加入的条件都不为false时才显示. reason='force'一般是强制、临时的
  467. if (!object.unvisibleReasons) object.unvisibleReasons = []; //如果length>0代表不可见
  468. if (!object.visibleReasons) object.visibleReasons = []; //在同级时,优先可见
  469. var update = function() {
  470. //先按从高到低的level排列
  471. object.unvisibleReasons = object.unvisibleReasons.sort((a, b) => b.level - a.level);
  472. object.visibleReasons = object.visibleReasons.sort((a, b) => b.level - a.level);
  473. var maxVisiLevel = object.visibleReasons[0] ? object.visibleReasons[0].level : -1;
  474. var maxunVisiLevel = object.unvisibleReasons[0] ? object.unvisibleReasons[0].level : -1;
  475. var shouldVisi = maxVisiLevel >= maxunVisiLevel;
  476. var visiBefore = object.visible;
  477. if (visiBefore != shouldVisi) {
  478. object.visible = shouldVisi;
  479. object.dispatchEvent({
  480. type: "isVisible",
  481. visible: shouldVisi,
  482. reason,
  483. });
  484. }
  485. };
  486. if (ifShow) {
  487. var index = object.unvisibleReasons.findIndex((e) => e.reason == reason);
  488. if (index > -1) {
  489. type = "cancel";
  490. object.unvisibleReasons.splice(index, 1);
  491. }
  492. if (type == "add") {
  493. if (!object.visibleReasons.some((e) => e.reason == reason)) {
  494. object.visibleReasons.push({ reason, level });
  495. }
  496. }
  497. } else {
  498. var index = object.visibleReasons.findIndex((e) => e.reason == reason);
  499. if (index > -1) {
  500. type = "cancel";
  501. object.visibleReasons.splice(index, 1);
  502. }
  503. if (type != "cancel") {
  504. if (!object.unvisibleReasons.some((e) => e.reason == reason)) {
  505. object.unvisibleReasons.push({ reason, level });
  506. }
  507. }
  508. }
  509. update();
  510. },
  511. getObjVisiByReason: function(object, reason) {
  512. //获取在某条件下是否可见. 注: 用户在数据集选择可不可见为"datasetSelection"
  513. if (object.visible) return true;
  514. else {
  515. return !object.unvisibleReasons || !object.unvisibleReasons.some((e) => e.reason == reason);
  516. }
  517. },
  518. };
  519. //--------------------------------------
  520. //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
  521. var Manage = function() {
  522. (this.weixinURL = "https://res.wx.qq.com/open/js/jweixin-1.2.0.js"), (this.time = "?" + new Date().getTime());
  523. this.loadAudio();
  524. // this.loadWeixin();
  525. };
  526. //动态加载js文件
  527. Manage.prototype.LoadJs = function(_files, succes) {
  528. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  529. var classcodes = [];
  530. var FileArray = [];
  531. if (typeof _files === "object") {
  532. FileArray = _files;
  533. } else {
  534. /*如果文件列表是字符串,则用,切分成数组*/
  535. if (typeof _files === "string") {
  536. FileArray = _files.split(",");
  537. }
  538. }
  539. if (FileArray != null && FileArray.length > 0) {
  540. var LoadedCount = 0;
  541. for (var i = 0; i < FileArray.length; i++) {
  542. loadFile(FileArray[i], function() {
  543. LoadedCount++;
  544. if (LoadedCount == FileArray.length) {
  545. try {
  546. succes();
  547. } catch (err) {
  548. console.log("err: 您未定义回调");
  549. }
  550. }
  551. });
  552. }
  553. }
  554. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  555. function loadFile(url, success) {
  556. if (!FileIsExt(classcodes, url)) {
  557. var _ThisType = GetFileType(url);
  558. var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0, _ThisType.indexOf("?"));
  559. var fileObj = null;
  560. if (ThisType == ".js") {
  561. fileObj = document.createElement("script");
  562. fileObj.src = url;
  563. } else if (ThisType == ".css") {
  564. fileObj = document.createElement("link");
  565. fileObj.href = url;
  566. fileObj.type = "text/css";
  567. fileObj.rel = "stylesheet";
  568. } else if (ThisType == ".less") {
  569. fileObj = document.createElement("link");
  570. fileObj.href = url;
  571. fileObj.type = "text/css";
  572. fileObj.rel = "stylesheet/less";
  573. }
  574. success = success || function() {};
  575. fileObj.onload = fileObj.onreadystatechange = function() {
  576. if (!this.readyState || "loaded" === this.readyState || "complete" === this.readyState) {
  577. success();
  578. classcodes.push(url);
  579. }
  580. };
  581. document.getElementsByTagName("head")[0].appendChild(fileObj);
  582. } else {
  583. success();
  584. }
  585. }
  586. /*获取文件类型,后缀名,小写*/
  587. function GetFileType(url) {
  588. if (url != null && url.length > 0) {
  589. return url.substr(url.lastIndexOf(".")).toLowerCase();
  590. }
  591. return "";
  592. }
  593. /*文件是否已加载*/
  594. function FileIsExt(FileArray, _url) {
  595. if (FileArray != null && FileArray.length > 0) {
  596. var len = FileArray.length;
  597. for (var i = 0; i < len; i++) {
  598. if (FileArray[i] == _url) {
  599. return true;
  600. }
  601. }
  602. }
  603. return false;
  604. }
  605. };
  606. //获取页面url后面的参数
  607. Manage.prototype.number = function(variable) {
  608. var query = window.location.search.substring(1);
  609. var vars = query.split("&");
  610. for (var i = 0; i < vars.length; i++) {
  611. var pair = vars[i].split("=");
  612. if (pair[0] == variable) {
  613. return pair[1];
  614. }
  615. }
  616. return false;
  617. };
  618. Manage.prototype.loadWeixin = function() {
  619. var that = this;
  620. this.LoadJs(that.weixinURL + that.time, function() {});
  621. };
  622. Manage.prototype.weixinShare = function() {
  623. console.log("weixinShare");
  624. $.ajax({
  625. url: "https://www.4dage.com/wechat/jssdk/",
  626. type: "post",
  627. data: {
  628. url: location.href.split("#")[0],
  629. },
  630. dataType: "jsonp",
  631. jsonpCallback: "success_jsonp",
  632. success: function(data, textStatus) {
  633. console.log("weixinShare success");
  634. console.log(data.appId);
  635. wx.config({
  636. // debug : true,
  637. appId: data.appId,
  638. timestamp: data.timestamp,
  639. nonceStr: data.nonceStr,
  640. signature: data.signature,
  641. jsApiList: [
  642. "checkJsApi",
  643. "onMenuShareTimeline",
  644. "onMenuShareAppMessage",
  645. "onMenuShareQQ",
  646. "onMenuShareWeibo",
  647. "hideMenuItems",
  648. "showMenuItems",
  649. "hideAllNonBaseMenuItem",
  650. "showAllNonBaseMenuItem",
  651. "translateVoice",
  652. "startRecord",
  653. "stopRecord",
  654. "onRecordEnd",
  655. "playVoice",
  656. "pauseVoice",
  657. "stopVoice",
  658. "uploadVoice",
  659. "downloadVoice",
  660. "chooseImage",
  661. "previewImage",
  662. "uploadImage",
  663. "downloadImage",
  664. "getNetworkType",
  665. "openLocation",
  666. "getLocation",
  667. "hideOptionMenu",
  668. "showOptionMenu",
  669. "closeWindow",
  670. "scanQRCode",
  671. "chooseWXPay",
  672. "openProductSpecificView",
  673. "addCard",
  674. "chooseCard",
  675. "openCard",
  676. ],
  677. });
  678. },
  679. error: function(XMLHttpRequest, textStatus, errorThrown) {
  680. console.log("jsonp.error:" + textStatus);
  681. },
  682. });
  683. var success_jsonp = function(json) {
  684. console.log(json);
  685. };
  686. wx.ready(function() {
  687. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  688. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  689. //分享到朋友圈
  690. console.log(g_weixinObj);
  691. wx.onMenuShareTimeline({
  692. title: g_weixinObj.title, // 分享标题
  693. link: g_weixinObj.lineLink, // 分享链接
  694. imgUrl: g_weixinObj.imgUrl, // 分享图标
  695. desc: g_weixinObj.desc,
  696. });
  697. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  698. wx.onMenuShareAppMessage({
  699. title: g_weixinObj.title, // 分享标题
  700. desc: g_weixinObj.desc, // 分享描述
  701. link: g_weixinObj.lineLink, // 分享链接
  702. imgUrl: g_weixinObj.imgUrl, // 分享图标
  703. type: "", // 分享类型,music、video或link,不填默认为link
  704. dataUrl: "", // 如果type是music或video,则要提供数据链接,默认为空
  705. });
  706. wx.onMenuShareWeibo({
  707. title: g_weixinObj.title, // 分享标题
  708. desc: g_weixinObj.desc, // 分享描述
  709. link: g_weixinObj.lineLink, // 分享链接
  710. imgUrl: g_weixinObj.imgUrl, // 分享图标
  711. success: function() {
  712. // 用户确认分享后执行的回调函数
  713. },
  714. cancel: function() {
  715. // 用户取消分享后执行的回调函数
  716. },
  717. });
  718. wx.onMenuShareQZone({
  719. title: g_weixinObj.title, // 分享标题
  720. desc: g_weixinObj.desc, // 分享描述
  721. link: g_weixinObj.lineLink, // 分享链接
  722. imgUrl: g_weixinObj.imgUrl, // 分享图标
  723. success: function() {
  724. // 用户确认分享后执行的回调函数
  725. },
  726. cancel: function() {
  727. // 用户取消分享后执行的回调函数
  728. },
  729. });
  730. wx.onMenuShareQQ({
  731. title: g_weixinObj.title, // 分享标题
  732. desc: g_weixinObj.desc, // 分享描述
  733. link: g_weixinObj.lineLink, // 分享链接
  734. imgUrl: g_weixinObj.imgUrl, // 分享图标
  735. success: function() {
  736. // 用户确认分享后执行的回调函数
  737. },
  738. cancel: function() {
  739. // 用户取消分享后执行的回调函数
  740. },
  741. });
  742. wx.error(function(res) {
  743. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  744. });
  745. });
  746. };
  747. Manage.prototype.dealURL = function(src, type) {
  748. //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
  749. //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
  750. if (window.isLocal && settings.localPrefix != void 0) {
  751. //本地将线上的前缀替换
  752. var oldPrefix = "super.4dage.com/"; //最简单的地址写一个,如果有其他完全不一样的地址就用数组逐个判断
  753. var index = src.indexOf(oldPrefix);
  754. if (index > -1) {
  755. var wholeOldPrefix = src.slice(0, index + oldPrefix.length);
  756. return src.replace(wholeOldPrefix, settings.localPrefix);
  757. }
  758. console.error("没有找到合适的本地链接");
  759. return src;
  760. } else {
  761. //add https://
  762. var prefix = g_Prefix.replace("https://", "").replace("http://", "");
  763. if (!src.includes("http:/") && !src.includes("https:/") && src.includes(prefix)) {
  764. src = "https://" + src;
  765. }
  766. return src;
  767. }
  768. };
  769. Manage.prototype.removeSrcPostMark = function(url) {
  770. //去除texture.load时自动加上的'?'
  771. var index = url.indexOf("?");
  772. if (index > -1) {
  773. return url.slice(0, index);
  774. } else return url;
  775. };
  776. Manage.prototype.showInfo = function(o) {
  777. // ({result:true, title:"发布成功"});
  778. var box = $(".resultBox");
  779. var title = o.title || o || i18n.get("保存成功");
  780. box
  781. .children()
  782. .eq(0)
  783. .html(title);
  784. //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000);
  785. var time = o.time || THREE.Math.clamp(title.length * 130, 1300, 5000);
  786. o.time || console.log("showtime " + time);
  787. //实际有一半的时间在渐变透明度
  788. this.showInfoTimer && clearTimeout(this.showInfoTimer);
  789. box.removeClass("animate"); //如果之后不久又要showinfo一个的话,先停止前面的animate
  790. setTimeout(
  791. function() {
  792. box.css({
  793. "-webkit-animation-duration": time + "ms",
  794. "animation-duration": time + "ms",
  795. });
  796. if (o.top) {
  797. box.children().css("top", o.top + "%");
  798. } else {
  799. box.children().css("top", "");
  800. }
  801. box.removeClass("hide");
  802. box.addClass("animate");
  803. if (o.dontInteract) {
  804. //遮挡对屏幕的操作
  805. box.css("pointer-events", "auto");
  806. } else {
  807. box.css("pointer-events", "none");
  808. }
  809. this.showInfoTimer = setTimeout(
  810. function() {
  811. box.removeClass("animate");
  812. box.addClass("hide");
  813. this.showInfoTimer = null;
  814. }.bind(this),
  815. time + 20
  816. );
  817. }.bind(this),
  818. 50
  819. ); //这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧
  820. }; //like: manage.showInfo({title:'a', top:20})
  821. //公用的函数
  822. function getQueryVariable(variable) {
  823. var query = window.location.search.substring(1);
  824. var vars = query.split("&");
  825. for (var i = 0; i < vars.length; i++) {
  826. var pair = vars[i].split("=");
  827. if (pair[0] == variable) {
  828. return pair[1];
  829. }
  830. }
  831. return false;
  832. }
  833. //隐藏公司Logo
  834. function showLogo() {
  835. $("#myCompany").hide();
  836. $("#loaderCoBrandName").hide();
  837. $("#title-logo").hide();
  838. $(".title-container").css("justify-content", "center");
  839. }
  840. //czj 添加随机的时间
  841. function randomTime() {
  842. return new Date();
  843. }
  844. function matcher(data) {
  845. if (!data || !g_version) return data;
  846. delete data.model.vision_version;
  847. var _data = {
  848. files: {
  849. templates: ["images/images{{number}}/{{filename}}"],
  850. },
  851. model: {
  852. sid: window.number,
  853. camera_start:
  854. data.model.images && data.model.images.length != 0
  855. ? {
  856. camera: {
  857. zoom: "-1",
  858. quaternion: [
  859. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  860. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  861. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  862. JSON.parse(data.model.images[0].metadata).camera_quaternion.y,
  863. ],
  864. },
  865. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  866. mode: "0",
  867. }
  868. : "",
  869. },
  870. sid: window.number,
  871. hoticon: {
  872. default: "https://super.4dage.com/images/4dagePoint2.png",
  873. higt: "https://super.4dage.com/images/4dagePoint.png",
  874. },
  875. special: "false",
  876. weixinDesc: "",
  877. };
  878. $.extend(true, data, _data);
  879. return data;
  880. }
  881. function hotMatcher(data = {}) {
  882. //if(!data || !g_version) return data;
  883. if (g_version) {
  884. data.tourAudio = data.audio || {};
  885. } else {
  886. data.tourAudio = {};
  887. }
  888. return data;
  889. }
  890. var GifTexDeal = {
  891. animateObjects: [],
  892. animateTexs: [],
  893. addAnimation: function(texture, owner, info, id) {
  894. /* if(this.animateObjects.find(e=>
  895. e.texture == texture && !ifSame(info, e.info)
  896. )) */
  897. var animation;
  898. var tex = this.animateTexs.find((e) => e.texture == texture);
  899. if (tex) {
  900. animation = tex;
  901. } else {
  902. animation = { texture, info };
  903. this.animateTexs.push(animation);
  904. this.setRepeart(animation);
  905. }
  906. var object = {
  907. animation, //默认相同的texture对应的info是一样的, 对应一个animation
  908. owner,
  909. };
  910. this.animateObjects.push(object);
  911. return object;
  912. },
  913. remove: function(object) {
  914. var index = this.animateObjects.indexOf(object);
  915. if (index > -1) {
  916. this.animateObjects.splice(index, 1);
  917. if (!this.animateObjects.find((e) => e.animation == object.animation)) {
  918. let i = this.animateTexs.indexOf(object.animation);
  919. this.animateTexs.splice(i, 1);
  920. object.animation.texture.repeat.set(1, 1);
  921. }
  922. this.stop(object);
  923. }
  924. },
  925. setRepeart: function(animation) {
  926. animation.texture.repeat.set(1 / animation.info.cellXcount, 1 / animation.info.cellYcount);
  927. },
  928. start: function(object) {
  929. if (!object || object.started) return;
  930. object.started = true;
  931. if (object.animation.started) return;
  932. object.animation.started = true;
  933. var info = object.animation.info;
  934. var count = info.cellXcount * info.cellYcount - (info.voidCount || 0);
  935. if (count <= 1) return;
  936. transitions.start(
  937. (progress) => {
  938. var index = Math.floor(count * progress);
  939. var indexX = index % info.cellXcount;
  940. var indexY = info.cellYcount - Math.floor(index / info.cellXcount) - 1; //uv.offset.y是从下到上的
  941. object.animation.texture.offset.x = indexX / info.cellXcount;
  942. object.animation.texture.offset.y = indexY / info.cellYcount;
  943. //console.log(object.id + " : "+ object.texture.offset.toArray())
  944. },
  945. info.duration * -1,
  946. null,
  947. /* ()=>{//done (-1):循环
  948. object.started = false
  949. object.texture.offset.x = 0;
  950. object.texture.offset.y = 0;
  951. this.start(object)
  952. }, */ 0,
  953. null,
  954. object.id,
  955. "gif_" + object.animation.texture.id
  956. );
  957. },
  958. stop: function(object) {
  959. if (!object || !object.started) return;
  960. object.started = false;
  961. //只有该object对应的texture对应的所有object都停止了,才能真的停止动画:
  962. if (this.animateObjects.find((e) => e.animation == object.animation && e.started)) return;
  963. transitions.cancelById("gif_" + object.animation.texture.id);
  964. object.animation.texture.offset.set(0, 0);
  965. object.animation.started = false;
  966. },
  967. };
  968. var CloneObject = function(copyObj, result, isSimpleCopy, extraReplace) {
  969. //isSimpleCopy只复制最外层
  970. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  971. if (!copyObj) return copyObj; //0 null undefined ''
  972. result = result || {};
  973. if (copyObj instanceof Array) {
  974. /* if (copyObj[0]instanceof Object) {
  975. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  976. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  977. }
  978. return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object
  979. return copyObj.map((e) => {
  980. if (e instanceof Object) {
  981. return CloneObject(e);
  982. } else return e;
  983. });
  984. } else {
  985. if (copyObj.clone instanceof Function) {
  986. //解决一部分
  987. return copyObj.clone();
  988. }
  989. }
  990. for (var key in copyObj) {
  991. if (copyObj[key] instanceof Object && !isSimpleCopy) result[key] = CloneObject(copyObj[key]);
  992. else result[key] = copyObj[key];
  993. //如果是函数类同基本数据,即复制引用
  994. }
  995. return result;
  996. };
  997. var ifSame = function(object1, object2) {
  998. if (object1 == object2) return true;
  999. // 0 != undefined , 0 == ''
  1000. else if (!object1 || !object2) return false;
  1001. else if (object1.constructor != object2.constructor) {
  1002. return false;
  1003. } else if (object1 instanceof Array) {
  1004. if (object1.length != object2.length) return false;
  1005. var _object2 = object2.slice(0);
  1006. for (let i = 0; i < object1.length; i++) {
  1007. var u = _object2.find((e) => ifSame(object1[i], e));
  1008. if (u == void 0 && !_object2.includes(u) && !object1.includes(u)) return false;
  1009. else {
  1010. let index = _object2.indexOf(u);
  1011. _object2.splice(index, 1);
  1012. }
  1013. }
  1014. return true;
  1015. } else if (object1.equals instanceof Function) {
  1016. //复杂数据仅支持这种,其他的可能卡住?
  1017. return object1.equals(object2);
  1018. } else if (typeof object1 == "number" || typeof object1 == "string") {
  1019. if (isNaN(object1) && isNaN(object2)) return true;
  1020. else return object1 == object2;
  1021. } else if (typeof object1 == "object") {
  1022. var keys1 = Object.keys(object1);
  1023. var keys2 = Object.keys(object2);
  1024. if (!ifSame(keys1, keys2)) return false;
  1025. for (let i in object1) {
  1026. var same = ifSame(object1[i], object2[i]);
  1027. if (!same) return false;
  1028. }
  1029. return true;
  1030. } else {
  1031. console.log("isSame出现例外");
  1032. }
  1033. };
  1034. function initByTHREE(THREE) {
  1035. window.bus = new THREE.EventDispatcher(); //因为player一开始总是没创建好,所以加一个事件传递器
  1036. THREE.TransitionPass = function(scene, camera) {
  1037. this.renderScene = scene;
  1038. this.renderCamera = camera;
  1039. this.coverRenderTarget = new THREE.WebGLRenderTarget(100, 100, {
  1040. minFilter: THREE.LinearFilter,
  1041. magFilter: THREE.LinearFilter,
  1042. format: THREE.RGBAFormat,
  1043. });
  1044. this.coverTex = this.coverRenderTarget.texture;
  1045. this.enabled = false;
  1046. this.oldClearColor = new THREE.Color();
  1047. this.oldClearAlpha = 1;
  1048. this.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
  1049. this.scene = new THREE.Scene();
  1050. this.material = this.getMaskMaterial();
  1051. var copyShader = THREE.CopyShader;
  1052. this.materialCopy = new THREE.ShaderMaterial({
  1053. uniforms: this.copyUniforms,
  1054. vertexShader: copyShader.vertexShader,
  1055. fragmentShader: copyShader.fragmentShader,
  1056. blending: THREE.NoBlending,
  1057. depthTest: false,
  1058. depthWrite: false,
  1059. transparent: true,
  1060. });
  1061. this.quad = new THREE.Mesh(new THREE.PlaneBufferGeometry(2, 2), this.material);
  1062. this.quad.frustumCulled = false; // Avoid getting clipped
  1063. this.scene.add(this.quad);
  1064. };
  1065. THREE.TransitionPass.prototype = {
  1066. //波形扩散,出下一个画面
  1067. constructor: THREE.TransitionPass,
  1068. setSize: function(width, height) {
  1069. this.coverRenderTarget.setSize(width, height);
  1070. },
  1071. render: function(renderer, writeBuffer, readBuffer, delta, maskActive) {
  1072. var oldAutoClear = renderer.autoClear;
  1073. renderer.autoClear = false;
  1074. var uniforms = this.quad.material.uniforms;
  1075. uniforms.bgTex.value = readBuffer.texture; //更新
  1076. uniforms.coverTex.value = this.coverTex;
  1077. uniforms.progress.value = player.model.skybox.material.uniforms.progress.value; //
  1078. uniforms.screenRatio.value = player.domElement.clientWidth / player.domElement.clientHeight; // 使波纹为圆形
  1079. uniforms.screenRatio.value *= uniforms.screenRatio.value;
  1080. renderer.render(this.scene, this.camera);
  1081. renderer.autoClear = oldAutoClear;
  1082. },
  1083. start: function(sceneRenderer) {
  1084. this.enabled = true;
  1085. //draw coverTex
  1086. this.quad.material.uniforms.progress.value = 1;
  1087. sceneRenderer.renderer.render(sceneRenderer.scene, sceneRenderer.camera, this.coverRenderTarget, true);
  1088. console.log("start111");
  1089. },
  1090. stop: function() {
  1091. this.enabled = false;
  1092. console.log("stop111");
  1093. },
  1094. getMaskMaterial: function() {
  1095. return new THREE.ShaderMaterial({
  1096. uniforms: {
  1097. coverTex: {
  1098. type: "t",
  1099. value: null,
  1100. },
  1101. bgTex: {
  1102. type: "t",
  1103. value: null,
  1104. },
  1105. progress: {
  1106. type: "f",
  1107. value: 0,
  1108. },
  1109. screenRatio: {
  1110. type: "f",
  1111. value: 1,
  1112. },
  1113. },
  1114. vertexShader: `
  1115. varying vec2 vUv;
  1116. void main()
  1117. {
  1118. vUv = uv;
  1119. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  1120. }
  1121. `,
  1122. fragmentShader: `
  1123. uniform sampler2D coverTex;
  1124. uniform sampler2D bgTex;
  1125. uniform float progress;
  1126. uniform float screenRatio;
  1127. varying vec2 vUv;
  1128. void main() {
  1129. const float maxRadius = 0.708; // sqrt(0.5^2+0.5^2)
  1130. const float minRadius = 0.0 ;
  1131. float radius = screenRatio>1.0 ? sqrt((vUv.x - 0.5)*(vUv.x - 0.5) + (vUv.y - 0.5)*(vUv.y - 0.5)/screenRatio) : sqrt((vUv.x - 0.5)*(vUv.x - 0.5)*screenRatio+ (vUv.y - 0.5)*(vUv.y - 0.5));
  1132. float diff = 0.292; //1.0-maxRadius;
  1133. float radiusIn = maxRadius * progress + minRadius * (1.0-progress);
  1134. float radiusOut = radiusIn + diff;
  1135. if(radius < radiusIn) {
  1136. gl_FragColor = texture2D(bgTex, vUv);
  1137. //gl_FragColor = vec4(0.0,0.0,1.0,1.0);//
  1138. }else if(radius>radiusOut){
  1139. gl_FragColor = texture2D(coverTex, vUv) ;
  1140. //gl_FragColor = vec4(1.0,1.0,0.0,1.0);//
  1141. }else{
  1142. vec4 color1 = texture2D(bgTex, vUv);
  1143. vec4 color2 = texture2D(coverTex, vUv);
  1144. float rotio = smoothstep(radiusIn ,radiusOut,radius);
  1145. gl_FragColor = mix(color1, color2, rotio);
  1146. }
  1147. }
  1148. `,
  1149. });
  1150. },
  1151. };
  1152. let labels = [];
  1153. class Label2D extends THREE.EventDispatcher {
  1154. constructor(o = {}) {
  1155. super();
  1156. this.position = o.position;
  1157. this.elem = $(o.innerHTML || "<div ><a></a></div>");
  1158. $(o.domElement).append(this.elem);
  1159. this.pos2d = new THREE.Vector3();
  1160. this.elem.css({ position: "absolute", "z-index": 999 });
  1161. this.clickFun = o.clickFun;
  1162. this.clickFun && this.elem.on("click", this.clickFun.bind(this));
  1163. if (o.autoUpdate) {
  1164. let update = (e) => {
  1165. if (e.cameraChanged) this.update();
  1166. };
  1167. player.on("view.changed", update); //确保player存在
  1168. this.addEventListener("dispose", (e) => {
  1169. player.off("view.changed", update);
  1170. });
  1171. }
  1172. this.visible = true;
  1173. this.shelterByModel = o.shelterByModel;
  1174. this.floorIndex = o.floorIndex;
  1175. labels.push(this);
  1176. if (window.player.model) {
  1177. this.init();
  1178. } else {
  1179. window.bus.addEventListener("playerAndModelReady", this.init.bind(this));
  1180. }
  1181. }
  1182. init() {
  1183. if (this.floorIndex != void 0) {
  1184. player.model.on("floor.changed", (currentFloor, mode, oldFloor) => {
  1185. this.update(currentFloor); //注: currentFloor 这时候还没成为 model.currentFloor
  1186. });
  1187. }
  1188. }
  1189. update(currentFloor) {
  1190. if (!this.position || !this.visible) return;
  1191. var p = convertTool.getPos2d(this.position);
  1192. if (!p || !p.trueSide) {
  1193. this.elem.css("display", "none");
  1194. return;
  1195. }
  1196. //判断label是否被模型遮挡,遮挡则消失(如果是漫游模式最好提前计算visiblePanos)
  1197. if (player.mode != "panorama") {
  1198. currentFloor = currentFloor || player.model.currentFloor;
  1199. if (!player.model.allFloorsVisible && this.floorIndex != void 0 && this.floorIndex != currentFloor.floorIndex) {
  1200. this.elem.css("display", "none");
  1201. return;
  1202. }
  1203. if (this.shelterByModel && convertTool.ifShelter(this.position, this.floorIndex)) {
  1204. this.elem.css("display", "none");
  1205. return;
  1206. }
  1207. }
  1208. this.elem.css({
  1209. left: p.pos.x + "px",
  1210. top: p.pos.y + "px",
  1211. });
  1212. /* if(settings.vrEnabled){
  1213. this.elem.css({transform:'rotate('+window.screenFaceOrient+'deg)'})
  1214. }else{
  1215. this.elem.css({transform:''})
  1216. } */
  1217. this.elem.css("display", "block");
  1218. this.pos2d = p.vector;
  1219. }
  1220. setVisible(visi, reason, level = 0, type) {
  1221. convertTool.updateVisible(this, reason, visi, level, type);
  1222. if (!this.visible) {
  1223. this.elem.css("display", "none");
  1224. } else {
  1225. this.update();
  1226. }
  1227. }
  1228. setPos(pos) {
  1229. this.position = pos;
  1230. this.update();
  1231. }
  1232. dispose() {
  1233. this.elem.remove();
  1234. this._listeners = {};
  1235. this.dispatchEvent({ type: "dispose" });
  1236. let index = labels.indexOf(this);
  1237. index > -1 && labels.splice(index, 1);
  1238. }
  1239. }
  1240. window.Label2D = Label2D;
  1241. class RoomLabel extends Label2D {
  1242. constructor(o) {
  1243. if (o.position instanceof Array) o.position = new THREE.Vector3().fromArray(o.position);
  1244. o.innerHTML = `<div class="room-label" ><a><p><span>${o.title}</span></p></a></div>`;
  1245. o.domElement = $(".widgets-doll-labels")[0];
  1246. (o.shelterByModel = true), (o.autoUpdate = true);
  1247. o.clickFun = () => {
  1248. if (player.roomLebelClickUnabled) return;
  1249. let result = common.sortByScore(
  1250. player.model.floors.index[this.floorIndex].panos,
  1251. [],
  1252. [
  1253. (pano) => {
  1254. return -pano.position.distanceToSquared(this.position);
  1255. },
  1256. ]
  1257. );
  1258. player.flyToPano({
  1259. pano: result && result[0] && result[0].item,
  1260. });
  1261. };
  1262. super(o);
  1263. this.setTitle(o.title);
  1264. }
  1265. init() {
  1266. super.init();
  1267. //飞入后不可见
  1268. player.on("mode.changing", (currentMode, mode, pano, duration) => {
  1269. //准备飞
  1270. this.setStyle(currentMode, mode, duration);
  1271. });
  1272. this.setStyle();
  1273. }
  1274. setStyle(currentMode, mode, duration) {
  1275. if (!mode) mode = player.mode;
  1276. if (mode == "panorama") {
  1277. this.setVisible(false, "isPanorama");
  1278. } else if (currentMode == "panorama") {
  1279. setTimeout(() => {
  1280. this.setVisible(true, "isPanorama");
  1281. }, duration * 0.7);
  1282. }
  1283. }
  1284. setTitle(title) {
  1285. this.title = title || "";
  1286. this.elem.html(`<a><p><span>${this.title}</span></p></a>`);
  1287. }
  1288. setEditSelect(state) {
  1289. //编辑页面用
  1290. this.editing = !!state;
  1291. this.setVisible(state, "editSelected", 1, state ? "add" : "cancel"); //强制可见
  1292. }
  1293. }
  1294. window.RoomLabel = RoomLabel;
  1295. window.bus.addEventListener("playerAndModelReady", () => {
  1296. player.on("mode.changing", (currentMode, mode, pano, duration) => {
  1297. let noLine = mode == "floorplan";
  1298. if (noLine) {
  1299. $(".widgets-doll-labels")
  1300. .addClass("noLine")
  1301. .addClass("noCorner");
  1302. } else {
  1303. $(".widgets-doll-labels")
  1304. .removeClass("noLine")
  1305. .removeClass("noCorner");
  1306. }
  1307. });
  1308. player.on("view.changed", (e) => {
  1309. if (e.cameraChanged) {
  1310. //if(needUpdateZIndex){ //如果某个label显示时需要更新index的话,加个参数
  1311. let label_ = labels.filter((e) => e.elem[0].style.display == "block");
  1312. label_.sort((a, b) => b.pos2d.z - a.pos2d.z);
  1313. label_.forEach((e, index) => e.elem.css("z-index", index + 1000));
  1314. //}
  1315. }
  1316. });
  1317. });
  1318. }
  1319. //最好能知道应该播放到的currentTime
  1320. var SoundManager = {
  1321. //暂不支持同时播放
  1322. currentAudio: null, //当前正在播放list中的哪一个
  1323. enableSound: true, //是否允许有声音
  1324. playHistory: [], //被打断的加入播放历史
  1325. list: [], //同一级别可以互相打断 //暂时不做多级别
  1326. play: function(name, src, currentTime) {
  1327. var object = this.list.find((e) => e.name == name);
  1328. if (object && this.currentAudio == object) {
  1329. if (this.currentAudio) {
  1330. this.pause(this.currentAudio.name, false, true);
  1331. }
  1332. {
  1333. //将当前要播放的播放历史中清除
  1334. let index = this.playHistory.indexOf(object);
  1335. if (index > -1) this.playHistory.splice(index, 1);
  1336. }
  1337. this.currentAudio = object;
  1338. if (src) {
  1339. this.setSrc(name, src);
  1340. }
  1341. if (currentTime != void 0) {
  1342. object.audio.currentTime = currentTime;
  1343. }
  1344. if (object.audio && object.src) {
  1345. object.audio.load(); // iOS 9 还需要额外的 load 一下, 否则直接 play 无效 *///https://www.cnblogs.com/interdrp/p/4211883.html 部分资料
  1346. object.audio.play();
  1347. object.callback && object.callback(true);
  1348. Log(name + " 播放 ");
  1349. }
  1350. }
  1351. },
  1352. pause: function(name, autoReplayLast, isInterrupt) {
  1353. //需要能自动恢复上一个被打算的音频。恢复前判断是否还需要播放
  1354. var object = this.list.find((e) => e.name == name);
  1355. if (object) {
  1356. this.currentAudio = null;
  1357. if (object.audio) {
  1358. object.audio.pause();
  1359. object.callback && object.callback(false);
  1360. object.audio.src && Log(name + " 中断音频 " + "(" + common.getFileNameFromUrl(object.audio.src) + ")");
  1361. }
  1362. if (isInterrupt) {
  1363. //一般主动调用不需要加这个
  1364. this.playHistory.push(object); //如果是被中断的,加入播放历史,等待恢复播放
  1365. }
  1366. if (autoReplayLast) {
  1367. //播放之前的音频。它们是被打断过的。
  1368. while (this.playHistory.length) {
  1369. var last = this.playHistory.pop();
  1370. if (last.src && last.canplay(last.audio)) {
  1371. this.play(last.name);
  1372. }
  1373. }
  1374. }
  1375. }
  1376. },
  1377. setSrc: function(name, src) {
  1378. //不能直接给audio赋src!一定要用这个函数!因为我要拿这里的src来判断有无src,因为貌似audio的src会自动变,''时会变成html的链接
  1379. var object = this.list.find((e) => e.name == name);
  1380. object.src = src;
  1381. object.audio.src = src;
  1382. Log(`${object.name} 设置src: ${src}`);
  1383. },
  1384. createAudio: function(object = {}) {
  1385. //name, level, canplay
  1386. if (!object.fake) {
  1387. object.audio = new Audio();
  1388. object.audio.loop = !!object.loop;
  1389. //object.audio.autoplay = true;
  1390. object.audio.addEventListener("ended", () => {
  1391. if (object.loop) {
  1392. //循环
  1393. Log(`${object.name} 播放完毕,重新播放`);
  1394. object.audio.play();
  1395. } else {
  1396. this.pause(object.name, true); //停止后的后续处理
  1397. }
  1398. });
  1399. object.audio.oncanplaythrough = () => {
  1400. Log(`${object.name} canplaythrough `);
  1401. };
  1402. }
  1403. this.list.push(object);
  1404. },
  1405. initAutoPlay: function() {
  1406. //处理设备自动播放限制
  1407. let play = function() {
  1408. if (this.currentAudio && this.currentAudio.audio && this.currentAudio.src) {
  1409. this.currentAudio.audio.play();
  1410. Log(`${this.currentAudio.name} 自动播放成功`); //即使设置src在这之后好像也能成功播放
  1411. } else {
  1412. }
  1413. document.removeEventListener("touchstart", play);
  1414. document.removeEventListener("click", play);
  1415. $("#player")[0] && $("#player")[0].removeEventListener("touchstart", play);
  1416. }.bind(this);
  1417. document.addEventListener("WeixinJSBridgeReady", play, false);
  1418. document.addEventListener("touchstart", play); //ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
  1419. document.addEventListener("click", play);
  1420. $("#player")[0] && $("#player")[0].addEventListener("touchstart", play);
  1421. },
  1422. };
  1423. function Log(value, color, fontSize) {
  1424. color = color || "#13f";
  1425. fontSize = fontSize || 14;
  1426. console.warn(`%c${value}`, `color:${color};font-size:${fontSize}px`);
  1427. }
  1428. Manage.prototype.loadAudio = function() {
  1429. //相关:g_tourAudio \ g_playAudio
  1430. //热点页面因为挡住了界面,所以暂时不存在别的音频阻止热点音频的可能
  1431. //box视频都静音,所以暂时不考虑
  1432. SoundManager.createAudio({
  1433. name: "bgm",
  1434. level: 0,
  1435. src: "",
  1436. loop: true,
  1437. canplay: (audio) => {
  1438. return this.bgmShouldPlay;
  1439. },
  1440. callback: (state) => {
  1441. //play或pause时随之触发的函数(即使还没开始播放)
  1442. if (state) {
  1443. $("#volume a img").attr("src", "./images/Volume btn_off.png");
  1444. $("#volume").attr("title", "关闭声音");
  1445. } else {
  1446. $("#volume a img").attr("src", "./images/Volume btn_on.png");
  1447. $("#volume").attr("title", "打开声音");
  1448. }
  1449. },
  1450. });
  1451. SoundManager.createAudio({
  1452. name: "tour",
  1453. level: 0,
  1454. src: "",
  1455. loop: false,
  1456. canplay: (audio) => {
  1457. return player.director && player.director.tourIsPlaying && player.director.getAudio();
  1458. },
  1459. });
  1460. SoundManager.createAudio({
  1461. name: "hot",
  1462. fake: true, //实际上没有audio. 只是为了来停止和续播其他音频
  1463. level: 1,
  1464. src: "",
  1465. loop: false,
  1466. canplay: (audio) => {},
  1467. });
  1468. $("#volume")
  1469. .find("a")
  1470. .on("click", () => {
  1471. if ($("#volume img")[0].src.indexOf("btn_on.png") > -1) {
  1472. this.switchBgmState(true);
  1473. } else if ($("#volume img")[0].src.indexOf("btn_off.png") > -1) {
  1474. this.switchBgmState(false);
  1475. }
  1476. });
  1477. this.switchBgmState(true); //初始设置允许播放bgm
  1478. SoundManager.initAutoPlay();
  1479. };
  1480. Manage.prototype.switchBgmState = function(state) {
  1481. //按钮的状态完全代表是否应该播放bgm,即使还没加载完
  1482. this.bgmShouldPlay = state;
  1483. if (state) {
  1484. SoundManager.play("bgm");
  1485. } else {
  1486. SoundManager.pause("bgm");
  1487. }
  1488. /* if(!g_bgAudio || !g_bgAudio.src) return;
  1489. var played = function(){
  1490. console.log('begin play bgm');
  1491. g_play = 1;
  1492. g_playAudio = g_bgAudio;
  1493. g_tourAudio && g_tourAudio.pause()
  1494. }
  1495. var paused = function(){
  1496. g_play = 0;
  1497. g_playAudio == g_bgAudio && (g_playAudio = null)
  1498. }
  1499. if(state ){
  1500. g_bgAudio.play();
  1501. if(g_bgAudio.paused){
  1502. paused()
  1503. }else{
  1504. played()
  1505. return true
  1506. }
  1507. }else{
  1508. g_bgAudio.pause();
  1509. paused()
  1510. }
  1511. g_bgAudio.pauseByHot = false
  1512. g_bgAudio.pauseByTour = false */
  1513. };
  1514. var manage = new Manage();
  1515. //处理cursor优先级
  1516. var CursorDeal = {
  1517. priorityEvent: [
  1518. //在前面的优先级高
  1519. { noIntersect: "not-allowed" },
  1520. { addHot: "cell" },
  1521. { hoverFootIcon: "pointer" },
  1522. { hoverHot: "pointer" },
  1523. { addLabel: "cell" },
  1524. { moveLabel: "grab" },
  1525. ],
  1526. domElements: [$("#player")[0] && $("#player")[0]],
  1527. list: [], //当前存在的cursor状态
  1528. currentCursorIndex: null,
  1529. /* init : function(viewer){
  1530. this.priorityEvent.forEach(e=>{//刚开始Potree.resourcePath没值,现在换
  1531. for(let i in e){
  1532. e[i] = Common.replaceAll(e[i],'{Potree.resourcePath}',Potree.resourcePath)
  1533. }
  1534. })
  1535. this.domElements = [viewer.renderArea, viewer.mapViewer.renderArea];
  1536. viewer.addEventListener("CursorChange",(e)=>{
  1537. if(e.action == 'add'){
  1538. this.add(e.name)
  1539. }else{
  1540. this.remove(e.name)
  1541. }
  1542. })
  1543. }, */
  1544. add: function(name) {
  1545. var priorityItem = this.priorityEvent.find((e) => e[name]);
  1546. if (!priorityItem) {
  1547. console.error("CursorDeal 未定义优先级 name:" + name);
  1548. return;
  1549. }
  1550. if (!this.list.includes(name)) {
  1551. this.judge({ addItem: priorityItem, name });
  1552. this.list.push(name);
  1553. }
  1554. },
  1555. remove: function(name) {
  1556. var index = this.list.indexOf(name);
  1557. if (index > -1) {
  1558. this.list.splice(index, 1);
  1559. this.judge();
  1560. }
  1561. },
  1562. judge: function(o = {}) {
  1563. //console.log(o,this.list)
  1564. if (o.addItem) {
  1565. var addIndex = this.priorityEvent.indexOf(o.addItem);
  1566. if (addIndex < this.currentCursorIndex || this.currentCursorIndex == void 0) {
  1567. this.domElements.forEach((e) => (e.style.cursor = o.addItem[o.name]));
  1568. this.currentCursorIndex = addIndex;
  1569. }
  1570. } else {
  1571. var levelMax = { index: Infinity, cursor: null };
  1572. this.list.forEach((name) => {
  1573. var priorityItem = this.priorityEvent.find((e) => e[name]);
  1574. var index = this.priorityEvent.indexOf(priorityItem);
  1575. if (index < levelMax.index) {
  1576. levelMax.index = index;
  1577. levelMax.cursor = priorityItem[name];
  1578. }
  1579. });
  1580. this.currentCursorIndex = levelMax.index;
  1581. this.domElements.forEach((e) => (e.style.cursor = levelMax.cursor || ""));
  1582. }
  1583. },
  1584. };
  1585. //兼容一代的場景
  1586. //請求地址統一管理
  1587. var g_onePregix = "https://bigscene.4dage.com/"; //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
  1588. var g_version = manage.number("version");
  1589. g_version === "one" ? (g_Prefix = g_onePregix) : "";