Hot.js 60 KB

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