Hot.js 62 KB

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