manage.js 56 KB

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