Hot_new.js 75 KB

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