Hot.js 59 KB

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