index.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>WebGL三维场景</title>
  6. <style>
  7. body {
  8. margin: 0;
  9. overflow: hidden;
  10. /* 隐藏body窗口区域滚动条 */
  11. }
  12. #imgCompass{
  13. width: 10%;
  14. position: absolute;
  15. margin-top: 320px;
  16. margin-left: 50px;
  17. opacity: 0.8;
  18. }
  19. .label {
  20. color: #FFF;
  21. font-family: sans-serif;
  22. padding: 2px;
  23. background: rgba(0, 0, 0, .6);
  24. display: none;
  25. }
  26. .active {
  27. display: block;
  28. }
  29. #CTXX {
  30. width: 300px;
  31. height: 130px;
  32. position: absolute;
  33. margin-top: 134px;
  34. background-color: #b9c5c5;
  35. /* margin-left: 22px; */
  36. right: 20px;
  37. z-index: 9999;
  38. }
  39. #CTXXTile,
  40. #CTWDTile {
  41. width: 100%;
  42. height: 30px;
  43. background-color: black;
  44. }
  45. #CW{
  46. width:100px;
  47. height:35px;
  48. line-height:35px;
  49. background-color:lightblue;
  50. position: absolute;
  51. margin-top: 84px;
  52. /* margin-left: 22px; */
  53. right: 20px;
  54. z-index: 9999;
  55. }
  56. #CTXXContent {
  57. width: 100%;
  58. height: 100px;
  59. }
  60. #LK1 {
  61. margin-left: 9px;
  62. margin-top: 3px;
  63. }
  64. #CTWD {
  65. z-index: 9999;
  66. width: 300px;
  67. height: 158px;
  68. position: absolute;
  69. margin-top: 277px;
  70. background-color: #b9c5c5;
  71. /* margin-left: 22px; */
  72. right: 20px;
  73. }
  74. .ctbtn {
  75. width: 145px;
  76. height: 30px;
  77. margin-left: 2px;
  78. background-color: lightblue;
  79. border-color: azure;
  80. }
  81. #CTTitle {
  82. width: 100%;
  83. height: 58px;
  84. background-color: #1a1a1a;
  85. position: absolute;
  86. }
  87. /* 下拉框 */
  88. .searchable-select {
  89. top: 100px;
  90. left: 10px;
  91. z-index: 100;
  92. }
  93. </style>
  94. <!--引入three.js三维引擎-->
  95. <script src="js/three.js"></script>
  96. <!-- 引入threejs扩展控件OrbitControls.js -->
  97. <script src="js/OrbitControls.js"></script>
  98. <!-- 引入obj模型加载库OBJLoader.js -->
  99. <script src="js/FBXLoader.js"></script>
  100. <!-- 辅助文件 -->
  101. <script src="js/inflate.min.js"></script>
  102. <script src="js/jquery.js"></script>
  103. <script src="js/CSS2DRenderer.js"></script>
  104. <script src="js/GLTFLoader.js"></script>
  105. <script src="js/LegacyJSONLoader.js"></script>
  106. <script src="js/Tween.js"></script>
  107. <script src="js/onEvent.js"></script>
  108. <script src="js/layer.js"></script>
  109. <link rel="stylesheet" type="text/css" href="css/layer.css" />
  110. <script src="js/jquery.rotate.min.js" type="text/javascript" charset="utf-8"></script>
  111. <script src="js/jquery.searchableSelect.js"></script>
  112. <link href="js/jquery.searchableSelect.css" rel="stylesheet" type="text/css">
  113. </head>
  114. <body>
  115. <select id="select">
  116. </select>
  117. </select>
  118. <div id="CT" onload="draw();">
  119. <div id="CTTitle" style="z-index: 9999;">
  120. <h2 style="position: absolute;color: #eee;margin-left: 18px;">粮情信息三维展示</h2>
  121. <img id="imgCompass" src="img/clock.png" />
  122. </div>
  123. </div>
  124. <button id="CW" onclick="oncwClick()">仓温</button>
  125. <div id="CTXX">
  126. <div id="CTXXTile">
  127. <b style="position: absolute;margin-top: 6px;margin-left: 12px;color: beige;opacity: 0.6;">仓体信息</b>
  128. </div>
  129. <div id="CTXXContent">
  130. <div id="LK1">
  131. <i>粮食等级:</i>
  132. <i id="LSDJ"></i>
  133. </div>
  134. <div id="LK1">
  135. <i>粮库名称:</i>
  136. <i id="LKMC"></i>
  137. </div>
  138. <div id="LK1">
  139. <i>保管员:</i>
  140. <i id="LKBGY"></i>
  141. </div>
  142. <div id="LK1">
  143. <i>粮食品种:</i>
  144. <i id="LSPZ"></i>
  145. </div>
  146. </div>
  147. </div>
  148. <div id="CTWD">
  149. <div id="CTWDTile">
  150. <b style="position: absolute;margin-top: 6px;margin-left: 12px;color: beige;opacity: 0.6;">仓体温度</b>
  151. </div>
  152. <div id="LK1">
  153. <i>仓内湿度:</i>
  154. <i id="CNSD"></i>
  155. </div>
  156. <div id="LK1">
  157. <i>仓内温度:</i>
  158. <i id="CNWD"></i>
  159. </div>
  160. <div id="LK1">
  161. <i>仓外湿度:</i>
  162. <i id="CWSD"></i>
  163. </div>
  164. <div id="LK1">
  165. <i>仓外温度:</i>
  166. <i id="CWWD"></i>
  167. </div>
  168. <button class="ctbtn" onclick="CWXQ()">测温详情</button>
  169. <button class="ctbtn" onclick="HFQJ()">恢复全景</button>
  170. </div>
  171. <script>
  172. var hwbm = location.href.split("?")[1].split("&&")[0];
  173. var cfbm = location.href.split("?")[1].split("&&")[1];
  174. console.log(hwbm);
  175. // $.each(location.href.split("?")[1].split("&"),function(i,n){
  176. // LCcs.push(n.split("=")[1]);
  177. // })
  178. // layer.msg('1111111', {
  179. // time: 20000, //20s后自动关闭
  180. // btn: ['确认'],
  181. // btnAlign: 'c'
  182. // });
  183. function isIE() {
  184. if (!!window.ActiveXObject || "ActiveXObject" in window) {
  185. return true;
  186. } else {
  187. return false;
  188. }
  189. }
  190. if (isIE()) {
  191. var script = document.createElement('script');
  192. script.type = 'text/javaScript';
  193. script.src = 'http://cdn.jsdelivr.net/bluebird/3.5.0/bluebird.min.js'; // bluebird 文件地址
  194. document.getElementsByTagName('head')[0].appendChild(script);
  195. }
  196. var CGQValue = [];
  197. var high;
  198. var whign;
  199. var low;
  200. var wlow;
  201. var LCcs = []; //用于接收地址参数
  202. var SensorID = -1;
  203. var AAA = -1;
  204. var BBB = 0;
  205. var CCC;
  206. var CGQcase; //根据接口返回规定不同的测温渲染状态0,1,2
  207. var CGQArray = [];
  208. var MeshArray = [];
  209. /**
  210. * 创建场景对象Scene
  211. */
  212. var scene = new THREE.Scene();
  213. scene.background = new THREE.CubeTextureLoader()
  214. .setPath("pic/")
  215. .load(['px.jpg', 'nx.jpg', 'py.jpg', 'ny.jpg', 'pz.jpg', 'nz.jpg', ])
  216. var axes = new THREE.AxesHelper(230);
  217. // scene.add(axes);
  218. /**
  219. * 光源设置
  220. */
  221. //点光源
  222. var point = new THREE.PointLight(0xffffff);
  223. point.position.set(400, 200, 300); //点光源位置
  224. scene.add(point); //点光源添加到场景中
  225. //环境光
  226. var ambient = new THREE.AmbientLight(0xFFFFF0);
  227. scene.add(ambient);
  228. /**
  229. * 相机设置
  230. */
  231. var width = window.innerWidth; //窗口宽度
  232. var height = window.innerHeight; //窗口高度
  233. var k = width / height; //窗口宽高比
  234. var s = 150; //三维场景显示范围控制系数,系数越大,显示的范围越大
  235. //创建相机对象
  236. // var camera = new THREE.OrthographicCamera(-s * k, s * k, s, -s, 1, 1000);
  237. var camera = new THREE.PerspectiveCamera(80, width / height, 1, 1000);
  238. scene.add(camera);
  239. camera.position.set(142, 25, 0); //设置相机位置
  240. camera.lookAt(scene.position); //设置相机方向(指向的场景对象)
  241. // THREE.onEvent(scene,camera);
  242. var geometryPlane = new THREE.PlaneGeometry(500, 500, 500);
  243. var texturePlane = new THREE.TextureLoader().load("img/cizhuan.jpg");
  244. texturePlane.wrapS = texturePlane.wrapT = THREE.RepeatWrapping;
  245. texturePlane.repeat.set(35, 35);
  246. var materialPlane = new THREE.MeshBasicMaterial({
  247. color: 0xFFFACD,
  248. side: THREE.DoubleSide,
  249. map: texturePlane
  250. });
  251. var meshPlane = new THREE.Mesh(geometryPlane, materialPlane);
  252. meshPlane.rotateX(Math.PI / 2);
  253. scene.add(meshPlane);
  254. var mixer = null; //声明一个混合器变量
  255. var loader = new THREE.FBXLoader(); //创建一个FBX加载器
  256. loader.load("model/10.fbx", function(obj) {
  257. console.log(obj)
  258. scene.add(obj)
  259. obj.scale.set(4, 4, 4);
  260. obj.position.set(1195, 0, 700);
  261. obj.rotateY(Math.PI / 2);
  262. obj.translateZ(50);
  263. })
  264. /**
  265. * 加载 glTF 格式的模型
  266. */
  267. var loader = new THREE.GLTFLoader();
  268. loader.load('camera.glb', function(obj) {
  269. console.log(obj);
  270. obj.scene.position.set(0, 25, -86);
  271. obj.scene.scale.set(0.04, 0.04, 0.04);
  272. scene.add(obj.scene);
  273. });
  274. var p1 = {
  275. x: 30,
  276. y: 25,
  277. z: 0
  278. };
  279. var position = camera.position;
  280. var tween1 = new TWEEN.Tween(position);
  281. tween1.to(p1, 5000);
  282. var update = function() {
  283. // camera.position.set(p1.x,p1.y,p1.z);
  284. camera.lookAt(20, 20, 0);
  285. controls.target = new THREE.Vector3(20, 20, 0);
  286. };
  287. tween1.onUpdate(update);
  288. tween1.easing(TWEEN.Easing.Cubic.Out);
  289. // setTimeout(function() {tween1.start();}, 3000);
  290. // $.ajax({
  291. // type: "get",
  292. // url: "http://124.193.70.90:9028/intelligents/wareHouseBasicInfo/getStorehouse?orgId=164&cfCode=005&libraryType=0",
  293. // data: {},
  294. // async:true,
  295. // dataType: "json",
  296. // success: function(e) {
  297. // console.log(e);
  298. // $("#LSDJ").text(e.data.dj);
  299. // $("#LKMC").text(e.data.lkmc);
  300. // $("#LKBGY").text(e.data.keeperName);
  301. // $("#LSPZ").text(e.data.pz)
  302. // }
  303. // });
  304. //
  305. // $.ajax({
  306. // type: "get",
  307. // url: "http://124.193.70.90:9028/intelligents/temperatureRecord/findById?id=2016420190731080044000003",
  308. // data: {},
  309. // async:true,
  310. // dataType: "json",
  311. // success: function(e) {
  312. // console.log(e);
  313. // $("#CNSD").text(e.data.inh);
  314. // $("#CNWD").text(e.data.intemp);
  315. // $("#CWWD").text(e.data.outtemp);
  316. // $("#CWSD").text(e.data.outh)
  317. // }
  318. // });
  319. //
  320. $.ajax({
  321. type: "post",
  322. url: 'http://'+window.location.host+'/api/kjjg/DXPLQJC/yzMap?'+hwbm,
  323. data: {},
  324. dataType: "json",
  325. async: true,
  326. success: function(e) {
  327. high = e.data.high;
  328. whign = e.data.whigh;
  329. low = e.data.low;
  330. wlow = e.data.wlow
  331. console.log(high);
  332. if (high == undefined && whign == undefined && low == undefined && wlow == undefined) {
  333. CGQcase = 0;
  334. } else if (high != undefined && whign == undefined && low == undefined && wlow == undefined) {
  335. CGQcase = 1;
  336. } else if (high != undefined && whign != undefined && low != undefined && wlow != undefined) {
  337. CGQcase = 2;
  338. }
  339. }
  340. });
  341. //仓房信息
  342. $.ajax({
  343. type: "post",
  344. url:'http://'+window.location.host+'/api/kjjg/DXPLQJC/cfData?'+hwbm,
  345. data: {},
  346. dataType: "json",
  347. async:false,
  348. success: function(e) {
  349. $("#LSDJ").html(e.data.djbm);
  350. $("#LKMC").html(e.data.cfmc);
  351. $("#LKBGY").html(e.data.bgy);
  352. $("#LSPZ").html(e.data.pzbm);
  353. }
  354. });
  355. //仓内信息
  356. $.ajax({
  357. type: "post",
  358. url:'http://'+window.location.host+'/api/kjjg/DXPLQJC/lwData?'+hwbm,
  359. data: {},
  360. dataType: "json",
  361. async:false,
  362. success: function(e) {
  363. $("#CNSD").html(e.data.cfns+"%");
  364. $("#CNWD").html(e.data.cfnw+"℃");
  365. $("#CWSD").html(e.data.cfws+"%");
  366. $("#CWWD").html(e.data.cfww+"℃");
  367. }
  368. });
  369. $.ajax({
  370. type: "post",
  371. url: 'http://'+window.location.host+'/api/kjjg/DXPLQJC/lwList?'+hwbm,
  372. data: {},
  373. dataType: "json",
  374. async: false,
  375. success: function(e) {
  376. for (var i = e.data.length - 1; i >= 0; i--) {
  377. document.getElementById("select").options.add(new Option(e.data[i], e.data[i]));
  378. }
  379. console.log(e);
  380. }
  381. });
  382. //下拉框模糊查询
  383. $(function() {
  384. $('#select').searchableSelect();
  385. });
  386. var setDate;
  387. //下拉框选择后触发事件
  388. // setDate = $(".searchable-select-holder").html();//初始化
  389. //鼠标滑轮
  390. function closeScroll(){
  391. controls.enableZoom = false;
  392. }
  393. function openScroll(){
  394. controls.enableZoom = true;
  395. }
  396. //重新选择时间
  397. function setselect() {
  398. controls.enableZoom = true;
  399. if (CGQArray.length != 0) {
  400. $.each(CGQArray, function(i, n) {
  401. scene.remove(n);
  402. })
  403. CGQArray = [];
  404. }
  405. if (MeshArray.length != 0) {
  406. $.each(MeshArray, function(i, n) {
  407. scene.remove(n);
  408. })
  409. MeshArray = [];
  410. }
  411. setDate = $(".searchable-select-holder").html();
  412. console.log(setDate);
  413. $.ajax({
  414. // type: "get",
  415. // url: "http://124.193.70.90:9028/intelligents/temperatureRecord/findByHouseAndTimes?lqId=2016420190731080044000003",
  416. type: "post",
  417. url: 'http://'+window.location.host+'/api/kjjg/DXPLQJC/lqList?'+hwbm+"&jcsj=" + setDate,
  418. data: {},
  419. // async:true,
  420. dataType: "json",
  421. error: function() {
  422. layer.msg('查询测温各点数据调用异常', {
  423. time: 20000, //20s后自动关闭
  424. btn: ['确认'],
  425. btnAlign: 'c'
  426. });
  427. },
  428. success: function(e) {
  429. console.log(e.data);
  430. AAA = -1;
  431. BBB = 0;
  432. CCC;
  433. //取第一个数
  434. for (let i in e.data[0]) {
  435. AAA++
  436. }
  437. console.log(AAA)
  438. //取第二个数
  439. var BBBArray = [];
  440. var arr = []
  441. $.each(e.data, function(i, n) {
  442. BBBArray.push(n[1]);
  443. })
  444. console.log(BBBArray);
  445. $.each(BBBArray, function(i, n) {
  446. if (i + 1 == n.split("-")[1]) {
  447. BBB++
  448. }
  449. })
  450. console.log(BBB);
  451. //取第三个数
  452. CCC = BBBArray.length / BBB
  453. console.log(CCC);
  454. var long = 170 / BBB;
  455. var wide = 50 / AAA;
  456. var tall = 35 / CCC;
  457. var geometry = new THREE.CylinderGeometry(.03, .03, tall * CCC);
  458. var material = new THREE.MeshLambertMaterial({
  459. color: 0
  460. });
  461. for (var x = AAA; x > 0; x--) {
  462. for (var z = 0; z < BBB; z++) {
  463. var mesh = new THREE.Mesh(geometry, material);
  464. mesh.position.set(x * wide, 0, z * long);
  465. mesh.translateY(CCC * tall / 2);
  466. mesh.translateZ(-(BBB - 1) * long / 2);
  467. mesh.translateX(-(AAA - 2) * wide / 2);
  468. // scene.add(mesh);
  469. MeshArray.push(mesh);
  470. }
  471. }
  472. var ckfloor = new THREE.BoxGeometry(180, 75, 1);
  473. var textureckfloor = (new THREE.TextureLoader).load("img/diban.jpg");
  474. textureckfloor.wrapS = textureckfloor.wrapT = THREE.RepeatWrapping;
  475. textureckfloor.repeat.set(8, 8);
  476. var ckfloormaterial = new THREE.MeshBasicMaterial({
  477. color: 16121850,
  478. map: textureckfloor
  479. });
  480. var ckfloormesh = new THREE.Mesh(ckfloor, ckfloormaterial);
  481. ckfloormesh.rotateX(Math.PI / 2);
  482. ckfloormesh.rotateZ(Math.PI / 2);
  483. ckfloormesh.position.set(5, 0.5, 3);
  484. scene.add(ckfloormesh);
  485. var tubeMaterial = new THREE.MeshPhongMaterial({
  486. // map: texture,
  487. color: 0x000000,
  488. transparent: true,
  489. });
  490. for (var x = AAA; x > 0; x--) {
  491. var curve = new THREE.CatmullRomCurve3([
  492. new THREE.Vector3(x * wide, CCC * tall, 0),
  493. new THREE.Vector3(x * wide, CCC * tall, (BBB - 1) * long),
  494. ], false /*是否闭合*/ );
  495. var tubeGeometry = new THREE.TubeGeometry(curve, 2, 0.05, 5, false);
  496. var tube = new THREE.Mesh(tubeGeometry, tubeMaterial);
  497. tube.translateZ(-(BBB - 1) * long / 2);
  498. tube.translateX(-(AAA - 2) * wide / 2);
  499. scene.add(tube);
  500. }
  501. var sphere = new THREE.SphereGeometry(0.8, 20, 20);
  502. $.ajax({
  503. type: "post",
  504. url: 'http://'+window.location.host+'/api/kjjg/DXPLQJC/lqList?'+hwbm+"&jcsj=" + setDate,
  505. data: {},
  506. async: false,
  507. dataType: "json",
  508. success: function(e) {
  509. console.log(e);
  510. $.each(e.data, function(e, a) {
  511. for (var t = 2; t < AAA + 2; t++) {
  512. CGQValue.push(a[t])
  513. }
  514. });
  515. console.log(CGQValue);
  516. for (var a = CCC; a > 0; a--) {
  517. for (var t = 0; t < BBB; t++) {
  518. for (var r = AAA; r > 0; r--) {
  519. SensorID = SensorID + 1;
  520. var o = CGQValue[SensorID];
  521. switch (CGQcase) {
  522. case 0:
  523. if (o == 0) {
  524. var n = new THREE.MeshLambertMaterial({
  525. color: "#636363",
  526. wireframe: false,
  527. transparent: true,
  528. opacity: 0.01
  529. })
  530. } else {
  531. var n = new THREE.MeshLambertMaterial({
  532. color: 8190976,
  533. wireframe: false,
  534. transparent: true,
  535. opacity: .7
  536. })
  537. }
  538. break;
  539. case 1:
  540. if (o >= high) {
  541. var n = new THREE.MeshLambertMaterial({
  542. color: 16711680,
  543. wireframe: false,
  544. transparent: true,
  545. opacity: .9
  546. })
  547. } else {
  548. var n = new THREE.MeshLambertMaterial({
  549. color: 8190976,
  550. wireframe: false,
  551. transparent: true,
  552. opacity: .7
  553. })
  554. }
  555. break;
  556. case 2:
  557. if (o >= high && o != 250) {
  558. var n = new THREE.MeshLambertMaterial({
  559. color: 16711680,
  560. wireframe: false,
  561. transparent: true,
  562. opacity: .9
  563. })
  564. } else if (o == 0) {
  565. var n = new THREE.MeshLambertMaterial({
  566. color: "#636363",
  567. wireframe: false,
  568. transparent: true,
  569. opacity: 0.01
  570. })
  571. } else if (o <= low) {
  572. var n = new THREE.MeshLambertMaterial({
  573. color: "#00F5FF",
  574. wireframe: false,
  575. transparent: true,
  576. opacity: .7
  577. })
  578. } else if (o >= whign && o < high) {
  579. var n = new THREE.MeshLambertMaterial({
  580. color: 15658496,
  581. wireframe: false,
  582. transparent: true,
  583. opacity: .7
  584. })
  585. } else if (o >= low && o < wlow) {
  586. var n = new THREE.MeshLambertMaterial({
  587. color: "#00F5FF",
  588. wireframe: false,
  589. transparent: true,
  590. opacity: .7
  591. })
  592. } else if (o < whign && o > wlow) {
  593. var n = new THREE.MeshLambertMaterial({
  594. color: 8190976,
  595. wireframe: false,
  596. transparent: true,
  597. opacity: .7
  598. })
  599. }
  600. break;
  601. }
  602. var s = new THREE.Mesh(sphere, n);
  603. s.position.set(r * wide, (a) * 2, t * long);
  604. s.translateZ(-(BBB - 1) * long / 2);
  605. s.translateX(-(AAA - 2) * wide / 2);
  606. s.rotateX(Math.PI / 2);
  607. s.name = SensorID.toString();
  608. var d = document.createElement("div");
  609. d.className = "label";
  610. d.id = "label" + SensorID.toString();
  611. d.textContent = CGQValue[SensorID];
  612. d.style.marginTop = "-1em";
  613. var c = new THREE.CSS2DObject(d);
  614. // c.name = "传感器" + SensorID.toString();
  615. // c.position.set(r,a,t);
  616. // c.position.set(poi.x,poi.z,poi.y);
  617. s.add(c);
  618. if(s.material.opacity<0.1){
  619. s.remove(c);
  620. scene.remove(s);
  621. }
  622. CGQArray.push(s);
  623. // s.on('click', function(m) {
  624. // console.log(m);
  625. // if (m.children.length > 1) {
  626. // alert(m.children[1].element.innerText);
  627. // } else{
  628. // alert(m.children[0].element.innerText);
  629. // }
  630. // });
  631. }
  632. }
  633. }
  634. $.each(CGQArray, function(i, n) {
  635. scene.add(n);
  636. })
  637. }
  638. });
  639. $.each(MeshArray, function(i, n) {
  640. scene.add(n);
  641. })
  642. }
  643. });
  644. };
  645. //仓房信息
  646. $.ajax({
  647. type: "post",
  648. url: 'http://'+window.location.host+'/api/kjjg/DXPLQJC/cfData?'+hwbm,
  649. data: {},
  650. dataType: "json",
  651. async: false,
  652. success: function(e) {
  653. for (var i = e.data.length - 1; i >= 0; i--) {
  654. document.getElementById("select").options.add(new Option(e.data[i], e.data[i]));
  655. }
  656. console.log(e);
  657. }
  658. });
  659. function oncwClick() {
  660. $.ajax({
  661. type: "post",
  662. url: 'http://'+window.location.host+'/api/kjjg/DXPMYSQLDATA/selectList?'+cfbm,
  663. data: {},
  664. dataType: "json",
  665. async: false,
  666. success: function(e) {
  667. }
  668. });
  669. }
  670. //声明raycaster和mouse变量
  671. var raycaster = new THREE.Raycaster();
  672. var mouse = new THREE.Vector2();
  673. function onMouseClick(event) {
  674. //通过鼠标点击的位置计算出raycaster所需要的点的位置,以屏幕中心为原点,值的范围为-1到1.
  675. mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
  676. mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
  677. // 通过鼠标点的位置和当前相机的矩阵计算出raycaster
  678. raycaster.setFromCamera(mouse, camera);
  679. // 获取raycaster直线和所有模型相交的数组集合
  680. var intersects = raycaster.intersectObjects(scene.children);
  681. // console.log(intersects[0].object.name);
  682. $('#label' + intersects[0].object.name).addClass("active");
  683. setTimeout(function() {
  684. $('#label' + intersects[0].object.name).removeClass("active");
  685. }, 3000)
  686. // document.body.style.backgroundImage="url(earth/map.jpg)";
  687. //将所有的相交的模型的颜色设置为红色,如果只需要将第一个触发事件,那就数组的第一个模型改变颜色即可
  688. // for ( var i = 0; i < intersects.length; i++ ) {
  689. // // intersects[0].object.material.color.set( 0xff0000 );
  690. // console.log(intersects[0].object);
  691. // }
  692. }
  693. window.addEventListener('dblclick', onMouseClick, false);
  694. labelRenderer = new THREE.CSS2DRenderer;
  695. labelRenderer.setSize(window.innerWidth, window.innerHeight);
  696. labelRenderer.domElement.style.position = "absolute";
  697. labelRenderer.domElement.style.top = 0;
  698. document.body.appendChild(labelRenderer.domElement);
  699. /**
  700. * 创建渲染器对象
  701. */
  702. var renderer = new THREE.WebGLRenderer();
  703. renderer.setSize(width, height); //设置渲染区域尺寸
  704. renderer.setClearColor(0xb9d3ff, 1); //设置背景颜色
  705. document.body.appendChild(renderer.domElement); //body元素中插入canvas对象
  706. //创建控件对象 相机对象camera作为参数 控件可以监听鼠标的变化,改变相机对象的属性
  707. var controls = new THREE.OrbitControls(camera);
  708. controls.maxPolarAngle = 1.3;
  709. controls.minPolarAngle = 0.8;
  710. // 创建一个时钟对象Clock
  711. var clock1 = new THREE.Clock();
  712. // 渲染函数
  713. function render() {
  714. renderer.render(scene, camera); //执行渲染操作
  715. labelRenderer.render(scene, camera);
  716. requestAnimationFrame(render); //请求再次执行渲染函数render,渲染下一帧
  717. TWEEN.update();
  718. var dir = new THREE.Vector3(-camera.position.x, 0, -camera.position.z).normalize();
  719. var theta = Math.atan2(-dir.x, -dir.z);
  720. $('#imgCompass').rotate(THREE.Math.radToDeg(theta));
  721. var delta = clock1.getDelta();
  722. controls.update(delta);
  723. }
  724. render();
  725. function CWXQ() {
  726. tween1.start();
  727. }
  728. function HFQJ() {
  729. controls.reset();
  730. }
  731. </script>
  732. </body>
  733. </html>