main2.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  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. switch (keyCode) {
  1045. case 37: // left
  1046. // reloadData();
  1047. break;
  1048. case 39: // right
  1049. break;
  1050. case 38: //up
  1051. break;
  1052. case 40: //down
  1053. break;
  1054. // case 13: //enter
  1055. // break;
  1056. case 33: //chanel +
  1057. break;
  1058. case 34: //chanel -
  1059. break;
  1060. case 48: //0
  1061. break;
  1062. default:
  1063. break;
  1064. }
  1065. },
  1066. onEnterPress: function() {
  1067. },
  1068. onBack: function() {
  1069. if(isAutoPlay){
  1070. isAutoPlay = false
  1071. }else{
  1072. if(model==='menu'){
  1073. model = 'full'
  1074. document.getElementById("menu").style.display='none';
  1075. // document.getElementById("menuTip").style.display='none';
  1076. // document.getElementById("menuTitle").style.display='none';
  1077. }else{
  1078. // window.location.href="index2.html?id="+house.idx
  1079. const backurl = house.backurl
  1080. const url = "pano3.html?id="+house.idx+'&backurl='+backurl
  1081. console.log('url',url)
  1082. document.getElementById('debug').innerHTML +="<br>" +url
  1083. return;
  1084. // window.location.replace(url)
  1085. // window.location.href = url
  1086. // VrBrowserToJS.vrBrowerExit()
  1087. }
  1088. }
  1089. return;
  1090. }
  1091. });
  1092. window.onBackEvent= function(){
  1093. document.getElementById('debug').innerHTML +="<br>" +'window.onBackEvent'
  1094. }