Hot.js 58 KB

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