【前端】智能库房综合管理系统前端项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

915 lines
27 KiB

3 years ago
  1. // 从这里开始
  2. var h1 = null;
  3. var h2 = null;
  4. var oldtransformNodex = null;
  5. var oldtransformNodeOther = null;
  6. var drag = null;
  7. var notmoveGroup = null;
  8. var movedGroup = null;
  9. var movesingle = false;
  10. var dynamicTexture = null;
  11. var dynamicTexture2 = null;
  12. var dynamicTexture3 = null;
  13. var dynamicTexture4 = null;
  14. var PointerOverYangan = null;
  15. var show = 50;
  16. var showdd = 50;
  17. var deviceData = [];
  18. BABYLON.DefaultLoadingScreen.prototype.displayLoadingUI = function() {
  19. if (document.getElementById("customLoadingScreenDiv")) {
  20. document.getElementById("customLoadingScreenDiv").style.display = "initial";
  21. return;
  22. }
  23. this._loadingDiv = document.createElement("div");
  24. //this._loadingDiv.style.height = '1750px';
  25. this._loadingDiv.id = "customLoadingScreenDiv";
  26. thecss = "lohingifpc";
  27. thecss2 = "zcpc";
  28. this._loadingDiv.innerHTML =
  29. "<div class='oka'><div class='" +
  30. thecss +
  31. "'><image src='./logok.gif' class='jiazaiimg'/></div><div class='" +
  32. thecss2 +
  33. "'>由 <image class='feitimg' src='./img/yxlogo.png'/> 阅行客 提供技术支持!</div></div>";
  34. this._resizeLoadingUI();
  35. window.addEventListener("resize", this._resizeLoadingUI);
  36. document.body.appendChild(this._loadingDiv);
  37. };
  38. BABYLON.DefaultLoadingScreen.prototype.hideLoadingUI = function() {
  39. show = 50;
  40. document.getElementById("customLoadingScreenDiv").style.display = "none";
  41. document.getElementById("customLoadingScreenDiv_first").style.display =
  42. "none";
  43. document.title = "整理室";
  44. //scene.getMaterialByName("材质.023").roughness = 0;
  45. var prepareGroupButtonOther = function(transformNodex, color) {
  46. var mesheses = null;
  47. if (transformNodex.getClassName() == "TransformNode") {
  48. mesheses = transformNodex.getChildMeshes(false);
  49. } else {
  50. mesheses = [];
  51. mesheses.push(transformNodex);
  52. }
  53. for (var i = 0; i < mesheses.length; i++) {
  54. mesheses[i].actionManager = new BABYLON.ActionManager(scene);
  55. var theScaling = mesheses[i].scaling;
  56. if (true) {
  57. try {
  58. //mesheses[i].actionManager.registerAction(new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPointerOutTrigger, mesheses[i], "scaling", new BABYLON.Vector3(theScaling.x, theScaling.y, theScaling.z), 100));
  59. // 初始化数据 温度/湿度
  60. deviceData.forEach(item => {
  61. if (item.id === transformNodex.nameID) {
  62. transformNodex.wendu = item.wendu;
  63. transformNodex.sidu = item.sidu;
  64. transformNodex.baojing = item.alarmState;
  65. }
  66. });
  67. mesheses[i].actionManager.registerAction(
  68. new BABYLON.ExecuteCodeAction(
  69. {
  70. trigger: BABYLON.ActionManager.OnPointerOverTrigger,
  71. parameter: ""
  72. },
  73. function() {
  74. clickbegin = true;
  75. if (true) {
  76. try {
  77. if (oldtransformNodeOther != null) {
  78. oldtransformNodeOther.removeBehavior(drag);
  79. var mesheses2 = null;
  80. if (
  81. oldtransformNodeOther.getClassName() == "TransformNode"
  82. ) {
  83. mesheses2 = oldtransformNodeOther.getChildMeshes(false);
  84. } else {
  85. mesheses2 = [];
  86. mesheses2.push(oldtransformNodeOther);
  87. }
  88. for (var i = 0; i < mesheses2.length; i++) {
  89. try {
  90. h2.removeMesh(mesheses2[i]);
  91. } catch (error) {
  92. // alert(error)
  93. }
  94. }
  95. }
  96. oldtransformNodeOther = transformNodex;
  97. //transformNodex.addBehavior(drag);
  98. var mesheses3 = null;
  99. if (transformNodex.getClassName() == "TransformNode") {
  100. mesheses3 = transformNodex.getChildMeshes(false);
  101. } else {
  102. mesheses3 = [];
  103. mesheses3.push(transformNodex);
  104. }
  105. for (var i = 0; i < mesheses3.length; i++) {
  106. try {
  107. if (transformNodex.baojing == true) {
  108. h2.addMesh(mesheses3[i], new BABYLON.Color3(1, 0, 0));
  109. } else {
  110. h2.addMesh(mesheses3[i], color);
  111. }
  112. } catch (error) {
  113. // alert(error)
  114. }
  115. }
  116. } catch (error) {
  117. // alert(error)
  118. }
  119. clickbegin = false;
  120. }
  121. if (transformNodex.name.indexOf("yangan") >= 0) {
  122. PointerOverYangan = transformNodex.name;
  123. if (transformNodex.baojing == true) {
  124. var location = transformNodex.absolutePosition;
  125. var xd = scene.getMeshByName("tapred");
  126. // x = x-0.6;; y = y+0.3 z=z+0.5
  127. xd.position = new BABYLON.Vector3(
  128. location.x - 0.6,
  129. location.y + 0.9,
  130. location.z + 0.5
  131. );
  132. var font_size = 36;
  133. var font = "bold " + font_size + "px Arial";
  134. dynamicTexture3.drawText(
  135. transformNodex.wendu + "°C",
  136. null,
  137. null,
  138. font,
  139. "#FFFFFF",
  140. "#000000",
  141. true
  142. );
  143. dynamicTexture4.drawText(
  144. transformNodex.sidu + "%",
  145. null,
  146. null,
  147. font,
  148. "#FFFFFF",
  149. "#000000",
  150. true
  151. );
  152. xd.setEnabled(true);
  153. } else {
  154. var location = transformNodex.absolutePosition;
  155. var xd = scene.getMeshByName("tapblue");
  156. // x = x-0.6;; y = y+0.3 z=z+0.5
  157. xd.position = new BABYLON.Vector3(
  158. location.x - 0.6,
  159. location.y + 0.9,
  160. location.z + 0.5
  161. );
  162. var font_size = 36;
  163. var font = "bold " + font_size + "px Arial";
  164. dynamicTexture.drawText(
  165. transformNodex.wendu + "°C",
  166. null,
  167. null,
  168. font,
  169. "#FFFFFF",
  170. "#000000",
  171. true
  172. );
  173. dynamicTexture2.drawText(
  174. transformNodex.sidu + "%",
  175. null,
  176. null,
  177. font,
  178. "#FFFFFF",
  179. "#000000",
  180. true
  181. );
  182. xd.setEnabled(true);
  183. }
  184. }
  185. }
  186. )
  187. );
  188. mesheses[i].actionManager.registerAction(
  189. new BABYLON.ExecuteCodeAction(
  190. {
  191. trigger: BABYLON.ActionManager.OnPointerOutTrigger,
  192. parameter: ""
  193. },
  194. function() {
  195. var mesheses2 = null;
  196. if (transformNodex.getClassName() == "TransformNode") {
  197. mesheses2 = transformNodex.getChildMeshes(false);
  198. } else {
  199. mesheses2 = [];
  200. mesheses2.push(transformNodex);
  201. }
  202. for (var i = 0; i < mesheses2.length; i++) {
  203. try {
  204. h2.removeMesh(mesheses2[i]);
  205. } catch (error) {
  206. // alert(error)
  207. }
  208. }
  209. if (transformNodex.name.indexOf("yangan") >= 0) {
  210. if (transformNodex.baojing == true) {
  211. var location = transformNodex.absolutePosition;
  212. var xd = scene.getMeshByName("tapred");
  213. // x = x-0.6;; y = y+0.3 z=z+0.5
  214. xd.setEnabled(false);
  215. } else {
  216. var location = transformNodex.absolutePosition;
  217. var xd = scene.getMeshByName("tapblue");
  218. // x = x-0.6;; y = y+0.3 z=z+0.5
  219. xd.setEnabled(false);
  220. }
  221. }
  222. }
  223. )
  224. );
  225. //mesheses[i].actionManager.registerAction(new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPointerOverTrigger, mesheses[i], "scaling", new BABYLON.Vector3(theScaling.x * 1.01, theScaling.y * 1.01, theScaling.z * 1.01), 100));
  226. } catch (error) {
  227. //alert(error)
  228. }
  229. }
  230. var clickbegin = false;
  231. mesheses[i].actionManager.registerAction(
  232. new BABYLON.ExecuteCodeAction(
  233. {
  234. trigger: BABYLON.ActionManager.OnPickTrigger,
  235. parameter: ""
  236. },
  237. function() {
  238. cameraClick(transformNodex);
  239. }
  240. )
  241. );
  242. }
  243. };
  244. var camera05 = scene.getTransformNodeByName("Camera05");
  245. var camera06 = scene.getTransformNodeByName("Camera06");
  246. camera05.name = "camera05";
  247. camera06.name = "camera06";
  248. camera05.nameID = "ZLS_MO_CAM_001";
  249. camera06.nameID = "ZLS_MO_CAM_002";
  250. camera05.baojing = false;
  251. camera06.baojing = false;
  252. var yangan05 = scene.getTransformNodeByName("yangan_4");
  253. yangan05.name = "yangan05";
  254. yangan05.nameID = "ZLS_MO_OAO_001";
  255. yangan05.wendu = 0;
  256. yangan05.sidu = 0;
  257. prepareGroupButtonOther(yangan05, new BABYLON.Color3(0, 0, 1));
  258. prepareGroupButtonOther(camera06, new BABYLON.Color3(0, 0, 1));
  259. prepareGroupButtonOther(camera05, new BABYLON.Color3(0, 0, 1));
  260. var x = scene.getMeshByName("立方体_2_17_primitive0");
  261. x.overlayColor = BABYLON.Color3.White();
  262. x.renderOverlay = true;
  263. //修改贴图
  264. var bluexMat = new BABYLON.StandardMaterial("bluex", scene);
  265. var tempddx = new BABYLON.Texture("./asset/blue.png", scene);
  266. bluexMat.emissiveTexture = tempddx;
  267. scene.getMeshByName("平面_1").material = bluexMat;
  268. tempddx.uAng = (180 * Math.PI) / 180;
  269. var redMat = new BABYLON.StandardMaterial("redMat", scene);
  270. var tempddx2 = new BABYLON.Texture("./asset/red.png", scene);
  271. redMat.emissiveTexture = tempddx2;
  272. scene.getMeshByName("平面_1_2").material = redMat;
  273. tempddx2.uAng = (180 * Math.PI) / 180;
  274. var font_size = 48;
  275. var font = "bold " + font_size + "px Arial";
  276. //Set height for plane
  277. var planeHeight = 3;
  278. //Set height for dynamic texture
  279. var DTHeight = 1.5 * font_size; //or set as wished
  280. //Calcultae ratio
  281. var ratio = planeHeight / DTHeight;
  282. //Set text
  283. var text = "10";
  284. //Use a temporay dynamic texture to calculate the length of the text on the dynamic texture canvas
  285. var temp = new BABYLON.DynamicTexture("DynamicTexture", 64, scene);
  286. var tmpctx = temp.getContext();
  287. tmpctx.font = font;
  288. var DTWidth = tmpctx.measureText(text).width + 58;
  289. //Calculate width the plane has to be
  290. var planeWidth = DTWidth * ratio;
  291. //Create dynamic texture and write the text
  292. dynamicTexture = new BABYLON.DynamicTexture(
  293. "DynamicTexture",
  294. { width: DTWidth, height: DTHeight },
  295. scene,
  296. false
  297. );
  298. var mat = new BABYLON.StandardMaterial("mat", scene);
  299. //var mat = new BABYLON.PBRMaterial("mat", scene);
  300. //mat.albedoColor = new BABYLON.Color4(0.7968, 0.3685, 0.1105, 1);
  301. mat.disableLighting = true;
  302. mat.emissiveTexture = dynamicTexture;
  303. mat.reflectivityColor = new BABYLON.Color3(0, 0, 0);
  304. dynamicTexture.uAng = (166.39 * Math.PI) / 180;
  305. //Create plane and set dynamic texture as material
  306. //var plane = BABYLON.MeshBuilder.CreatePlane("plane", {width:planeWidth, height:planeHeight}, scene);
  307. var vxd = scene.getMeshByName("平面_2"); //blue
  308. vxd.material = mat;
  309. //平面3
  310. dynamicTexture2 = new BABYLON.DynamicTexture(
  311. "DynamicTexture2",
  312. { width: DTWidth, height: DTHeight },
  313. scene,
  314. false
  315. );
  316. //var mat = new BABYLON.StandardMaterial("mat", scene);
  317. //mat.disableLighting = true;
  318. var mat2 = new BABYLON.StandardMaterial("mat2", scene);
  319. //mat.albedoColor = new BABYLON.Color4(0.7968, 0.3685, 0.1105, 1);
  320. //mat2.ambientTexture = dynamicTexture2;
  321. mat2.emissiveTexture = dynamicTexture2;
  322. mat2.reflectivityColor = new BABYLON.Color3(0, 0, 0);
  323. dynamicTexture2.uAng = (166.39 * Math.PI) / 180;
  324. //Create plane and set dynamic texture as material
  325. //var plane = BABYLON.MeshBuilder.CreatePlane("plane", {width:planeWidth, height:planeHeight}, scene);
  326. var vxd2 = scene.getMeshByName("平面_3");
  327. vxd2.material = mat2;
  328. //-------------------------------------------------------------------------------------
  329. dynamicTexture3 = new BABYLON.DynamicTexture(
  330. "DynamicTexture3",
  331. { width: DTWidth, height: DTHeight },
  332. scene,
  333. false
  334. );
  335. //var mat = new BABYLON.StandardMaterial("mat", scene);
  336. //mat.disableLighting = true;
  337. var mat3 = new BABYLON.StandardMaterial("mat3", scene);
  338. //mat.albedoColor = new BABYLON.Color4(0.7968, 0.3685, 0.1105, 1);
  339. //mat2.ambientTexture = dynamicTexture2;
  340. mat3.emissiveTexture = dynamicTexture3;
  341. mat3.reflectivityColor = new BABYLON.Color3(0, 0, 0);
  342. dynamicTexture3.uAng = (166.39 * Math.PI) / 180;
  343. //Create plane and set dynamic texture as material
  344. //var plane = BABYLON.MeshBuilder.CreatePlane("plane", {width:planeWidth, height:planeHeight}, scene);
  345. var vxd3 = scene.getMeshByName("平面_2_2"); //blue
  346. vxd3.material = mat3;
  347. //-------------------------------------------------------------------------------------
  348. dynamicTexture4 = new BABYLON.DynamicTexture(
  349. "dynamicTexture4",
  350. { width: DTWidth, height: DTHeight },
  351. scene,
  352. false
  353. );
  354. //var mat = new BABYLON.StandardMaterial("mat", scene);
  355. //mat.disableLighting = true;
  356. var mat4 = new BABYLON.StandardMaterial("mat4", scene);
  357. //mat.albedoColor = new BABYLON.Color4(0.7968, 0.3685, 0.1105, 1);
  358. //mat2.ambientTexture = dynamicTexture2;
  359. mat4.emissiveTexture = dynamicTexture4;
  360. mat4.reflectivityColor = new BABYLON.Color3(0, 0, 0);
  361. dynamicTexture4.uAng = (166.39 * Math.PI) / 180;
  362. //Create plane and set dynamic texture as material
  363. //var plane = BABYLON.MeshBuilder.CreatePlane("plane", {width:planeWidth, height:planeHeight}, scene);
  364. var vxd4 = scene.getMeshByName("平面_3_2");
  365. vxd4.material = mat4;
  366. scene.getMeshByName("tapblue").setEnabled(false);
  367. scene.getMeshByName("tapred").setEnabled(false);
  368. };
  369. // createScene function that creates and return the scene
  370. var createScene = function() {
  371. engine.displayLoadingUI();
  372. // create a basic BJS Scene object
  373. var scene = new BABYLON.Scene(engine);
  374. // scene.debugLayer.show();
  375. var camera = new BABYLON.ArcRotateCamera(
  376. "Camera",
  377. 0,
  378. 0,
  379. 5,
  380. new BABYLON.Vector3(0, -1, 0),
  381. scene
  382. );
  383. camera.setTarget(new BABYLON.Vector3(0, 3.5, 0));
  384. camera.attachControl(canvas, true);
  385. camera.lowerRadiusLimit = 2.0; // 这里是最大的位置,值越大,物体越小
  386. camera.upperRadiusLimit = 40;
  387. camera.radius = 19.328;
  388. camera.alpha = (Math.PI * -211.4) / 180;
  389. camera.beta = (Math.PI * 66) / 180;
  390. camera.inertia = 0.1; // 缩放的快慢
  391. camera.useAutoRotationBehavior = true; // 自动旋转
  392. camera.panningDistanceLimit = 2; //平移半径
  393. camera.panningInertia = 0;
  394. camera.autoTransitionRange = 1;
  395. camera.pinchToPanMaxDistance = 0.1;
  396. camera.pinchDeltaPercentage = 0.001;
  397. camera.useAutoRotationBehavior = false;
  398. scene.activeCamera = camera;
  399. // 改变场景背景颜色 - 背景颜色opacity值设为0,达到透明背景的效果
  400. scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
  401. scene.activeCamera.useInputToRestoreState = true;
  402. var camera1_status = scene.activeCamera.storeState();
  403. var assetsManager = new BABYLON.AssetsManager(scene);
  404. var meshTask = assetsManager.addMeshTask(
  405. "skull task",
  406. "",
  407. "asset/",
  408. "B4.glb"
  409. );
  410. meshTask.onSuccess = function(task) {
  411. task.loadedMeshes[0].scaling = new BABYLON.Vector3(0.4, 0.4, -0.4);
  412. task.loadedMeshes[0].position = new BABYLON.Vector3(0.0, 2, 0);
  413. };
  414. meshTask.onError = function(task, message, exception) {
  415. console.log(message, exception);
  416. };
  417. var meshTask_tapblue = assetsManager.addMeshTask(
  418. "skull task",
  419. "",
  420. "asset/",
  421. "tapBlue.glb"
  422. );
  423. meshTask_tapblue.onSuccess = function(task) {
  424. task.loadedMeshes[0].scaling = new BABYLON.Vector3(0.4, 0.4, -0.4);
  425. task.loadedMeshes[0].position = new BABYLON.Vector3(0, 0, 0);
  426. //-2.5,3.77,1.45
  427. // x = x-0.6;; y = y+0.3 z=z+0.5
  428. task.loadedMeshes[0].rotation = new BABYLON.Vector3(0, 0, 0);
  429. task.loadedMeshes[0].name = "tapblue";
  430. var vx = scene.getTransformNodeByName("蓝");
  431. vx.position = new BABYLON.Vector3(0, -1.2, 0);
  432. vx.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);
  433. vx.scaling = new BABYLON.Vector3(0.015, 0.015, 0.015);
  434. };
  435. meshTask_tapblue.onError = function(task, message, exception) {
  436. console.log(message, exception);
  437. };
  438. var meshTask_tapred = assetsManager.addMeshTask(
  439. "skull task",
  440. "",
  441. "asset/",
  442. "tapRed.glb"
  443. );
  444. meshTask_tapred.onSuccess = function(task) {
  445. task.loadedMeshes[0].scaling = new BABYLON.Vector3(0.4, 0.4, -0.4);
  446. task.loadedMeshes[0].position = new BABYLON.Vector3(-1.929, 4.029, 0.968);
  447. //-2.5,3.77,1.45
  448. // x = x-0.6;; y = y+0.3 z=z+0.5
  449. task.loadedMeshes[0].rotation = new BABYLON.Vector3(0, 0, 0);
  450. task.loadedMeshes[0].name = "tapred";
  451. var vx = scene.getTransformNodeByName("红");
  452. vx.position = new BABYLON.Vector3(0, -1.2, 0);
  453. vx.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);
  454. vx.scaling = new BABYLON.Vector3(0.015, 0.015, 0.015);
  455. };
  456. meshTask_tapred.onError = function(task, message, exception) {
  457. console.log(message, exception);
  458. };
  459. var hdrTexture = new BABYLON.CubeTexture.CreateFromPrefilteredData(
  460. "textures/environmentSpecular.env",
  461. scene
  462. );
  463. //var hdrTexture = new BABYLON.CubeTexture.CreateFromPrefilteredData("textures/environment.env", scene);
  464. scene.environmentTexture = hdrTexture;
  465. // renderCanvas.style.backgroundImage = 'url("./textures/' + '4' + '.jpg")';
  466. assetsManager.load();
  467. drag = new BABYLON.PointerDragBehavior({
  468. dragPlaneNormal: new BABYLON.Vector3(0, 0, 1)
  469. });
  470. //drag.useObjectOrienationForDragging = false;
  471. drag.validateDrag = targetPosition => {
  472. console.log(targetPosition);
  473. if (targetPosition.x > 10.5 || targetPosition.x < -10.5) {
  474. return false;
  475. }
  476. if (targetPosition.z > 10.5 || targetPosition.z < -10.5) {
  477. return false;
  478. }
  479. if (oldtransformNodex != null) {
  480. return true;
  481. }
  482. };
  483. drag.onDragEndObservable.add(event => {
  484. console.log("dragEnd");
  485. //console.log(event);
  486. //console.log(line03_position)
  487. });
  488. //GUI
  489. h1 = new BABYLON.HighlightLayer("hl1", scene);
  490. h2 = new BABYLON.HighlightLayer("hl2", scene);
  491. h3 = new BABYLON.HighlightLayer("hl3", scene);
  492. var step = 0.1;
  493. var currentx = 1;
  494. var step2 = 0.1;
  495. var currentx2 = 0.1;
  496. h1.blurHorizontalSize = 0.1;
  497. var showx = 0;
  498. var showx2 = 2;
  499. scene.registerAfterRender(() => {
  500. h1.blurHorizontalSize = h1.blurVerticalSize + currentx;
  501. h2.blurHorizontalSize = h2.blurVerticalSize + currentx2;
  502. h3.blurHorizontalSize = h3.blurVerticalSize + currentx2;
  503. var nodealert = scene.getTransformNodeByName("yangan05");
  504. if (nodealert != null) {
  505. var mesheses3 = null;
  506. if (nodealert.getClassName() == "TransformNode") {
  507. mesheses3 = nodealert.getChildMeshes(false);
  508. } else {
  509. mesheses3 = [];
  510. mesheses3.push(nodealert);
  511. }
  512. for (var i = 0; i < mesheses3.length; i++) {
  513. try {
  514. if (nodealert.baojing == true) {
  515. h3.addMesh(mesheses3[i], new BABYLON.Color3(1, 0, 0));
  516. } else {
  517. h3.removeMesh(mesheses3[i]);
  518. }
  519. } catch (error) {
  520. // alert(error)
  521. }
  522. }
  523. }
  524. var nodealert = scene.getTransformNodeByName("camera05");
  525. if (nodealert != null) {
  526. var mesheses3 = null;
  527. if (nodealert.getClassName() == "TransformNode") {
  528. mesheses3 = nodealert.getChildMeshes(false);
  529. } else {
  530. mesheses3 = [];
  531. mesheses3.push(nodealert);
  532. }
  533. for (var i = 0; i < mesheses3.length; i++) {
  534. try {
  535. if (nodealert.baojing == true) {
  536. h3.addMesh(mesheses3[i], new BABYLON.Color3(1, 0, 0));
  537. } else {
  538. h3.removeMesh(mesheses3[i]);
  539. }
  540. } catch (error) {
  541. // alert(error)
  542. }
  543. }
  544. }
  545. var nodealert = scene.getTransformNodeByName("camera06");
  546. if (nodealert != null) {
  547. var mesheses3 = null;
  548. if (nodealert.getClassName() == "TransformNode") {
  549. mesheses3 = nodealert.getChildMeshes(false);
  550. } else {
  551. mesheses3 = [];
  552. mesheses3.push(nodealert);
  553. }
  554. for (var i = 0; i < mesheses3.length; i++) {
  555. try {
  556. if (nodealert.baojing == true) {
  557. h3.addMesh(mesheses3[i], new BABYLON.Color3(1, 0, 0));
  558. } else {
  559. h3.removeMesh(mesheses3[i]);
  560. }
  561. } catch (error) {
  562. // alert(error)
  563. }
  564. }
  565. }
  566. var a = scene.getMaterialByName("carpaint_baseRed");
  567. if (a != null) {
  568. if (a.albedoColor == b) {
  569. b = new BABYLON.Color3(0, 1, 0);
  570. a.albedoColor = b;
  571. }
  572. }
  573. var v2 = scene.getMeshByName("tapblue");
  574. if (v2 != null) {
  575. v2.lookAt(camera.globalPosition, 0, 0, Math.PI);
  576. }
  577. var v3 = scene.getMeshByName("tapred");
  578. if (v3 != null) {
  579. v3.lookAt(camera.globalPosition, 0, 0, Math.PI);
  580. }
  581. if (currentx > 0.5) {
  582. step *= -1;
  583. }
  584. if (currentx < 0) {
  585. step *= -1;
  586. }
  587. currentx += step;
  588. if (currentx2 > 5) {
  589. step2 *= -1;
  590. }
  591. if (currentx2 < 0) {
  592. step2 *= -1;
  593. }
  594. currentx2 += step2;
  595. if (dynamicTexture != null && PointerOverYangan != null) {
  596. var textx = scene.getTransformNodeByName(PointerOverYangan).wendu;
  597. var font_size = 36;
  598. var font = "bold " + font_size + "px Arial";
  599. dynamicTexture.drawText(
  600. textx + "°C",
  601. null,
  602. null,
  603. font,
  604. "#FFFFFF",
  605. "#000000",
  606. true
  607. );
  608. showx++;
  609. show = 50;
  610. }
  611. if (dynamicTexture2 != null && PointerOverYangan != null) {
  612. var textx = scene.getTransformNodeByName(PointerOverYangan).sidu;
  613. var font_size = 36;
  614. var font = "bold " + font_size + "px Arial";
  615. dynamicTexture2.drawText(
  616. textx + "%",
  617. null,
  618. null,
  619. font,
  620. "#FFFFFF",
  621. "#000000",
  622. true
  623. );
  624. }
  625. if (dynamicTexture3 != null && PointerOverYangan != null) {
  626. var textx = scene.getTransformNodeByName(PointerOverYangan).wendu;
  627. var font_size = 36;
  628. var font = "bold " + font_size + "px Arial";
  629. dynamicTexture3.drawText(
  630. textx + "°C",
  631. null,
  632. null,
  633. font,
  634. "#FFFFFF",
  635. "#000000",
  636. true
  637. );
  638. }
  639. if (dynamicTexture4 != null && PointerOverYangan != null) {
  640. var textx = scene.getTransformNodeByName(PointerOverYangan).sidu;
  641. var font_size = 36;
  642. var font = "bold " + font_size + "px Arial";
  643. dynamicTexture4.drawText(
  644. textx + "%",
  645. null,
  646. null,
  647. font,
  648. "#FFFFFF",
  649. "#000000",
  650. true
  651. );
  652. }
  653. /*show--;
  654. showdd--;*/
  655. });
  656. return scene;
  657. };
  658. var canvas = document.getElementById("renderCanvas");
  659. // load the 3D engine
  660. var engine = new BABYLON.Engine(canvas, true, {
  661. stencil: true
  662. });
  663. // call the createScene function
  664. var scene = createScene();
  665. scene.autoClear = true;
  666. scene.imageProcessingConfiguration.exposure = 1;
  667. scene.imageProcessingConfiguration.contrast = 1;
  668. scene.environmentIntensity = 1;
  669. engine.runRenderLoop(function() {
  670. scene.render();
  671. });
  672. window.addEventListener("resize", function() {
  673. engine.resize();
  674. });
  675. function HashMap() {
  676. //定义长度
  677. var length = 0;
  678. //创建一个对象
  679. var obj = new Object();
  680. //判断Map是否为空
  681. this.isEmpty = function() {
  682. return length == 0;
  683. };
  684. //判断对象中是否包含给定Key
  685. this.containsKey = function(key) {
  686. return key in obj;
  687. };
  688. //判断对象中是否包含给定的Value
  689. this.containsValue = function(value) {
  690. for (var key in obj) {
  691. if (obj[key] == value) {
  692. return true;
  693. }
  694. }
  695. return false;
  696. };
  697. //向map中添加数据
  698. this.put = function(key, value) {
  699. if (!this.containsKey(key)) {
  700. length++;
  701. }
  702. obj[key] = value;
  703. };
  704. //根据给定的key获取Value
  705. this.get = function(key) {
  706. return this.containsKey(key) ? obj[key] : null;
  707. };
  708. //根据给定的Key删除一个值
  709. this.remove = function(key) {
  710. if (this.containsKey(key) && delete obj[key]) {
  711. length--;
  712. }
  713. };
  714. //获得Map中所有的value
  715. this.values = function() {
  716. var _values = new Array();
  717. for (var key in obj) {
  718. _values.push(obj[key]);
  719. }
  720. return _values;
  721. };
  722. //获得Map中的所有key
  723. this.keySet = function() {
  724. var _keys = new Array();
  725. for (var key in obj) {
  726. _keys.push(key);
  727. }
  728. return _keys;
  729. };
  730. //获得Map的长度
  731. this.size = function() {
  732. return length;
  733. };
  734. //清空Map
  735. this.clear = function() {
  736. length = 0;
  737. obj = new Object();
  738. };
  739. }
  740. var yangans = new HashMap();
  741. yangans.put("ZLS_MO_OAO_001", "yangan05");
  742. yangans.put("ZLS_MO_CAM_001", "camera05");
  743. yangans.put("ZLS_MO_CAM_002", "camera06");
  744. //功能转入报警
  745. function Myalert(MathineID, baojing) {
  746. scene.getMeshByName("tapblue").setEnabled(false);
  747. scene.getMeshByName("tapred").setEnabled(false);
  748. var theName = yangans.get(MathineID);
  749. alert(theName);
  750. if (theName == "yangan05") {
  751. scene.getTransformNodeByName("yangan05").baojing = baojing;
  752. }
  753. if (theName == "camera05") {
  754. scene.getTransformNodeByName("camera05").baojing = baojing;
  755. }
  756. if (theName == "camera06") {
  757. scene.getTransformNodeByName("camera06").baojing = baojing;
  758. }
  759. }
  760. //报警 true:表示报警, false :表示不报警
  761. // Myalert("DAK_MO_OAO_001",true)
  762. //设置温湿度
  763. function setAlertValue(MathineID, wendu, sidu) {
  764. var theName = yangans.get(MathineID);
  765. if (theName == "yangan05") {
  766. scene.getTransformNodeByName("yangan05").wendu = wendu;
  767. scene.getTransformNodeByName("yangan05").sidu = sidu;
  768. }
  769. }
  770. //设置温湿度: setAlertValue("DAK_MO_OAO_001",4,5)
  771. // function cameraClick(TheCamera) {
  772. // alert(TheCamera.nameID);
  773. // }
  774. function cameraClick(TheCamera) {
  775. window.parent.postMessage(
  776. {
  777. data: TheCamera.nameID
  778. },
  779. "*"
  780. );
  781. }
  782. // 监测父页面传来得初始化得温度湿度值
  783. window.addEventListener(
  784. "message",
  785. function(e) {
  786. deviceData = e.data.data;
  787. },
  788. false
  789. );