Hot.js 64 KB

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