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

800 lines
27 KiB

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