Hot.js 76 KB

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