Hot.js 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  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('/edit-backstage','')
  42. }
  43. var removeSrcPostMark = function(url){//去除texture.load时自动加上的'?'
  44. var index = url.indexOf('?')
  45. if(index>-1){
  46. return url.slice(0, index)
  47. }else return url
  48. }
  49. {//get plane Bound
  50. var planeBound = new THREE.Box3()
  51. var cornerPoint = [
  52. new THREE.Vector3(-0.5, 0.5, 0),
  53. new THREE.Vector3(0.5, 0.5, 0),
  54. new THREE.Vector3(0.5, -0.5, 0),
  55. new THREE.Vector3(-0.5, -0.5, 0),
  56. ]
  57. cornerPoint.forEach(e=>{
  58. planeBound.expandByPoint(e)
  59. })
  60. }
  61. var shineMats = [];
  62. var getShineMat = function(texture1, texture2){
  63. var mat = shineMats.find(e=>e.uniforms.texture1.value == texture1 && e.uniforms.texture2.value == texture2)
  64. if(mat) return mat
  65. else{
  66. var mat = new THREE.ShaderMaterial({
  67. uniforms: {
  68. opac: {
  69. type: "f",
  70. value: 0
  71. },
  72. texture1: {
  73. type: "t",
  74. value: texture1
  75. },
  76. texture2: {
  77. type: "t",
  78. value: texture2
  79. }
  80. },
  81. vertexShader: "varying vec2 vUv;\n\nvoid main() {\n\n vUv = uv ;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n}\n",
  82. fragmentShader: "varying vec3 vNormal;\n\nvarying vec2 vUv;\n\nuniform float opac;\n\n uniform sampler2D texture1;\n\nuniform sampler2D texture2;\n\nvoid main() {\n\nvec4 tcolor1 = texture2D( texture1, vUv );\n\nvec4 tcolor2 = texture2D( texture2, vUv );\n\ngl_FragColor = mix(tcolor1,tcolor2 ,opac) + tcolor2*0.2; }\n"
  83. ,transparent: !0
  84. })
  85. shineMats.push(mat)
  86. return mat
  87. }
  88. }
  89. var modelGeos = [];
  90. var getModelGeo = function(url){
  91. var geo = modelGeos.find(e=>e.url = url )
  92. if(geo) return geo
  93. else{
  94. var geo = null;
  95. geo.url = url
  96. }
  97. }
  98. class Hot extends THREE.Object3D{
  99. constructor(info, source){
  100. super()
  101. this.sid = info.sid;
  102. this.preDeal(info, source)// source:旧版来源
  103. this.info = info
  104. this.cornerPoints = []
  105. this.build(info);
  106. this.name = "hot_" + this.sid ;
  107. model.hots[info.sid] = this
  108. }
  109. build(info) {
  110. hotGroup.add(this)
  111. this.setTitleElem()
  112. this.setFromInfo(info)
  113. }
  114. setFromInfo(info, media, objObject) {
  115. //1 恢复到编辑之前 2 初始加载
  116. var plane = this.plane;
  117. /* var transformAtPanos = {}
  118. for(var i in info.transformAtPanos){
  119. transformAtPanos[i] = {//只保留一个位移,主要原因是大小变化和热点大小设置冲突了, isSprite和qutaernion衝突
  120. pos : info.transformAtPanos[i].pos && info.transformAtPanos[i].pos.clone(),
  121. //qua : info.transformAtPanos[i].qua && info.transformAtPanos[i].qua.clone(),
  122. }
  123. }
  124. this.transformAtPanos = transformAtPanos */
  125. //在每个漫游点独立设置的position。
  126. var curPanoTransform = this.info.transformAtPanos[ getTransformSid()] || {}
  127. //没有单独设置position的漫游点使用的position
  128. this.position.copy(curPanoTransform.pos || info.position)
  129. this.rotation.copy(info.rotation)
  130. this.scale.copy(info.scale)
  131. this.changeTexType(info.texType, media)
  132. if(!info.objSrc){
  133. this.addPlane()
  134. if (!!this.hasBox != !!info.hasBox) {
  135. this.addBox(!this.hasBox);
  136. }
  137. }else{
  138. this.addModel(objObject || new THREE.Mesh())//暂时创建个空的
  139. }
  140. this.updateMatrixWorld()
  141. /* if(!this.info.visiblePanos){//移到model.build时,在collider建好之后
  142. this.getVisiblePanos()
  143. } */
  144. {//gif
  145. if(this.animation){
  146. GifTexDeal.remove(this.animation)
  147. }
  148. if(this.info.animateInfo && this.material_.map){
  149. this.animation = GifTexDeal.addAnimation(this.material_.map, this, this.info.animateInfo, this.sid )
  150. this.visible && this.inSight() && GifTexDeal.start(this.animation)
  151. }
  152. }
  153. /* if(this.info.modelBound){
  154. this.mesh.updateMatrixWorld()
  155. this.mesh.boxHelper2 = new THREE.Box3Helper( new THREE.Box3().copy(this.info.modelBound.bound).applyMatrix4(this.mesh.matrixWorld), new THREE.Color("#00aaee"));
  156. model.add(this.mesh.boxHelper2)
  157. }else{
  158. var bound = new THREE.Box3()
  159. var cornerPoint = [
  160. new THREE.Vector3(-0.5, 0.5, 0),
  161. new THREE.Vector3(0.5, 0.5, 0),
  162. new THREE.Vector3(0.5, -0.5, 0),
  163. new THREE.Vector3(-0.5, -0.5, 0),
  164. ]
  165. cornerPoint.forEach(e=>{
  166. bound.expandByPoint(e)
  167. })
  168. this.mesh.updateMatrixWorld()
  169. this.mesh.boxHelper2 = new THREE.Box3Helper( bound.applyMatrix4(this.mesh.matrixWorld), new THREE.Color("#00aaee"));
  170. model.add(this.mesh.boxHelper2)
  171. } */
  172. }
  173. changeTexType(texType, media){
  174. var plane = this.plane;
  175. if( this.texType != texType || media == 'clear'){
  176. //删除旧的
  177. if(this.texType == 'shine'){
  178. /* this.material_.uniforms.texture1.value.dispose()
  179. this.material_.uniforms.texture2.value.dispose() */ //为了恢复 不删
  180. }else{
  181. //this.material_.map.dispose()
  182. if(this.texType == 'video'){
  183. this.texMedia && this.texMedia.pause()
  184. }else{
  185. }
  186. }
  187. if(this.material_ && !hotGroup.children.find(e=>e!=this && e.material_ == this.material_ )){
  188. this.material_.dispose()
  189. }
  190. //添加新的
  191. if(texType == 'shine'){
  192. }else{
  193. this.changeMaterial(new THREE.MeshBasicMaterial({
  194. color: "#00c8af",
  195. opacity: 0.4,
  196. transparent: !0,
  197. polygonOffset: true,
  198. //是否开启多边形偏移 //ie不开启时blank也不会闪烁
  199. polygonOffsetFactor: -0.9,
  200. //多边形偏移因子
  201. polygonOffsetUnits: -4.0,
  202. //多边形偏移单位
  203. }))
  204. if(texType == 'video'){
  205. }else{
  206. }
  207. }
  208. }
  209. this.texType = texType
  210. if(media == 'clear'){
  211. this.material_.opacity = 0.4;
  212. this.texMedia = null
  213. return
  214. }
  215. if(texType == 'video'){//视频不能共用一个,否则会一起播放暂停
  216. var video
  217. if(media){
  218. video = media
  219. }else{
  220. if(!this.info.texSrc)return
  221. var video = $(`<video controls="controls" loop x5-playsinline="" webkit-playsinline="true" playsinline="true" controlslist="nodownload" preload="meta" ></video>`)[0]
  222. if(window.isEdit) video.src = manage.dealURL(this.info.texSrc); //注意,src赋值就会自动加载, preload="meta" 只加载元数据,提高加载速度,否则一开始卡
  223. /* let src = this.info.texSrc
  224. if(window.isEdit) src = manage.dealURL(src);
  225. var video = window.videoPlayer.getVideo(src)*/
  226. video.name = this.info.fileName
  227. }
  228. video.setAttribute("crossOrigin", 'Anonymous')//要在src设置好前解决跨域
  229. $(video).on('contextmenu', function() {
  230. return false;
  231. });//禁止右键点击出
  232. this.texMedia = video;
  233. video.oncanplaythrough = (e)=> {
  234. if(this.texMedia == video){
  235. /* if(video.paused) *///console.log({str:'oncanplaythrough '+this.sid, level:1})
  236. //this.material_.map.needsUpdate = !0 //当初为何加这句?
  237. //this.update(player)
  238. }
  239. }
  240. /* video.onloadstart = (e)=> {
  241. console.log({str:'onloadstart '+this.sid, level:1})
  242. }
  243. video.onloadedmetadata = (e)=> {
  244. console.log({str:'onloadedmetadata '+this.sid, level:1})
  245. }
  246. video.onloadeddata = (e)=> {
  247. console.log({str:'onloadeddata '+this.sid, level:1})
  248. }
  249. video.oncanplay = (e)=> {
  250. console.log({str:'oncanplay '+this.sid, level:1})
  251. } */
  252. video.volume = 0
  253. video.muted = true
  254. video.currentTime = 0
  255. if(!window.isEdit) this.material_.opacity = 0.3;
  256. this.material_.map = new THREE.VideoTexture(video)
  257. this.material_.map.wrapS = this.material_.map.wrapT = THREE.ClampToEdgeWrapping;
  258. this.material_.map.generateMipmaps = true;
  259. }else if(texType == 'photo'){
  260. if(media){
  261. this.texMedia = media;
  262. this.info.texSrc = media.src;
  263. this.material_.map = new THREE.Texture(); //texture也不能共用一个,因为有的会有动画,就不一样
  264. this.material_.map.image = media //image可以共用
  265. this.material_.map.needsUpdate = !0
  266. this.material_.opacity = 1
  267. }else{
  268. if(!this.info.texSrc)return
  269. this._loadDones = []
  270. this.material_.opacity = 0.1;
  271. }
  272. }else if(texType == 'shine'){
  273. if(media){
  274. this.changeShineTex(media)
  275. }else{
  276. this.styleImg = /* this.styleImg || */ [];
  277. if(this.info.styleImg){
  278. this.styleImg = this.info.styleImg.map((src)=>{
  279. return {src:/* manage.dealURL( */src } //如果要dealURL,在predeal里
  280. })
  281. }
  282. this.changeShineTex(this.styleImg)
  283. }
  284. this.info.texSrc = null
  285. }
  286. if(this.material_.map){
  287. /* this.material_.map.minFilter = THREE.LinearFilter;
  288. this.material_.map.magFilter = THREE.LinearFilter; */
  289. dealMap(this.material_.map);
  290. this.material_.color.set("#FFFFFF");
  291. this.material_.needsUpdate = true
  292. }
  293. }
  294. changeShineTex(styleImg){
  295. styleImg = styleImg || this.styleImg
  296. var tex1, tex2
  297. if(styleImg.length){
  298. tex1 = Texture.load(styleImg[0].src);
  299. tex2 = Texture.load(styleImg[1]&&styleImg[1].src || styleImg[0].src);
  300. dealMap(tex1,{ignoreResize:true} )
  301. dealMap(tex2,{ignoreResize:true} )
  302. }else{
  303. tex1 = defaultTex1;
  304. tex2 = defaultTex2;
  305. }
  306. this.changeMaterial(getShineMat(tex1, tex2))
  307. this.styleImg = styleImg
  308. this.info.styleImg = styleImg.map(img=>img.src)
  309. }
  310. changeMaterial(mat){
  311. this.material_ = mat;
  312. this.mesh && this.mesh.traverse((mesh)=>{
  313. if(mesh.material && !(mesh instanceof THREE.Box3Helper)){
  314. mesh.material = this.material_;
  315. }
  316. })
  317. }
  318. preDeal(info, source){// source:来源
  319. var convertValue = function(v ,Type){
  320. var value;
  321. if(v instanceof Array){
  322. v.forEach((v1)=>{v1 = parseFloat(v1)})
  323. value = new Type().fromArray(v);
  324. }else{
  325. if(!(v instanceof Type)){
  326. for(let i in v){v[i] = parseFloat(v[i])}
  327. value = new Type().copy(v);
  328. }else{
  329. value = v
  330. }
  331. }
  332. return value
  333. }
  334. if (!info.transformAtPanos) info.transformAtPanos = {}
  335. if(source == 'byHot'){
  336. var infoAttribute = info.infoAttribute || {}
  337. info.title = infoAttribute.title || info.title
  338. info.model = infoAttribute.model || info.model || [] //模型链接
  339. info.images = infoAttribute.images || info.images || []
  340. info.video = infoAttribute.video || info.video || []
  341. info.bgName = infoAttribute.bgName || info.bgName
  342. info.backgroundMusic = info.backgroundMusic || info.backgroundMusic
  343. info.iframe = infoAttribute.iframe || info.iframe || []
  344. info.styleImg = infoAttribute.styleImg || info.styleImg || []
  345. info.content = infoAttribute.content || info.content
  346. {
  347. let action = CloneObject(settings.hotClickEvent.shine);
  348. if(info.actionType == 'noAction' || info.noAction){
  349. action.examine = false,
  350. action.openHot = false
  351. }else if(info.actionType == 'dontExam'){
  352. action.examine = false
  353. }
  354. info.actionType = action
  355. }
  356. if(info.quaternion){
  357. info.rotation = new THREE.Euler().setFromVector3(convertValue(info.quaternion, THREE.Quaternion ))
  358. }else{
  359. info.rotation = new THREE.Euler().setFromVector3(convertValue(info.rotation, THREE.Vector3 )) //热点的旧数据很多是字符串
  360. }
  361. var s = Hot.getDefaulScale(info.hotIconScale) //旧版的大小,统一转换成新版
  362. info.scale = new THREE.Vector3(s,s,0.02)
  363. delete info.infoAttribute;
  364. /* for (let i in this.transformAtPanos) {
  365. info.transformAtPanos[i].pos = new THREE.Vector3().fromArray(info.transformAtPanos[i].pos)
  366. info.transformAtPanos[i].qua && (info.transformAtPanos[i].qua = new THREE.Quaternion().fromArray(info.transformAtPanos[i].qua))
  367. } */
  368. info.texType = "shine"
  369. }else{
  370. if(source == 'byOverlay'){
  371. info.texType = info.media[0]
  372. //info.title = info.texType == 'video'?'视频':'图片'
  373. info.texSrc = info.file
  374. info.actionType = CloneObject(settings.hotClickEvent[info.texType]);//给一个默认
  375. delete info.media
  376. info.rotation = new THREE.Euler().setFromQuaternion(convertValue(info.qua, THREE.Quaternion ))
  377. info.position = info.pos
  378. delete info.pos;
  379. delete info.qua;
  380. let a = info.texSrc.split('/');
  381. info.fileName = a.pop()
  382. info.scale = new THREE.Vector3(
  383. info.width,
  384. info.height,
  385. info.depth
  386. )
  387. delete info.width; delete info.height; delete info.depth;
  388. delete info.file
  389. }else{
  390. info.rotation = new THREE.Euler().fromArray(info.rotation)//.setFromVector3(info.rotation)
  391. }
  392. info.model = info.model || [] //模型链接
  393. info.images = info.images || []
  394. info.video = info.video || []
  395. info.iframe = info.iframe || []
  396. info.styleImg = info.styleImg || []
  397. info.imagesDesc = info.imagesDesc || []
  398. info.videosDesc = info.videosDesc || []
  399. info.titleShowType = info.titleShowType || 'hover'
  400. info.titlePos = info.titlePos || 'right'
  401. }
  402. if(info.texSrc){
  403. info.texSrc = manage.removeSrcPostMark(info.texSrc)
  404. }
  405. //whole:
  406. //为了兼容旧数据,尽量和hot的数据靠近,最后保存在hot里
  407. info.position = convertValue(info.position, THREE.Vector3)
  408. info.scale = convertValue(info.scale, THREE.Vector3)
  409. delete info.quaternion
  410. info.linkType = info.linkType || "common"
  411. for (let i in info.transformAtPanos) {
  412. info.transformAtPanos[i].pos = new THREE.Vector3().fromArray(info.transformAtPanos[i].pos)
  413. //info.transformAtPanos[i].qua = new THREE.Quaternion().fromArray(info.transformAtPanos[i].qua)
  414. }
  415. }
  416. addBox(state) {
  417. if (state == !!this.hasBox) {
  418. return;
  419. }
  420. if (state) {
  421. var box = new THREE.Mesh(_boxGeometry,_boxMat)
  422. box.position.set(0, 0, 1 / 2);
  423. box.renderOrder = 3
  424. this.plane.position.set(0, 0, 1);
  425. this.add(box);
  426. this.box = box;
  427. } else {
  428. this.plane.position.set(0, 0, 0);
  429. this.remove(this.box);
  430. this.box = null;
  431. }
  432. this.hasBox = this.info.hasBox = state
  433. }
  434. /* getSizeByScale() {
  435. return {
  436. width: settings.defaultOverlaySize[0] * this.scale.x,
  437. height: settings.defaultOverlaySize[1] * this.scale.y
  438. }
  439. }
  440. getScaleBySize(width, height) {
  441. return {
  442. x: width / settings.defaultOverlaySize[0],
  443. y: height / settings.defaultOverlaySize[1],
  444. }
  445. }*/
  446. setVisiblePanos(visibleData){
  447. if(visibleData)this.info.visiblePanos = visibleData
  448. else if(!this.info.visiblePanos) this.getVisiblePanos()
  449. }
  450. getVisiblePanos(){//在不同点还不一样
  451. var depth = this.hasBox ? this.scale.z : 0;
  452. var width = this.scale.x, height = this.scale.y
  453. var cornerPoint
  454. if(this.plane){
  455. cornerPoint = [
  456. new THREE.Vector3(0, 0, depth),
  457. new THREE.Vector3(-width/2, height/2, depth),
  458. new THREE.Vector3(width/2, height/2, depth),
  459. new THREE.Vector3(width/2, -height/2, depth),
  460. new THREE.Vector3(-width/2, -height/2, depth),
  461. ]
  462. }else{
  463. var bound = new THREE.Box3().copy(this.info.modelBound.bound)
  464. var center = bound.center()
  465. cornerPoint = [
  466. new THREE.Vector3(center.x,center.y,center.z),
  467. new THREE.Vector3(bound.min.x, bound.min.y, bound.min.z ),
  468. new THREE.Vector3(bound.min.x, bound.min.y, bound.max.z ),
  469. new THREE.Vector3(bound.min.x, bound.max.y, bound.min.z ),
  470. new THREE.Vector3(bound.max.x, bound.min.y, bound.min.z ),
  471. new THREE.Vector3(bound.max.x, bound.max.y, bound.min.z ),
  472. new THREE.Vector3(bound.max.x, bound.min.y, bound.max.z ),
  473. new THREE.Vector3(bound.min.x, bound.max.y, bound.max.z ),
  474. new THREE.Vector3(bound.max.x, bound.max.y, bound.max.z ),
  475. ];
  476. }
  477. var getPos = (position)=>{//每个overlay位置对应5个坐标,plane中心和四个角的位置
  478. if(this.plane){
  479. return cornerPoint.map(e=>{
  480. return e.clone().applyEuler(this.info.rotation).add(position)
  481. })
  482. }else{
  483. var matrixWorld = new THREE.Matrix4().compose(position, this.quaternion, this.scale)
  484. matrixWorld.multiplyMatrices(matrixWorld, this.mesh.matrix)
  485. return cornerPoint.map(e=>{
  486. return e.clone().applyMatrix4(matrixWorld);
  487. })
  488. }
  489. }
  490. this.info.visiblePanos = []
  491. var customPositions = getPos(this.info.position )
  492. var posAtPanos = {}
  493. for(let panoId in this.info.transformAtPanos){
  494. if(panoId == 'outSide')continue;
  495. posAtPanos[panoId] = getPos(this.info.transformAtPanos[panoId].pos )
  496. }
  497. let maxCount = browser.isMobile() ? 2000 : 5000
  498. let possiblePanos = model.panos.list
  499. if(this.plane){//目前都是单面,所以只要可以看到的一面的热点
  500. let dir1 = new THREE.Vector3(0,0,-1).applyQuaternion(this.quaternion).negate()
  501. possiblePanos = possiblePanos.filter(pano=>{
  502. let dir2 = new THREE.Vector3().subVectors(pano.position, this.position).normalize();
  503. return dir1.dot(dir2)>0
  504. })
  505. }
  506. let c = model.panos.list.length * model.colliders.length
  507. if(window.isEdit || c < maxCount){ //编辑页面保险起见还是全部算完后才可浏览,就能保证保存全部的visiblePano
  508. this.info.visiblePanos = common.getVisiblePano(customPositions, possiblePanos , {
  509. model: model.colliders , posAtPanos
  510. })
  511. }else{
  512. let start = 0
  513. let interval = setInterval(()=>{
  514. let end = start + Hot.visiPanosCountSlice;
  515. end = Math.min(end, possiblePanos.length)
  516. let i = start
  517. start = end
  518. let panos = possiblePanos.slice(i,end)
  519. this.info.visiblePanos = this.info.visiblePanos.concat( common.getVisiblePano(customPositions, panos, {
  520. model: model.colliders , posAtPanos
  521. }));
  522. if(end>=possiblePanos.length){
  523. //console.log(window.hotsi ?(++window.hotsi): (window.hotsi = 1))
  524. clearInterval(interval)
  525. }
  526. }, Hot.visiEveryDurSlice )// visiEveryDurSlice 等在main中定义
  527. }
  528. }
  529. updateVisible(panos, visibility) {
  530. if(window.isEdit && editTool.hotpoint.editSpot == this){
  531. return this.visible = true
  532. }
  533. this.visible = visibility != void 0 ? visibility : (!this.info.visiblePanos || !!panos.find(pano=>this.info.visiblePanos.includes(pano.id)))
  534. this.titleElem && this.titleElem.setVisible(this.visible, 'hotVisible', 1)
  535. if (this.texType == 'video'){
  536. //this.switchPlay(this.visible, this.visible ? null : 'stop' );//可见时不操作;不可见时停止
  537. this.update(player)
  538. }
  539. }
  540. getBoundOri(){
  541. let bound
  542. if(this.objObject){
  543. bound = new THREE.Box3().copy(this.info.modelBound.bound)
  544. }else{
  545. bound = planeBound.clone()
  546. }
  547. return bound
  548. }
  549. getCornerPoint(){//获取在每个漫游点上的视觉边界点 可以打开boxHelper和addBall来观测是否准确
  550. if(this.cornerPoints[player.currentPano.id]){
  551. return this.cornerPoints[player.currentPano.id]
  552. }else{
  553. var boundPoint, cornerPoint
  554. var center//中心点
  555. if(this.plane){
  556. center = this.plane.getWorldPosition()
  557. boundPoint = [
  558. new THREE.Vector3(-0.5, 0.5, 0),
  559. new THREE.Vector3(0.5, 0.5, 0),
  560. new THREE.Vector3(0.5, -0.5, 0),
  561. new THREE.Vector3(-0.5, -0.5, 0),
  562. ]
  563. }else{
  564. var bound = new THREE.Box3().copy(this.info.modelBound.bound)
  565. boundPoint = [
  566. new THREE.Vector3(bound.min.x, bound.min.y, bound.min.z ),
  567. new THREE.Vector3(bound.min.x, bound.min.y, bound.max.z ),
  568. new THREE.Vector3(bound.min.x, bound.max.y, bound.min.z ),
  569. new THREE.Vector3(bound.max.x, bound.min.y, bound.min.z ),
  570. new THREE.Vector3(bound.max.x, bound.max.y, bound.min.z ),
  571. new THREE.Vector3(bound.max.x, bound.min.y, bound.max.z ),
  572. new THREE.Vector3(bound.min.x, bound.max.y, bound.max.z ),
  573. new THREE.Vector3(bound.max.x, bound.max.y, bound.max.z ),
  574. ];
  575. }
  576. var maxLon = -Infinity
  577. var minLon = +Infinity
  578. var maxLat = -Infinity
  579. var minLat = +Infinity
  580. var pos1 = player.currentPano.position.clone();
  581. center = this.position.clone() //模型bound的中心点已经位移到了hot中心点。 注意不能用getWorldPosition,得到的会是偏移的
  582. var dir = center.clone().sub(pos1).normalize()
  583. var centerDirInfo = { }
  584. player.cameraControls.controls.panorama.lookAt.call( centerDirInfo , null, dir )
  585. boundPoint.forEach(e=>{//lon左右
  586. var point = e.applyMatrix4(this.mesh.matrixWorld);
  587. var dir = point.clone().sub(pos1).normalize()
  588. var dirInfo = { }
  589. player.cameraControls.controls.panorama.lookAt.call( dirInfo , null, dir )
  590. var diffLon = (dirInfo.lon-centerDirInfo.lon) % 360
  591. if(Math.abs(diffLon)>180){//因为有时需要根据符号判断是在中心的左边还是右边,所以限制在180内
  592. diffLon += (diffLon>0 ? -360 : 360)
  593. }
  594. var diffLat = dirInfo.lat-centerDirInfo.lat
  595. maxLon = Math.max(diffLon, maxLon)
  596. minLon = Math.min(diffLon, minLon)
  597. maxLat = Math.max(diffLat, maxLat)
  598. minLat = Math.min(diffLat, minLat)
  599. })
  600. var diffLon = maxLon - minLon
  601. var diffLat = maxLat - minLat
  602. if(diffLat>180) {//可能是到了反面。不好算,直接返回所有boundPoint
  603. cornerPoint = boundPoint
  604. }else{
  605. //读取lon lat的最大最小值,勾勒出一个没有倾斜的矩形 。它比boundPoint看起来范围更大些
  606. maxLon = maxLon + centerDirInfo.lon
  607. maxLat = maxLat + centerDirInfo.lat
  608. minLon = minLon + centerDirInfo.lon
  609. minLat = minLat + centerDirInfo.lat
  610. var dirs = [
  611. math.getDirByLonLat(maxLon, maxLat),
  612. math.getDirByLonLat(minLon, minLat),
  613. math.getDirByLonLat(maxLon, minLat),
  614. math.getDirByLonLat(minLon, maxLat),
  615. ]
  616. cornerPoint = dirs.map(e=>{
  617. return e.clone().add(pos1)
  618. })
  619. cornerPoint = [center, ...cornerPoint] //最后增加一个中心点
  620. }
  621. /* if(this.objObject){
  622. cornerPoint = [pos2, ...cornerPoint]
  623. } */
  624. //addPoints(cornerPoint)
  625. this.cornerPoints[player.currentPano.id] = {cornerPoint, diffLon, diffLat}
  626. return this.cornerPoints[player.currentPano.id]
  627. }
  628. }
  629. getMediaSize(){
  630. let size = new THREE.Vector2;
  631. if(this.texMedia){
  632. if(this.texType == 'photo'){
  633. size.x = this.texMedia.width;
  634. size.y = this.texMedia.height;
  635. //动画的话再变
  636. if(this.info.animateInfo){
  637. size.x /= this.info.animateInfo.cellXcount
  638. size.y /= this.info.animateInfo.cellYcount
  639. }
  640. }else{
  641. size.x = this.texMedia.videoWidth || this.videoWidth
  642. size.y = this.texMedia.videoHeight || this.videoHeight
  643. }
  644. }
  645. return size
  646. }
  647. inSight(){
  648. //return true
  649. if(window.isEdit)return true // 太容易move了
  650. if(player.mode == 'panorama' && player.currentPano){
  651. if(!player.camera) return
  652. var cornerPointInfo = this.getCornerPoint();
  653. var cornerPoint
  654. let min = new THREE.Vector2(5,5)
  655. let scaleRatio = 1/player.zoomLevel;
  656. //根据media原始大小来调整阈值: media的原始大小能代表期望显示的大小,如果显示大小的远小于期望大小,就不显示(此时能感受到贴图锯齿严重,清晰度被浪费)。比如如果gif是一个很小的按钮,即使diffLon很小也要显示。缺点:需要用户根据所需上传合适清晰度的图。
  657. let size = this.getMediaSize()
  658. if(size.x>0){
  659. scaleRatio *= Math.sqrt(size.x * size.y) / 1000
  660. }
  661. min.multiplyScalar(scaleRatio)
  662. if(cornerPointInfo.diffLon < min.x || cornerPointInfo.diffLat < min.y ){
  663. //console.log('two far and small')
  664. return false
  665. }
  666. if(cornerPointInfo.diffLon < 15 && cornerPointInfo.diffLat < 15){//当很小的时候,只判断中心点即可
  667. cornerPoint = [cornerPointInfo.cornerPoint[0]];
  668. }else{
  669. cornerPoint = cornerPointInfo.cornerPoint
  670. }
  671. for(let i=0,j=cornerPoint.length;i<j;i++){//只要有一点可见就算看见
  672. var pos2d = math.getPos2d(cornerPoint[i], player.camera, $("#player")[0])
  673. if(pos2d.trueSide && pos2d.inSight) return true
  674. }
  675. }else{//飞出 只判断在不在画面内
  676. //return playVideoWhenFlyOut//true
  677. let frustumMatrix = new THREE.Matrix4
  678. frustumMatrix.multiplyMatrices(player.camera.projectionMatrix, player.camera.matrixWorldInverse)
  679. let frustum = new THREE.Frustum();
  680. frustum.setFromMatrix(frustumMatrix)
  681. let bound = this.getBoundOri()
  682. bound.applyMatrix4(this.matrixWorld)
  683. return frustum.intersectsBox(bound)
  684. }
  685. }
  686. update(player){
  687. if(this.info.isSprite){
  688. this.quaternion.copy(player.camera.quaternion)
  689. }
  690. this.updateScale()
  691. this.updateTitle()
  692. }
  693. updateScale(e, t) {//自适应调节大小
  694. if(!DATA.autoAdjustHotScale || this.texType != 'shine' || !this.plane )return
  695. var scale = convertTool.getScaleForConstantSize($.extend({},autoSizeInfo,{
  696. position: this.position.clone()
  697. }))
  698. this.plane.scale.set(scale,scale,scale)
  699. }
  700. switchPlay(state){//手动播放暂停
  701. this.pausedByUser = !state
  702. this.videoControl(state)
  703. }
  704. loadVideo(video){
  705. if(video.src_)return
  706. video.src = video.src_ = manage.dealURL(this.info.texSrc);
  707. }
  708. videoControl(state){
  709. if(this.texType != "video" || !this.material_.map)return
  710. var video = this.texMedia
  711. this.shouldPlay = state
  712. if(!state || state == 'stop'){
  713. if(!video.paused){
  714. video.pause()
  715. console.log({str: "paused " + this.sid, level:1})
  716. }
  717. /* video.lastCurTime = state == 'stop' ? 0 : video.currentTime //记录
  718. video.src = video.src_ = '' */
  719. if(state == 'stop'){
  720. video.currentTime = 0;
  721. }
  722. }else if(state){
  723. if(/* !isVideoPlayed(video) */ video.paused ){
  724. console.log({str: 'videoControl play ' +", "+ this.sid, level:1})
  725. this.loadVideo(video)
  726. video.play()
  727. //video.currentTime = video.lastCurTime || 0
  728. this.changeOpaWhenPlay(video)
  729. if(isVideoPlayed(video))console.log({str:"played " + this.sid + video.duration ,level:1})
  730. }
  731. }
  732. }
  733. changeOpaWhenPlay(video){//当播放成功后,恢复为不透明
  734. if(isNaN(video.duration)){//未加载好
  735. return setTimeout(()=>{
  736. this.changeOpaWhenPlay(video)
  737. },100)
  738. }
  739. const minPlayedTime = Math.min(video.duration/10, 0.1); //到这个时间说明加载成功
  740. if(!video.hasInitedOpacity){
  741. setTimeout(e=>{
  742. //console.log('trychangeOpa ',this.sid,video.currentTime)
  743. if(video.currentTime>minPlayedTime){
  744. this.material_.opacity = 1
  745. video.hasInitedOpacity = true
  746. //console.log('changeOpaWhenPlay',this.sid)
  747. }else{
  748. if(!video.paused){//再次尝试
  749. return setTimeout(()=>{
  750. this.changeOpaWhenPlay(video)
  751. },500)
  752. }
  753. }
  754. },minPlayedTime*1000+500)
  755. }
  756. }
  757. /* setDefaultHotScale = function(){//设置成默认热点大小
  758. var w = DATA.hotIconScale) * g_HotMeshSize.g_HotMeshWidth
  759. this.scale.set( w, w, this.scale.z)
  760. } */
  761. setTitleElem(){
  762. var title = this.info.title;
  763. if(title){
  764. if(!this.titleElem){
  765. this.titleElem = new Label2D({position:this.position, innerHTML:`<div>${title}</div>`, domElement:$("#hot")[0], shelterByModel:true })
  766. }else{
  767. this.titleElem.elem.html(`<div>${title}</div>`)
  768. }
  769. this.titleElem.setVisible(this.visible, 'hotVisible')
  770. this.setHoverState(false)
  771. this.setTitleDir()
  772. }else{
  773. if(this.titleElem){
  774. this.titleElem.dispose()
  775. this.titleElem = null;
  776. }
  777. }
  778. }
  779. setTitleDir(){
  780. this.titleElem && this.titleElem.elem.attr('pos',this.info.titlePos)
  781. }
  782. updateTitle(){
  783. this.titleElem && this.titleElem.update()
  784. }
  785. setHoverState(state){
  786. if(!this.titleElem)return
  787. this.hovered = !!state
  788. var v = this.info.titleShowType != 'unvisible' && (this.info.titleShowType == 'always' || this.hovered)
  789. this.titleElem.setVisible(v, 'hoveredVisi', 1)
  790. //this.updateTitle()
  791. }
  792. closestPanoTowardTag(e, t) {
  793. var i = []
  794. , n = []
  795. , r = this.mesh.getWorldPosition();
  796. if (e === "panorama") {
  797. /* var o = t.position.clone().sub(r).normalize();
  798. n.push(function(t, i) {//scoreFunctions.direction 最好这个漫游点在currentPano到热点之间的路径上。但是这样的话可能就看不到热点正面,所以删掉
  799. return function(e) {
  800. return e.position.clone().sub(t).normalize().dot(i) * window._settings.navigation.directionFactor
  801. }}(r, o)
  802. ) */
  803. }
  804. var a = new THREE.Vector3;
  805. i.push(function(e) {
  806. 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
  807. },
  808. function(e) {
  809. a.copy(r).sub(e.position);
  810. var t = -THREE.Math.radToDeg(Math.atan(a.y / Math.sqrt(a.x * a.x + a.z * a.z)))
  811. , i = window._settings.tags.navigate.tiltTolerance
  812. return window._settings.insideLookLimitDown - i < t && t < window._settings.insideLookLimitUp + i
  813. },
  814. (pano)=>{ // add
  815. return player.checkHasNeighbor(pano)
  816. },
  817. (pano)=>{ // add
  818. // 周恩光改 解决visiblePanos为undefined时的bug
  819. return !this.info.visiblePanos || this.info.visiblePanos.includes(pano.id)
  820. }
  821. )
  822. n.push(
  823. (function(hot, i) { //scoreFunctions.distanceSquared
  824. return function(pano) {
  825. //i = a.navigation.distanceFactor
  826. return hot ? hot.position.distanceToSquared(pano.position) * i : 0
  827. }
  828. })(this, -2)
  829. ,
  830. (pano)=>{//尽量正对hot
  831. let dir = new THREE.Vector3(0,0,1).applyQuaternion(this.quaternion)
  832. let dir2 = new THREE.Vector3().subVectors(pano.position, this.position).normalize();
  833. let s = dir.dot(dir2) * 60;
  834. //console.log(pano.id + ":" + s)
  835. return s
  836. }
  837. );
  838. /* var tanD = player.domElement.clientWidth / player.domElement.clientHeight * Math.tan((THREE.Math.degToRad(player.zoomFov/2))) ;
  839. var goodDistance = overlay.width / 2 / tanD;
  840. n.push(
  841. function (pano) { //寻找正对着overlay的pano
  842. var overlayDir = new THREE.Vector3(0,0,1).applyQuaternion(overlay.quaternion)
  843. var v1 = overlayDir//.setY(0); 朝上的话set0会得到0,0,0 无法求angle
  844. var v2 = pano.position.clone().sub(overlay.position)//.setY(0)
  845. var angle = v1.angleTo(v2)
  846. angles[pano.id] = angle;
  847. angle = -angle * 100
  848. return angle
  849. },
  850. function (pano) { //寻找正对着overlay的pano
  851. var dis = pano.position.clone().distanceToSquared(overlay.position)
  852. var goodDistance2 = goodDistance * Math.abs(Math.cos(angles[pano.id]))//考虑了倾斜角度后的最佳距离
  853. var result = - 300 * Math.abs(dis-goodDistance2) / goodDistance2 //dis和goodDistance2差距越大分数越低
  854. return result;
  855. }
  856. ) */
  857. var s = t.model.panos.sortByScore(i, n);
  858. console.log(s)
  859. return s && 0 < s.length && s[0].item
  860. }
  861. examine(options={}) {
  862. var openHot = this.info.link && this.info.actionType.openHot && !options.dontOpen
  863. var fastTran = !options.dontFastTran && ( this.info.actionType.fastTran || settings.hotFastTran || options.fastTran)
  864. if(fastTran){//瞬间过渡 1到固定方位 2到和普通过渡一样的位置,也就是最适合的位置
  865. let info = this.info.cameraData
  866. if(info){
  867. player.blackToPano({
  868. pano: player.model.panos.index[info.pano.uuid],
  869. quaternion: new THREE.Quaternion().fromArray(info.camera.quaternion)
  870. })
  871. }
  872. }
  873. var needExamine = !fastTran && (options.examine || (!settings.dontExamHot && this.info.actionType.examine))
  874. if(!openHot && !needExamine)return;
  875. if(openHot && this.info.linkType!="common" && this.info.iframe && this.info.iframe[0]){
  876. var src = getLink(this.info.iframe[0]);
  877. if(this.info.linkType=="jumpLink"){
  878. var newPage = window.open(src, "_blank" );
  879. newPage.focus();
  880. }else if(this.info.linkType=="iframeDiv"){
  881. var div = document.createElement("div");
  882. div.style.position = 'fixed';
  883. div.style.width = div.style.height = "100%";
  884. div.style.left = div.style.top = '0';
  885. div.style["z-index"] = "999"
  886. var exit = document.createElement("div");
  887. exit.style["background-image"] = "url(images/vrOffImg.png)";
  888. exit.style.position = 'absolute';
  889. exit.style.width = exit.style.height = "50px";
  890. exit.style.left = '17px'; exit.style.top = "20px"
  891. exit.style.cursor = "pointer";
  892. exit.style["background-repeat"] = "no-repeat";
  893. exit.style["background-size"] = "25%";
  894. exit.style["background-position"] = "center center";
  895. exit.style["background-color"] = "rgba(0, 0, 0, 0.2)";
  896. exit.style["border-radius"] = "50%";
  897. exit.style["z-index"] = "3"
  898. exit.onclick = ()=>{
  899. $(div).remove()
  900. Hot.closePopup()
  901. }
  902. var myElement = document.createElement("iframe");
  903. myElement.style.position = 'absolute';
  904. myElement.style.width = myElement.style.height = "100%";
  905. myElement.style.left = myElement.style.top = '0';
  906. myElement.src = src
  907. $("body").append(div);
  908. div.appendChild(exit);
  909. div.appendChild(myElement)
  910. SoundManager.play('hot')
  911. }
  912. return;
  913. }
  914. if(!player.currentPano)return;
  915. var popup = document.getElementById("popup");
  916. if (openHot) {
  917. if(window.parent.sceneBackIconStatus) {
  918. // 关闭返回按钮
  919. window.parent.sceneBackIconStatus(false)
  920. }
  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. // 关闭热点,显示返回按钮
  1292. if(window.parent&&window.parent.sceneBackIconStatus){
  1293. window.parent.sceneBackIconStatus(true)
  1294. }
  1295. g_currentHot = null;
  1296. var hotPop = document.getElementById('popup');
  1297. hotPop.style.display = "none";
  1298. document.querySelector(".popup-content").removeChild(document.getElementById("id1"));
  1299. $("#popup iframe:last").remove();
  1300. SoundManager.pause('hot', true)//自动播放被中断的音频 (bgm
  1301. return false
  1302. }
  1303. if(browser.isMobile()){
  1304. $('#closepop').on("touchstart",Hot.closePopup);
  1305. }else{
  1306. $('#closepop').on("click",Hot.closePopup);
  1307. }
  1308. Hot.createHotList = function() {
  1309. if(!window.DATA.showHotListSta)return
  1310. var docFragment = document.createDocumentFragment();
  1311. var hots = hotGroup.children.filter(hot=>hot.info.actionType.openHot);
  1312. hots = hots.sort((a,b)=>{return a.order - b.order});
  1313. hots.forEach((hot)=>{
  1314. var li = document.createElement('li');
  1315. var span = document.createElement('span');
  1316. span.innerHTML = hot.info.title || '热点';
  1317. // console.log(span.innerHTML);
  1318. li.hot = hot; // 列表每一项对应一个热点
  1319. li.appendChild(span);
  1320. docFragment.appendChild(li);
  1321. })
  1322. setTimeout(()=>{
  1323. var ul = document.querySelector('#hotListContent ul');
  1324. ul && ul.appendChild(docFragment);
  1325. },3000) //部分安卓手机的钉钉和支付宝浏览器如果立即添加到列表会卡住
  1326. }
  1327. Hot.mobileAutoPlay = function(player){//移动端。不这么写video不会播放 . (2022.11.29: 可为何加了Hot.updateHots之后又会自动播了?https有关?
  1328. if(browser.isMobile()){
  1329. hotGroup.children.forEach((hot)=>{
  1330. /* if(hot.texType == 'video' && hot.shouldPlay){
  1331. console.log(1)
  1332. } */
  1333. if(!hot.clickToPlayInited && hot.texType == 'video' && !isVideoPlayed(hot.texMedia) && hot.shouldPlay){
  1334. //hot.update(player)
  1335. console.log({str:'try mobileAutoPlay '+ hot.sid, level:1})
  1336. hot.videoControl(true)
  1337. if(isVideoPlayed(hot.texMedia)){
  1338. console.log({str:'clickToPlayInited '+ hot.sid, level:1})
  1339. hot.clickToPlayInited = true
  1340. hot.changeOpaWhenPlay(video)
  1341. }
  1342. }
  1343. })
  1344. }
  1345. }
  1346. Hot.updateHots = function(){
  1347. for(var i in player.model.hots){
  1348. player.model.hots[i].update(player)
  1349. }
  1350. if( !player.ready)return
  1351. this.needUpdate = true
  1352. common.intervalTool.isWaiting('updateHots', ()=>{ //延时update,防止卡顿
  1353. if(!this.needUpdate)return
  1354. this.needUpdate = false
  1355. let videoCanPlay = [], aniCanPlay = [];
  1356. for(var i in player.model.hots){
  1357. let hot = player.model.hots[i]
  1358. {//实时监测播放
  1359. if(hot.texType == "video" && !player.flying){ //飞行时不判断
  1360. if(hot.visible && !hot.pausedByUser && hot.inSight()){ //注意edit时insight一直为true
  1361. //this.videoControl(true)
  1362. videoCanPlay.push(hot)
  1363. }else{
  1364. hot.videoControl(false)
  1365. }
  1366. }else if(hot.info.animateInfo){
  1367. if(hot.visible && hot.inSight()){
  1368. aniCanPlay.push(hot)
  1369. }else{
  1370. GifTexDeal.stop(hot.animation)
  1371. }
  1372. }
  1373. }
  1374. }
  1375. let filter = (type,max,list,playFun)=>{
  1376. if(list.length < max){
  1377. list.forEach(hot=>type == 'video' ? hot.videoControl(true) : GifTexDeal.start(hot.animation))
  1378. }else{
  1379. let playerDir = player.getDirection()
  1380. let request = []
  1381. let planeDir = new Map()
  1382. if(player.mode != 'panorama'){
  1383. request.push((hot)=>{
  1384. if(hot.plane){//考虑plane的方向,它甚至可能背对镜头
  1385. let dir = new THREE.Vector3(0,0,-1).applyQuaternion(hot.quaternion)
  1386. let angle = dir.dot(playerDir)
  1387. planeDir.set(hot, angle)
  1388. return angle > 0
  1389. }else return true
  1390. })
  1391. }
  1392. let r = common.sortByScore(list,request,[(hot)=>{ //方向因素
  1393. var cornerPointInfo = hot.getCornerPoint(); //仅支持漫游模式
  1394. let dir = new THREE.Vector3().subVectors(hot.position, player.position).normalize()
  1395. score = dir.dot(playerDir)
  1396. player.mode == 'panorama' && (score *= Math.pow(cornerPointInfo.diffLat,0.5))// pow降低高度的权重,因为宽度更重要些。之所以两个函数都乘以diffLat,也是为了防止在两个item的分数相同diffLon不同时,diffLat增长相同倍数却能造成分数差异的情况
  1397. return score
  1398. },
  1399. (hot)=>{//面积因素
  1400. if(player.mode == 'panorama'){
  1401. var cornerPointInfo = hot.getCornerPoint(); //仅支持漫游模式
  1402. let area = cornerPointInfo.diffLon * Math.pow(cornerPointInfo.diffLat,0.5) / 1000 //占据面积
  1403. return area
  1404. }else{
  1405. let dis = player.position.distanceTo(hot.position);
  1406. let size = hot.getBoundOri().applyMatrix4(hot.matrixWorld).size(new THREE.Vector3).length() / 2
  1407. let score = Math.atan(size / Math.pow(dis,1.2)) * 50 // 在镜头中所占fov angle 的一半 。 pow是因为实际感受还是尽量显示近处的
  1408. if(hot.plane){//考虑plane的方向,越倾斜分越低
  1409. score *= planeDir.get(hot)
  1410. }
  1411. return score
  1412. }
  1413. } ])
  1414. //getCornerPoint仅支持漫游模式 Lat高度(纬度).
  1415. //console.log(r)
  1416. r && r.forEach((e,j)=>{
  1417. let hot = e.item
  1418. if(j<max){
  1419. type == 'video' ? hot.videoControl(true) : GifTexDeal.start(hot.animation)
  1420. }else{
  1421. type == 'video' ? hot.videoControl(false) : GifTexDeal.stop(hot.animation)
  1422. }
  1423. })
  1424. }
  1425. }
  1426. filter('video',playVideoMax, videoCanPlay);
  1427. filter('animateInfo',playAniMax, aniCanPlay);
  1428. //console.log('updateHots')
  1429. return true
  1430. }, 800)
  1431. }
  1432. }
  1433. function isVideoPlayed(video){
  1434. return !video.paused && !isNaN(video.duration) //注意,有的手机首次play时会立即paused为false,但其实没加载好, duration为NAN
  1435. }
  1436. /*
  1437. 保存 JSON.stringify(editTool.hotpoint.getSavingInfo())
  1438. 可能需要再写一份保存到overlay 给旧场景项目使用
  1439. 最好后台有针对手机版的做一个压缩。压缩成几个档位。
  1440. 安卓手机firefox出现过视频mesh不可见或者闪烁的情况。
  1441. 视频最容易导致崩溃, 模型还好
  1442. 数据速率为4064kbps,1920*1080px 时测试部门电脑崩溃
  1443. 数据速率为1824kbps,720 *576px 时正常
  1444. 所以尽量降到2000以下 同时播放个数最好不超过2个 可能需要将src归零 并延迟加载、不自动播放
  1445. 有遇到某张图在ios里显示不出,但在ps重新输出后就可以。这张图的dpi高达500,不知道是否与此有关。
  1446. 遇到过ios14.8.1、14.7.1 无法播放webm(来自1050)。 onloadedmetadata失败
  1447. */