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

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