Hot.js 60 KB

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