Hot.js 62 KB

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