main2.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  1. // import * as THREE from './js/three.module.js';
  2. // // import {OrbitControls} from './js/OrbitControls.js';
  3. // import TWEEN from './js/tween.esm.js';
  4. // const TWEEN = require('@tweenjs/tween.esm.js')
  5. let camera, scene, renderer,controls,material,mesh;
  6. let isAutoPlay = false,model = 'full' // full/menu
  7. let delta =0, millis = 0
  8. let timeIds=[]; // double click
  9. var timeStart,timeEnd,timeLongPress; // long press
  10. let is_key_down = false,key_down_frequency = 0;
  11. let is_pc = false
  12. const LONG_PRESS_TIMES = 3
  13. let loader=null;
  14. let materialArray=null;
  15. var container;
  16. const house ={
  17. // curr_id:2,
  18. idx:0,
  19. // direction:'B',
  20. nextId:null,
  21. isLoading:false,
  22. numLoaded:0,
  23. texture:{
  24. id:-1,
  25. curr:null,
  26. next:null,
  27. isloading:false,
  28. },
  29. config:{
  30. lat_step:10,
  31. lon_step:10,
  32. },
  33. title:"南京世茂项目",
  34. src:[
  35. {id:1,name:"01frontGate",title:'01正门',home:{T:50,R:70},view:{lat:-0.825, lon:19.875},image:"panos/01frontGate.png",
  36. L:{id:14,angle:{lat: -10, lon: 16.3},offset:180},R:{id:25,angle:{lat: -13.7, lon: 75.3},offset:-70},F:null,B:null,LF:null,
  37. LB:null,RF:null,RB:null,
  38. spots:[{id:14,name:'14',position:{x: 230, y: -60, z: 50},rotate:{x:Math.PI/2,y:0,z:0},scale:{x:1,y:1,z:1},angle:{lat: -10, lon: 16.3},offset:180},
  39. {id:25,name:'25',position:{x: -90, y: -60, z: -30},rotate:{x:Math.PI/2,y:0,z:0},scale:{x:1,y:1,z:1},angle:{lat: -13.7, lon: 75.3},offset:-70}]},
  40. {id:2,name:"02masterBedroom",title:'02主卧',home:{T:83,R:45},view:{lat: -7.8000000000000025 ,lon: 180},image:"panos/02masterBedroom.png",
  41. L:null,R:{id:4,angle:{lat: -9.5, lon: 50},offset:180},F:{id:6,angle:{lat: -4, lon: -77},offset:-90},B:{id:3,angle:{lat: -3.7, lon: 0.5},
  42. offset:0},LF:null,LB:null,RF:null,RB:null,
  43. },
  44. {id:3,name:"03masterBedroom",title:'03主卧',home:{T:85,R:36},view:{lat: -2.5500000000000007 ,lon: 110.1},
  45. image:"panos/03masterBedroom.png",L:null,R:{id:4,angle:{lat: -13.6, lon: 54},offset:180},F:{id:2,angle:{lat: 2.7, lon: 16.7},
  46. offset:90},B:null,LF:null,LB:null,RF:null,RB:null,
  47. },
  48. {id:4,name:"04masterBedroom",title:'04主卧',home:{T:75,R:30},view:{lat: -4.425 ,lon: 219.52499999999998},
  49. image:"panos/04masterBedroom.png",L:null,R:{id:3,angle:{lat: 0, lon: 13.5},offset:0},F:null,B:{id:2,angle:{lat: 3, lon: 17.1},offset:90},
  50. LF:null,LB:null,RF:null,RB:null,
  51. },
  52. {id:5,name:"05masterBedroomToilet",title:'05主卧卫生间',home:{T:60,R:30},view:{lat: -4.725 ,lon: 97.125},
  53. image:"panos/05masterBedroomToilet.png",L:null,R:null,F:{id:7,angle:{lat: -13, lon: 50},offset:0},B:null,LF:null,LB:null,
  54. RF:null,RB:null,
  55. },
  56. {id:6,name:"06masterBedroomPorch",title:'06主卧门廊',home:{T:66,R:45},view:{lat: -10.124999999999998 ,lon: 93.225},
  57. image:"panos/06masterBedroomPorch.png",L:null,R:{id:25,angle:{lat: -10, lon: 150},offset:-75},F:{id:2,angle:{lat: -6.5, lon: -86},
  58. offset:90},B:{id:7,angle:{lat: -2, lon: 146},offset:35},LF:null,LB:null,RF:null,RB:null,
  59. },
  60. {id:7,name:"07masterBedroomCloakroom",title:'07主卧衣帽间',home:{T:60,R:48},view:{lat: -9.750000000000002 ,lon: 326.62499999999994},
  61. image:"panos/07masterBedroomCloakroom.png",L:{id:6,angle:{lat: 1.9, lon: 86},offset:-90},R:null,F:null,B:null,LF:null,LB:{id:6,
  62. angle:{lat: 1.9, lon: 86},offset:-90},RF:null,RB:{id:5,angle:{lat: -3.2, lon: -80},offset:0},
  63. },
  64. {id:8,name:"08AguestRoom",title:'08客房',home:{T:90,R:100},view:{lat: -6.0749999999999975 ,lon: 191.55},image:"panos/08AguestRoom.png",
  65. L:null,R:{id:9,angle:{lat: -4.5, lon: -48},offset:-90},F:null,B:null,LF:null,LB:null,RF:null,RB:null,
  66. },
  67. {id:9,name:"09guestRoomA",title:'09客房A',home:{T:80,R:90},view:{lat: -10.575000000000001 ,lon: 292.425},image:"panos/09guestRoomA.png",
  68. L:null,R:null,F:{id:8,angle:{lat: -5.7, lon: -25},offset:30},B:{id:10,angle:{lat: -6.4, lon: 187},offset:-90},LF:null,LB:null,RF:null,
  69. RB:null,
  70. },
  71. {id:10,name:"10guestRoomAToilet",title:'10客房卫生间',home:{T:70,R:100},view:{lat: -4.874999999999999 ,lon: 83.85},
  72. image:"panos/10guestRoomAToilet.png",L:null,R:null,F:{id:25,angle:{lat: 3.8, lon: -15},offset:-90},B:null,LF:null,LB:null,
  73. RF:null,RB:null,
  74. },
  75. {id:11,name:"11guestRoomB",title:'11客房B',home:{T:85,R:70},view:{lat: -5.8500000000000005 ,lon: 102.74999999999999},
  76. image:"panos/11guestRoomB.png",L:null,R:{id:12,angle:{lat: -2.8, lon: 17},offset:180},F:{id:25,angle:{lat: -7, lon: -118},offset:-60},
  77. B:null,LF:null,LB:{id:13,angle:{lat: -1.4, lon: -172},offset:160},RF:null,RB:null,
  78. },
  79. {id:12,name:"12guestRoomB",title:'12客房B',home:{T:80,R:60},view:{lat: -0.675000000000002 ,lon: 226.5},image:"panos/12guestRoomB.png",
  80. L:null,R:{id:11,angle:{lat: -10, lon: -43},offset:90},F:null,B:null,LF:null,LB:null,RF:null,RB:null,
  81. },
  82. {id:13,name:"13guestRoomB",title:'13客房B',home:{T:95,R:70},view:{lat: -6.149999999999997 ,lon: 10.500000000000016},
  83. image:"panos/13guestRoomB.png",L:{id:11,angle:{lat: -6, lon: 120},offset:60},R:null,F:null,B:null,LF:null,LB:null,RF:null,RB:null,
  84. },
  85. {id:14,name:"14livingRoom",title:'14客厅',home:{T:20,R:70},view:{lat: -4.2 ,lon: 38.475},image:"panos/14livingRoom.png",L:null,R:null,
  86. F:{id:16,angle:{lat: 1.4, lon: 80},offset:180},B:null,LF:{id:17,angle:{lat: -2.4, lon: 36},offset:150},LB:null,RF:{id:15,
  87. angle:{lat: -6, lon: 148},offset:130},RB:{id:1,angle:{lat: -2.1, lon: 187},offset:180},
  88. },
  89. {id:15,name:"15livingRoom",title:'15客厅',home:{T:30,R:50},view:{lat: -7.574999999999999 ,lon: 50.025},image:"panos/15livingRoom.png",
  90. L:null,R:null,F:null,B:null,LF:{id:16,angle:{lat: -7.2, lon: -13},offset:180},LB:{id:14,angle:{lat: 0, lon: -57},offset:150},
  91. RF:{id:22,angle:{lat: -1.4, lon: 73},offset:180},RB:{id:20,angle:{lat: 0, lon: 0},offset:0},
  92. },
  93. {id:16,name:"16livingRoom",title:'16客厅',home:{T:20,R:50},view:{lat: -7.199999999999999 ,lon: 170.92499999999998},
  94. image:"panos/16livingRoom.png",L:{id:19,angle:{lat: -2, lon: -3},offset:180},R:{id:15,angle:{lat: -3, lon: 230},offset:120},
  95. F:{id:22,angle:{lat: 4.5, lon: 119},offset:180},B:{id:14,angle:{lat: 2.5, lon: -80},offset:160},LF:{id:18,angle:{lat: -10, lon: -20},
  96. offset:-130},LB:{id:17,angle:{lat: 0, lon: 0},offset:160},RF:null,RB:null,
  97. },
  98. {id:17,name:"17livingRoom",title:'17客厅',home:{T:8,R:60},view:{lat: -7.125 ,lon: -1.5},image:"panos/17livingRoom.png",
  99. L:{id:23,angle:{lat: -1, lon: -236},offset:30},R:{id:16,angle:{lat: -8.2, lon: 178},offset:180},F:null,B:null,LF:{id:23,
  100. angle:{lat: -1.4, lon: -210},offset:80},LB:null,RF:{id:19,angle:{lat: -2, lon: 75},offset:180},RB:{id:14,
  101. angle:{lat: -6.3, lon: 221},offset:150},
  102. },
  103. {id:18,name:"18livingRoom",title:'18客厅',home:{T:8,R:40},view:{lat: -12.374999999999998 ,lon: 145.12499999999997},
  104. image:"panos/18livingRoom.png",L:null,R:null,F:null,B:null,LF:null,LB:{id:24,angle:{lat: -3, lon: -52},offset:-120},
  105. RF:{id:16,angle:{lat: 5.2, lon: 179},offset:180},RB:{id:19,angle:{lat: -1.2, lon: -81},offset:180},
  106. },
  107. {id:19,name:"19livingRoom",title:'19客厅',home:{T:8,R:50},view:{lat: -7.574999999999999 ,lon: 83.24999999999999},
  108. image:"panos/19livingRoom.png",L:null,R:{id:16,angle:{lat: -8.2, lon: 178},offset:180},F:{id:18,angle:{lat: -2, lon: 75},offset:180},
  109. B:{id:17,angle:{lat: -1.2, lon: -81},offset:180},LF:null,LB:{id:23,angle:{lat: -1, lon: -236},offset:0},RF:null,
  110. RB:{id:14,angle:{lat: -7, lon: 251},offset:120},
  111. },
  112. {id:20,name:"20livingRoom",title:'20客厅',home:{T:40,R:45},view:{lat: -4.35 ,lon: 16.34999999999999},
  113. image:"panos/20livingRoom.png",L:{id:21,angle:{lat: -0.6, lon: -117},offset:150},R:{id:15,angle:{lat: 2, lon: 55},offset:120},
  114. F:null,B:{id:22,angle:{lat: -1, lon: 70},offset:180},LF:null,LB:null,RF:{id:14,angle:{lat: -1.8, lon: -44},offset:180},RB:null,
  115. },
  116. {id:21,name:"21livingRoom",title:'21客厅',home:{T:42,R:55},view:{lat: -3.0749999999999993 ,lon: 64.350000},
  117. image:"panos/21livingRoom.png",L:null,R:null,F:{id:20,angle:{lat: 0, lon: -179},offset:0},B:null,LF:{id:20,angle:{lat: -1.1, lon: -190},
  118. offset:0},LB:null,RF:null,RB:null,
  119. },
  120. {id:22,name:"22livingRoom",title:'22客厅',home:{T:23,R:20},view:{lat: -8.475000000000001 ,lon: -135.674},
  121. image:"panos/22livingRoom.png",L:null,R:null,F:null,B:null,LF:null,LB:null,RF:null,RB:{id:20,angle:{lat: -2, lon: 84},offset:0},
  122. },
  123. {id:23,name:"23kitchen",title:'23厨房',home:{T:-5,R:65},view:{lat: -11.174999999999999 ,lon: 278},image:"panos/23kitchen.png",
  124. L:null,R:null,F:null,B:{id:17,angle:{lat: 0, lon: 165},offset:180},LF:null,LB:{id:17,angle:{lat: -5.7, lon: 197},offset:160},
  125. RF:null,RB:null,
  126. },
  127. {id:24,name:"24laundry",title:'24洗衣间',home:{T:-5,R:40},view:{lat: -2.099999999999999 ,lon: 139.79999},image:"panos/24laundry.png",
  128. L:null,R:null,F:null,B:null,LF:null,LB:null,RF:{id:18,angle:{lat: 1.3, lon: 152},offset:230},RB:null,
  129. },
  130. {id:25,name:"25frontGatePorch",title:'25前门门廊',home:{T:65,R:75},view:{lat: -6.675000000000004 ,lon: 248.7749999},
  131. image:"panos/25frontGatePorch.jpg",L:{id:6,angle:{lat: -6, lon: 47},offset:-90},R:{id:10,angle:{lat: 2.2, lon: -85},offset:180},
  132. F:{id:11,angle:{lat: -5, lon: -67},offset:60},B:{id:1,angle:{lat: 1.7, lon: 17},offset:180},LF:null,LB:null,
  133. RF:{id:9,angle:{lat: -10, lon: -230},offset:-90},RB:{id:1,angle:{lat: 0, lon: 0},offset:180},
  134. },
  135. ],
  136. direction:[
  137. {id:1,name:"B",at:{x:0,y:0,z:-1}},
  138. {id:2,name:"F",at:{x:0,y:0,z:1}},
  139. {id:3,name:"R",at:{x:-1,y:0,z:0}},
  140. {id:4,name:"L",at:{x:1,y:0,z:0}},
  141. {id:5,name:"down",at:{x:0,y:1,z:0}},
  142. {id:6,name:"up",at:{x:0,y:-1,z:0}},
  143. {id:1,name:"LF",at:{x:1,y:0,z:1}},
  144. {id:2,name:"RF",at:{x:-1,y:0,z:1}},
  145. {id:3,name:"LB",at:{x:1,y:0,z:-1}},
  146. {id:4,name:"RB",at:{x:-1,y:0,z:-1}},
  147. ],
  148. playList:{
  149. idx:0,
  150. orders:[
  151. {id:1},{id:14},{id:17},{id:23},{id:19},{id:24},{id:18},{id:16},{id:22},{id:20},{id:21},{id:15},
  152. {id:25},{id:2},{id:3},{id:4},{id:5},{id:6},{id:7},{id:8},{id:9},{id:10},{id:11},{id:12},
  153. {id:13}
  154. ]
  155. },
  156. menuList:[
  157. {id:1},{id:2},{id:5},{id:9},{id:12},{id:16},{id:20},{id:17},{id:14}
  158. ]
  159. }
  160. var isUserInteracting = false,
  161. onMouseDownMouseX = 0,
  162. onMouseDownMouseY = 0,
  163. lon = 0,
  164. onMouseDownLon = 0,
  165. lat = 0,
  166. onMouseDownLat = 0,
  167. phi = 0,
  168. theta = 0;
  169. const spotGroup = new THREE.Group()
  170. init();
  171. animate();
  172. function init() {
  173. container = document.getElementById('container');
  174. // camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 1100);
  175. camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 5100);
  176. camera.target = new THREE.Vector3(0, 0, 0);
  177. scene = new THREE.Scene();
  178. // invert the geometry on the x-axis so that all of the faces point inward
  179. const geometry = new THREE.BoxGeometry(512, 512, 512);
  180. geometry.scale(-1, 1, 1);
  181. // if (!texture){
  182. // loader = new THREE.TextureLoader();
  183. loader = new THREE.TextureLoader().setPath('./panos/');
  184. const queryString = window.location.search;
  185. const urlParams = new URLSearchParams(queryString);
  186. const panoId = urlParams.get('id')?urlParams.get('id'):0
  187. const backurl = urlParams.get('backurl')?urlParams.get('backurl'):'pano3.html'
  188. house.idx = panoId
  189. house.backurl = backurl
  190. // var texture = new THREE.TextureLoader().load('images/02.png');
  191. const imgPath = house.src[house.idx].image
  192. // const texture = new THREE.TextureLoader().load(imgPath);
  193. const fileName = house.src[house.idx].name
  194. // const texture = loader.load(
  195. // // urls of images used in the cube texture
  196. // [
  197. // fileName+ '_b.png',
  198. // fileName+ '_f.png',
  199. // fileName+ '_u.png',
  200. // fileName+ '_d.png', //d
  201. // fileName+ '_l.png',
  202. // fileName+ '_r.png',
  203. // ])
  204. // // let loader2 = new THREE.TextureLoader().setPath('./panos/');
  205. materialArray = [
  206. new THREE.MeshBasicMaterial( { name:'f',map: loader.load(fileName+ '4k_f.jpg') } ),
  207. new THREE.MeshBasicMaterial( { name:'b',map: loader.load(fileName+ '4k_b.jpg') } ),
  208. new THREE.MeshBasicMaterial( { name:'u',map: loader.load(fileName+ '4k_u.jpg') } ),
  209. new THREE.MeshBasicMaterial( { name:'d',map: loader.load(fileName+ '4k_d.jpg') } ),
  210. new THREE.MeshBasicMaterial( { name:'l',map: loader.load(fileName+ '4k_l.jpg') } ),
  211. new THREE.MeshBasicMaterial( { name:'r',map: loader.load(fileName+ '4k_r.jpg') } ),
  212. ];
  213. setHomePosition()
  214. // }
  215. //
  216. // material = new THREE.MeshBasicMaterial({ envMap: texture});
  217. mesh = new THREE.Mesh(geometry, materialArray);
  218. scene.add(mesh);
  219. var light = new THREE.AmbientLight( 0x404040 ); // soft white light
  220. scene.add( light );
  221. renderer = new THREE.WebGLRenderer();
  222. renderer.setPixelRatio(window.devicePixelRatio);
  223. renderer.setSize(window.innerWidth, window.innerHeight);
  224. container.appendChild(renderer.domElement);
  225. // camera.position.set( 1000, 2000, 10 );
  226. window.camera=camera
  227. scene.add(spotGroup)
  228. initMenu()
  229. lat = house.src[house.idx].view.lat
  230. lon = house.src[house.idx].view.lon
  231. is_pc = IsPC()
  232. // controls = new OrbitControls( camera, renderer.domElement );
  233. // controls.update();
  234. // document.getElementById("map_img").addEventListener('mousedown', onPointerStart, false);
  235. document.addEventListener('mousedown', onPointerStart, false);
  236. document.addEventListener('mousemove', onPointerMove, false);
  237. document.addEventListener('mouseup', onPointerUp, false);
  238. document.addEventListener('wheel', onDocumentMouseWheel, false);
  239. document.addEventListener('touchstart', onPointerStart, false);
  240. document.addEventListener('touchmove', onPointerMove, false);
  241. document.addEventListener('touchend', onPointerUp, false);
  242. document.addEventListener('dblclick', onDbClickChange, false);
  243. //
  244. // document.addEventListener('dragover', function(event) {
  245. // event.preventDefault();
  246. // event.dataTransfer.dropEffect = 'copy';
  247. // }, false);
  248. // document.addEventListener('dragenter', function() {
  249. // document.body.style.opacity = 0.5;
  250. // }, false);
  251. // document.addEventListener('dragleave', function() {
  252. // document.body.style.opacity = 1;
  253. // }, false);
  254. // document.addEventListener('drop', function(event) {
  255. // event.preventDefault();
  256. // var reader = new FileReader();
  257. // reader.addEventListener('load', function(event) {
  258. // material.map.image.src = event.target.result;
  259. // material.map.needsUpdate = true;
  260. // }, false);
  261. // reader.readAsDataURL(event.dataTransfer.files[0]);
  262. // document.body.style.opacity = 1;
  263. // }, false);
  264. document.addEventListener('keydown', onKeyDown);
  265. document.addEventListener('keyup', onKeyUp);
  266. window.addEventListener('resize', onWindowResize, false);
  267. }
  268. function initMenu(){
  269. var menu=document.getElementById("menu");
  270. while (menu.firstChild) {
  271. menu.removeChild(menu.firstChild);
  272. }
  273. let mid = 0
  274. for(let item of house.menuList){
  275. const dpano = document.createElement("div");
  276. dpano.className = 'pano'
  277. // dpano.attr({'data-id':item.id})
  278. for(let i in house.src){
  279. if(house.src[i].id===item.id){
  280. mid = i
  281. break
  282. }
  283. }
  284. dpano.setAttribute('data-id',mid);
  285. const title = document.createElement("div");
  286. title.className = 'title'
  287. title.innerHTML = house.src[mid].title
  288. const thumb = document.createElement("div");
  289. thumb.className = 'thumb'
  290. // thumb.innerHTML = house.src[i].name
  291. const img=document.createElement("img");
  292. img.src= './panos/'+house.src[mid].name + '4k_b.jpg';
  293. thumb.appendChild(img);
  294. dpano.appendChild(title);
  295. dpano.appendChild(thumb);
  296. menu.appendChild(dpano);
  297. }
  298. const ddiv = document.createElement("div");
  299. ddiv.innerHTML='-'
  300. ddiv.className = 'panoEnd'
  301. menu.appendChild(ddiv);
  302. // var menuTitle=document.getElementById("menuTitle");
  303. // menuTitle.innerHTML = house.title
  304. }
  305. function walkingCamera(){
  306. const d = getCameraDirection()
  307. walkOn(d)
  308. }
  309. function zoomIn(){
  310. fov = camera.fov + 10
  311. fov = THREE.MathUtils.clamp(fov, 15, 75);
  312. if(fov!==camera.fov){
  313. updateCameraTo(fov)
  314. }
  315. }
  316. function zoomOut(){
  317. fov = camera.fov - 10
  318. fov = THREE.MathUtils.clamp(fov, 15, 75);
  319. if(fov!==camera.fov){
  320. updateCameraTo(fov)
  321. }
  322. }
  323. function displayMenu(){
  324. model = 'menu'
  325. document.getElementById("menu").style.display='flex';
  326. // document.getElementById("menuTitle").style.display='flex';
  327. // document.getElementById("menuTip").style.display='flex';
  328. //
  329. // setTimeout( function(){
  330. // document.getElementById("menuTip").style.display='none';
  331. // }, 5000 );
  332. }
  333. function doubleDelay(doubleCallback,callback,p){
  334. timeId = setTimeout( function(){
  335. if(Date.now()-delta<400){
  336. for(let i in timeIds){
  337. clearTimeout(timeIds[i])
  338. }
  339. // const d = getCameraDirection()
  340. // walkOn(d)
  341. if(doubleCallback){
  342. doubleCallback()
  343. }
  344. }else{
  345. // lookDirection(2)
  346. callback(p)
  347. }
  348. }, 400 );
  349. timeIds.push(timeId)
  350. }
  351. function onKeyDown(e){
  352. key_down_frequency++
  353. delta = Date.now()
  354. if(key_down_frequency>LONG_PRESS_TIMES){
  355. switch(e.keyCode){
  356. case 38://ArrowUp
  357. lat +=1.5
  358. break
  359. case 40: //ArrowDown
  360. lat -=1.5
  361. break
  362. case 37: //ArrowLeft
  363. lon -= 1.5
  364. break
  365. case 39://ArrowRight
  366. lon += 1.5
  367. break
  368. case 13://Enter
  369. isAutoPlay = true
  370. break
  371. default:
  372. break
  373. }
  374. }
  375. }
  376. function onKeyUp(e){
  377. // console.log(e.keyCode)
  378. document.getElementById('debug').innerHTML +="<br>" +e.key + ' '+e.keyCode
  379. if(key_down_frequency<LONG_PRESS_TIMES){
  380. switch(e.keyCode){
  381. case 38://ArrowUp
  382. if(model==='full'){
  383. doubleDelay(walkingCamera,lookDirection,2)
  384. }else if(model==='menu'){
  385. }
  386. break
  387. case 40: //ArrowDown
  388. if(model==='full'){
  389. doubleDelay(null,lookDirection,1)
  390. }else if(model==='menu'){
  391. const firstChild = document.getElementById('menu').firstChild
  392. firstChild.className = 'panoSelect'
  393. }
  394. break
  395. case 37: //ArrowLeft
  396. if(model==='full'){
  397. doubleDelay(zoomIn,lookDirection,3)
  398. }else if(model==='menu'){
  399. let pano_select = -1
  400. const nodess = document.getElementById("menu").childNodes;
  401. for(let i =0;i<nodess.length-1;i++){
  402. if(nodess[i].className==='panoSelect'){
  403. pano_select=i===0?nodess.length -2:i-1
  404. nodess[i].className = 'pano'
  405. nodess[pano_select].className = 'panoSelect'
  406. const fromLeft = document.getElementById('menu').scrollLeft
  407. const toLeft = 270*pano_select;
  408. const coords = {x: fromLeft, y: 0} // Start at (0, 0)
  409. const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  410. .to({x: toLeft, y: 200}, 1000) // Move to (300, 200) in 1 second.
  411. .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  412. .onUpdate(() => {
  413. // Called after tween.js updates 'coords'.
  414. // Move 'box' to the position described by 'coords' with a CSS translation.
  415. document.getElementById('menu').scrollLeft = coords.x
  416. })
  417. .start() // Start the tween immediately.
  418. i = nodess.length
  419. }
  420. }
  421. }
  422. break
  423. case 39://ArrowRight
  424. if(model==='full'){
  425. doubleDelay(zoomOut,lookDirection,4)
  426. }else if(model==='menu'){
  427. let pano_select = -1
  428. const nodess = document.getElementById("menu").childNodes;
  429. for(let i =0;i<nodess.length-1;i++){
  430. if(nodess[i].className==='panoSelect'){
  431. pano_select=nodess.length-2===i?0:i+1
  432. // document.getElementById('menu').scrollLeft =270*pano_select;
  433. const fromLeft = document.getElementById('menu').scrollLeft
  434. const toLeft = 270*pano_select;
  435. const coords = {x: fromLeft, y: 0} // Start at (0, 0)
  436. const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  437. .to({x: toLeft, y: 200}, 1000) // Move to (300, 200) in 1 second.
  438. .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  439. .onUpdate(() => {
  440. // Called after tween.js updates 'coords'.
  441. // Move 'box' to the position described by 'coords' with a CSS translation.
  442. document.getElementById('menu').scrollLeft = coords.x
  443. })
  444. .start() // Start the tween immediately.
  445. nodess[i].className = 'pano'
  446. nodess[pano_select].className = 'panoSelect'
  447. i = nodess.length
  448. }
  449. }
  450. }
  451. break
  452. case 13://Enter
  453. if(model==='full'){
  454. let pano_select = -1
  455. const nodess = document.getElementById("menu").childNodes;
  456. for(let i =0;i<nodess.length;i++){
  457. if(nodess[i].className==='panoSelect'){
  458. pano_select=nodess[i].getAttribute('data-id')
  459. i = nodess.length
  460. }
  461. }
  462. if(pano_select===-1){
  463. house.menu_control_select = 0
  464. const firstChild = document.getElementById('menu').firstChild
  465. firstChild.className = 'panoSelect'
  466. document.getElementById('menu').scrollLeft = 0
  467. }
  468. doubleDelay(defaultCameraFov,displayMenu,null)
  469. }else if(model==='menu'){
  470. model = 'full'
  471. document.getElementById("menu").style.display='none';
  472. // document.getElementById("menuTip").style.display='none';
  473. // document.getElementById("menuTitle").style.display='none';
  474. let pano_select = -1
  475. const nodess = document.getElementById("menu").childNodes;
  476. for(let i =0;i<nodess.length;i++){
  477. if(nodess[i].className==='panoSelect'){
  478. pano_select=nodess[i].getAttribute('data-id')
  479. i = nodess.length
  480. house.idx = pano_select
  481. }
  482. }
  483. autoUpdateMaterial(house.idx)
  484. }
  485. break
  486. case 48: // auto play
  487. isAutoPlay = !isAutoPlay
  488. camera.fov = isAutoPlay?75:45
  489. camera.updateProjectionMatrix();
  490. var points=document.getElementById("redPoints");
  491. while (points.firstChild) {
  492. points.removeChild(points.firstChild);
  493. }
  494. break
  495. case 49:
  496. // document.getElementById('menu').scrollLeft+=270;
  497. break
  498. default:
  499. break
  500. }
  501. }
  502. key_down_frequency = 0
  503. }
  504. // function onKeyUp(e){
  505. // switch(e.keyCode){
  506. // case 38://ArrowUp
  507. // if(model==='full'){
  508. // // doubleDelay(walkingCamera,lookDirection,2)
  509. // }else if(model==='menu'){
  510. // }
  511. // break
  512. // case 40: //ArrowDown
  513. // if(model==='full'){
  514. // //doubleDelay(null,lookDirection,1)
  515. // }else if(model==='menu'){
  516. // // const firstChild = document.getElementById('menu').firstChild
  517. // // firstChild.className = 'panoSelect'
  518. // }
  519. // break
  520. // case 37: //ArrowLeft
  521. // if(model==='full'){
  522. // // doubleDelay(zoomIn,lookDirection,3)
  523. // }else if(model==='menu'){
  524. // // let pano_select = -1
  525. // // const nodess = document.getElementById("menu").childNodes;
  526. // // for(let i =0;i<nodess.length;i++){
  527. // // if(nodess[i].className==='panoSelect'){
  528. // // pano_select=i===0?nodess.length -1:i-1
  529. // // nodess[i].className = 'pano'
  530. // // nodess[pano_select].className = 'panoSelect'
  531. // // document.getElementById('menu').scrollLeft =100*pano_select;
  532. // // i = nodess.length
  533. // // }
  534. // // }
  535. // }
  536. // break
  537. // case 39://ArrowRight
  538. // if(model==='full'){
  539. // // doubleDelay(zoomOut,lookDirection,4)
  540. // }else if(model==='menu'){
  541. // // let pano_select = -1
  542. // // const nodess = document.getElementById("menu").childNodes;
  543. // // for(let i =0;i<nodess.length;i++){
  544. // // if(nodess[i].className==='panoSelect'){
  545. // // pano_select=nodess.length-1===i?0:i+1
  546. // // document.getElementById('menu').scrollLeft =100*pano_select;
  547. // // nodess[i].className = 'pano'
  548. // // nodess[pano_select].className = 'panoSelect'
  549. // // i = nodess.length
  550. // // }
  551. // // }
  552. // }
  553. // break
  554. // case 13://Enter
  555. // // single click
  556. // if(model==='full'){
  557. // // doubleDelay(defaultCameraFov,displayMenu,null)
  558. // }else if(model==='menu'){
  559. // // model = 'full'
  560. // // document.getElementById("menu").style.display='none';
  561. // // let pano_select = -1
  562. // // const nodess = document.getElementById("menu").childNodes;
  563. // // for(let i =0;i<nodess.length;i++){
  564. // // if(nodess[i].className==='panoSelect'){
  565. // // // console.log(nodess[i].getAttribute('data-id'),'hkkkkkkkkkkkkk' )
  566. // // // pano_select=i
  567. // // pano_select=nodess[i].getAttribute('data-id')
  568. // // i = nodess.length
  569. // // }
  570. // // }
  571. // // house.idx = pano_select
  572. // // autoUpdateMaterial(house.idx)
  573. // }
  574. // break
  575. // case 48: // auto play
  576. // break
  577. // case 49: //`1`
  578. // break
  579. // default:
  580. // break
  581. // }
  582. // }
  583. function onWindowResize() {
  584. camera.aspect = window.innerWidth / window.innerHeight;
  585. camera.updateProjectionMatrix();
  586. renderer.setSize(window.innerWidth, window.innerHeight);
  587. }
  588. function pauseEvent(e){
  589. if(e.stopPropagation) e.stopPropagation();
  590. if(e.preventDefault) e.preventDefault();
  591. e.cancelBubble=true;
  592. e.returnValue=false;
  593. return false;
  594. }
  595. function onPointerStart(event) {
  596. isUserInteracting = true;
  597. if(is_pc){
  598. // pauseEvent(event)
  599. }
  600. // if(model==='menu'){
  601. //
  602. // }
  603. var clientX = event.clientX || event.touches[0].clientX;
  604. var clientY = event.clientY || event.touches[0].clientY;
  605. onMouseDownMouseX = clientX;
  606. onMouseDownMouseY = clientY;
  607. onMouseDownLon = lon;
  608. onMouseDownLat = lat;
  609. }
  610. function onPointerMove(event) {
  611. if (isUserInteracting === true) {
  612. var clientX = event.clientX || (typeof(event.touches)!=='undefined'?event.touches[0].clientX:0);
  613. var clientY = event.clientY || (typeof(event.touches)!=='undefined'?event.touches[0].clientY:0);
  614. // lon = (onMouseDownMouseX - clientX) * 0.1 + onMouseDownLon;
  615. // lat = (clientY - onMouseDownMouseY) * 0.1 + onMouseDownLat;
  616. if(model==='full'){
  617. lon = (onMouseDownMouseX - clientX) * 0.075 + onMouseDownLon;
  618. lat = (clientY - onMouseDownMouseY) * 0.075 + onMouseDownLat;
  619. }else if(model==='menu'){
  620. const deltaX = (onMouseDownMouseX - clientX) * 0.031
  621. const fromLeft = document.getElementById('menu').scrollLeft
  622. const toLeft = fromLeft + deltaX
  623. document.getElementById('menu').scrollLeft = toLeft
  624. }
  625. }
  626. }
  627. function onPointerUp() {
  628. isUserInteracting = false;
  629. }
  630. function onDocumentMouseWheel(event) {
  631. var fov = camera.fov + event.deltaY * 0.05;
  632. camera.fov = THREE.MathUtils.clamp(fov, 15, 75);
  633. camera.updateProjectionMatrix();
  634. }
  635. function IsPC(){
  636. var userAgentInfo = navigator.userAgent;
  637. var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
  638. var flag = true;
  639. for (var v = 0; v < Agents.length; v++) {
  640. if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }
  641. }
  642. return flag;
  643. }
  644. //------------------------------------------
  645. function onDbClickChange(event){
  646. const d = getCameraDirection()
  647. walkOn(d)
  648. }
  649. function getCameraDirection(){
  650. // camera.rotation.y =Math.PI/2
  651. let min_angle = Math.PI
  652. let target_name = ""
  653. const cameraTarget = camera.target.normalize()
  654. for(const d in house.direction){
  655. const dat = new THREE.Vector3(house.direction[d].at.x,house.direction[d].at.y,house.direction[d].at.z).normalize()
  656. const angle = cameraTarget.angleTo(dat)
  657. if(min_angle>angle){
  658. min_angle = angle
  659. target_name = house.direction[d].name
  660. }
  661. }
  662. return target_name
  663. }
  664. function walkOn(d){
  665. let nextId = null
  666. switch(d){
  667. case 'L':
  668. nextId = house.src[house.idx].L
  669. break
  670. case 'R':
  671. nextId = house.src[house.idx].R
  672. break
  673. case 'F':
  674. nextId = house.src[house.idx].F
  675. break
  676. case 'B':
  677. nextId = house.src[house.idx].B
  678. break
  679. case 'LF':
  680. nextId = house.src[house.idx].LF
  681. break
  682. case 'LB':
  683. nextId = house.src[house.idx].LB
  684. break
  685. case 'RF':
  686. nextId = house.src[house.idx].RF
  687. break
  688. case 'RB':
  689. nextId = house.src[house.idx].RB
  690. break
  691. default:
  692. break
  693. }
  694. if(nextId&&!house.isLoading){
  695. changeTexture(nextId)
  696. }else{
  697. moveNull()
  698. }
  699. }
  700. function changeTexture(nextId){
  701. const idx = getIdxFromId(nextId.id)
  702. house.numLoaded = 0
  703. house.isLoading = true
  704. // document.getElementById('tip').style.display = 'flex'
  705. updateFaceTexture(nextId,idx,'f')
  706. updateFaceTexture(nextId,idx,'b')
  707. updateFaceTexture(nextId,idx,'l')
  708. updateFaceTexture(nextId,idx,'r')
  709. updateFaceTexture(nextId,idx,'u')
  710. updateFaceTexture(nextId,idx,'d')
  711. }
  712. function updateFaceTexture(nextId,idx, face){
  713. const imgPath = house.src[idx].name +"4k_"+face+'.jpg'
  714. // load a resource
  715. loader.load(
  716. // resource URL
  717. imgPath,
  718. // onLoad callback
  719. function ( texture ) {
  720. house.numLoaded++
  721. updateFaceMaterial(texture,face)
  722. if(house.numLoaded===mesh.material.length){
  723. updateFaceCamera(texture,nextId,idx,face)
  724. }
  725. },
  726. // onProgress callback currently not supported
  727. undefined,
  728. // onError callback
  729. function ( err ) {
  730. console.error( 'An error happened.' );
  731. }
  732. );
  733. }
  734. function updateFaceMaterial(texture,face){
  735. for(let i=0;i<mesh.material.length;i++){
  736. if(mesh.material[i].name===face){
  737. mesh.material[i].map.dispose()
  738. mesh.material[i].map = texture
  739. mesh.material[i].map.needsUpdate = true;
  740. i=mesh.material.length
  741. }
  742. }
  743. }
  744. function updateFaceCamera(texture,nextId,idx,face){
  745. const coords = {x: camera.fov*35/20, y: lat,z:lon} // Start at (0, 0)
  746. const fov = camera.fov
  747. lat = nextId.angle.lat
  748. lon = nextId.angle.lon
  749. // for(let i=spotGroup.children.length-1;i>=0;i--){
  750. // spotGroup.remove(spotGroup.children[i])
  751. // }
  752. const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  753. .to({x:fov,y:nextId.angle.lat,z:nextId.angle.lon}, 1200) // Move to (300, 200) in 1 second.
  754. .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  755. .onUpdate((e,t) => {
  756. camera.fov = coords.x
  757. camera.updateProjectionMatrix();
  758. })
  759. .onComplete(()=>{
  760. house.nextId = nextId
  761. house.idx = idx
  762. camera.fov = fov
  763. camera.updateProjectionMatrix();
  764. house.isLoading = false
  765. // document.getElementById('tip').style.display = 'none'
  766. setHomePosition()
  767. })
  768. .start() // Start the tween immediately.
  769. }
  770. function range360(a){
  771. while(a>180){
  772. a -=360
  773. }
  774. while(a<-180){
  775. a +=360
  776. }
  777. return a
  778. }
  779. function defaultCameraFov(){
  780. let ilat = range360(lat)
  781. let ilon = range360(lon)
  782. const coords = {x: camera.fov, y: ilat,z:ilon} // Start at (0, 0)
  783. const fov = 45
  784. const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  785. .to({x:fov,y:0,z:0}, 1200) // Move to (300, 200) in 1 second.
  786. .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  787. .onUpdate((e,t) => {
  788. camera.fov = coords.x
  789. camera.updateProjectionMatrix();
  790. // lat = coords.y
  791. lon = coords.z
  792. })
  793. .onComplete(()=>{
  794. // house.nextId = nextId
  795. // house.idx = idx
  796. // camera.fov = fov
  797. // camera.updateProjectionMatrix();
  798. // house.isLoading = false
  799. // document.getElementById('tip').style.display = 'none'
  800. })
  801. .start() // Start the tween immediately.
  802. }
  803. // ------------- auto update material ------------
  804. function autoLoadNextTexture(idx,face){
  805. const imgPath = house.src[idx].name +"_"+face+'.jpg'
  806. // for(let i=spotGroup.children.length-1;i>=0;i--){
  807. // spotGroup.remove(spotGroup.children[i])
  808. // }
  809. // load a resource
  810. loader.load(
  811. // resource URL
  812. imgPath,
  813. // onLoad callback
  814. function ( texture ) {
  815. house.numLoaded++
  816. updateFaceMaterial(texture,face)
  817. if(house.numLoaded===mesh.material.length){
  818. house.isLoading = false
  819. // document.getElementById('tip').style.display = 'none'
  820. lat = house.src[idx].view.lat
  821. lon = house.src[idx].view.lon
  822. setHomePosition()
  823. }
  824. },
  825. // onProgress callback currently not supported
  826. undefined,
  827. // onError callback
  828. function ( err ) {
  829. console.error( 'An error happened.' );
  830. }
  831. );
  832. }
  833. function autoUpdateMaterial(idx){
  834. house.numLoaded = 0
  835. house.isLoading = true
  836. // document.getElementById('tip').style.display = 'flex'
  837. autoLoadNextTexture(idx,'f')
  838. autoLoadNextTexture(idx,'b')
  839. autoLoadNextTexture(idx,'l')
  840. autoLoadNextTexture(idx,'r')
  841. autoLoadNextTexture(idx,'u')
  842. autoLoadNextTexture(idx,'d')
  843. }
  844. function updateCameraTo(fov){
  845. const coords = {x: camera.fov, y: 0} // Start at (0, 0)
  846. const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  847. .to({x:fov,y:0}, 600) // Move to (300, 200) in 1 second.
  848. .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  849. .delay(300)
  850. .onUpdate((e,t) => {
  851. camera.fov = coords.x
  852. camera.updateProjectionMatrix();
  853. })
  854. .onComplete(()=>{
  855. })
  856. .start() // Start the tween immediately.
  857. }
  858. function setHomePosition(){
  859. // const angle = house.src[house.idx].home.A
  860. const top = house.src[house.idx].home.T
  861. const right = house.src[house.idx].home.R
  862. document.getElementById('cam').style.top = top + 'px';
  863. document.getElementById('cam').style.right = right+ 'px';
  864. if(!isAutoPlay){
  865. updateMapPoint()
  866. }
  867. }
  868. function updateHome(){
  869. if(!house.isLoading){
  870. const offset = house.nextId!==null?house.nextId.offset:180
  871. const angle = lon + offset
  872. document.getElementById('cam').style.transform = 'rotate('+angle+'deg)';
  873. }
  874. }
  875. function moveNull(){
  876. const coords = {x: camera.fov, y: 0} // Start at (0, 0)
  877. const fov = camera.fov-5
  878. const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  879. .to({x:fov,y:0}, 400) // Move to (300, 200) in 1 second.
  880. .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  881. .onUpdate((e,t) => {
  882. camera.fov = coords.x
  883. camera.updateProjectionMatrix();
  884. })
  885. .onComplete(()=>{
  886. moveNullBack()
  887. })
  888. .start() // Start the tween immediately.
  889. }
  890. function moveNullBack(){
  891. lookZoom(5,400)
  892. }
  893. function lookZoom(z=5,t=600){
  894. const fromX = camera.fov
  895. const coords = {x: fromX, y: 0} // Start at (0, 0)
  896. const toX = camera.fov + z
  897. const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  898. .to({x:toX,y:0}, t) // Move to (300, 200) in 1 second.
  899. .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  900. .onUpdate((e,t) => {
  901. camera.fov = coords.x
  902. camera.updateProjectionMatrix();
  903. })
  904. .start() // Start the tween immediately.
  905. }
  906. // direction 1/up 2/down 3/left 4/right
  907. function lookDirection(d=1){
  908. const fromX = d===1||d===2?lat:lon
  909. const coords = {x: fromX, y: 0} // Start at (0, 0)
  910. const toX = d===1?lat-house.config.lat_step:d===2?lat+house.config.lat_step:d===3?lon-house.config.lon_step:lon+house.config.lon_step
  911. const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
  912. .to({x:toX,y:0}, 600) // Move to (300, 200) in 1 second.
  913. .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
  914. .onUpdate((e,t) => {
  915. if(d===1||d===2){
  916. lat = coords.x
  917. }else{
  918. lon = coords.x
  919. }
  920. })
  921. .start() // Start the tween immediately.
  922. }
  923. function updateMapPoint(){
  924. const idx = house.idx
  925. let id = -1
  926. var points=document.getElementById("redPoints");
  927. while (points.firstChild) {
  928. points.removeChild(points.firstChild);
  929. }
  930. // points.remove();
  931. if(house.src[idx].L){
  932. id = house.src[idx].L.id - 1
  933. createMapPoint(id)
  934. }
  935. if(house.src[idx].R){
  936. id = house.src[idx].R.id - 1
  937. createMapPoint(id)
  938. }
  939. if(house.src[idx].F){
  940. id = house.src[idx].F.id - 1
  941. createMapPoint(id)
  942. }
  943. if(house.src[idx].B){
  944. id = house.src[idx].B.id - 1
  945. createMapPoint(id)
  946. }
  947. if(house.src[idx].LF){
  948. id = house.src[idx].LF.id - 1
  949. createMapPoint(id)
  950. }
  951. if(house.src[idx].LB){
  952. id = house.src[idx].LB.id - 1
  953. createMapPoint(id)
  954. }
  955. if(house.src[idx].RF){
  956. id = house.src[idx].RF.id - 1
  957. createMapPoint(id)
  958. }
  959. if(house.src[idx].RB){
  960. id = house.src[idx].RB.id - 1
  961. createMapPoint(id)
  962. }
  963. }
  964. function createMapPoint(id){
  965. const top = house.src[id].home.T
  966. const right = house.src[id].home.R
  967. const img=document.createElement("img");
  968. img.src="panos/redPoint.png";
  969. img.style.position = 'absolute'
  970. img.style.top = top +15+ 'px';
  971. img.style.right = right-5+ 'px';
  972. img.style.width = 8+ 'px';
  973. img.style.height = 8+ 'px';
  974. const points=document.getElementById("redPoints");
  975. points.appendChild(img);
  976. }
  977. function getIdxFromId(id){
  978. let idx = -1
  979. for(const item in house.src){
  980. if(house.src[item].id===id){
  981. idx = item
  982. break
  983. }
  984. }
  985. return idx
  986. }
  987. function animate() {
  988. requestAnimationFrame(animate);
  989. update();
  990. }
  991. function update() {
  992. // controls.update();
  993. if (isUserInteracting === false) {
  994. // lon += 0.1;
  995. }
  996. if(isAutoPlay){
  997. // if(lon>360&&!house.texture.isloading){
  998. if(lon>360&&!house.isloading){
  999. lon = 0
  1000. // house.idx++
  1001. // if(house.idx>=house.src.length){
  1002. // house.idx = 0
  1003. // }
  1004. house.playList.idx++
  1005. if(house.playList.idx>=house.playList.orders.length){
  1006. house.playList.idx = 0
  1007. }
  1008. for(let i in house.src){
  1009. if(house.src[i].id===house.playList.orders[house.playList.idx].id){
  1010. house.idx = i
  1011. break
  1012. }
  1013. }
  1014. // house.idx = house.playList.orders[house.playList.idx].id-1
  1015. autoUpdateMaterial(house.idx)
  1016. }else{
  1017. lon += 0.2;
  1018. }
  1019. }
  1020. lat = Math.max(-85, Math.min(85, lat));
  1021. phi = THREE.MathUtils.degToRad(90 - lat);
  1022. theta = THREE.MathUtils.degToRad(lon);
  1023. camera.target.x = 512 * Math.sin(phi) * Math.cos(theta);
  1024. camera.target.y = 512 * Math.cos(phi);
  1025. camera.target.z = 512 * Math.sin(phi) * Math.sin(theta);
  1026. updateHome()
  1027. camera.lookAt(camera.target);
  1028. TWEEN.update()
  1029. renderer.render(scene, camera);
  1030. }
  1031. var btn = new tvSysBtnBind({
  1032. id: "Jdoc",
  1033. className: "ctrlBtn",
  1034. currentClass: "current",
  1035. keyRemoveDefault: false,
  1036. effect: "base",
  1037. currentIndex: 0,
  1038. onLoad: function(e) {
  1039. // console.log(e);
  1040. },
  1041. onPress:function() {
  1042. var keyCode = this.event.keyCode;
  1043. // alert('keyCode:'+keyCode)
  1044. document.getElementById('debug').innerHTML +="<br> onPress:" +keyCode
  1045. switch (keyCode) {
  1046. case 37: // left
  1047. // reloadData();
  1048. break;
  1049. case 39: // right
  1050. break;
  1051. case 38: //up
  1052. break;
  1053. case 40: //down
  1054. break;
  1055. // case 13: //enter
  1056. // break;
  1057. case 33: //chanel +
  1058. break;
  1059. case 34: //chanel -
  1060. break;
  1061. case 48: //0
  1062. break;
  1063. default:
  1064. break;
  1065. }
  1066. },
  1067. onEnterPress: function() {
  1068. },
  1069. onBack: function() {
  1070. if(isAutoPlay){
  1071. isAutoPlay = false
  1072. }else{
  1073. if(model==='menu'){
  1074. model = 'full'
  1075. document.getElementById("menu").style.display='none';
  1076. // document.getElementById("menuTip").style.display='none';
  1077. // document.getElementById("menuTitle").style.display='none';
  1078. }else{
  1079. // window.location.href="index2.html?id="+house.idx
  1080. const backurl = house.backurl
  1081. const url = "pano3.html?id="+house.idx+'&backurl='+backurl
  1082. console.log('url',url)
  1083. document.getElementById('debug').innerHTML +="<br>" +url
  1084. return;
  1085. // window.location.replace(url)
  1086. // window.location.href = url
  1087. // VrBrowserToJS.vrBrowerExit()
  1088. }
  1089. }
  1090. return;
  1091. }
  1092. });
  1093. window.onBackEvent= function(){
  1094. document.getElementById('debug').innerHTML +="<br>" +'window.onBackEvent'
  1095. }