Hot.js 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007
  1. //合并热点和展览
  2. g_currentHot = null;
  3. const playVideoWhenFlyOut = false;
  4. //同时可播放的最大个数:
  5. const playVideoMax = window.isEdit ? 3 : browser.isMobile() ? 1 : 2;
  6. const playAniMax = window.isEdit ? 6 : browser.isMobile() ? 3 : 5;
  7. window.initHot = function (model) {
  8. var objLoader = new THREE.OBJLoader();
  9. var _planeGeometry = new THREE.PlaneGeometry(1, 1);
  10. var _boxGeometry = new THREE.BoxBufferGeometry(1, 1, 1);
  11. {
  12. //ie的mesh 加了polygonOffset也是会重叠。所以去掉前面的face: (但是突然ie又播放不了videoTexture)
  13. var newIndex = [..._boxGeometry.index.array];
  14. newIndex.splice(4 * 6, 12);
  15. _boxGeometry.setIndex(
  16. new THREE.BufferAttribute(new Uint16Array(newIndex), 1)
  17. );
  18. }
  19. var originPhotoCount = (photoLoaded = originModelCount = modelLoaded = 0);
  20. var defaultTex1 = Texture.load(g_HotImage.point);
  21. var defaultTex2 = Texture.load(g_HotImage.point2);
  22. dealMap(defaultTex1, { ignoreResize: true });
  23. dealMap(defaultTex2, { ignoreResize: true }); //这张图改为linear有黑边。 但即使不改,chrome调试手机版也有黑边和锯齿
  24. /* var _boxMat = new THREE.MeshBasicMaterial({
  25. color: "#eeeeee",
  26. transparent: !0,
  27. opacity: 0.8
  28. }) */
  29. var _boxMat = new THREE.MeshPhongMaterial({
  30. color: "#eeeeee",
  31. transparent: !0,
  32. opacity: 0.8,
  33. side: THREE.DoubleSide,
  34. });
  35. var autoSizeInfo = /* {width2d:50}// */ {
  36. minSize: 120,
  37. maxSize: 600,
  38. nearBound: 1,
  39. farBound: 15,
  40. };
  41. window.hotGroup = new THREE.Object3D();
  42. hotGroup.name = "hotGroup";
  43. model.add(hotGroup);
  44. model.hotGroup = hotGroup;
  45. console.log("createHotList", hotGroup);
  46. var animateTexSrcs = {};
  47. var getLink = function (link) {
  48. var src = "";
  49. var r = link.substring(link.indexOf("html") + 4),
  50. o = "en" == manage.number("lang") ? "&lang=" + manage.number("lang") : "";
  51. -1 == r.indexOf("?")
  52. ? (src =
  53. link + "?time=" + randomTime().getTime() + "&id=" + window.number + o)
  54. : (src =
  55. link +
  56. "&time=" +
  57. randomTime().getTime() +
  58. "&title=" +
  59. window.selectedHotTitle +
  60. "&curLang=" +
  61. localStorage.getItem("locale") +
  62. "&id=" +
  63. window.number +
  64. o);
  65. // return src.replace(
  66. // "https://www.4dmodel.com/SuperTwo/hot_online1",
  67. // "http://192.168.0.68:8080"
  68. // );
  69. return src.replace(
  70. "https://www.4dmodel.com/SuperTwo/hot_online1",
  71. "https://houseoss.4dkankan.com/project/aoMenScene/hot"
  72. );
  73. // return src //打包
  74. };
  75. var removeSrcPostMark = function (url) {
  76. //去除texture.load时自动加上的'?'
  77. var index = url.indexOf("?");
  78. if (index > -1) {
  79. return url.slice(0, index);
  80. } else return url;
  81. };
  82. {
  83. //get plane Bound
  84. var planeBound = new THREE.Box3();
  85. var cornerPoint = [
  86. new THREE.Vector3(-0.5, 0.5, 0),
  87. new THREE.Vector3(0.5, 0.5, 0),
  88. new THREE.Vector3(0.5, -0.5, 0),
  89. new THREE.Vector3(-0.5, -0.5, 0),
  90. ];
  91. cornerPoint.forEach((e) => {
  92. planeBound.expandByPoint(e);
  93. });
  94. }
  95. var shineMats = [];
  96. var getShineMat = function (texture1, texture2) {
  97. var mat = shineMats.find(
  98. (e) =>
  99. e.uniforms.texture1.value == texture1 &&
  100. e.uniforms.texture2.value == texture2
  101. );
  102. if (mat) return mat;
  103. else {
  104. var mat = new THREE.ShaderMaterial({
  105. uniforms: {
  106. opac: {
  107. type: "f",
  108. value: 0,
  109. },
  110. texture1: {
  111. type: "t",
  112. value: texture1,
  113. },
  114. texture2: {
  115. type: "t",
  116. value: texture2,
  117. },
  118. },
  119. vertexShader:
  120. "varying vec2 vUv;\n\nvoid main() {\n\n vUv = uv ;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n}\n",
  121. fragmentShader:
  122. "varying vec3 vNormal;\n\nvarying vec2 vUv;\n\nuniform float opac;\n\n uniform sampler2D texture1;\n\nuniform sampler2D texture2;\n\nvoid main() {\n\nvec4 tcolor1 = texture2D( texture1, vUv );\n\nvec4 tcolor2 = texture2D( texture2, vUv );\n\ngl_FragColor = mix(tcolor1,tcolor2 ,opac) + tcolor2*0.2; }\n",
  123. transparent: !0,
  124. });
  125. shineMats.push(mat);
  126. return mat;
  127. }
  128. };
  129. var modelGeos = [];
  130. var getModelGeo = function (url) {
  131. var geo = modelGeos.find((e) => (e.url = url));
  132. if (geo) return geo;
  133. else {
  134. var geo = null;
  135. geo.url = url;
  136. }
  137. };
  138. class Hot extends THREE.Object3D {
  139. constructor(info, source) {
  140. super();
  141. this.sid = info.sid;
  142. this.preDeal(info, source); // source:旧版来源
  143. this.info = info;
  144. this.cornerPoints = [];
  145. this.build(info);
  146. this.name = "hot_" + this.sid;
  147. model.hots[info.sid] = this;
  148. }
  149. build(info) {
  150. hotGroup.add(this);
  151. this.setTitleElem();
  152. this.setFromInfo(info);
  153. }
  154. setFromInfo(info, media, objObject) {
  155. //1 恢复到编辑之前 2 初始加载
  156. var plane = this.plane;
  157. /* var transformAtPanos = {}
  158. for(var i in info.transformAtPanos){
  159. transformAtPanos[i] = {//只保留一个位移,主要原因是大小变化和热点大小设置冲突了, isSprite和qutaernion衝突
  160. pos : info.transformAtPanos[i].pos && info.transformAtPanos[i].pos.clone(),
  161. //qua : info.transformAtPanos[i].qua && info.transformAtPanos[i].qua.clone(),
  162. }
  163. }
  164. this.transformAtPanos = transformAtPanos */
  165. //在每个漫游点独立设置的position。
  166. var curPanoTransform =
  167. this.info.transformAtPanos[getTransformSid()] || {};
  168. //没有单独设置position的漫游点使用的position
  169. this.position.copy(curPanoTransform.pos || info.position);
  170. this.rotation.copy(info.rotation);
  171. this.scale.copy(info.scale);
  172. this.changeTexType(info.texType, media);
  173. if (!info.objSrc) {
  174. this.addPlane();
  175. if (!!this.hasBox != !!info.hasBox) {
  176. this.addBox(!this.hasBox);
  177. }
  178. } else {
  179. this.addModel(objObject || new THREE.Mesh()); //暂时创建个空的
  180. }
  181. this.updateMatrixWorld();
  182. /* if(!this.info.visiblePanos){//移到model.build时,在collider建好之后
  183. this.getVisiblePanos()
  184. } */
  185. {
  186. //gif
  187. if (this.animation) {
  188. GifTexDeal.remove(this.animation);
  189. }
  190. if (this.info.animateInfo && this.material_.map) {
  191. this.animation = GifTexDeal.addAnimation(
  192. this.material_.map,
  193. this,
  194. this.info.animateInfo,
  195. this.sid
  196. );
  197. this.visible && this.inSight() && GifTexDeal.start(this.animation);
  198. }
  199. }
  200. /* if(this.info.modelBound){
  201. this.mesh.updateMatrixWorld()
  202. this.mesh.boxHelper2 = new THREE.Box3Helper( new THREE.Box3().copy(this.info.modelBound.bound).applyMatrix4(this.mesh.matrixWorld), new THREE.Color("#00aaee"));
  203. model.add(this.mesh.boxHelper2)
  204. }else{
  205. var bound = new THREE.Box3()
  206. var cornerPoint = [
  207. new THREE.Vector3(-0.5, 0.5, 0),
  208. new THREE.Vector3(0.5, 0.5, 0),
  209. new THREE.Vector3(0.5, -0.5, 0),
  210. new THREE.Vector3(-0.5, -0.5, 0),
  211. ]
  212. cornerPoint.forEach(e=>{
  213. bound.expandByPoint(e)
  214. })
  215. this.mesh.updateMatrixWorld()
  216. this.mesh.boxHelper2 = new THREE.Box3Helper( bound.applyMatrix4(this.mesh.matrixWorld), new THREE.Color("#00aaee"));
  217. model.add(this.mesh.boxHelper2)
  218. } */
  219. }
  220. changeTexType(texType, media) {
  221. var plane = this.plane;
  222. if (this.texType != texType || media == "clear") {
  223. //删除旧的
  224. if (this.texType == "shine") {
  225. /* this.material_.uniforms.texture1.value.dispose()
  226. this.material_.uniforms.texture2.value.dispose() */
  227. //为了恢复 不删
  228. } else {
  229. //this.material_.map.dispose()
  230. if (this.texType == "video") {
  231. this.texMedia && this.texMedia.pause();
  232. } else {
  233. }
  234. }
  235. if (
  236. this.material_ &&
  237. !hotGroup.children.find(
  238. (e) => e != this && e.material_ == this.material_
  239. )
  240. ) {
  241. this.material_.dispose();
  242. }
  243. //添加新的
  244. if (texType == "shine") {
  245. } else {
  246. this.changeMaterial(
  247. new THREE.MeshBasicMaterial({
  248. color: "#00c8af",
  249. opacity: 0.4,
  250. transparent: !0,
  251. polygonOffset: true,
  252. //是否开启多边形偏移 //ie不开启时blank也不会闪烁
  253. polygonOffsetFactor: -0.9,
  254. //多边形偏移因子
  255. polygonOffsetUnits: -4.0,
  256. //多边形偏移单位
  257. })
  258. );
  259. if (texType == "video") {
  260. } else {
  261. }
  262. }
  263. }
  264. this.texType = texType;
  265. if (media == "clear") {
  266. this.material_.opacity = 0.4;
  267. this.texMedia = null;
  268. return;
  269. }
  270. if (texType == "video") {
  271. //视频不能共用一个,否则会一起播放暂停
  272. var video;
  273. if (media) {
  274. video = media;
  275. } else {
  276. if (!this.info.texSrc) return;
  277. var video = $(
  278. `<video controls="controls" loop x5-playsinline="" webkit-playsinline="true" playsinline="true" controlslist="nodownload" preload="meta" ></video>`
  279. )[0];
  280. if (window.isEdit) video.src = manage.dealURL(this.info.texSrc); //注意,src赋值就会自动加载, preload="meta" 只加载元数据,提高加载速度,否则一开始卡
  281. /* let src = this.info.texSrc
  282. if(window.isEdit) src = manage.dealURL(src);
  283. var video = window.videoPlayer.getVideo(src)*/
  284. video.name = this.info.fileName;
  285. }
  286. video.setAttribute("crossOrigin", "Anonymous"); //要在src设置好前解决跨域
  287. $(video).on("contextmenu", function () {
  288. return false;
  289. }); //禁止右键点击出
  290. this.texMedia = video;
  291. video.oncanplaythrough = (e) => {
  292. if (this.texMedia == video) {
  293. /* if(video.paused) */
  294. //console.log({str:'oncanplaythrough '+this.sid, level:1})
  295. //this.material_.map.needsUpdate = !0 //当初为何加这句?
  296. //this.update(player)
  297. }
  298. };
  299. /* video.onloadstart = (e)=> {
  300. console.log({str:'onloadstart '+this.sid, level:1})
  301. }
  302. video.onloadedmetadata = (e)=> {
  303. console.log({str:'onloadedmetadata '+this.sid, level:1})
  304. }
  305. video.onloadeddata = (e)=> {
  306. console.log({str:'onloadeddata '+this.sid, level:1})
  307. }
  308. video.oncanplay = (e)=> {
  309. console.log({str:'oncanplay '+this.sid, level:1})
  310. } */
  311. video.volume = 0;
  312. video.muted = true;
  313. video.currentTime = 0;
  314. if (!window.isEdit) this.material_.opacity = 0.3;
  315. this.material_.map = new THREE.VideoTexture(video);
  316. this.material_.map.wrapS = this.material_.map.wrapT =
  317. THREE.ClampToEdgeWrapping;
  318. this.material_.map.generateMipmaps = true;
  319. } else if (texType == "photo") {
  320. if (media) {
  321. this.texMedia = media;
  322. this.info.texSrc = media.src;
  323. this.material_.map = new THREE.Texture(); //texture也不能共用一个,因为有的会有动画,就不一样
  324. this.material_.map.image = media; //image可以共用
  325. this.material_.map.needsUpdate = !0;
  326. this.material_.opacity = 1;
  327. } else {
  328. if (!this.info.texSrc) return;
  329. this._loadDones = [];
  330. this.material_.opacity = 0.1;
  331. }
  332. } else if (texType == "shine") {
  333. if (media) {
  334. this.changeShineTex(media);
  335. } else {
  336. this.styleImg = /* this.styleImg || */ [];
  337. if (this.info.styleImg) {
  338. this.styleImg = this.info.styleImg.map((src) => {
  339. return { src: /* manage.dealURL( */ src }; //如果要dealURL,在predeal里
  340. });
  341. }
  342. this.changeShineTex(this.styleImg);
  343. }
  344. this.info.texSrc = null;
  345. }
  346. if (this.material_.map) {
  347. /* this.material_.map.minFilter = THREE.LinearFilter;
  348. this.material_.map.magFilter = THREE.LinearFilter; */
  349. dealMap(this.material_.map);
  350. this.material_.color.set("#FFFFFF");
  351. this.material_.needsUpdate = true;
  352. }
  353. }
  354. changeShineTex(styleImg) {
  355. styleImg = styleImg || this.styleImg;
  356. var tex1, tex2;
  357. if (styleImg.length) {
  358. tex1 = Texture.load(styleImg[0].src);
  359. tex2 = Texture.load(
  360. (styleImg[1] && styleImg[1].src) || styleImg[0].src
  361. );
  362. dealMap(tex1, { ignoreResize: true });
  363. dealMap(tex2, { ignoreResize: true });
  364. } else {
  365. tex1 = defaultTex1;
  366. tex2 = defaultTex2;
  367. }
  368. this.changeMaterial(getShineMat(tex1, tex2));
  369. this.styleImg = styleImg;
  370. this.info.styleImg = styleImg.map((img) => img.src);
  371. }
  372. changeMaterial(mat) {
  373. this.material_ = mat;
  374. this.mesh &&
  375. this.mesh.traverse((mesh) => {
  376. if (mesh.material && !(mesh instanceof THREE.Box3Helper)) {
  377. mesh.material = this.material_;
  378. }
  379. });
  380. }
  381. preDeal(info, source) {
  382. // source:来源
  383. var convertValue = function (v, Type) {
  384. var value;
  385. if (v instanceof Array) {
  386. v.forEach((v1) => {
  387. v1 = parseFloat(v1);
  388. });
  389. value = new Type().fromArray(v);
  390. } else {
  391. if (!(v instanceof Type)) {
  392. for (let i in v) {
  393. v[i] = parseFloat(v[i]);
  394. }
  395. value = new Type().copy(v);
  396. } else {
  397. value = v;
  398. }
  399. }
  400. return value;
  401. };
  402. if (!info.transformAtPanos) info.transformAtPanos = {};
  403. if (source == "byHot") {
  404. var infoAttribute = info.infoAttribute || {};
  405. info.title = infoAttribute.title || info.title;
  406. info.model = infoAttribute.model || info.model || []; //模型链接
  407. info.images = infoAttribute.images || info.images || [];
  408. info.video = infoAttribute.video || info.video || [];
  409. info.bgName = infoAttribute.bgName || info.bgName;
  410. info.backgroundMusic = info.backgroundMusic || info.backgroundMusic;
  411. info.iframe = infoAttribute.iframe || info.iframe || [];
  412. info.styleImg = infoAttribute.styleImg || info.styleImg || [];
  413. info.content = infoAttribute.content || info.content;
  414. {
  415. let action = CloneObject(settings.hotClickEvent.shine);
  416. if (info.actionType == "noAction" || info.noAction) {
  417. (action.examine = false), (action.openHot = false);
  418. } else if (info.actionType == "dontExam") {
  419. action.examine = false;
  420. }
  421. info.actionType = action;
  422. }
  423. if (info.quaternion) {
  424. info.rotation = new THREE.Euler().setFromVector3(
  425. convertValue(info.quaternion, THREE.Quaternion)
  426. );
  427. } else {
  428. info.rotation = new THREE.Euler().setFromVector3(
  429. convertValue(info.rotation, THREE.Vector3)
  430. ); //热点的旧数据很多是字符串
  431. }
  432. var s = Hot.getDefaulScale(info.hotIconScale); //旧版的大小,统一转换成新版
  433. info.scale = new THREE.Vector3(s, s, 0.02);
  434. delete info.infoAttribute;
  435. /* for (let i in this.transformAtPanos) {
  436. info.transformAtPanos[i].pos = new THREE.Vector3().fromArray(info.transformAtPanos[i].pos)
  437. info.transformAtPanos[i].qua && (info.transformAtPanos[i].qua = new THREE.Quaternion().fromArray(info.transformAtPanos[i].qua))
  438. } */
  439. info.texType = "shine";
  440. } else {
  441. if (source == "byOverlay") {
  442. info.texType = info.media[0];
  443. //info.title = info.texType == 'video'?'视频':'图片'
  444. info.texSrc = info.file;
  445. info.actionType = CloneObject(settings.hotClickEvent[info.texType]); //给一个默认
  446. delete info.media;
  447. info.rotation = new THREE.Euler().setFromQuaternion(
  448. convertValue(info.qua, THREE.Quaternion)
  449. );
  450. info.position = info.pos;
  451. delete info.pos;
  452. delete info.qua;
  453. let a = info.texSrc.split("/");
  454. info.fileName = a.pop();
  455. info.scale = new THREE.Vector3(info.width, info.height, info.depth);
  456. delete info.width;
  457. delete info.height;
  458. delete info.depth;
  459. delete info.file;
  460. } else {
  461. info.rotation = new THREE.Euler().fromArray(info.rotation); //.setFromVector3(info.rotation)
  462. }
  463. info.model = info.model || []; //模型链接
  464. info.images = info.images || [];
  465. info.video = info.video || [];
  466. info.iframe = info.iframe || [];
  467. info.styleImg = info.styleImg || [];
  468. info.imagesDesc = info.imagesDesc || [];
  469. info.videosDesc = info.videosDesc || [];
  470. info.titleShowType = info.titleShowType || "hover";
  471. info.titlePos = info.titlePos || "right";
  472. }
  473. if (info.texSrc) {
  474. info.texSrc = manage.removeSrcPostMark(info.texSrc);
  475. }
  476. //whole:
  477. //为了兼容旧数据,尽量和hot的数据靠近,最后保存在hot里
  478. info.position = convertValue(info.position, THREE.Vector3);
  479. info.scale = convertValue(info.scale, THREE.Vector3);
  480. delete info.quaternion;
  481. info.linkType = info.linkType || "common";
  482. for (let i in info.transformAtPanos) {
  483. info.transformAtPanos[i].pos = new THREE.Vector3().fromArray(
  484. info.transformAtPanos[i].pos
  485. );
  486. //info.transformAtPanos[i].qua = new THREE.Quaternion().fromArray(info.transformAtPanos[i].qua)
  487. }
  488. }
  489. addBox(state) {
  490. if (state == !!this.hasBox) {
  491. return;
  492. }
  493. if (state) {
  494. var box = new THREE.Mesh(_boxGeometry, _boxMat);
  495. box.position.set(0, 0, 1 / 2);
  496. box.renderOrder = 3;
  497. this.plane.position.set(0, 0, 1);
  498. this.add(box);
  499. this.box = box;
  500. } else {
  501. this.plane.position.set(0, 0, 0);
  502. this.remove(this.box);
  503. this.box = null;
  504. }
  505. this.hasBox = this.info.hasBox = state;
  506. }
  507. /* getSizeByScale() {
  508. return {
  509. width: settings.defaultOverlaySize[0] * this.scale.x,
  510. height: settings.defaultOverlaySize[1] * this.scale.y
  511. }
  512. }
  513. getScaleBySize(width, height) {
  514. return {
  515. x: width / settings.defaultOverlaySize[0],
  516. y: height / settings.defaultOverlaySize[1],
  517. }
  518. }*/
  519. setVisiblePanos(visibleData) {
  520. if (visibleData) this.info.visiblePanos = visibleData;
  521. else if (!this.info.visiblePanos) this.getVisiblePanos();
  522. }
  523. getVisiblePanos() {
  524. //在不同点还不一样
  525. var depth = this.hasBox ? this.scale.z : 0;
  526. var width = this.scale.x,
  527. height = this.scale.y;
  528. var cornerPoint;
  529. if (this.plane) {
  530. cornerPoint = [
  531. new THREE.Vector3(0, 0, depth),
  532. new THREE.Vector3(-width / 2, height / 2, depth),
  533. new THREE.Vector3(width / 2, height / 2, depth),
  534. new THREE.Vector3(width / 2, -height / 2, depth),
  535. new THREE.Vector3(-width / 2, -height / 2, depth),
  536. ];
  537. } else {
  538. var bound = new THREE.Box3().copy(this.info.modelBound.bound);
  539. var center = bound.center();
  540. cornerPoint = [
  541. new THREE.Vector3(center.x, center.y, center.z),
  542. new THREE.Vector3(bound.min.x, bound.min.y, bound.min.z),
  543. new THREE.Vector3(bound.min.x, bound.min.y, bound.max.z),
  544. new THREE.Vector3(bound.min.x, bound.max.y, bound.min.z),
  545. new THREE.Vector3(bound.max.x, bound.min.y, bound.min.z),
  546. new THREE.Vector3(bound.max.x, bound.max.y, bound.min.z),
  547. new THREE.Vector3(bound.max.x, bound.min.y, bound.max.z),
  548. new THREE.Vector3(bound.min.x, bound.max.y, bound.max.z),
  549. new THREE.Vector3(bound.max.x, bound.max.y, bound.max.z),
  550. ];
  551. }
  552. var getPos = (position) => {
  553. //每个overlay位置对应5个坐标,plane中心和四个角的位置
  554. if (this.plane) {
  555. return cornerPoint.map((e) => {
  556. return e.clone().applyEuler(this.info.rotation).add(position);
  557. });
  558. } else {
  559. var matrixWorld = new THREE.Matrix4().compose(
  560. position,
  561. this.quaternion,
  562. this.scale
  563. );
  564. matrixWorld.multiplyMatrices(matrixWorld, this.mesh.matrix);
  565. return cornerPoint.map((e) => {
  566. return e.clone().applyMatrix4(matrixWorld);
  567. });
  568. }
  569. };
  570. this.info.visiblePanos = [];
  571. var customPositions = getPos(this.info.position);
  572. var posAtPanos = {};
  573. for (let panoId in this.info.transformAtPanos) {
  574. if (panoId == "outSide") continue;
  575. posAtPanos[panoId] = getPos(this.info.transformAtPanos[panoId].pos);
  576. }
  577. let maxCount = browser.isMobile() ? 2000 : 5000;
  578. let possiblePanos = model.panos.list;
  579. if (this.plane) {
  580. //目前都是单面,所以只要可以看到的一面的热点
  581. let dir1 = new THREE.Vector3(0, 0, -1)
  582. .applyQuaternion(this.quaternion)
  583. .negate();
  584. possiblePanos = possiblePanos.filter((pano) => {
  585. let dir2 = new THREE.Vector3()
  586. .subVectors(pano.position, this.position)
  587. .normalize();
  588. return dir1.dot(dir2) > 0;
  589. });
  590. }
  591. let c = model.panos.list.length * model.colliders.length;
  592. if (window.isEdit || c < maxCount) {
  593. //编辑页面保险起见还是全部算完后才可浏览,就能保证保存全部的visiblePano
  594. this.info.visiblePanos = common.getVisiblePano(
  595. customPositions,
  596. possiblePanos,
  597. {
  598. model: model.colliders,
  599. posAtPanos,
  600. }
  601. );
  602. } else {
  603. let start = 0;
  604. let interval = setInterval(() => {
  605. let end = start + Hot.visiPanosCountSlice;
  606. end = Math.min(end, possiblePanos.length);
  607. let i = start;
  608. start = end;
  609. let panos = possiblePanos.slice(i, end);
  610. this.info.visiblePanos = this.info.visiblePanos.concat(
  611. common.getVisiblePano(customPositions, panos, {
  612. model: model.colliders,
  613. posAtPanos,
  614. })
  615. );
  616. if (end >= possiblePanos.length) {
  617. //console.log(window.hotsi ?(++window.hotsi): (window.hotsi = 1))
  618. clearInterval(interval);
  619. }
  620. }, Hot.visiEveryDurSlice); // visiEveryDurSlice 等在main中定义
  621. }
  622. }
  623. updateVisible(panos, visibility) {
  624. if (window.isEdit && editTool.hotpoint.editSpot == this) {
  625. return (this.visible = true);
  626. }
  627. this.visible =
  628. visibility != void 0
  629. ? visibility
  630. : !this.info.visiblePanos ||
  631. !!panos.find((pano) => this.info.visiblePanos.includes(pano.id));
  632. this.titleElem && this.titleElem.setVisible(this.visible, "hotVisible");
  633. if (this.texType == "video") {
  634. //this.switchPlay(this.visible, this.visible ? null : 'stop' );//可见时不操作;不可见时停止
  635. this.update(player);
  636. }
  637. }
  638. getBoundOri() {
  639. let bound;
  640. if (this.objObject) {
  641. bound = new THREE.Box3().copy(this.info.modelBound.bound);
  642. } else {
  643. bound = planeBound.clone();
  644. }
  645. return bound;
  646. }
  647. getCornerPoint() {
  648. //获取在每个漫游点上的视觉边界点 可以打开boxHelper和addBall来观测是否准确
  649. if (this.cornerPoints[player.currentPano.id]) {
  650. return this.cornerPoints[player.currentPano.id];
  651. } else {
  652. var boundPoint, cornerPoint;
  653. var center; //中心点
  654. if (this.plane) {
  655. center = this.plane.getWorldPosition();
  656. boundPoint = [
  657. new THREE.Vector3(-0.5, 0.5, 0),
  658. new THREE.Vector3(0.5, 0.5, 0),
  659. new THREE.Vector3(0.5, -0.5, 0),
  660. new THREE.Vector3(-0.5, -0.5, 0),
  661. ];
  662. } else {
  663. var bound = new THREE.Box3().copy(this.info.modelBound.bound);
  664. boundPoint = [
  665. new THREE.Vector3(bound.min.x, bound.min.y, bound.min.z),
  666. new THREE.Vector3(bound.min.x, bound.min.y, bound.max.z),
  667. new THREE.Vector3(bound.min.x, bound.max.y, bound.min.z),
  668. new THREE.Vector3(bound.max.x, bound.min.y, bound.min.z),
  669. new THREE.Vector3(bound.max.x, bound.max.y, bound.min.z),
  670. new THREE.Vector3(bound.max.x, bound.min.y, bound.max.z),
  671. new THREE.Vector3(bound.min.x, bound.max.y, bound.max.z),
  672. new THREE.Vector3(bound.max.x, bound.max.y, bound.max.z),
  673. ];
  674. }
  675. var maxLon = -Infinity;
  676. var minLon = +Infinity;
  677. var maxLat = -Infinity;
  678. var minLat = +Infinity;
  679. var pos1 = player.currentPano.position.clone();
  680. center = this.position.clone(); //模型bound的中心点已经位移到了hot中心点。 注意不能用getWorldPosition,得到的会是偏移的
  681. var dir = center.clone().sub(pos1).normalize();
  682. var centerDirInfo = {};
  683. player.cameraControls.controls.panorama.lookAt.call(
  684. centerDirInfo,
  685. null,
  686. dir
  687. );
  688. boundPoint.forEach((e) => {
  689. //lon左右
  690. var point = e.applyMatrix4(this.mesh.matrixWorld);
  691. var dir = point.clone().sub(pos1).normalize();
  692. var dirInfo = {};
  693. player.cameraControls.controls.panorama.lookAt.call(
  694. dirInfo,
  695. null,
  696. dir
  697. );
  698. var diffLon = (dirInfo.lon - centerDirInfo.lon) % 360;
  699. if (Math.abs(diffLon) > 180) {
  700. //因为有时需要根据符号判断是在中心的左边还是右边,所以限制在180内
  701. diffLon += diffLon > 0 ? -360 : 360;
  702. }
  703. var diffLat = dirInfo.lat - centerDirInfo.lat;
  704. maxLon = Math.max(diffLon, maxLon);
  705. minLon = Math.min(diffLon, minLon);
  706. maxLat = Math.max(diffLat, maxLat);
  707. minLat = Math.min(diffLat, minLat);
  708. });
  709. var diffLon = maxLon - minLon;
  710. var diffLat = maxLat - minLat;
  711. if (diffLat > 180) {
  712. //可能是到了反面。不好算,直接返回所有boundPoint
  713. cornerPoint = boundPoint;
  714. } else {
  715. //读取lon lat的最大最小值,勾勒出一个没有倾斜的矩形 。它比boundPoint看起来范围更大些
  716. maxLon = maxLon + centerDirInfo.lon;
  717. maxLat = maxLat + centerDirInfo.lat;
  718. minLon = minLon + centerDirInfo.lon;
  719. minLat = minLat + centerDirInfo.lat;
  720. var dirs = [
  721. math.getDirByLonLat(maxLon, maxLat),
  722. math.getDirByLonLat(minLon, minLat),
  723. math.getDirByLonLat(maxLon, minLat),
  724. math.getDirByLonLat(minLon, maxLat),
  725. ];
  726. cornerPoint = dirs.map((e) => {
  727. return e.clone().add(pos1);
  728. });
  729. cornerPoint = [center, ...cornerPoint]; //最后增加一个中心点
  730. }
  731. /* if(this.objObject){
  732. cornerPoint = [pos2, ...cornerPoint]
  733. } */
  734. //addPoints(cornerPoint)
  735. this.cornerPoints[player.currentPano.id] = {
  736. cornerPoint,
  737. diffLon,
  738. diffLat,
  739. };
  740. return this.cornerPoints[player.currentPano.id];
  741. }
  742. }
  743. getMediaSize() {
  744. let size = new THREE.Vector2();
  745. if (this.texMedia) {
  746. if (this.texType == "photo") {
  747. size.x = this.texMedia.width;
  748. size.y = this.texMedia.height;
  749. //动画的话再变
  750. if (this.info.animateInfo) {
  751. size.x /= this.info.animateInfo.cellXcount;
  752. size.y /= this.info.animateInfo.cellYcount;
  753. }
  754. } else {
  755. size.x = this.texMedia.videoWidth || this.videoWidth;
  756. size.y = this.texMedia.videoHeight || this.videoHeight;
  757. }
  758. }
  759. return size;
  760. }
  761. inSight() {
  762. //return true
  763. if (window.isEdit) return true; // 太容易move了
  764. if (player.mode == "panorama" && player.currentPano) {
  765. if (!player.camera) return;
  766. var cornerPointInfo = this.getCornerPoint();
  767. var cornerPoint;
  768. let min = new THREE.Vector2(5, 5);
  769. let scaleRatio = 1 / player.zoomLevel;
  770. //根据media原始大小来调整阈值: media的原始大小能代表期望显示的大小,如果显示大小的远小于期望大小,就不显示(此时能感受到贴图锯齿严重,清晰度被浪费)。比如如果gif是一个很小的按钮,即使diffLon很小也要显示。缺点:需要用户根据所需上传合适清晰度的图。
  771. let size = this.getMediaSize();
  772. if (size.x > 0) {
  773. scaleRatio *= Math.sqrt(size.x * size.y) / 1000;
  774. }
  775. min.multiplyScalar(scaleRatio);
  776. if (
  777. cornerPointInfo.diffLon < min.x ||
  778. cornerPointInfo.diffLat < min.y
  779. ) {
  780. //console.log('two far and small')
  781. return false;
  782. }
  783. if (cornerPointInfo.diffLon < 15 && cornerPointInfo.diffLat < 15) {
  784. //当很小的时候,只判断中心点即可
  785. cornerPoint = [cornerPointInfo.cornerPoint[0]];
  786. } else {
  787. cornerPoint = cornerPointInfo.cornerPoint;
  788. }
  789. for (let i = 0, j = cornerPoint.length; i < j; i++) {
  790. //只要有一点可见就算看见
  791. var pos2d = math.getPos2d(
  792. cornerPoint[i],
  793. player.camera,
  794. $("#player")[0]
  795. );
  796. if (pos2d.trueSide && pos2d.inSight) return true;
  797. }
  798. } else {
  799. //飞出 只判断在不在画面内
  800. //return playVideoWhenFlyOut//true
  801. let frustumMatrix = new THREE.Matrix4();
  802. frustumMatrix.multiplyMatrices(
  803. player.camera.projectionMatrix,
  804. player.camera.matrixWorldInverse
  805. );
  806. let frustum = new THREE.Frustum();
  807. frustum.setFromMatrix(frustumMatrix);
  808. let bound = this.getBoundOri();
  809. bound.applyMatrix4(this.matrixWorld);
  810. return frustum.intersectsBox(bound);
  811. }
  812. }
  813. update(player) {
  814. if (this.info.isSprite) {
  815. this.quaternion.copy(player.camera.quaternion);
  816. }
  817. this.updateScale();
  818. this.updateTitle();
  819. }
  820. updateScale(e, t) {
  821. //自适应调节大小
  822. if (!DATA.autoAdjustHotScale || this.texType != "shine" || !this.plane)
  823. return;
  824. var scale = convertTool.getScaleForConstantSize(
  825. $.extend({}, autoSizeInfo, {
  826. position: this.position.clone(),
  827. })
  828. );
  829. this.plane.scale.set(scale, scale, scale);
  830. }
  831. switchPlay(state) {
  832. //手动播放暂停
  833. this.pausedByUser = !state;
  834. this.videoControl(state);
  835. }
  836. loadVideo(video) {
  837. if (video.src_) return;
  838. video.src = video.src_ = manage.dealURL(this.info.texSrc);
  839. }
  840. videoControl(state) {
  841. if (this.texType != "video" || !this.material_.map) return;
  842. var video = this.texMedia;
  843. this.shouldPlay = state;
  844. if (!state || state == "stop") {
  845. if (!video.paused) {
  846. video.pause();
  847. console.log({ str: "paused " + this.sid, level: 1 });
  848. }
  849. /* video.lastCurTime = state == 'stop' ? 0 : video.currentTime //记录
  850. video.src = video.src_ = '' */
  851. if (state == "stop") {
  852. video.currentTime = 0;
  853. }
  854. } else if (state) {
  855. if (/* !isVideoPlayed(video) */ video.paused) {
  856. console.log({
  857. str: "videoControl play " + ", " + this.sid,
  858. level: 1,
  859. });
  860. this.loadVideo(video);
  861. video.play();
  862. //video.currentTime = video.lastCurTime || 0
  863. this.changeOpaWhenPlay(video);
  864. if (isVideoPlayed(video))
  865. console.log({
  866. str: "played " + this.sid + video.duration,
  867. level: 1,
  868. });
  869. }
  870. }
  871. }
  872. changeOpaWhenPlay(video) {
  873. //当播放成功后,恢复为不透明
  874. if (isNaN(video.duration)) {
  875. //未加载好
  876. return setTimeout(() => {
  877. this.changeOpaWhenPlay(video);
  878. }, 100);
  879. }
  880. const minPlayedTime = Math.min(video.duration / 10, 0.1); //到这个时间说明加载成功
  881. if (!video.hasInitedOpacity) {
  882. setTimeout((e) => {
  883. //console.log('trychangeOpa ',this.sid,video.currentTime)
  884. if (video.currentTime > minPlayedTime) {
  885. this.material_.opacity = 1;
  886. video.hasInitedOpacity = true;
  887. //console.log('changeOpaWhenPlay',this.sid)
  888. } else {
  889. if (!video.paused) {
  890. //再次尝试
  891. return setTimeout(() => {
  892. this.changeOpaWhenPlay(video);
  893. }, 500);
  894. }
  895. }
  896. }, minPlayedTime * 1000 + 500);
  897. }
  898. }
  899. /* setDefaultHotScale = function(){//设置成默认热点大小
  900. var w = DATA.hotIconScale) * g_HotMeshSize.g_HotMeshWidth
  901. this.scale.set( w, w, this.scale.z)
  902. } */
  903. setTitleElem() {
  904. const hotlist = window.i18n.t("hotlist");
  905. var title =
  906. hotlist.find((item) => item.value === this?.info.title)?.title ||
  907. this.info.title;
  908. // var title = localStorage.getItem('locale') + this.info.title
  909. // console.log(currentHotlist, 'ppppxxxxxxxxxxxx')
  910. if (title) {
  911. if (!this.titleElem) {
  912. this.titleElem = new Label2D({
  913. position: this.position,
  914. innerHTML: `<div>${title}</div>`,
  915. domElement: $("#hot")[0],
  916. shelterByModel: true,
  917. });
  918. } else {
  919. this.titleElem.elem.html(`<div>${title}</div>`);
  920. }
  921. this.titleElem.setVisible(this.visible, "hotVisible");
  922. this.setHoverState(false);
  923. this.setTitleDir();
  924. } else {
  925. if (this.titleElem) {
  926. this.titleElem.dispose();
  927. this.titleElem = null;
  928. }
  929. }
  930. }
  931. setTitleDir() {
  932. this.titleElem && this.titleElem.elem.attr("pos", this.info.titlePos);
  933. }
  934. updateTitle() {
  935. this.titleElem && this.titleElem.update();
  936. }
  937. setHoverState(state) {
  938. if (!this.titleElem) return;
  939. this.hovered = !!state;
  940. var v =
  941. this.info.titleShowType != "unvisible" &&
  942. (this.info.titleShowType == "always" || this.hovered);
  943. this.titleElem.setVisible(v, "hoveredVisi");
  944. //this.updateTitle()
  945. }
  946. closestPanoTowardTag(e, t) {
  947. var i = [],
  948. n = [],
  949. r = this.mesh.getWorldPosition();
  950. if (e === "panorama") {
  951. /* var o = t.position.clone().sub(r).normalize();
  952. n.push(function(t, i) {//scoreFunctions.direction 最好这个漫游点在currentPano到热点之间的路径上。但是这样的话可能就看不到热点正面,所以删掉
  953. return function(e) {
  954. return e.position.clone().sub(t).normalize().dot(i) * window._settings.navigation.directionFactor
  955. }}(r, o)
  956. ) */
  957. }
  958. var a = new THREE.Vector3();
  959. i.push(
  960. function (e) {
  961. return (
  962. Math.abs(e.position.x - r.x) >
  963. window._settings.tags.visibility.cameraClearance ||
  964. Math.abs(e.position.z - r.z) >
  965. window._settings.tags.visibility.cameraClearance
  966. );
  967. },
  968. function (e) {
  969. a.copy(r).sub(e.position);
  970. var t = -THREE.Math.radToDeg(
  971. Math.atan(a.y / Math.sqrt(a.x * a.x + a.z * a.z))
  972. ),
  973. i = window._settings.tags.navigate.tiltTolerance;
  974. return (
  975. window._settings.insideLookLimitDown - i < t &&
  976. t < window._settings.insideLookLimitUp + i
  977. );
  978. },
  979. (pano) => {
  980. // add
  981. return player.checkHasNeighbor(pano);
  982. },
  983. (pano) => {
  984. // add
  985. // 周恩光改 解决visiblePanos为undefined时的bug
  986. return (
  987. !this.info.visiblePanos || this.info.visiblePanos.includes(pano.id)
  988. );
  989. }
  990. );
  991. n.push(
  992. (function (hot, i) {
  993. //scoreFunctions.distanceSquared
  994. return function (pano) {
  995. //i = a.navigation.distanceFactor
  996. return hot ? hot.position.distanceToSquared(pano.position) * i : 0;
  997. };
  998. })(this, -2),
  999. (pano) => {
  1000. //尽量正对hot
  1001. let dir = new THREE.Vector3(0, 0, 1).applyQuaternion(this.quaternion);
  1002. let dir2 = new THREE.Vector3()
  1003. .subVectors(pano.position, this.position)
  1004. .normalize();
  1005. let s = dir.dot(dir2) * 60;
  1006. //console.log(pano.id + ":" + s)
  1007. return s;
  1008. }
  1009. );
  1010. /* var tanD = player.domElement.clientWidth / player.domElement.clientHeight * Math.tan((THREE.Math.degToRad(player.zoomFov/2))) ;
  1011. var goodDistance = overlay.width / 2 / tanD;
  1012. n.push(
  1013. function (pano) { //寻找正对着overlay的pano
  1014. var overlayDir = new THREE.Vector3(0,0,1).applyQuaternion(overlay.quaternion)
  1015. var v1 = overlayDir//.setY(0); 朝上的话set0会得到0,0,0 无法求angle
  1016. var v2 = pano.position.clone().sub(overlay.position)//.setY(0)
  1017. var angle = v1.angleTo(v2)
  1018. angles[pano.id] = angle;
  1019. angle = -angle * 100
  1020. return angle
  1021. },
  1022. function (pano) { //寻找正对着overlay的pano
  1023. var dis = pano.position.clone().distanceToSquared(overlay.position)
  1024. var goodDistance2 = goodDistance * Math.abs(Math.cos(angles[pano.id]))//考虑了倾斜角度后的最佳距离
  1025. var result = - 300 * Math.abs(dis-goodDistance2) / goodDistance2 //dis和goodDistance2差距越大分数越低
  1026. return result;
  1027. }
  1028. ) */
  1029. var s = t.model.panos.sortByScore(i, n);
  1030. console.log(s);
  1031. return s && 0 < s.length && s[0].item;
  1032. }
  1033. examine(options = {}) {
  1034. console.log("xxxxxxxxxxx", this.info.title);
  1035. window.selectedHotTitle = this.info.title;
  1036. var openHot =
  1037. this.info.link && this.info.actionType.openHot && !options.dontOpen;
  1038. var fastTran =
  1039. !options.dontFastTran &&
  1040. (this.info.actionType.fastTran ||
  1041. settings.hotFastTran ||
  1042. options.fastTran);
  1043. if (fastTran) {
  1044. //瞬间过渡 1到固定方位 2到和普通过渡一样的位置,也就是最适合的位置
  1045. let info = this.info.cameraData;
  1046. if (info) {
  1047. player.blackToPano({
  1048. pano: player.model.panos.index[info.pano.uuid],
  1049. quaternion: new THREE.Quaternion().fromArray(
  1050. info.camera.quaternion
  1051. ),
  1052. });
  1053. }
  1054. }
  1055. var needExamine =
  1056. !fastTran &&
  1057. (options.examine ||
  1058. (!settings.dontExamHot && this.info.actionType.examine));
  1059. if (!openHot && !needExamine) return;
  1060. if (
  1061. openHot &&
  1062. this.info.linkType != "common" &&
  1063. this.info.iframe &&
  1064. this.info.iframe[0]
  1065. ) {
  1066. var src = getLink(this.info.iframe[0]);
  1067. if (this.info.linkType == "jumpLink") {
  1068. var newPage = window.open(src, "_blank");
  1069. newPage.focus();
  1070. } else if (this.info.linkType == "iframeDiv") {
  1071. var div = document.createElement("div");
  1072. div.style.position = "fixed";
  1073. div.style.width = div.style.height = "100%";
  1074. div.style.left = div.style.top = "0";
  1075. div.style["z-index"] = "999";
  1076. var exit = document.createElement("div");
  1077. // exit.style["background-image"] = "url(images/vrOffImg.png)";
  1078. exit.style.position = "absolute";
  1079. exit.style.width = exit.style.height = "50px";
  1080. exit.style.left = "17px";
  1081. exit.style.top = "20px";
  1082. exit.style.cursor = "pointer";
  1083. exit.style["background-repeat"] = "no-repeat";
  1084. exit.style["background-size"] = "25%";
  1085. exit.style["background-position"] = "center center";
  1086. exit.style["background-color"] = "rgba(0, 0, 0, 0.2)";
  1087. exit.style["border-radius"] = "50%";
  1088. exit.style["z-index"] = "3";
  1089. exit.onclick = () => {
  1090. $(div).remove();
  1091. Hot.closePopup();
  1092. };
  1093. var myElement = document.createElement("iframe");
  1094. myElement.style.position = "absolute";
  1095. myElement.style.width = myElement.style.height = "100%";
  1096. myElement.style.left = myElement.style.top = "0";
  1097. myElement.src = src;
  1098. $("body").append(div);
  1099. div.appendChild(exit);
  1100. div.appendChild(myElement);
  1101. SoundManager.play("hot");
  1102. }
  1103. return;
  1104. }
  1105. if (!player.currentPano) return;
  1106. var popup = document.getElementById("popup");
  1107. if (openHot) {
  1108. (g_currentHot = this),
  1109. (popup.style.display = "block"),
  1110. popup.classList.add("wait");
  1111. var n = document.createElement("iframe");
  1112. SoundManager.play("hot");
  1113. var src = getLink(this.info.link);
  1114. n.src = src;
  1115. (n.id = "id1"), (n.allowTransparency = "true");
  1116. n.allowFullscreen = "true";
  1117. var a = document.getElementById("id1");
  1118. if (void 0 === a || null == a) {
  1119. document.querySelector(".popup-content").appendChild(n);
  1120. var s = !1;
  1121. (window.loaddingSuccess = function () {
  1122. s = !0;
  1123. }),
  1124. setTimeout(function e() {
  1125. if (s) {
  1126. var t = document.querySelector("#id1").contentWindow.document;
  1127. t.querySelector("video") &&
  1128. (t.querySelector("video").play(),
  1129. !t.querySelector("video").paused &&
  1130. t.querySelector(".playPause") &&
  1131. t.querySelector(".playPause").classList.add("fa-pause")),
  1132. t.querySelector("audio") && t.querySelector("audio").play();
  1133. } else setTimeout(e, 300);
  1134. }, 800);
  1135. }
  1136. }
  1137. var done = function () {
  1138. player.flyingToTag = !1;
  1139. openHot && popup.classList.remove("wait");
  1140. }.bind(this);
  1141. if (!needExamine) {
  1142. done();
  1143. return;
  1144. }
  1145. var c =
  1146. this.closestPanoTowardTag(player.mode, player.currentPano) ||
  1147. player.currentPano,
  1148. h = this.mesh.getWorldPosition();
  1149. player.flyingToTag = !0;
  1150. if (player.mode === "panorama") {
  1151. var d = {
  1152. pano: c,
  1153. lookAtPoint: h,
  1154. duration: options.duration,
  1155. maxDistanceOverride: null,
  1156. skipWarpingCheck: !1,
  1157. aimDuration: options.aimDuration,
  1158. };
  1159. if (fastTran) {
  1160. let f = new THREE.Matrix4().lookAt(
  1161. c.position,
  1162. h,
  1163. new THREE.Vector3(0, 1, 0)
  1164. );
  1165. let quaternion = new THREE.Quaternion().setFromRotationMatrix(f);
  1166. player.blackToPano({
  1167. pano: c,
  1168. quaternion,
  1169. });
  1170. done();
  1171. } else {
  1172. player.flyToPano(d, done);
  1173. }
  1174. } else {
  1175. var p = {
  1176. pano: c,
  1177. };
  1178. if (h) {
  1179. var f = new THREE.Matrix4().lookAt(
  1180. c.position,
  1181. h,
  1182. new THREE.Vector3(0, 1, 0)
  1183. );
  1184. p.quaternion = new THREE.Quaternion().setFromRotationMatrix(f);
  1185. }
  1186. (p.callback = done),
  1187. (p.duration = options.duration || 1500),
  1188. (p.mode = "panorama"),
  1189. (p.aimDuration = options.aimDuration);
  1190. player.flyToNewMode(p);
  1191. }
  1192. }
  1193. addModel(object) {
  1194. if (this.objObject) {
  1195. this.remove(this.objObject);
  1196. }
  1197. this.objObject = object;
  1198. /* object.traverse((mesh)=>{
  1199. if(mesh.material && mesh.type == "hotSprite"){
  1200. mesh.material = this.material_;
  1201. }
  1202. }) */
  1203. object.name = this.info.objName;
  1204. object.src = this.info.objSrc;
  1205. this.info.hasBox = false;
  1206. this.addBox(false);
  1207. this.remove(this.plane);
  1208. this.plane = null;
  1209. this.setMesh(this.objObject);
  1210. //this.adjustModelAuto()
  1211. if (this.info.modelBound) {
  1212. //应该不会改变
  1213. var s = this.info.modelBound.scaleRatio;
  1214. this.mesh.scale.set(s, s, s);
  1215. this.mesh.position.fromArray(this.info.modelBound.position);
  1216. this.mesh.modelBound = this.info.modelBound;
  1217. }
  1218. this.material_.side = THREE.FrontSide;
  1219. this.changeBoxHelperDisplay(false);
  1220. //this.mesh.boxHelper.visible = true
  1221. }
  1222. addPlane() {
  1223. //换成plane
  1224. if (this.plane) return;
  1225. this.plane = new THREE.Mesh(_planeGeometry, this.material_);
  1226. this.remove(this.objObject);
  1227. this.objObject = null;
  1228. delete this.info.objSrc;
  1229. delete this.info.objName;
  1230. delete this.info.modelBound;
  1231. this.setMesh(this.plane);
  1232. //this.material_.side = THREE.DoubleSide //双面的话飞出来会看到悬空的
  1233. }
  1234. setMesh(mesh) {
  1235. this.mesh = mesh;
  1236. this.add(this.mesh);
  1237. this.changeMaterial(this.material_); //re applyTo every mesh
  1238. this.mesh.traverse((mesh) => {
  1239. mesh.type = "hotSprite"; //raycaster use
  1240. mesh.renderOrder = 3;
  1241. });
  1242. if (!this.mesh.boxHelper) {
  1243. var boxHelper = this.mesh.children.find(
  1244. (e) => e instanceof THREE.Box3Helper
  1245. );
  1246. if (boxHelper) {
  1247. this.mesh.boxHelper = boxHelper;
  1248. } else {
  1249. var bound = this.getBoundOri();
  1250. bound.expandByVector(new THREE.Vector3(0.0001, 0.0001, 0.0001));
  1251. this.mesh.boxHelper = new THREE.Box3Helper(
  1252. bound,
  1253. new THREE.Color("#00ffff")
  1254. );
  1255. this.mesh.add(this.mesh.boxHelper);
  1256. this.mesh.boxHelper.material.depthTest = false;
  1257. this.mesh.boxHelper.material.transparent = true;
  1258. this.mesh.boxHelper.visible = false;
  1259. }
  1260. }
  1261. }
  1262. changeBoxHelperDisplay(show) {
  1263. if (show) {
  1264. this.visible_ = this.visible;
  1265. this.visible = true;
  1266. this.mesh.boxHelper.visible = true;
  1267. } else {
  1268. if (this.visible_ != void 0) {
  1269. this.visible = this.visible_;
  1270. }
  1271. this.mesh.boxHelper.visible = false;
  1272. }
  1273. }
  1274. /* addToLoadQueue() {
  1275. if (this.texType == 'photo') {
  1276. Hot.loadQueue.includes(this) || Hot.loadQueue.push(this)
  1277. }
  1278. } */
  1279. requestDownload(type, callback) {
  1280. var plane = this.plane;
  1281. if (type == "photo") {
  1282. if (this.photoHasRequestLoad || this.texType != "photo") {
  1283. return; //为什么之前1191需要在这加callback() 才能呢。现在又没事了
  1284. }
  1285. //console.log(' beginDownload : ' + this.sid)
  1286. /* this.material_.map = */ Texture.load(this.info.texSrc, (tex) => {
  1287. callback && callback();
  1288. if (!tex.image) {
  1289. return; //只是单纯用了相同src的tex,但image仍未加载完
  1290. }
  1291. if (!this._loadDones) {
  1292. return;
  1293. }
  1294. dealMap(tex);
  1295. setTimeout(Hot.loadNext, 50);
  1296. hotGroup.children.forEach((e) => {
  1297. if (e.info.texSrc == this.info.texSrc && e.info.texType == type) {
  1298. e.material_.color.set("#FFFFFF");
  1299. e.material_.opacity = 1;
  1300. //console.log('overlay loaded: ' + e.sid + " - " + this.info.texSrc.split('/').pop());
  1301. e.texMedia = tex.image;
  1302. {
  1303. //animation不同致使的不能使用同一个texture
  1304. if (window.isEdit) {
  1305. if (animateTexSrcs[e.info.texSrc]) {
  1306. e.material_.map = tex.clone(); //编辑动画直接不用一个texture, 故而animation也不同
  1307. e.material_.map.needsUpdate = true;
  1308. } else {
  1309. e.material_.map = tex;
  1310. animateTexSrcs[e.info.texSrc] = 1;
  1311. }
  1312. } else {
  1313. if (animateTexSrcs[e.info.texSrc]) {
  1314. //已有该texSrc
  1315. let finded = false;
  1316. for (let i of animateTexSrcs[e.info.texSrc]) {
  1317. if (ifSame(i[0], e.info.animateInfo)) {
  1318. e.material_.map = i[1];
  1319. finded = true;
  1320. break;
  1321. }
  1322. }
  1323. if (!finded) {
  1324. let tex_ = tex.clone();
  1325. tex_.needsUpdate = true; //clone后不写这句会黑块
  1326. animateTexSrcs[e.info.texSrc].set(
  1327. e.info.animateInfo,
  1328. tex_
  1329. );
  1330. e.material_.map = tex_;
  1331. }
  1332. } else {
  1333. let object = new Map();
  1334. object.set(e.info.animateInfo, tex);
  1335. animateTexSrcs[e.info.texSrc] = object; //注册第一个texSrc
  1336. e.material_.map = tex;
  1337. }
  1338. }
  1339. }
  1340. if (e.info.animateInfo && !e.animation) {
  1341. e.animation = GifTexDeal.addAnimation(
  1342. e.material_.map,
  1343. e,
  1344. e.info.animateInfo,
  1345. e.sid
  1346. );
  1347. e.visible && e.inSight() && GifTexDeal.start(e.animation);
  1348. }
  1349. if (++photoLoaded == originPhotoCount) {
  1350. //data2.js中的所有photo加载完毕
  1351. Hot.allPhotoLoaded = true;
  1352. Hot.whenAllFileLoaded &&
  1353. Hot.allModelLoaded &&
  1354. Hot.whenAllFileLoaded();
  1355. }
  1356. {
  1357. e._loadDones.forEach((a) => a());
  1358. e._loadDones = null;
  1359. //e.photoHasRequestLoad = true //这句不能加,否则会无法执行callback
  1360. }
  1361. e.material_.needsUpdate = true;
  1362. }
  1363. });
  1364. });
  1365. this.photoHasRequestLoad = true;
  1366. } else if (type == "model") {
  1367. if (this.modelHasRequestLoad || !this.info.objSrc) return;
  1368. //需要处理重复?
  1369. objLoader.load(this.info.objSrc, (object) => {
  1370. this.remove(this.mesh);
  1371. this.addModel(object);
  1372. callback && callback();
  1373. if (++modelLoaded == originModelCount) {
  1374. //data2.js中的所有photo加载完毕
  1375. Hot.allModelLoaded = true;
  1376. Hot.whenAllFileLoaded &&
  1377. Hot.allPhotoLoaded &&
  1378. Hot.whenAllFileLoaded();
  1379. }
  1380. });
  1381. this.modelHasRequestLoad = true;
  1382. }
  1383. }
  1384. dispose() {
  1385. this.parent.remove(this);
  1386. this.titleElem && this.titleElem.dispose();
  1387. delete player.model.hots[this.sid];
  1388. }
  1389. }
  1390. Hot.updateVisibles = function (panos) {
  1391. //只显示没被遮挡的,否则会卡
  1392. if (panos === true) {
  1393. model.hotGroup.children.forEach((e) => e.updateVisible(null, true));
  1394. } else {
  1395. model.hotGroup.children.forEach((e) => e.updateVisible(panos));
  1396. }
  1397. };
  1398. Hot.beginShineHot = function () {
  1399. if (!window.isEdit && shineMats.length == 0) return;
  1400. transitions.trigger({
  1401. func: function (e) {
  1402. var opa = e <= 0.5 ? 2 * e : -2 * e + 2;
  1403. shineMats.forEach((mat) => {
  1404. mat.uniforms.opac.value = opa;
  1405. });
  1406. },
  1407. cycling: !0,
  1408. duration: 3e3,
  1409. name: "hotShine",
  1410. });
  1411. };
  1412. Hot.getDefaulScale = function (hotIconScale) {
  1413. return (hotIconScale || DATA.hotIconScale) * g_HotMeshSize.g_HotMeshWidth;
  1414. };
  1415. var loadings = [];
  1416. Hot.loadQueue = []; //等待下载的overlay,目前只针对photo
  1417. Hot.maxLoadingCount = 3; //同时正在load图片的数量
  1418. Hot.loadNext = () => {
  1419. //继续requestDownload loadQueue中前排的item
  1420. let count = Hot.maxLoadingCount - loadings.length;
  1421. Hot.loadQueue.slice(0, count).forEach((e) => {
  1422. loadings.push(e);
  1423. //console.log('requestDownload', e.hot.info.texSrc)
  1424. e.hot.requestDownload(e.type, () => {
  1425. var i = loadings.indexOf(e);
  1426. //console.log('requestDownloaded index', i)
  1427. i > -1 && loadings.splice(i, 1);
  1428. });
  1429. });
  1430. Hot.loadQueue.splice(0, count);
  1431. };
  1432. Hot.getNeedLoad = function () {
  1433. //计算获取loadQueue,每次都重新计算,覆盖旧的
  1434. if (!player || !player.domElement || !player.mode) return;
  1435. var hots1, hots2;
  1436. if (player.mode != "panorama") {
  1437. if (Hot.loadQueue.length == 0) {
  1438. hots1 = model.hotGroup.children.filter(
  1439. (e) => e.texType == "photo" && !e.photoHasRequestLoad
  1440. );
  1441. hots2 = model.hotGroup.children.filter(
  1442. (e) => e.info.objSrc && !e.modelHasRequestLoad
  1443. );
  1444. Hot.loadQueue = hots1
  1445. .map((e) => {
  1446. return { hot: e, type: "photo" };
  1447. })
  1448. .concat(
  1449. hots2.map((e) => {
  1450. return { hot: e, type: "model" };
  1451. })
  1452. );
  1453. }
  1454. return;
  1455. }
  1456. //Hot.loadWhenOutside = true
  1457. hots1 = model.hotGroup.children.filter(
  1458. (e) =>
  1459. e.texType == "photo" &&
  1460. !e.photoHasRequestLoad &&
  1461. (!e.info.visiblePanos ||
  1462. e.info.visiblePanos.includes(player.currentPano.id))
  1463. );
  1464. hots2 = model.hotGroup.children.filter(
  1465. (e) =>
  1466. e.info.objSrc &&
  1467. !e.modelHasRequestLoad &&
  1468. (!e.info.visiblePanos ||
  1469. e.info.visiblePanos.includes(player.currentPano.id))
  1470. );
  1471. if (hots1.length + hots2.length == 0) {
  1472. hots1 = model.hotGroup.children.filter(
  1473. (e) => e.texType == "photo" && !e.photoHasRequestLoad
  1474. );
  1475. hots2 = model.hotGroup.children.filter(
  1476. (e) => e.info.objSrc && !e.modelHasRequestLoad
  1477. );
  1478. }
  1479. var cameraDir = player.getDirection();
  1480. Hot.loadQueue = hots1
  1481. .map((e) => {
  1482. return { hot: e, type: "photo" };
  1483. })
  1484. .concat(
  1485. hots2.map((e) => {
  1486. return { hot: e, type: "model" };
  1487. })
  1488. );
  1489. var request = [
  1490. (item) => {
  1491. return true;
  1492. },
  1493. ];
  1494. var rank = [
  1495. (item) => {
  1496. var dis = item.hot.mesh.getWorldPosition().distanceTo(player.position);
  1497. return -dis;
  1498. },
  1499. (item) => {
  1500. var tagDir = item.hot.mesh.getWorldPosition().sub(player.position);
  1501. var angle = tagDir.angleTo(cameraDir);
  1502. return -angle * 20;
  1503. },
  1504. ];
  1505. var result = common.sortByScore(Hot.loadQueue, request, rank);
  1506. //Hot.loadQueue = result ? result.slice(0, 5).map(e=>e.item) : model.hotGroup.children.filter(e=>e.texType == 'photo' && !e.hasRequestLoad).slice(0, 2);
  1507. Hot.loadQueue = result ? result.slice(0, 5).map((e) => e.item) : [];
  1508. };
  1509. Hot.load = () => {
  1510. //开始下载图片
  1511. Hot.getNeedLoad();
  1512. Hot.loadNext();
  1513. var hots1 = model.hotGroup.children.filter(
  1514. (e) => e.texType == "photo" && !e.photoHasRequestLoad
  1515. );
  1516. var hots2 = model.hotGroup.children.filter(
  1517. (e) => e.info.objSrc && !e.modelHasRequestLoad
  1518. );
  1519. if (hots1.length + hots2.length > 0) {
  1520. setTimeout(Hot.load, 200);
  1521. } else {
  1522. Hot.allRequestLoad = true;
  1523. console.log("allRequestLoad");
  1524. }
  1525. };
  1526. Hot.startLoad = () => {
  1527. originPhotoCount = hotGroup.children.filter(
  1528. (e) => e.texType == "photo"
  1529. ).length;
  1530. originModelCount = hotGroup.children.filter((e) => !!e.info.objSrc).length;
  1531. if (originPhotoCount == 0) Hot.allPhotoLoaded = true;
  1532. if (originModelCount == 0) Hot.allModelLoaded = true;
  1533. if (Hot.allModelLoaded && Hot.allPhotoLoaded)
  1534. Hot.whenAllFileLoaded && Hot.whenAllFileLoaded();
  1535. //所有加载完毕
  1536. else {
  1537. Hot.load();
  1538. }
  1539. setTimeout(Hot.beginShineHot, 1000);
  1540. player.emit("gotHotAndStartload");
  1541. };
  1542. window.Hot = Hot;
  1543. /* var ball = new THREE.Mesh(new THREE.SphereBufferGeometry(0.01),new THREE.MeshBasicMaterial({color:"#f00",depthTest:false,transparent:true}))
  1544. var balls = []
  1545. var addPoint = function(point){
  1546. console.log(point)
  1547. var ball1 = ball.clone()
  1548. model.add(ball1);
  1549. ball1.position.copy(point)
  1550. balls.push(ball1)
  1551. }
  1552. var addPoints = function(points){
  1553. balls.forEach(e=>model.remove(e))
  1554. balls = []
  1555. points.forEach(e=>addPoint(e))
  1556. }
  1557. */
  1558. //判断是否是移动端,如果是给关闭按钮添加touchstart事件
  1559. Hot.closePopup = () => {
  1560. // 关闭热点页面
  1561. if (!g_currentHot) return;
  1562. g_currentHot = null;
  1563. var hotPop = document.getElementById("popup");
  1564. hotPop.style.display = "none";
  1565. document
  1566. .querySelector(".popup-content")
  1567. .removeChild(document.getElementById("id1"));
  1568. $("#popup iframe:last").remove();
  1569. SoundManager.pause("hot", true); //自动播放被中断的音频 (bgm
  1570. return false;
  1571. };
  1572. if (browser.isMobile()) {
  1573. $("#closepop").on("touchstart", Hot.closePopup);
  1574. } else {
  1575. $("#closepop").on("click", Hot.closePopup);
  1576. }
  1577. Hot.createHotList = function () {
  1578. // if(!window.DATA.showHotListSta)return
  1579. var docFragment = document.createDocumentFragment();
  1580. var hots = hotGroup.children.filter((hot) => hot.info.actionType.openHot);
  1581. hots = hots.sort((a, b) => {
  1582. return a.order - b.order;
  1583. });
  1584. console.log("createHotList", hotGroup.children);
  1585. window.myHotList = hots;
  1586. hots.forEach((hot) => {
  1587. var li = document.createElement("li");
  1588. var span = document.createElement("span");
  1589. span.innerHTML = hot.info.title || "热点";
  1590. // console.log(span.innerHTML);
  1591. li.hot = hot; // 列表每一项对应一个热点
  1592. li.appendChild(span);
  1593. docFragment.appendChild(li);
  1594. });
  1595. setTimeout(() => {
  1596. var ul = document.querySelector("#hotListContent ul");
  1597. ul && ul.appendChild(docFragment);
  1598. }, 3000); //部分安卓手机的钉钉和支付宝浏览器如果立即添加到列表会卡住
  1599. };
  1600. Hot.mobileAutoPlay = function (player) {
  1601. //移动端。不这么写video不会播放 . (2022.11.29: 可为何加了Hot.updateHots之后又会自动播了?https有关?
  1602. if (browser.isMobile()) {
  1603. hotGroup.children.forEach((hot) => {
  1604. /* if(hot.texType == 'video' && hot.shouldPlay){
  1605. console.log(1)
  1606. } */
  1607. if (
  1608. !hot.clickToPlayInited &&
  1609. hot.texType == "video" &&
  1610. !isVideoPlayed(hot.texMedia) &&
  1611. hot.shouldPlay
  1612. ) {
  1613. //hot.update(player)
  1614. console.log({ str: "try mobileAutoPlay " + hot.sid, level: 1 });
  1615. hot.videoControl(true);
  1616. if (isVideoPlayed(hot.texMedia)) {
  1617. console.log({ str: "clickToPlayInited " + hot.sid, level: 1 });
  1618. hot.clickToPlayInited = true;
  1619. hot.changeOpaWhenPlay(video);
  1620. }
  1621. }
  1622. });
  1623. }
  1624. };
  1625. Hot.updateHots = function () {
  1626. for (var i in player.model.hots) {
  1627. player.model.hots[i].update(player);
  1628. }
  1629. if (!player.ready) return;
  1630. this.needUpdate = true;
  1631. common.intervalTool.isWaiting(
  1632. "updateHots",
  1633. () => {
  1634. //延时update,防止卡顿
  1635. if (!this.needUpdate) return;
  1636. this.needUpdate = false;
  1637. let videoCanPlay = [],
  1638. aniCanPlay = [];
  1639. for (var i in player.model.hots) {
  1640. let hot = player.model.hots[i];
  1641. {
  1642. //实时监测播放
  1643. if (hot.texType == "video" && !player.flying) {
  1644. //飞行时不判断
  1645. if (hot.visible && !hot.pausedByUser && hot.inSight()) {
  1646. //注意edit时insight一直为true
  1647. //this.videoControl(true)
  1648. videoCanPlay.push(hot);
  1649. } else {
  1650. hot.videoControl(false);
  1651. }
  1652. } else if (hot.info.animateInfo) {
  1653. if (hot.visible && hot.inSight()) {
  1654. aniCanPlay.push(hot);
  1655. } else {
  1656. GifTexDeal.stop(hot.animation);
  1657. }
  1658. }
  1659. }
  1660. }
  1661. let filter = (type, max, list, playFun) => {
  1662. if (list.length < max) {
  1663. list.forEach((hot) =>
  1664. type == "video"
  1665. ? hot.videoControl(true)
  1666. : GifTexDeal.start(hot.animation)
  1667. );
  1668. } else {
  1669. let playerDir = player.getDirection();
  1670. let request = [];
  1671. let planeDir = new Map();
  1672. if (player.mode != "panorama") {
  1673. request.push((hot) => {
  1674. if (hot.plane) {
  1675. //考虑plane的方向,它甚至可能背对镜头
  1676. let dir = new THREE.Vector3(0, 0, -1).applyQuaternion(
  1677. hot.quaternion
  1678. );
  1679. let angle = dir.dot(playerDir);
  1680. planeDir.set(hot, angle);
  1681. return angle > 0;
  1682. } else return true;
  1683. });
  1684. }
  1685. let r = common.sortByScore(list, request, [
  1686. (hot) => {
  1687. //方向因素
  1688. var cornerPointInfo = hot.getCornerPoint(); //仅支持漫游模式
  1689. let dir = new THREE.Vector3()
  1690. .subVectors(hot.position, player.position)
  1691. .normalize();
  1692. score = dir.dot(playerDir);
  1693. player.mode == "panorama" &&
  1694. (score *= Math.pow(cornerPointInfo.diffLat, 0.5)); // pow降低高度的权重,因为宽度更重要些。之所以两个函数都乘以diffLat,也是为了防止在两个item的分数相同diffLon不同时,diffLat增长相同倍数却能造成分数差异的情况
  1695. return score;
  1696. },
  1697. (hot) => {
  1698. //面积因素
  1699. if (player.mode == "panorama") {
  1700. var cornerPointInfo = hot.getCornerPoint(); //仅支持漫游模式
  1701. let area =
  1702. (cornerPointInfo.diffLon *
  1703. Math.pow(cornerPointInfo.diffLat, 0.5)) /
  1704. 1000; //占据面积
  1705. return area;
  1706. } else {
  1707. let dis = player.position.distanceTo(hot.position);
  1708. let size =
  1709. hot
  1710. .getBoundOri()
  1711. .applyMatrix4(hot.matrixWorld)
  1712. .size(new THREE.Vector3())
  1713. .length() / 2;
  1714. let score = Math.atan(size / Math.pow(dis, 1.2)) * 50; // 在镜头中所占fov angle 的一半 。 pow是因为实际感受还是尽量显示近处的
  1715. if (hot.plane) {
  1716. //考虑plane的方向,越倾斜分越低
  1717. score *= planeDir.get(hot);
  1718. }
  1719. return score;
  1720. }
  1721. },
  1722. ]);
  1723. //getCornerPoint仅支持漫游模式 Lat高度(纬度).
  1724. //console.log(r)
  1725. r &&
  1726. r.forEach((e, j) => {
  1727. let hot = e.item;
  1728. if (j < max) {
  1729. type == "video"
  1730. ? hot.videoControl(true)
  1731. : GifTexDeal.start(hot.animation);
  1732. } else {
  1733. type == "video"
  1734. ? hot.videoControl(false)
  1735. : GifTexDeal.stop(hot.animation);
  1736. }
  1737. });
  1738. }
  1739. };
  1740. filter("video", playVideoMax, videoCanPlay);
  1741. filter("animateInfo", playAniMax, aniCanPlay);
  1742. //console.log('updateHots')
  1743. return true;
  1744. },
  1745. 800
  1746. );
  1747. };
  1748. };
  1749. function isVideoPlayed(video) {
  1750. return !video.paused && !isNaN(video.duration); //注意,有的手机首次play时会立即paused为false,但其实没加载好, duration为NAN
  1751. }
  1752. /*
  1753. 保存 JSON.stringify(editTool.hotpoint.getSavingInfo())
  1754. 可能需要再写一份保存到overlay 给旧场景项目使用
  1755. 最好后台有针对手机版的做一个压缩。压缩成几个档位。
  1756. 安卓手机firefox出现过视频mesh不可见或者闪烁的情况。
  1757. 视频最容易导致崩溃, 模型还好
  1758. 数据速率为4064kbps,1920*1080px 时测试部门电脑崩溃
  1759. 数据速率为1824kbps,720 *576px 时正常
  1760. 所以尽量降到2000以下 同时播放个数最好不超过2个 可能需要将src归零 并延迟加载、不自动播放
  1761. 有遇到某张图在ios里显示不出,但在ps重新输出后就可以。这张图的dpi高达500,不知道是否与此有关。
  1762. 遇到过ios14.8.1、14.7.1 无法播放webm(来自1050)。 onloadedmetadata失败
  1763. */