1
0

Hot.js 76 KB

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