Hot.js 85 KB

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