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

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