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

923 lines
27 KiB

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