Hot.js 61 KB

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