Hot.js 76 KB

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