Hot.js 72 KB

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