【前端】智能库房综合管理系统前端项目
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.

934 lines
27 KiB

3 years ago
3 years ago
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.PBRMaterial("bluex", scene);
  265. var tempddxa = new BABYLON.Texture("./asset/blue.png", scene);
  266. var tempddxb = new BABYLON.Texture("./asset/blue.png", scene);
  267. tempddxa.hasAlpha = true;
  268. tempddxa.hasAlpha = true;
  269. tempddxa.uAng = 180 * Math.PI / 180;
  270. tempddxb.uAng = 180 * Math.PI / 180;
  271. bluexMat.useAlphaFromAlbedoTexture = true;
  272. bluexMat.albedoTexture =tempddxa;
  273. bluexMat.reflectionColor = new BABYLON.Color3(0,0,0);
  274. bluexMat.lightmapTexture =tempddxb;
  275. scene.getMeshByName("平面_1").material = bluexMat;
  276. var redMat = new BABYLON.PBRMaterial("redMat", scene);
  277. var tempddx2 = new BABYLON.Texture("./asset/red.png", scene);
  278. var tempddx3 = new BABYLON.Texture("./asset/red.png", scene);
  279. tempddx2.hasAlpha = true;
  280. tempddx3.hasAlpha = true;
  281. tempddx2.uAng = 180 * Math.PI / 180;
  282. tempddx3.uAng = 180 * Math.PI / 180;
  283. redMat.useAlphaFromAlbedoTexture = true;
  284. redMat.reflectionColor = new BABYLON.Color3(0,0,0);
  285. //redMat.emissiveTexture =tempddx2;
  286. redMat.albedoTexture =tempddx2;
  287. redMat.lightmapTexture =tempddx3;
  288. scene.getMeshByName("平面_1_2").material = redMat;
  289. var font_size = 48;
  290. var font = "bold " + font_size + "px Arial";
  291. //Set height for plane
  292. var planeHeight = 3;
  293. //Set height for dynamic texture
  294. var DTHeight = 1.5 * font_size; //or set as wished
  295. //Calcultae ratio
  296. var ratio = planeHeight / DTHeight;
  297. //Set text
  298. var text = "10";
  299. //Use a temporay dynamic texture to calculate the length of the text on the dynamic texture canvas
  300. var temp = new BABYLON.DynamicTexture("DynamicTexture", 64, scene);
  301. var tmpctx = temp.getContext();
  302. tmpctx.font = font;
  303. var DTWidth = tmpctx.measureText(text).width + 58;
  304. //Calculate width the plane has to be
  305. var planeWidth = DTWidth * ratio;
  306. //Create dynamic texture and write the text
  307. dynamicTexture = new BABYLON.DynamicTexture(
  308. "DynamicTexture",
  309. { width: DTWidth, height: DTHeight },
  310. scene,
  311. false
  312. );
  313. var mat = new BABYLON.StandardMaterial("mat", scene);
  314. //var mat = new BABYLON.PBRMaterial("mat", scene);
  315. //mat.albedoColor = new BABYLON.Color4(0.7968, 0.3685, 0.1105, 1);
  316. mat.disableLighting = true;
  317. mat.emissiveTexture = dynamicTexture;
  318. mat.reflectivityColor = new BABYLON.Color3(0, 0, 0);
  319. dynamicTexture.uAng = (166.39 * Math.PI) / 180;
  320. //Create plane and set dynamic texture as material
  321. //var plane = BABYLON.MeshBuilder.CreatePlane("plane", {width:planeWidth, height:planeHeight}, scene);
  322. var vxd = scene.getMeshByName("平面_2"); //blue
  323. vxd.material = mat;
  324. //平面3
  325. dynamicTexture2 = new BABYLON.DynamicTexture(
  326. "DynamicTexture2",
  327. { width: DTWidth, height: DTHeight },
  328. scene,
  329. false
  330. );
  331. //var mat = new BABYLON.StandardMaterial("mat", scene);
  332. //mat.disableLighting = true;
  333. var mat2 = new BABYLON.StandardMaterial("mat2", scene);
  334. //mat.albedoColor = new BABYLON.Color4(0.7968, 0.3685, 0.1105, 1);
  335. //mat2.ambientTexture = dynamicTexture2;
  336. mat2.emissiveTexture = dynamicTexture2;
  337. mat2.reflectivityColor = new BABYLON.Color3(0, 0, 0);
  338. dynamicTexture2.uAng = (166.39 * Math.PI) / 180;
  339. //Create plane and set dynamic texture as material
  340. //var plane = BABYLON.MeshBuilder.CreatePlane("plane", {width:planeWidth, height:planeHeight}, scene);
  341. var vxd2 = scene.getMeshByName("平面_3");
  342. vxd2.material = mat2;
  343. //-------------------------------------------------------------------------------------
  344. dynamicTexture3 = new BABYLON.DynamicTexture(
  345. "DynamicTexture3",
  346. { width: DTWidth, height: DTHeight },
  347. scene,
  348. false
  349. );
  350. //var mat = new BABYLON.StandardMaterial("mat", scene);
  351. //mat.disableLighting = true;
  352. var mat3 = new BABYLON.StandardMaterial("mat3", scene);
  353. //mat.albedoColor = new BABYLON.Color4(0.7968, 0.3685, 0.1105, 1);
  354. //mat2.ambientTexture = dynamicTexture2;
  355. mat3.emissiveTexture = dynamicTexture3;
  356. mat3.reflectivityColor = new BABYLON.Color3(0, 0, 0);
  357. dynamicTexture3.uAng = (166.39 * Math.PI) / 180;
  358. //Create plane and set dynamic texture as material
  359. //var plane = BABYLON.MeshBuilder.CreatePlane("plane", {width:planeWidth, height:planeHeight}, scene);
  360. var vxd3 = scene.getMeshByName("平面_2_2"); //blue
  361. vxd3.material = mat3;
  362. //-------------------------------------------------------------------------------------
  363. dynamicTexture4 = new BABYLON.DynamicTexture(
  364. "dynamicTexture4",
  365. { width: DTWidth, height: DTHeight },
  366. scene,
  367. false
  368. );
  369. //var mat = new BABYLON.StandardMaterial("mat", scene);
  370. //mat.disableLighting = true;
  371. var mat4 = new BABYLON.StandardMaterial("mat4", scene);
  372. //mat.albedoColor = new BABYLON.Color4(0.7968, 0.3685, 0.1105, 1);
  373. //mat2.ambientTexture = dynamicTexture2;
  374. mat4.emissiveTexture = dynamicTexture4;
  375. mat4.reflectivityColor = new BABYLON.Color3(0, 0, 0);
  376. dynamicTexture4.uAng = (166.39 * Math.PI) / 180;
  377. //Create plane and set dynamic texture as material
  378. //var plane = BABYLON.MeshBuilder.CreatePlane("plane", {width:planeWidth, height:planeHeight}, scene);
  379. var vxd4 = scene.getMeshByName("平面_3_2");
  380. vxd4.material = mat4;
  381. scene.getMeshByName("tapblue").setEnabled(false);
  382. scene.getMeshByName("tapred").setEnabled(false);
  383. };
  384. // createScene function that creates and return the scene
  385. var createScene = function() {
  386. engine.displayLoadingUI();
  387. // create a basic BJS Scene object
  388. var scene = new BABYLON.Scene(engine);
  389. // scene.debugLayer.show();
  390. var camera = new BABYLON.ArcRotateCamera(
  391. "Camera",
  392. 0,
  393. 0,
  394. 5,
  395. new BABYLON.Vector3(0, -1, 0),
  396. scene
  397. );
  398. camera.setTarget(new BABYLON.Vector3(0, 3.5, 0));
  399. camera.attachControl(canvas, true);
  400. camera.lowerRadiusLimit = 2.0; // 这里是最大的位置,值越大,物体越小
  401. camera.upperRadiusLimit = 40;
  402. camera.radius = 14.888;
  403. camera.alpha = (Math.PI * -240.2) / 180;
  404. camera.beta = (Math.PI * 66) / 180;
  405. camera.inertia = 0.1; // 缩放的快慢
  406. camera.useAutoRotationBehavior = true; // 自动旋转
  407. camera.panningDistanceLimit = 2; //平移半径
  408. camera.panningInertia = 0;
  409. camera.autoTransitionRange = 1;
  410. camera.pinchToPanMaxDistance = 0.1;
  411. camera.pinchDeltaPercentage = 0.001;
  412. camera.useAutoRotationBehavior = false;
  413. scene.activeCamera = camera;
  414. // 改变场景背景颜色 - 背景颜色opacity值设为0,达到透明背景的效果
  415. scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
  416. scene.activeCamera.useInputToRestoreState = true;
  417. var camera1_status = scene.activeCamera.storeState();
  418. var assetsManager = new BABYLON.AssetsManager(scene);
  419. var meshTask = assetsManager.addMeshTask(
  420. "skull task",
  421. "",
  422. "asset/",
  423. "B4.glb"
  424. );
  425. meshTask.onSuccess = function(task) {
  426. task.loadedMeshes[0].scaling = new BABYLON.Vector3(0.4, 0.4, -0.4);
  427. task.loadedMeshes[0].position = new BABYLON.Vector3(0.0, 2, 0);
  428. };
  429. meshTask.onError = function(task, message, exception) {
  430. console.log(message, exception);
  431. };
  432. var meshTask_tapblue = assetsManager.addMeshTask(
  433. "skull task",
  434. "",
  435. "asset/",
  436. "tapBlue.glb"
  437. );
  438. meshTask_tapblue.onSuccess = function(task) {
  439. task.loadedMeshes[0].scaling = new BABYLON.Vector3(0.4, 0.4, -0.4);
  440. task.loadedMeshes[0].position = new BABYLON.Vector3(0, 0, 0);
  441. //-2.5,3.77,1.45
  442. // x = x-0.6;; y = y+0.3 z=z+0.5
  443. task.loadedMeshes[0].rotation = new BABYLON.Vector3(0, 0, 0);
  444. task.loadedMeshes[0].name = "tapblue";
  445. var vx = scene.getTransformNodeByName("蓝");
  446. vx.position = new BABYLON.Vector3(0, -1.2, 0);
  447. vx.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);
  448. vx.scaling = new BABYLON.Vector3(0.015, 0.015, 0.015);
  449. };
  450. meshTask_tapblue.onError = function(task, message, exception) {
  451. console.log(message, exception);
  452. };
  453. var meshTask_tapred = assetsManager.addMeshTask(
  454. "skull task",
  455. "",
  456. "asset/",
  457. "tapRed.glb"
  458. );
  459. meshTask_tapred.onSuccess = function(task) {
  460. task.loadedMeshes[0].scaling = new BABYLON.Vector3(0.4, 0.4, -0.4);
  461. task.loadedMeshes[0].position = new BABYLON.Vector3(-1.929, 4.029, 0.968);
  462. //-2.5,3.77,1.45
  463. // x = x-0.6;; y = y+0.3 z=z+0.5
  464. task.loadedMeshes[0].rotation = new BABYLON.Vector3(0, 0, 0);
  465. task.loadedMeshes[0].name = "tapred";
  466. var vx = scene.getTransformNodeByName("红");
  467. vx.position = new BABYLON.Vector3(0, -1.2, 0);
  468. vx.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);
  469. vx.scaling = new BABYLON.Vector3(0.015, 0.015, 0.015);
  470. };
  471. meshTask_tapred.onError = function(task, message, exception) {
  472. console.log(message, exception);
  473. };
  474. var hdrTexture = new BABYLON.CubeTexture.CreateFromPrefilteredData(
  475. "textures/environmentSpecular.env",
  476. scene
  477. );
  478. //var hdrTexture = new BABYLON.CubeTexture.CreateFromPrefilteredData("textures/environment.env", scene);
  479. scene.environmentTexture = hdrTexture;
  480. // renderCanvas.style.backgroundImage = 'url("./textures/' + '4' + '.jpg")';
  481. assetsManager.load();
  482. drag = new BABYLON.PointerDragBehavior({
  483. dragPlaneNormal: new BABYLON.Vector3(0, 0, 1)
  484. });
  485. //drag.useObjectOrienationForDragging = false;
  486. drag.validateDrag = targetPosition => {
  487. console.log(targetPosition);
  488. if (targetPosition.x > 10.5 || targetPosition.x < -10.5) {
  489. return false;
  490. }
  491. if (targetPosition.z > 10.5 || targetPosition.z < -10.5) {
  492. return false;
  493. }
  494. if (oldtransformNodex != null) {
  495. return true;
  496. }
  497. };
  498. drag.onDragEndObservable.add(event => {
  499. console.log("dragEnd");
  500. //console.log(event);
  501. //console.log(line03_position)
  502. });
  503. //GUI
  504. h1 = new BABYLON.HighlightLayer("hl1", scene);
  505. h2 = new BABYLON.HighlightLayer("hl2", scene);
  506. h3 = new BABYLON.HighlightLayer("hl3", scene);
  507. var step = 0.1;
  508. var currentx = 1;
  509. var step2 = 0.1;
  510. var currentx2 = 0.1;
  511. h1.blurHorizontalSize = 0.1;
  512. var showx = 0;
  513. var showx2 = 2;
  514. scene.registerAfterRender(() => {
  515. h1.blurHorizontalSize = h1.blurVerticalSize + currentx;
  516. h2.blurHorizontalSize = h2.blurVerticalSize + currentx2;
  517. h3.blurHorizontalSize = h3.blurVerticalSize + currentx2;
  518. var nodealert = scene.getTransformNodeByName("yangan05");
  519. if (nodealert != null) {
  520. var mesheses3 = null;
  521. if (nodealert.getClassName() == "TransformNode") {
  522. mesheses3 = nodealert.getChildMeshes(false);
  523. } else {
  524. mesheses3 = [];
  525. mesheses3.push(nodealert);
  526. }
  527. for (var i = 0; i < mesheses3.length; i++) {
  528. try {
  529. if (nodealert.baojing == true) {
  530. h3.addMesh(mesheses3[i], new BABYLON.Color3(1, 0, 0));
  531. } else {
  532. h3.removeMesh(mesheses3[i]);
  533. }
  534. } catch (error) {
  535. // alert(error)
  536. }
  537. }
  538. }
  539. var nodealert = scene.getTransformNodeByName("camera05");
  540. if (nodealert != null) {
  541. var mesheses3 = null;
  542. if (nodealert.getClassName() == "TransformNode") {
  543. mesheses3 = nodealert.getChildMeshes(false);
  544. } else {
  545. mesheses3 = [];
  546. mesheses3.push(nodealert);
  547. }
  548. for (var i = 0; i < mesheses3.length; i++) {
  549. try {
  550. if (nodealert.baojing == true) {
  551. h3.addMesh(mesheses3[i], new BABYLON.Color3(1, 0, 0));
  552. } else {
  553. h3.removeMesh(mesheses3[i]);
  554. }
  555. } catch (error) {
  556. // alert(error)
  557. }
  558. }
  559. }
  560. var nodealert = scene.getTransformNodeByName("camera06");
  561. if (nodealert != null) {
  562. var mesheses3 = null;
  563. if (nodealert.getClassName() == "TransformNode") {
  564. mesheses3 = nodealert.getChildMeshes(false);
  565. } else {
  566. mesheses3 = [];
  567. mesheses3.push(nodealert);
  568. }
  569. for (var i = 0; i < mesheses3.length; i++) {
  570. try {
  571. if (nodealert.baojing == true) {
  572. h3.addMesh(mesheses3[i], new BABYLON.Color3(1, 0, 0));
  573. } else {
  574. h3.removeMesh(mesheses3[i]);
  575. }
  576. } catch (error) {
  577. // alert(error)
  578. }
  579. }
  580. }
  581. var a = scene.getMaterialByName("carpaint_baseRed");
  582. if (a != null) {
  583. if (a.albedoColor == b) {
  584. b = new BABYLON.Color3(0, 1, 0);
  585. a.albedoColor = b;
  586. }
  587. }
  588. var v2 = scene.getMeshByName("tapblue");
  589. if (v2 != null) {
  590. v2.lookAt(camera.globalPosition, 0, 0, Math.PI);
  591. }
  592. var v3 = scene.getMeshByName("tapred");
  593. if (v3 != null) {
  594. v3.lookAt(camera.globalPosition, 0, 0, Math.PI);
  595. }
  596. if (currentx > 0.5) {
  597. step *= -1;
  598. }
  599. if (currentx < 0) {
  600. step *= -1;
  601. }
  602. currentx += step;
  603. if (currentx2 > 5) {
  604. step2 *= -1;
  605. }
  606. if (currentx2 < 0) {
  607. step2 *= -1;
  608. }
  609. currentx2 += step2;
  610. if (dynamicTexture != null && PointerOverYangan != null) {
  611. var textx = scene.getTransformNodeByName(PointerOverYangan).wendu;
  612. var font_size = 36;
  613. var font = "bold " + font_size + "px Arial";
  614. dynamicTexture.drawText(
  615. textx + "°C",
  616. null,
  617. null,
  618. font,
  619. "#FFFFFF",
  620. "#000000",
  621. true
  622. );
  623. showx++;
  624. show = 50;
  625. }
  626. if (dynamicTexture2 != null && PointerOverYangan != null) {
  627. var textx = scene.getTransformNodeByName(PointerOverYangan).sidu;
  628. var font_size = 36;
  629. var font = "bold " + font_size + "px Arial";
  630. dynamicTexture2.drawText(
  631. textx + "%",
  632. null,
  633. null,
  634. font,
  635. "#FFFFFF",
  636. "#000000",
  637. true
  638. );
  639. }
  640. if (dynamicTexture3 != null && PointerOverYangan != null) {
  641. var textx = scene.getTransformNodeByName(PointerOverYangan).wendu;
  642. var font_size = 36;
  643. var font = "bold " + font_size + "px Arial";
  644. dynamicTexture3.drawText(
  645. textx + "°C",
  646. null,
  647. null,
  648. font,
  649. "#FFFFFF",
  650. "#000000",
  651. true
  652. );
  653. }
  654. if (dynamicTexture4 != null && PointerOverYangan != null) {
  655. var textx = scene.getTransformNodeByName(PointerOverYangan).sidu;
  656. var font_size = 36;
  657. var font = "bold " + font_size + "px Arial";
  658. dynamicTexture4.drawText(
  659. textx + "%",
  660. null,
  661. null,
  662. font,
  663. "#FFFFFF",
  664. "#000000",
  665. true
  666. );
  667. }
  668. /*show--;
  669. showdd--;*/
  670. });
  671. return scene;
  672. };
  673. var canvas = document.getElementById("renderCanvas");
  674. // load the 3D engine
  675. var engine = new BABYLON.Engine(canvas, true, {
  676. stencil: true
  677. });
  678. // call the createScene function
  679. var scene = createScene();
  680. scene.autoClear = true;
  681. scene.imageProcessingConfiguration.exposure = 1;
  682. scene.imageProcessingConfiguration.contrast = 1;
  683. scene.environmentIntensity = 1;
  684. engine.runRenderLoop(function() {
  685. scene.render();
  686. });
  687. window.addEventListener("resize", function() {
  688. engine.resize();
  689. });
  690. function HashMap() {
  691. //定义长度
  692. var length = 0;
  693. //创建一个对象
  694. var obj = new Object();
  695. //判断Map是否为空
  696. this.isEmpty = function() {
  697. return length == 0;
  698. };
  699. //判断对象中是否包含给定Key
  700. this.containsKey = function(key) {
  701. return key in obj;
  702. };
  703. //判断对象中是否包含给定的Value
  704. this.containsValue = function(value) {
  705. for (var key in obj) {
  706. if (obj[key] == value) {
  707. return true;
  708. }
  709. }
  710. return false;
  711. };
  712. //向map中添加数据
  713. this.put = function(key, value) {
  714. if (!this.containsKey(key)) {
  715. length++;
  716. }
  717. obj[key] = value;
  718. };
  719. //根据给定的key获取Value
  720. this.get = function(key) {
  721. return this.containsKey(key) ? obj[key] : null;
  722. };
  723. //根据给定的Key删除一个值
  724. this.remove = function(key) {
  725. if (this.containsKey(key) && delete obj[key]) {
  726. length--;
  727. }
  728. };
  729. //获得Map中所有的value
  730. this.values = function() {
  731. var _values = new Array();
  732. for (var key in obj) {
  733. _values.push(obj[key]);
  734. }
  735. return _values;
  736. };
  737. //获得Map中的所有key
  738. this.keySet = function() {
  739. var _keys = new Array();
  740. for (var key in obj) {
  741. _keys.push(key);
  742. }
  743. return _keys;
  744. };
  745. //获得Map的长度
  746. this.size = function() {
  747. return length;
  748. };
  749. //清空Map
  750. this.clear = function() {
  751. length = 0;
  752. obj = new Object();
  753. };
  754. }
  755. var yangans = new HashMap();
  756. yangans.put("ZLS_MO_OAO_001", "yangan05");
  757. yangans.put("ZLS_MO_CAM_001", "camera05");
  758. yangans.put("ZLS_MO_CAM_002", "camera06");
  759. //功能转入报警
  760. function Myalert(MathineID, baojing) {
  761. scene.getMeshByName("tapblue").setEnabled(false);
  762. scene.getMeshByName("tapred").setEnabled(false);
  763. var theName = yangans.get(MathineID);
  764. alert(theName);
  765. if (theName == "yangan05") {
  766. scene.getTransformNodeByName("yangan05").baojing = baojing;
  767. }
  768. if (theName == "camera05") {
  769. scene.getTransformNodeByName("camera05").baojing = baojing;
  770. }
  771. if (theName == "camera06") {
  772. scene.getTransformNodeByName("camera06").baojing = baojing;
  773. }
  774. }
  775. //报警 true:表示报警, false :表示不报警
  776. // Myalert("DAK_MO_OAO_001",true)
  777. //设置温湿度
  778. function setAlertValue(MathineID, wendu, sidu) {
  779. var theName = yangans.get(MathineID);
  780. if (theName == "yangan05") {
  781. scene.getTransformNodeByName("yangan05").wendu = wendu;
  782. scene.getTransformNodeByName("yangan05").sidu = sidu;
  783. }
  784. }
  785. //设置温湿度: setAlertValue("DAK_MO_OAO_001",4,5)
  786. // function cameraClick(TheCamera) {
  787. // alert(TheCamera.nameID);
  788. // }
  789. function cameraClick(TheCamera) {
  790. window.parent.postMessage(
  791. {
  792. data: TheCamera.nameID
  793. },
  794. "*"
  795. );
  796. }
  797. // 监测父页面传来得初始化得温度湿度值
  798. window.addEventListener(
  799. "message",
  800. function(e) {
  801. deviceData = e.data.data;
  802. },
  803. false
  804. );