Hot.js 62 KB

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