Hot.js 65 KB

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