Hot.js 75 KB

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