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

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