Hot.js 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718
  1. //合并热点和展览
  2. g_currentHot = null
  3. window.initHot = function (model) {
  4. var objLoader = new THREE.OBJLoader()
  5. var _planeGeometry = new THREE.PlaneGeometry(1, 1)
  6. var _boxGeometry = new THREE.BoxBufferGeometry(1, 1, 1)
  7. {//ie的mesh 加了polygonOffset也是会重叠。所以去掉前面的face: (但是突然ie又播放不了videoTexture)
  8. var newIndex = [..._boxGeometry.index.array]
  9. newIndex.splice(4 * 6, 12)
  10. _boxGeometry.setIndex(new THREE.BufferAttribute(new Uint16Array(newIndex), 1))
  11. }
  12. var originPhotoCount = photoLoaded = originModelCount = modelLoaded = 0;
  13. var defaultTex1 = Texture.load(g_HotImage.point);
  14. var defaultTex2 = Texture.load(g_HotImage.point2)
  15. /* var _boxMat = new THREE.MeshBasicMaterial({
  16. color: "#eeeeee",
  17. transparent: !0,
  18. opacity: 0.8
  19. }) */
  20. var _boxMat = new THREE.MeshPhongMaterial({
  21. color: "#eeeeee",
  22. transparent: !0,
  23. opacity: 0.8,
  24. side: THREE.DoubleSide
  25. })
  26. var autoSizeInfo = { minSize: 120, maxSize: 600, nearBound: 1, farBound: 15 }
  27. var hotGroup = new THREE.Object3D; hotGroup.name = "hotGroup"
  28. model.add(hotGroup); model.hotGroup = hotGroup
  29. var animateTexSrcs = {}
  30. var getLink = function (link) {
  31. var querySectionInLink = link.split('?')[1]
  32. var langParam = "en" == manage.number("lang") ? "&lang=" + manage.number("lang") : "";
  33. // return `http://192.168.20.16:8085/#/${browser.isMobile() ? 'mobile' : 'web'}/?${querySectionInLink}&time=${randomTime().getTime()}&id=${window.number}${langParam}`
  34. return `/AnhuiDaily/hotspot/index.html#/${browser.isMobile() ? 'mobile' : 'web'}/?${querySectionInLink}&time=${randomTime().getTime()}&id=${window.number}${langParam}`
  35. }
  36. var removeSrcPostMark = function (url) {//去除texture.load时自动加上的'?'
  37. var index = url.indexOf('?')
  38. if (index > -1) {
  39. return url.slice(0, index)
  40. } else return url
  41. }
  42. {//get plane Bound
  43. var planeBound = new THREE.Box3()
  44. var cornerPoint = [
  45. new THREE.Vector3(-0.5, 0.5, 0),
  46. new THREE.Vector3(0.5, 0.5, 0),
  47. new THREE.Vector3(0.5, -0.5, 0),
  48. new THREE.Vector3(-0.5, -0.5, 0),
  49. ]
  50. cornerPoint.forEach(e => {
  51. planeBound.expandByPoint(e)
  52. })
  53. }
  54. var shineMats = [];
  55. var getShineMat = function (texture1, texture2) {
  56. var mat = shineMats.find(e => e.uniforms.texture1.value == texture1 && e.uniforms.texture2.value == texture2)
  57. if (mat) return mat
  58. else {
  59. var mat = new THREE.ShaderMaterial({
  60. uniforms: {
  61. color: {
  62. type: "c",
  63. value: new THREE.Color(16720384)
  64. },
  65. opac: {
  66. type: "f",
  67. value: 0
  68. },
  69. texture1: {
  70. type: "t",
  71. value: texture1
  72. },
  73. texture2: {
  74. type: "t",
  75. value: texture2
  76. }
  77. },
  78. vertexShader: "varying vec2 vUv;\n\nvoid main() {\n\n vUv = uv ;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n}\n",
  79. fragmentShader: "varying vec3 vNormal;\n\nvarying vec2 vUv;\n\nuniform float opac;\n\nuniform vec3 color;\n\nuniform 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"
  80. , transparent: !0
  81. })
  82. shineMats.push(mat)
  83. return mat
  84. }
  85. }
  86. var modelGeos = [];
  87. var getModelGeo = function (url) {
  88. var geo = modelGeos.find(e => e.url = url)
  89. if (geo) return geo
  90. else {
  91. var geo = null;
  92. geo.url = url
  93. }
  94. }
  95. class Hot extends THREE.Object3D {
  96. constructor(info, source) {
  97. super()
  98. this.sid = info.sid;
  99. this.preDeal(info, source)// source:来源
  100. this.info = info
  101. this.cornerPoints = []
  102. this.build(info);
  103. this.name = "hot_" + this.sid;
  104. model.hots[info.sid] = this
  105. }
  106. build(info) {
  107. /* this.changeMaterial(new THREE.MeshBasicMaterial({
  108. color: "#00c8af",
  109. opacity: 0.4,
  110. transparent: !0,
  111. polygonOffset: true,
  112. //是否开启多边形偏移 //ie不开启时blank也不会闪烁
  113. polygonOffsetFactor: -0.9,
  114. //多边形偏移因子
  115. polygonOffsetUnits: -4.0,
  116. //多边形偏移单位
  117. }))
  118. if(!info.objSrc){
  119. this.addPlane()
  120. if (info.hasBox) this.addBox(true)
  121. }else{
  122. this.addModel(new THREE.Mesh())//暂时创建个空的
  123. } */
  124. hotGroup.add(this)
  125. this.setTitleElem()
  126. this.setFromInfo(info)
  127. }
  128. setFromInfo(info, media, objObject) {
  129. //1 恢复到编辑之前 2 初始加载
  130. var plane = this.plane;
  131. /* var transformAtPanos = {}
  132. for(var i in info.transformAtPanos){
  133. transformAtPanos[i] = {//只保留一个位移,主要原因是大小变化和热点大小设置冲突了, isSprite和qutaernion衝突
  134. pos : info.transformAtPanos[i].pos && info.transformAtPanos[i].pos.clone(),
  135. //qua : info.transformAtPanos[i].qua && info.transformAtPanos[i].qua.clone(),
  136. }
  137. }
  138. this.transformAtPanos = transformAtPanos */
  139. //在每个漫游点独立设置的position。
  140. var curPanoTransform = this.info.transformAtPanos[getTransformSid()] || {}
  141. //没有单独设置position的漫游点使用的position
  142. this.position.copy(curPanoTransform.pos || info.position)
  143. this.rotation.copy(info.rotation)
  144. this.scale.copy(info.scale)
  145. this.changeTexType(info.texType, media)
  146. if (!info.objSrc) {
  147. this.addPlane()
  148. if (!!this.hasBox != !!info.hasBox) {
  149. this.addBox(!this.hasBox);
  150. }
  151. } else {
  152. this.addModel(objObject || new THREE.Mesh())//暂时创建个空的
  153. }
  154. this.updateMatrixWorld()
  155. /* if(!this.info.visiblePanos){//移到model.build时,在collider建好之后
  156. this.getVisiblePanos()
  157. } */
  158. {//gif
  159. if (this.animation) {
  160. GifTexDeal.remove(this.animation)
  161. }
  162. if (this.info.animateInfo && this.material_.map) {
  163. this.animation = GifTexDeal.addAnimation(this.material_.map, this, this.info.animateInfo, this.sid)
  164. this.visible && this.inSight() && GifTexDeal.start(this.animation)
  165. }
  166. }
  167. /* if(this.info.modelBound){
  168. this.mesh.updateMatrixWorld()
  169. this.mesh.boxHelper2 = new THREE.Box3Helper( new THREE.Box3().copy(this.info.modelBound.bound).applyMatrix4(this.mesh.matrixWorld), new THREE.Color("#00aaee"));
  170. model.add(this.mesh.boxHelper2)
  171. }else{
  172. var bound = new THREE.Box3()
  173. var cornerPoint = [
  174. new THREE.Vector3(-0.5, 0.5, 0),
  175. new THREE.Vector3(0.5, 0.5, 0),
  176. new THREE.Vector3(0.5, -0.5, 0),
  177. new THREE.Vector3(-0.5, -0.5, 0),
  178. ]
  179. cornerPoint.forEach(e=>{
  180. bound.expandByPoint(e)
  181. })
  182. this.mesh.updateMatrixWorld()
  183. this.mesh.boxHelper2 = new THREE.Box3Helper( bound.applyMatrix4(this.mesh.matrixWorld), new THREE.Color("#00aaee"));
  184. model.add(this.mesh.boxHelper2)
  185. } */
  186. }
  187. changeTexType(texType, media) {
  188. var plane = this.plane;
  189. if (this.texType != texType || media == 'clear') {
  190. //删除旧的
  191. if (this.texType == 'shine') {
  192. /* this.material_.uniforms.texture1.value.dispose()
  193. this.material_.uniforms.texture2.value.dispose() */ //为了恢复 不删
  194. } else {
  195. //this.material_.map.dispose()
  196. if (this.texType == 'video') {
  197. this.texMedia && this.texMedia.pause()
  198. } else {
  199. }
  200. }
  201. if (this.material_ && !hotGroup.children.find(e => e != this && e.material_ == this.material_)) {
  202. this.material_.dispose()
  203. }
  204. //添加新的
  205. if (texType == 'shine') {
  206. } else {
  207. this.changeMaterial(new THREE.MeshBasicMaterial({
  208. color: "#00c8af",
  209. opacity: 0.4,
  210. transparent: !0,
  211. polygonOffset: true,
  212. //是否开启多边形偏移 //ie不开启时blank也不会闪烁
  213. polygonOffsetFactor: -0.9,
  214. //多边形偏移因子
  215. polygonOffsetUnits: -4.0,
  216. //多边形偏移单位
  217. }))
  218. if (texType == 'video') {
  219. } else {
  220. }
  221. }
  222. }
  223. this.texType = texType
  224. if (media == 'clear') {
  225. this.material_.opacity = 0.4;
  226. this.texMedia = null
  227. return
  228. }
  229. if (texType == 'video') {//视频不能共用一个,否则会一起播放暂停
  230. var video
  231. if (media) {
  232. video = media
  233. } else {
  234. if (!this.info.texSrc) return
  235. var video = $(`<video controls="controls" loop autoplay x5-playsinline="" webkit-playsinline="true" playsinline="true" controlslist="nodownload"></video>`)[0]
  236. video.src = manage.dealURL(this.info.texSrc);
  237. video.name = this.info.fileName
  238. }
  239. video.setAttribute("crossOrigin", 'Anonymous')//要在src设置好前解决跨域
  240. $(video).on('contextmenu', function () {
  241. return false;
  242. });//禁止右键点击出
  243. this.texMedia = video;
  244. video.oncanplaythrough = () => {
  245. if (this.texMedia == video) {
  246. this.material_.map.needsUpdate = !0
  247. video.play()
  248. }
  249. }
  250. video.volume = 0
  251. video.muted = true
  252. video.currentTime = 0
  253. this.material_.map = new THREE.VideoTexture(video)
  254. this.material_.map.wrapS = this.material_.map.wrapT = THREE.ClampToEdgeWrapping;
  255. this.material_.map.generateMipmaps = true;
  256. } else if (texType == 'photo') {
  257. if (media) {
  258. this.texMedia = media;
  259. this.info.texSrc = media.src;
  260. this.material_.map = new THREE.Texture(); //texture也不能共用一个,因为有的会有动画,就不一样
  261. this.material_.map.image = media //image可以共用
  262. this.material_.map.needsUpdate = !0
  263. } else {
  264. if (!this.info.texSrc) return
  265. this._loadDones = []
  266. this.material_.opacity = 0.1;
  267. }
  268. } else if (texType == 'shine') {
  269. if (media) {
  270. this.changeShineTex(media)
  271. } else {
  272. this.styleImg = /* this.styleImg || */[];
  273. if (this.info.styleImg) {
  274. this.styleImg = this.info.styleImg.map((src) => {
  275. return { src:/* manage.dealURL( */src } //如果要dealURL,在predeal里
  276. })
  277. }
  278. this.changeShineTex(this.styleImg)
  279. }
  280. this.info.texSrc = null
  281. }
  282. if (this.material_.map) {
  283. /* this.material_.map.minFilter = THREE.LinearFilter;
  284. this.material_.map.magFilter = THREE.LinearFilter; */
  285. dealMap(this.material_.map);
  286. this.material_.color.set("#FFFFFF");
  287. this.material_.opacity = 1
  288. this.material_.needsUpdate = true
  289. }
  290. }
  291. changeShineTex(styleImg) {
  292. styleImg = styleImg || this.styleImg
  293. var tex1, tex2
  294. if (styleImg.length) {
  295. tex1 = Texture.load(styleImg[0].src);
  296. tex2 = Texture.load(styleImg[1] && styleImg[1].src || styleImg[0].src);
  297. } else {
  298. tex1 = defaultTex1;
  299. tex2 = defaultTex2;
  300. }
  301. this.changeMaterial(getShineMat(tex1, tex2))
  302. this.styleImg = styleImg
  303. this.info.styleImg = styleImg.map(img => img.src)
  304. }
  305. changeMaterial(mat) {
  306. this.material_ = mat;
  307. this.mesh && this.mesh.traverse((mesh) => {
  308. if (mesh.material && !(mesh instanceof THREE.Box3Helper)) {
  309. mesh.material = this.material_;
  310. }
  311. })
  312. }
  313. /*
  314. actionType: "common"
  315. infoAttribute: {images: [], styleImg: [], model: [], video: [], bgName: "background", iframe: [], title: "11",…}
  316. bgName: "background"
  317. content: "111"
  318. iframe: []
  319. images: []
  320. model: []
  321. styleImg: []
  322. title: "11"
  323. video: []
  324. isSprite: 0
  325. link: "https://www.4dmodel.com/SuperTwo/hot_online1/index.html#/?m=EDwn769489868"
  326. linkType: "common"
  327. noAction: 0
  328. order: 4
  329. position: {x: -4.238, y: 1.32, z: -0.648}
  330. rotation: {x: 0, y: 0.018105110200249575, z: 0}
  331. transformAtPanos: {}
  332. IO4Kq7494332: {actionTy
  333. depth: 0.08
  334. file: "https://super.4dage.com/data/TEST/edit/20200805_172635119.mp4"
  335. hasBox: 1
  336. height: 0.7289
  337. media: ["video"]
  338. pos: [-5.562, 1.349, 1.994]
  339. qua: [0, 0.70672, 0, 0.70749]
  340. sid: "1596619585929"
  341. transformAtPanos: {,…} */
  342. preDeal(info, source) {// source:来源
  343. var convertValue = function (v, Type) {
  344. var value;
  345. if (v instanceof Array) {
  346. v.forEach((v1) => { v1 = parseFloat(v1) })
  347. value = new Type().fromArray(v);
  348. } else {
  349. if (!(v instanceof Type)) {
  350. for (let i in v) { v[i] = parseFloat(v[i]) }
  351. value = new Type().copy(v);
  352. } else {
  353. value = v
  354. }
  355. }
  356. return value
  357. }
  358. if (!info.transformAtPanos) info.transformAtPanos = {}
  359. if (source == 'byHot') {
  360. var infoAttribute = info.infoAttribute || {}
  361. info.title = infoAttribute.title || info.title
  362. info.model = infoAttribute.model || info.model || [] //模型链接
  363. info.images = infoAttribute.images || info.images || []
  364. info.video = infoAttribute.video || info.video || []
  365. info.bgName = infoAttribute.bgName || info.bgName
  366. info.backgroundMusic = info.backgroundMusic || info.backgroundMusic
  367. info.iframe = infoAttribute.iframe || info.iframe || []
  368. info.styleImg = infoAttribute.styleImg || info.styleImg || []
  369. info.content = infoAttribute.content || info.content
  370. {
  371. let action = CloneObject(settings.hotClickEvent.shine);
  372. if (info.actionType == 'noAction' || info.noAction) {
  373. action.examine = false,
  374. action.openHot = false
  375. } else if (info.actionType == 'dontExam') {
  376. action.examine = false
  377. }
  378. info.actionType = action
  379. }
  380. if (info.quaternion) {
  381. info.rotation = new THREE.Euler().setFromVector3(convertValue(info.quaternion, THREE.Quaternion))
  382. } else {
  383. info.rotation = new THREE.Euler().setFromVector3(convertValue(info.rotation, THREE.Vector3)) //热点的旧数据很多是字符串
  384. }
  385. var s = Hot.getDefaulScale(info.hotIconScale)
  386. info.scale = new THREE.Vector3(s, s, 0.02)
  387. delete info.infoAttribute;
  388. /* for (let i in this.transformAtPanos) {
  389. info.transformAtPanos[i].pos = new THREE.Vector3().fromArray(info.transformAtPanos[i].pos)
  390. info.transformAtPanos[i].qua && (info.transformAtPanos[i].qua = new THREE.Quaternion().fromArray(info.transformAtPanos[i].qua))
  391. } */
  392. info.texType = "shine"
  393. } else {
  394. if (source == 'byOverlay') {
  395. info.texType = info.media[0]
  396. //info.title = info.texType == 'video'?'视频':'图片'
  397. info.texSrc = info.file
  398. info.actionType = CloneObject(settings.hotClickEvent[info.texType]);//给一个默认
  399. delete info.media
  400. info.rotation = new THREE.Euler().setFromQuaternion(convertValue(info.qua, THREE.Quaternion))
  401. info.position = info.pos
  402. delete info.pos;
  403. delete info.qua;
  404. let a = info.texSrc.split('/');
  405. info.fileName = a.pop()
  406. info.scale = new THREE.Vector3(
  407. info.width,
  408. info.height,
  409. info.depth
  410. )
  411. delete info.width; delete info.height; delete info.depth;
  412. delete info.file
  413. } else {
  414. info.rotation = new THREE.Euler().fromArray(info.rotation)//.setFromVector3(info.rotation)
  415. }
  416. info.model = info.model || [] //模型链接
  417. info.images = info.images || []
  418. info.video = info.video || []
  419. info.iframe = info.iframe || []
  420. info.styleImg = info.styleImg || []
  421. }
  422. if (info.texSrc) {
  423. info.texSrc = manage.removeSrcPostMark(info.texSrc)
  424. }
  425. //whole:
  426. //为了兼容旧数据,尽量和hot的数据靠近,最后保存在hot里
  427. info.position = convertValue(info.position, THREE.Vector3)
  428. info.scale = convertValue(info.scale, THREE.Vector3)
  429. delete info.quaternion
  430. info.linkType = info.linkType || "common"
  431. for (let i in info.transformAtPanos) {
  432. info.transformAtPanos[i].pos = new THREE.Vector3().fromArray(info.transformAtPanos[i].pos)
  433. //info.transformAtPanos[i].qua = new THREE.Quaternion().fromArray(info.transformAtPanos[i].qua)
  434. }
  435. }
  436. addBox(state) {
  437. if (state == !!this.hasBox) {
  438. return;
  439. }
  440. if (state) {
  441. var box = new THREE.Mesh(_boxGeometry, _boxMat)
  442. box.position.set(0, 0, 1 / 2);
  443. box.renderOrder = 3
  444. this.plane.position.set(0, 0, 1);
  445. this.add(box);
  446. this.box = box;
  447. } else {
  448. this.plane.position.set(0, 0, 0);
  449. this.remove(this.box);
  450. this.box = null;
  451. }
  452. this.hasBox = this.info.hasBox = state
  453. }
  454. /* getSizeByScale() {
  455. return {
  456. width: settings.defaultOverlaySize[0] * this.scale.x,
  457. height: settings.defaultOverlaySize[1] * this.scale.y
  458. }
  459. }
  460. getScaleBySize(width, height) {
  461. return {
  462. x: width / settings.defaultOverlaySize[0],
  463. y: height / settings.defaultOverlaySize[1],
  464. }
  465. }*/
  466. setVisiblePanos(visibleData) {
  467. if (visibleData) this.info.visiblePanos = visibleData
  468. else if (!this.info.visiblePanos) this.getVisiblePanos()
  469. }
  470. getVisiblePanos() {//在不同点还不一样
  471. var depth = this.hasBox ? this.scale.z : 0;
  472. var width = this.scale.x, height = this.scale.y
  473. var cornerPoint
  474. if (this.plane) {
  475. cornerPoint = [
  476. new THREE.Vector3(0, 0, depth),
  477. new THREE.Vector3(-width / 2, height / 2, depth),
  478. new THREE.Vector3(width / 2, height / 2, depth),
  479. new THREE.Vector3(width / 2, -height / 2, depth),
  480. new THREE.Vector3(-width / 2, -height / 2, depth),
  481. ]
  482. } else {
  483. var bound = new THREE.Box3().copy(this.info.modelBound.bound)
  484. var center = bound.center()
  485. cornerPoint = [
  486. new THREE.Vector3(center.x, center.y, center.z),
  487. new THREE.Vector3(bound.min.x, bound.min.y, bound.min.z),
  488. new THREE.Vector3(bound.min.x, bound.min.y, bound.max.z),
  489. new THREE.Vector3(bound.min.x, bound.max.y, bound.min.z),
  490. new THREE.Vector3(bound.max.x, bound.min.y, bound.min.z),
  491. new THREE.Vector3(bound.max.x, bound.max.y, bound.min.z),
  492. new THREE.Vector3(bound.max.x, bound.min.y, bound.max.z),
  493. new THREE.Vector3(bound.min.x, bound.max.y, bound.max.z),
  494. new THREE.Vector3(bound.max.x, bound.max.y, bound.max.z),
  495. ];
  496. }
  497. var getPos = (position) => {//每个overlay位置对应5个坐标,plane中心和四个角的位置
  498. if (this.plane) {
  499. return cornerPoint.map(e => {
  500. return e.clone().applyEuler(this.info.rotation).add(position)
  501. })
  502. } else {
  503. var matrixWorld = new THREE.Matrix4().compose(position, this.quaternion, this.scale)
  504. matrixWorld.multiplyMatrices(matrixWorld, this.mesh.matrix)
  505. return cornerPoint.map(e => {
  506. return e.clone().applyMatrix4(matrixWorld);
  507. })
  508. }
  509. }
  510. this.info.visiblePanos = []
  511. var customPositions = getPos(this.info.position)
  512. var posAtPanos = {}
  513. for (let panoId in this.info.transformAtPanos) {
  514. if (panoId == 'outSide') continue;
  515. posAtPanos[panoId] = getPos(this.info.transformAtPanos[panoId].pos)
  516. }
  517. let maxCount = browser.isMobile() ? 2000 : 5000
  518. let c = model.panos.list.length * model.colliders.length
  519. if (window.isEdit || c < maxCount) { //编辑页面保险起见还是全部算完后才可浏览,就能保证保存全部的visiblePano
  520. this.info.visiblePanos = common.getVisiblePano(customPositions, model.panos.list, {
  521. model: model.colliders, posAtPanos
  522. })
  523. } else {
  524. let start = 0
  525. let interval = setInterval(() => {
  526. let end = start + Hot.visiPanosCountSlice;
  527. end = Math.min(end, model.panos.list.length)
  528. let i = start
  529. start = end
  530. let panos = model.panos.list.slice(i, end)
  531. this.info.visiblePanos = this.info.visiblePanos.concat(common.getVisiblePano(customPositions, panos, {
  532. model: model.colliders, posAtPanos
  533. }));
  534. if (end >= model.panos.list.length) {
  535. console.log(window.hotsi ? (++window.hotsi) : (window.hotsi = 1))
  536. clearInterval(interval)
  537. }
  538. }, Hot.visiEveryDurSlice)// visiEveryDurSlice 等在main中定义
  539. }
  540. }
  541. updateVisible(panos, visibility) {
  542. if (window.isEdit && editTool.hotpoint.editSpot == this) {
  543. return this.visible = true
  544. }
  545. this.visible = visibility != void 0 ? visibility : (!this.info.visiblePanos || !!panos.find(pano => this.info.visiblePanos.includes(pano.id)))
  546. if (this.texType == 'video') {
  547. //this.switchPlay(this.visible, this.visible ? null : 'stop' );//可见时不操作;不可见时停止
  548. this.update(player)
  549. }
  550. }
  551. getCornerPoint() {//获取在每个漫游点上的视觉边界点 可以打开boxHelper和addBall来观测是否准确
  552. if (this.cornerPoints[player.currentPano.id]) {
  553. return this.cornerPoints[player.currentPano.id]
  554. } else {
  555. var boundPoint, cornerPoint
  556. var center//中心点
  557. if (this.plane) {
  558. center = this.plane.getWorldPosition()
  559. boundPoint = [
  560. new THREE.Vector3(-0.5, 0.5, 0),
  561. new THREE.Vector3(0.5, 0.5, 0),
  562. new THREE.Vector3(0.5, -0.5, 0),
  563. new THREE.Vector3(-0.5, -0.5, 0),
  564. ]
  565. } else {
  566. var bound = new THREE.Box3().copy(this.info.modelBound.bound)
  567. boundPoint = [
  568. new THREE.Vector3(bound.min.x, bound.min.y, bound.min.z),
  569. new THREE.Vector3(bound.min.x, bound.min.y, bound.max.z),
  570. new THREE.Vector3(bound.min.x, bound.max.y, bound.min.z),
  571. new THREE.Vector3(bound.max.x, bound.min.y, bound.min.z),
  572. new THREE.Vector3(bound.max.x, bound.max.y, bound.min.z),
  573. new THREE.Vector3(bound.max.x, bound.min.y, bound.max.z),
  574. new THREE.Vector3(bound.min.x, bound.max.y, bound.max.z),
  575. new THREE.Vector3(bound.max.x, bound.max.y, bound.max.z),
  576. ];
  577. }
  578. var maxLon = -Infinity
  579. var minLon = +Infinity
  580. var maxLat = -Infinity
  581. var minLat = +Infinity
  582. var pos1 = player.currentPano.position.clone();
  583. center = this.position.clone() //模型bound的中心点已经位移到了hot中心点。 注意不能用getWorldPosition,得到的会是偏移的
  584. var dir = center.clone().sub(pos1).normalize()
  585. var centerDirInfo = {}
  586. player.cameraControls.controls.panorama.lookAt.call(centerDirInfo, null, dir)
  587. boundPoint.forEach(e => {//lon左右
  588. var point = e.applyMatrix4(this.mesh.matrixWorld);
  589. var dir = point.clone().sub(pos1).normalize()
  590. var dirInfo = {}
  591. player.cameraControls.controls.panorama.lookAt.call(dirInfo, null, dir)
  592. var diffLon = (dirInfo.lon - centerDirInfo.lon) % 360
  593. if (Math.abs(diffLon) > 180) {//因为有时需要根据符号判断是在中心的左边还是右边,所以限制在180内
  594. diffLon += (diffLon > 0 ? -360 : 360)
  595. }
  596. var diffLat = dirInfo.lat - centerDirInfo.lat
  597. maxLon = Math.max(diffLon, maxLon)
  598. minLon = Math.min(diffLon, minLon)
  599. maxLat = Math.max(diffLat, maxLat)
  600. minLat = Math.min(diffLat, minLat)
  601. })
  602. var diffLon = maxLon - minLon
  603. var diffLat = maxLat - minLat
  604. if (diffLat > 180) {//可能是到了反面。不好算,直接返回所有boundPoint
  605. cornerPoint = boundPoint
  606. } else {
  607. //读取lon lat的最大最小值,勾勒出一个没有倾斜的矩形 。它比boundPoint看起来范围更大些
  608. maxLon = maxLon + centerDirInfo.lon
  609. maxLat = maxLat + centerDirInfo.lat
  610. minLon = minLon + centerDirInfo.lon
  611. minLat = minLat + centerDirInfo.lat
  612. var dirs = [
  613. math.getDirByLonLat(maxLon, maxLat),
  614. math.getDirByLonLat(minLon, minLat),
  615. math.getDirByLonLat(maxLon, minLat),
  616. math.getDirByLonLat(minLon, maxLat),
  617. ]
  618. cornerPoint = dirs.map(e => {
  619. return e.clone().add(pos1)
  620. })
  621. cornerPoint = [center, ...cornerPoint] //最后增加一个中心点
  622. }
  623. /* if(this.objObject){
  624. cornerPoint = [pos2, ...cornerPoint]
  625. } */
  626. //addPoints(cornerPoint)
  627. this.cornerPoints[player.currentPano.id] = { cornerPoint, diffLon, diffLat }
  628. return this.cornerPoints[player.currentPano.id]
  629. }
  630. }
  631. inSight() {
  632. //return true
  633. if (window.isEdit) return true // 太容易move了
  634. if (player.mode == 'panorama') {
  635. if (!player.camera) return
  636. var cornerPointInfo = this.getCornerPoint();
  637. var cornerPoint
  638. if (cornerPointInfo.diffLon < 15 && cornerPointInfo.diffLat < 15) {//当很小的时候,只判断中心点即可
  639. cornerPoint = [cornerPointInfo.cornerPoint[0]];
  640. } else {
  641. cornerPoint = cornerPointInfo.cornerPoint
  642. }
  643. for (let i = 0, j = cornerPoint.length; i < j; i++) {//只要有一点可见就算看见
  644. var pos2d = math.getPos2d(cornerPoint[i], player.camera, $("#player")[0])
  645. if (pos2d.trueSide && pos2d.inSight) return true
  646. }
  647. } else {//飞出要判断模型阻挡,有点耗时就算了
  648. return true
  649. }
  650. }
  651. update(player) {
  652. if (player.mode == 'panorama') {//实时监测播放
  653. if (this.texType == "video") {
  654. if (this.visible && !this.pausedByUser && this.inSight()) {
  655. this.videoControl(true)
  656. } else {
  657. this.videoControl(false)
  658. }
  659. } else if (this.info.animateInfo) {
  660. if (this.visible && this.inSight()) {
  661. GifTexDeal.start(this.animation)
  662. } else {
  663. GifTexDeal.stop(this.animation)
  664. }
  665. }
  666. }
  667. if (this.info.isSprite) {
  668. this.quaternion.copy(player.camera.quaternion)
  669. }
  670. this.updateScale()
  671. }
  672. updateScale(e, t) {//自适应调节大小
  673. if (!DATA.autoAdjustHotScale || this.texType != 'shine') return
  674. //let renderSize = player.sceneRenderer.renderer.domElement
  675. let renderSize = player.sceneRenderer.renderer.getSize()
  676. var scale = convertTool.getScaleForConstantSize($.extend(autoSizeInfo, {
  677. camera: player.camera, resolution: { x: renderSize.width, y: renderSize.height },
  678. position: this.position.clone(),
  679. }))
  680. this.plane.scale.set(scale, scale, scale)
  681. }
  682. switchPlay(state) {//手动播放暂停
  683. this.pausedByUser = !state
  684. this.videoControl(state)
  685. }
  686. videoControl(state) {
  687. if (this.texType != "video" || !this.material_.map) return
  688. var video = this.material_.map.image
  689. if (!state || state == 'stop') {
  690. if (!video.paused) {
  691. video.pause()
  692. //console.log("pause " + this.sid)
  693. }
  694. if (state == 'stop') {
  695. video.currentTime = 0;
  696. }
  697. } else if (state) {
  698. if (video.paused) {
  699. video.play()
  700. //console.log("play " + this.sid)
  701. }
  702. }
  703. }
  704. /* setDefaultHotScale = function(){//设置成默认热点大小
  705. var w = DATA.hotIconScale) * g_HotMeshSize.g_HotMeshWidth
  706. this.scale.set( w, w, this.scale.z)
  707. } */
  708. setTitleElem() {
  709. var root = $("#hot");
  710. var title = this.info.title;
  711. if (title) {
  712. if (!this.titleElem) {
  713. var elem = $(`<div></div>`)
  714. root.append(elem);
  715. this.titleElem = elem;
  716. }
  717. this.titleElem.text(title)
  718. } else {
  719. if (this.titleElem) {
  720. this.titleElem.remove()
  721. this.titleElem = null;
  722. }
  723. }
  724. }
  725. showTitle() {
  726. if (!this.titleElem) return;
  727. var pos = math.getPos2d(this.position, player.camera, $("#player")[0])
  728. if (pos.trueSide) {//inSight
  729. this.titleElem.css({ "left": `${pos.pos.x}px`, "top": `${pos.pos.y}px ` });
  730. this.titleElem.css("display", "block");
  731. } else {
  732. this.titleElem.css("display", "none");
  733. }
  734. }
  735. hideTitle() {
  736. if (!this.titleElem) return;
  737. this.titleElem.css("display", "none");
  738. }
  739. closestPanoTowardTag(e, t) {
  740. var i = []
  741. , n = []
  742. , r = this.mesh.getWorldPosition();
  743. if (e === "panorama") {
  744. /* var o = t.position.clone().sub(r).normalize();
  745. n.push(function(t, i) {//scoreFunctions.direction 最好这个漫游点在currentPano到热点之间的路径上。但是这样的话可能就看不到热点正面,所以删掉
  746. return function(e) {
  747. return e.position.clone().sub(t).normalize().dot(i) * window._settings.navigation.directionFactor
  748. }}(r, o)
  749. ) */
  750. }
  751. var a = new THREE.Vector3;
  752. i.push(function (e) {
  753. return Math.abs(e.position.x - r.x) > window._settings.tags.visibility.cameraClearance || Math.abs(e.position.z - r.z) > window._settings.tags.visibility.cameraClearance
  754. },
  755. function (e) {
  756. a.copy(r).sub(e.position);
  757. var t = -THREE.Math.radToDeg(Math.atan(a.y / Math.sqrt(a.x * a.x + a.z * a.z)))
  758. , i = window._settings.tags.navigate.tiltTolerance
  759. return window._settings.insideLookLimitDown - i < t && t < window._settings.insideLookLimitUp + i
  760. },
  761. (pano) => { // add
  762. return player.checkHasNeighbor(pano)
  763. },
  764. (pano) => { // add
  765. // if (this.info && this.info.visiblePanos)
  766. return this.info.visiblePanos.includes(pano.id)
  767. }
  768. )
  769. n.push(
  770. (function (hot, i) { //scoreFunctions.distanceSquared
  771. return function (pano) {
  772. //i = a.navigation.distanceFactor
  773. return hot ? hot.position.distanceToSquared(pano.position) * i : 0
  774. }
  775. })(this, -2)
  776. ,
  777. (pano) => {//尽量正对hot
  778. let dir = new THREE.Vector3(0, 0, 1).applyQuaternion(this.quaternion)
  779. let dir2 = new THREE.Vector3().subVectors(pano.position, this.position).normalize();
  780. let s = dir.dot(dir2) * 10;
  781. //console.log(pano.id + ":" + s)
  782. return s
  783. }
  784. );
  785. var s = t.model.panos.sortByScore(i, n);
  786. console.log(s)
  787. return s && 0 < s.length && s[0].pano
  788. }
  789. examine(options = {}) {
  790. console.log('打开热点,关闭背景音乐')
  791. // 判断当前背景音乐是开的还是关的
  792. let tempp = document.querySelector('#openMusic')
  793. if (tempp.style.display === 'block') {
  794. // 背景音乐当前为关闭状态
  795. window.musicFlagNow = '音乐关'
  796. } else {
  797. window.musicFlagNow = '音乐开'
  798. SoundManager.pause('bgm')
  799. }
  800. var openHot = this.info.link && this.info.actionType.openHot && !options.dontOpen
  801. var needExamine = options.examine || (!settings.dontExamHot && this.info.actionType.examine)
  802. if (!openHot && !needExamine) return
  803. if (openHot && this.info.linkType != "common" && this.info.iframe && this.info.iframe[0]) {
  804. // 注意,因为网站用了vue router, url里看上去像是查询片段的那一段其实是放在hash片段中的。
  805. const hotspotWebQuerySection = new URLSearchParams(this.info.iframe[0].split('?')[1])
  806. const targetSceneCode = hotspotWebQuerySection.get('m')
  807. const currentLocationQuerySection = new URLSearchParams(location.href.split('?')[1])
  808. const currentSceneCode = currentLocationQuerySection.get('m')
  809. if (currentSceneCode === '1300' && targetSceneCode === '1302') {
  810. const iframeElem = document.createElement('iframe')
  811. iframeElem.style.position = 'absolute'
  812. iframeElem.style.top = '50%'
  813. iframeElem.style.left = '50%'
  814. iframeElem.style.width = '600px'
  815. iframeElem.style.height = '800px'
  816. iframeElem.style.transform = 'translate(-50%, -50%)'
  817. iframeElem.style.zIndex = '9999'
  818. iframeElem.style.boxShadow = '0 0 0 1000px rgba(0, 0, 0, 0.85)'
  819. // iframeElem.src = 'http://192.168.20.16:8081/#/topic'
  820. iframeElem.src = '/AnhuiDaily/quiz/index.html#/topic'
  821. document.documentElement.appendChild(iframeElem)
  822. const onMsg = (msg) => {
  823. console.log('message received!', msg);
  824. window.removeEventListener('message', onMsg, false)
  825. if (msg.data === 'quiz over') {
  826. // 跳转到新场景
  827. currentLocationQuerySection.set('m', targetSceneCode)
  828. const newLocation = location.href.split('?')[0] + '?' + currentLocationQuerySection.toString()
  829. location.assign(newLocation)
  830. location.reload(true)
  831. }
  832. }
  833. window.addEventListener('message', onMsg, false)
  834. } else {
  835. // 跳转到新场景
  836. currentLocationQuerySection.set('m', targetSceneCode)
  837. const newLocation = location.href.split('?')[0] + '?' + currentLocationQuerySection.toString()
  838. location.assign(newLocation)
  839. location.reload(true)
  840. }
  841. return
  842. var src = getLink(this.info.iframe[0])
  843. if (this.info.linkType == "jumpLink") {
  844. var newPage = window.open(src, "_blank")
  845. newPage.focus()
  846. } else if (this.info.linkType == "iframeDiv") {
  847. var div = document.createElement("div")
  848. div.style.position = 'fixed'
  849. div.style.width = div.style.height = "100%"
  850. div.style.left = div.style.top = '0'
  851. div.style["z-index"] = "999"
  852. var exit = document.createElement("div")
  853. exit.style["background-image"] = "url(images/vrOffImg.png)"
  854. exit.style.position = 'absolute'
  855. exit.style.width = exit.style.height = "50px"
  856. exit.style.left = '17px'; exit.style.top = "20px"
  857. exit.style.cursor = "pointer"
  858. exit.style["background-repeat"] = "no-repeat"
  859. exit.style["background-size"] = "25%"
  860. exit.style["background-position"] = "center center"
  861. exit.style["background-color"] = "rgba(0, 0, 0, 0.2)"
  862. exit.style["border-radius"] = "50%"
  863. exit.style["z-index"] = "3"
  864. exit.onclick = () => {
  865. $(div).remove()
  866. Hot.closePopup()
  867. }
  868. var myElement = document.createElement("iframe")
  869. myElement.style.position = 'absolute'
  870. myElement.style.width = myElement.style.height = "100%"
  871. myElement.style.left = myElement.style.top = '0'
  872. myElement.src = src
  873. $("body").append(div)
  874. div.appendChild(exit)
  875. div.appendChild(myElement)
  876. SoundManager.play('hot')
  877. }
  878. return
  879. }
  880. if (!player.currentPano) return
  881. var popup = document.getElementById("popup")
  882. if (openHot) {
  883. g_currentHot = this,
  884. popup.style.display = "block",
  885. popup.classList.add("wait")
  886. var n = document.createElement("iframe")
  887. SoundManager.play('hot')
  888. var src = getLink(this.info.link)
  889. n.src = src
  890. n.id = "id1",
  891. n.allowTransparency = "true"
  892. var a = document.getElementById("id1")
  893. if (void 0 === a || null == a) {
  894. document.querySelector(".popup-content").appendChild(n)
  895. var s = !1
  896. window.loaddingSuccess = function () {
  897. s = !0
  898. }
  899. ,
  900. setTimeout(function e() {
  901. if (s) {
  902. var t = document.querySelector("#id1").contentWindow.document
  903. t.querySelector("video") && (t.querySelector("video").play(),
  904. !t.querySelector("video").paused && t.querySelector(".playPause") && t.querySelector(".playPause").classList.add("fa-pause")),
  905. t.querySelector("audio") && t.querySelector("audio").play()
  906. } else
  907. setTimeout(e, 300)
  908. }, 800)
  909. }
  910. }
  911. var done = function () {
  912. player.flyingToTag = !1
  913. openHot && popup.classList.remove("wait")
  914. }.bind(this)
  915. if (!needExamine) {
  916. done()
  917. return
  918. }
  919. var c = this.closestPanoTowardTag(player.mode, player.currentPano) || player.currentPano
  920. , h = this.mesh.getWorldPosition()
  921. player.flyingToTag = !0
  922. if (player.mode === 'panorama') {
  923. var d = {
  924. pano: c,
  925. lookAtPoint: h,
  926. duration: options.duration,
  927. maxDistanceOverride: null,
  928. skipWarpingCheck: !1,
  929. aimDuration: options.aimDuration,
  930. }
  931. player.flyToPano(d, done)
  932. } else {
  933. var p = {
  934. pano: c
  935. }
  936. if (h) {
  937. var f = (new THREE.Matrix4).lookAt(c.position, h, new THREE.Vector3(0, 1, 0))
  938. p.quaternion = (new THREE.Quaternion).setFromRotationMatrix(f)
  939. }
  940. p.callback = done,
  941. p.duration = options.duration || 1500,
  942. p.mode = 'panorama',
  943. p.aimDuration = options.aimDuration
  944. player.flyToNewMode(p)
  945. }
  946. }
  947. addModel(object) {
  948. if (this.objObject) {
  949. this.remove(this.objObject)
  950. }
  951. this.objObject = object;
  952. /* object.traverse((mesh)=>{
  953. if(mesh.material && mesh.type == "hotSprite"){
  954. mesh.material = this.material_;
  955. }
  956. }) */
  957. object.name = this.info.objName;
  958. object.src = this.info.objSrc
  959. this.info.hasBox = false
  960. this.addBox(false)
  961. this.remove(this.plane);
  962. this.plane = null;
  963. this.setMesh(this.objObject)
  964. //this.adjustModelAuto()
  965. if (this.info.modelBound) {//应该不会改变
  966. var s = this.info.modelBound.scaleRatio
  967. this.mesh.scale.set(s, s, s)
  968. this.mesh.position.fromArray(this.info.modelBound.position)
  969. this.mesh.modelBound = this.info.modelBound
  970. }
  971. this.material_.side = THREE.FrontSide
  972. this.changeBoxHelperDisplay(false)
  973. //this.mesh.boxHelper.visible = true
  974. }
  975. addPlane() {//换成plane
  976. if (this.plane) return
  977. this.plane = new THREE.Mesh(_planeGeometry, this.material_)
  978. this.remove(this.objObject)
  979. this.objObject = null
  980. delete this.info.objSrc
  981. delete this.info.objName
  982. delete this.info.modelBound
  983. this.setMesh(this.plane)
  984. //this.material_.side = THREE.DoubleSide //双面的话飞出来会看到悬空的
  985. }
  986. setMesh(mesh) {
  987. this.mesh = mesh
  988. this.add(this.mesh);
  989. this.mesh.renderOrder = 3
  990. this.changeMaterial(this.material_) //re applyTo every mesh
  991. this.mesh.traverse((mesh) => {
  992. mesh.type = "hotSprite" //raycaster use
  993. })
  994. if (!this.mesh.boxHelper) {
  995. var boxHelper = this.mesh.children.find(e => e instanceof THREE.Box3Helper)
  996. if (boxHelper) {
  997. this.mesh.boxHelper = boxHelper
  998. } else {
  999. var bound
  1000. if (this.objObject) {
  1001. bound = new THREE.Box3().copy(this.info.modelBound.bound)
  1002. } else {
  1003. bound = planeBound
  1004. }
  1005. bound.expandByVector(new THREE.Vector3(0.0001, 0.0001, 0.0001))
  1006. this.mesh.boxHelper = new THREE.Box3Helper(bound, new THREE.Color("#00ffff"));
  1007. this.mesh.add(this.mesh.boxHelper)
  1008. this.mesh.boxHelper.material.depthTest = false;
  1009. this.mesh.boxHelper.material.transparent = true
  1010. this.mesh.boxHelper.visible = false
  1011. }
  1012. }
  1013. }
  1014. changeBoxHelperDisplay(show) {
  1015. if (show) {
  1016. this.visible_ = this.visible
  1017. this.visible = true
  1018. this.mesh.boxHelper.visible = true
  1019. } else {
  1020. if (this.visible_ != void 0) {
  1021. this.visible = this.visible_
  1022. }
  1023. this.mesh.boxHelper.visible = false
  1024. }
  1025. }
  1026. /* addToLoadQueue() {
  1027. if (this.texType == 'photo') {
  1028. Hot.loadQueue.includes(this) || Hot.loadQueue.push(this)
  1029. }
  1030. } */
  1031. requestDownload(type, callback) {
  1032. var plane = this.plane;
  1033. if (type == 'photo') {
  1034. if (this.photoHasRequestLoad || this.texType != 'photo') return;
  1035. //console.log('overlay beginDownload : ' + this.sid)
  1036. /* this.material_.map = */Texture.load(this.info.texSrc, (tex) => {
  1037. callback && callback()
  1038. if (!tex.image) {
  1039. return //只是单纯用了相同src的tex,但image仍未加载完
  1040. }
  1041. if (!this._loadDones) return
  1042. dealMap(tex)
  1043. setTimeout(Hot.loadNext, 50)
  1044. hotGroup.children.forEach(e => {
  1045. if (e.info.texSrc == this.info.texSrc && e.info.texType == type) {
  1046. e.material_.color.set("#FFFFFF")
  1047. e.material_.opacity = 1;
  1048. console.log('overlay loaded: ' + e.sid + " - " + this.info.texSrc.split('/').pop());
  1049. e.texMedia = tex.image
  1050. {//animation不同致使的不能使用同一个texture
  1051. if (window.isEdit) {
  1052. if (animateTexSrcs[e.info.texSrc]) {
  1053. e.material_.map = tex.clone(); //编辑动画直接不用一个texture, 故而animation也不同
  1054. e.material_.map.needsUpdate = true
  1055. } else {
  1056. e.material_.map = tex
  1057. animateTexSrcs[e.info.texSrc] = 1
  1058. }
  1059. } else {
  1060. if (animateTexSrcs[e.info.texSrc]) {//已有该texSrc
  1061. let finded = false
  1062. for (let i of animateTexSrcs[e.info.texSrc]) {
  1063. if (ifSame(i[0], e.info.animateInfo)) {
  1064. e.material_.map = i[1]; finded = true; break;
  1065. }
  1066. }
  1067. if (!finded) {
  1068. let tex_ = tex.clone();
  1069. animateTexSrcs[e.info.texSrc].set(e.info.animateInfo, tex_)
  1070. e.material_.map = tex_
  1071. }
  1072. } else {
  1073. let object = new Map();
  1074. object.set(e.info.animateInfo, tex)
  1075. animateTexSrcs[e.info.texSrc] = object//注册第一个texSrc
  1076. e.material_.map = tex
  1077. }
  1078. }
  1079. }
  1080. if (e.info.animateInfo && !e.animation) {
  1081. e.animation = GifTexDeal.addAnimation(e.material_.map, e, e.info.animateInfo, e.sid)
  1082. e.visible && e.inSight() && GifTexDeal.start(e.animation)
  1083. }
  1084. if (++photoLoaded == originPhotoCount) {//data2.js中的所有photo加载完毕
  1085. Hot.allPhotoLoaded = true;
  1086. Hot.whenAllFileLoaded && Hot.allModelLoaded && Hot.whenAllFileLoaded()
  1087. }
  1088. {
  1089. e._loadDones.forEach(a => a())
  1090. e._loadDones = null
  1091. e.photoHasRequestLoad = true
  1092. }
  1093. e.material_.needsUpdate = true
  1094. }
  1095. })
  1096. })
  1097. this.photoHasRequestLoad = true
  1098. } else if (type == 'model') {
  1099. if (this.modelHasRequestLoad || !this.info.objSrc) return;
  1100. //需要处理重复?
  1101. objLoader.load(this.info.objSrc, (object) => {
  1102. this.remove(this.mesh)
  1103. this.addModel(object)
  1104. callback && callback()
  1105. if (++modelLoaded == originModelCount) {//data2.js中的所有photo加载完毕
  1106. Hot.allModelLoaded = true;
  1107. Hot.whenAllFileLoaded && Hot.allPhotoLoaded && Hot.whenAllFileLoaded()
  1108. }
  1109. })
  1110. this.modelHasRequestLoad = true
  1111. }
  1112. }
  1113. }
  1114. Hot.updateVisibles = function (panos) {
  1115. if (panos === true) {
  1116. model.hotGroup.children.forEach(e => e.updateVisible(null, true))
  1117. } else {
  1118. model.hotGroup.children.forEach(e => e.updateVisible(panos))
  1119. }
  1120. }
  1121. Hot.beginShineHot = function () {
  1122. if (!window.isEdit && shineMats.length == 0) return
  1123. transitions.trigger({
  1124. func: function (e) {
  1125. var opa = e <= .5 ? 2 * e : -2 * e + 2
  1126. shineMats.forEach(mat => {
  1127. mat.uniforms.opac.value = opa;
  1128. })
  1129. },
  1130. cycling: !0,
  1131. duration: 3e3,
  1132. name: "hotShine"
  1133. })
  1134. }
  1135. Hot.getDefaulScale = function (hotIconScale) {
  1136. return (hotIconScale || DATA.hotIconScale) * g_HotMeshSize.g_HotMeshWidth
  1137. }
  1138. var loadings = [];
  1139. Hot.loadQueue = []; //等待下载的overlay,目前只针对photo
  1140. Hot.maxLoadingCount = 3; //同时正在load图片的数量
  1141. Hot.loadNext = () => {//继续requestDownload loadQueue中前排的item
  1142. let count = Hot.maxLoadingCount - loadings.length
  1143. Hot.loadQueue.slice(0, count).forEach(e => {
  1144. loadings.push(e)
  1145. //console.log(e)
  1146. e.hot.requestDownload(e.type, () => {
  1147. var i = loadings.indexOf(e)
  1148. loadings.splice(i, 1)
  1149. })
  1150. })
  1151. Hot.loadQueue.splice(0, count)
  1152. }
  1153. Hot.getNeedLoad = function () {//计算获取loadQueue,每次都重新计算,覆盖旧的
  1154. if (!player || !player.domElement || !player.mode)
  1155. return;
  1156. var hots1, hots2
  1157. if (player.mode != 'panorama') {
  1158. if (Hot.loadQueue.length == 0) {
  1159. hots1 = model.hotGroup.children.filter(e => e.texType == 'photo' && !e.photoHasRequestLoad)
  1160. hots2 = model.hotGroup.children.filter(e => e.info.objSrc && !e.modelHasRequestLoad)
  1161. Hot.loadQueue = hots1.map(e => { return { hot: e, type: "photo" } }).concat(
  1162. hots2.map(e => { return { hot: e, type: "model" } })
  1163. )
  1164. }
  1165. return
  1166. }
  1167. //Hot.loadWhenOutside = true
  1168. hots1 = model.hotGroup.children.filter(e => e.texType == 'photo' && !e.photoHasRequestLoad && (!e.info.visiblePanos || e.info.visiblePanos.includes(player.currentPano.id)))
  1169. hots2 = model.hotGroup.children.filter(e => e.info.objSrc && !e.modelHasRequestLoad && (!e.info.visiblePanos || e.info.visiblePanos.includes(player.currentPano.id)))
  1170. if (hots1.length + hots2.length == 0) {
  1171. hots1 = model.hotGroup.children.filter(e => e.texType == 'photo' && !e.photoHasRequestLoad)
  1172. hots2 = model.hotGroup.children.filter(e => e.info.objSrc && !e.modelHasRequestLoad)
  1173. }
  1174. var cameraDir = player.getDirection()
  1175. Hot.loadQueue = hots1.map(e => { return { hot: e, type: "photo" } }).concat(
  1176. hots2.map(e => { return { hot: e, type: "model" } })
  1177. )
  1178. var request = [(item) => {
  1179. return true
  1180. }];
  1181. var rank = [(item) => {
  1182. var dis = item.hot.mesh.getWorldPosition().distanceTo(player.position);
  1183. return -dis
  1184. }
  1185. , (item) => {
  1186. var tagDir = item.hot.mesh.getWorldPosition().sub(player.position)
  1187. var angle = tagDir.angleTo(cameraDir)
  1188. return -angle * 20
  1189. }]
  1190. var result = common.sortByScore(Hot.loadQueue, request, rank);
  1191. //Hot.loadQueue = result ? result.slice(0, 5).map(e=>e.item) : model.hotGroup.children.filter(e=>e.texType == 'photo' && !e.hasRequestLoad).slice(0, 2);
  1192. Hot.loadQueue = result ? result.slice(0, 5).map(e => e.item) : []
  1193. }
  1194. Hot.load = () => {//开始下载图片
  1195. Hot.getNeedLoad()
  1196. Hot.loadNext()
  1197. var hots1 = model.hotGroup.children.filter(e => e.texType == 'photo' && !e.photoHasRequestLoad)
  1198. var hots2 = model.hotGroup.children.filter(e => e.info.objSrc && !e.modelHasRequestLoad)
  1199. if (hots1.length + hots2.length > 0) {
  1200. setTimeout(Hot.load, 200)
  1201. } else {
  1202. Hot.allRequestLoad = true
  1203. console.log('allRequestLoad')
  1204. }
  1205. }
  1206. Hot.startLoad = () => {
  1207. originPhotoCount = hotGroup.children.filter(e => e.texType == 'photo').length
  1208. originModelCount = hotGroup.children.filter(e => !!e.info.objSrc).length
  1209. if (originPhotoCount == 0) Hot.allPhotoLoaded = true
  1210. if (originModelCount == 0) Hot.allModelLoaded = true;
  1211. if (Hot.allModelLoaded && Hot.allPhotoLoaded) Hot.whenAllFileLoaded && Hot.whenAllFileLoaded()//所有加载完毕
  1212. else {
  1213. Hot.load()
  1214. }
  1215. }
  1216. window.Hot = Hot
  1217. /* var ball = new THREE.Mesh(new THREE.SphereBufferGeometry(0.01),new THREE.MeshBasicMaterial({color:"#f00",depthTest:false,transparent:true}))
  1218. var balls = []
  1219. var addPoint = function(point){
  1220. console.log(point)
  1221. var ball1 = ball.clone()
  1222. model.add(ball1);
  1223. ball1.position.copy(point)
  1224. balls.push(ball1)
  1225. }
  1226. var addPoints = function(points){
  1227. balls.forEach(e=>model.remove(e))
  1228. balls = []
  1229. points.forEach(e=>addPoint(e))
  1230. }
  1231. */
  1232. //判断是否是移动端,如果是给关闭按钮添加touchstart事件
  1233. Hot.closePopup = () => {// 关闭热点页面
  1234. if (!g_currentHot) return;
  1235. console.log('关闭热点,打开背景音乐');
  1236. if(window.musicFlagNow === '音乐开') SoundManager.play('bgm')
  1237. g_currentHot = null;
  1238. var hotPop = document.getElementById('popup');
  1239. hotPop.style.display = "none";
  1240. document.querySelector(".popup-content").removeChild(document.getElementById("id1"));
  1241. $("#popup iframe:last").remove();
  1242. SoundManager.pause('hot', true)//自动播放被中断的音频 (bgm
  1243. return false
  1244. }
  1245. if (browser.isMobile()) {
  1246. $('#closepop').on("touchstart", Hot.closePopup);
  1247. } else {
  1248. $('#closepop').on("click", Hot.closePopup);
  1249. }
  1250. Hot.createHotList = function () {
  1251. var docFragment = document.createDocumentFragment();
  1252. var hots = hotGroup.children.filter(hot => hot.info.actionType.openHot);
  1253. hots = hots.sort((a, b) => { return a.order - b.order });
  1254. window.myHotList = hots
  1255. console.log(123, window.myHotList);
  1256. hots.forEach((hot) => {
  1257. var li = document.createElement('li');
  1258. var span = document.createElement('span');
  1259. span.innerHTML = hot.info.title || '热点';
  1260. // console.log(span.innerHTML);
  1261. li.hot = hot; // 列表每一项对应一个热点
  1262. li.appendChild(span);
  1263. docFragment.appendChild(li);
  1264. })
  1265. var ul = document.querySelector('#hotListContent ul');
  1266. ul && ul.appendChild(docFragment);
  1267. }
  1268. }
  1269. /*
  1270. 保存 JSON.stringify(editTool.hotpoint.getSavingInfo())
  1271. 可能需要再写一份保存到overlay 给旧场景项目使用
  1272. 最好后台有针对手机版的做一个压缩。压缩成几个档位。
  1273. 安卓手机firefox出现过视频mesh不可见或者闪烁的情况。
  1274. 视频最容易导致崩溃, 模型还好
  1275. 数据速率为4064kbps,1920*1080px 时测试部门电脑崩溃
  1276. 数据速率为1824kbps,720 *576px 时正常
  1277. 所以尽量降到2000以下 同时播放个数最好不超过2个 可能需要将src归零 并延迟加载、不自动播放
  1278. */