1
0

Hot.js 76 KB

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