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

857 lines
29 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
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 = "<div class='oka'><div class='" + thecss + "'><image src='./logok.gif' class='jiazaiimg'/></div>";
  31. // this._loadingDiv.innerHTML =
  32. // "<div class='oka'><div class='" +
  33. // thecss +
  34. // "'><image src='./logok.gif' class='jiazaiimg'/></div><div class='" +
  35. // thecss2 +
  36. // "'>由 <image class='feitimg' src='./img/yxlogo.png'/> 阅行客 提供技术支持!</div></div>";
  37. this._resizeLoadingUI();
  38. window.addEventListener("resize", this._resizeLoadingUI);
  39. document.body.appendChild(this._loadingDiv);
  40. };
  41. BABYLON.DefaultLoadingScreen.prototype.hideLoadingUI = function () {
  42. show = 50;
  43. document.getElementById("customLoadingScreenDiv").style.display = "none";
  44. document.getElementById("customLoadingScreenDiv_first").style.display = "none";
  45. document.title = '整理室';
  46. //scene.getMaterialByName("材质.023").roughness = 0;
  47. var prepareGroupButtonOther = function (transformNodex, color) {
  48. var mesheses = null;
  49. if (transformNodex.getClassName() == "TransformNode") {
  50. mesheses = transformNodex.getChildMeshes(false);
  51. } else {
  52. mesheses = [];
  53. mesheses.push(transformNodex);
  54. }
  55. for (var i = 0; i < mesheses.length; i++) {
  56. mesheses[i].actionManager = new BABYLON.ActionManager(scene);
  57. var theScaling = mesheses[i].scaling;
  58. if (true) {
  59. try {
  60. //mesheses[i].actionManager.registerAction(new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPointerOutTrigger, mesheses[i], "scaling", new BABYLON.Vector3(theScaling.x, theScaling.y, theScaling.z), 100));
  61. // 初始化数据 温度/湿度
  62. deviceData.forEach(item => {
  63. if (item.id === transformNodex.nameID) {
  64. transformNodex.wendu = item.wendu;
  65. transformNodex.sidu = item.sidu;
  66. transformNodex.baojing = item.alarmState;
  67. }
  68. });
  69. mesheses[i].actionManager.registerAction(
  70. new BABYLON.ExecuteCodeAction({
  71. trigger: BABYLON.ActionManager.OnPointerOverTrigger,
  72. parameter: ""
  73. },
  74. function () {
  75. clickbegin = true;
  76. if (true) {
  77. try {
  78. if (oldtransformNodeOther != null) {
  79. oldtransformNodeOther.removeBehavior(drag);
  80. var mesheses2 = null;
  81. if (oldtransformNodeOther.getClassName() == "TransformNode") {
  82. mesheses2 = oldtransformNodeOther.getChildMeshes(false);
  83. } else {
  84. mesheses2 = [];
  85. mesheses2.push(oldtransformNodeOther);
  86. }
  87. for (var i = 0; i < mesheses2.length; i++) {
  88. try {
  89. h2.removeMesh(mesheses2[i]);
  90. } catch (error) {
  91. // alert(error)
  92. }
  93. }
  94. }
  95. oldtransformNodeOther = transformNodex;
  96. //transformNodex.addBehavior(drag);
  97. var mesheses3 = null;
  98. if (transformNodex.getClassName() == "TransformNode") {
  99. mesheses3 = transformNodex.getChildMeshes(false);
  100. } else {
  101. mesheses3 = [];
  102. mesheses3.push(transformNodex);
  103. }
  104. for (var i = 0; i < mesheses3.length; i++) {
  105. try {
  106. if (transformNodex.baojing == true) {
  107. h2.addMesh(mesheses3[i], new BABYLON.Color3(1, 0, 0));
  108. } else {
  109. h2.addMesh(mesheses3[i], color);
  110. }
  111. } catch (error) {
  112. // alert(error)
  113. }
  114. }
  115. } catch (error) {
  116. // alert(error)
  117. }
  118. clickbegin = false;
  119. }
  120. if (transformNodex.name.indexOf("yangan") >= 0) {
  121. console.log(transformNodex.name)
  122. PointerOverYangan = transformNodex.name;
  123. if (transformNodex.baojing == true) {
  124. var location = transformNodex.absolutePosition;
  125. var xd = scene.getMeshByName("tapred");
  126. // x = x-0.6;; y = y+0.3 z=z+0.5
  127. xd.position = new BABYLON.Vector3(location.x - 0.6, location.y + 0.9, location.z + 0.5);
  128. var font_size = 36;
  129. var font = "bold " + font_size + "px Arial";
  130. dynamicTexture3.drawText(transformNodex.wendu + "°C", null, null, font, "#FFFFFF", "#000000", true);
  131. dynamicTexture4.drawText(transformNodex.sidu + "%", null, null, font, "#FFFFFF", "#000000", true);
  132. if (transformNodex.canshow == true) {
  133. xd.setEnabled(true);
  134. }
  135. } else {
  136. var location = transformNodex.absolutePosition;
  137. var xd = scene.getMeshByName("tapblue");
  138. // x = x-0.6;; y = y+0.3 z=z+0.5
  139. xd.position = new BABYLON.Vector3(location.x - 0.6, location.y + 0.9, location.z + 0.5);
  140. var font_size = 36;
  141. var font = "bold " + font_size + "px Arial";
  142. dynamicTexture.drawText(transformNodex.wendu + "°C", null, null, font, "#FFFFFF", "#000000", true);
  143. dynamicTexture2.drawText(transformNodex.sidu + "%", null, null, font, "#FFFFFF", "#000000", true);
  144. if (transformNodex.canshow == true) {
  145. xd.setEnabled(true);
  146. }
  147. }
  148. }
  149. }
  150. )
  151. );
  152. mesheses[i].actionManager.registerAction(
  153. new BABYLON.ExecuteCodeAction({
  154. trigger: BABYLON.ActionManager.OnPointerOutTrigger,
  155. parameter: ""
  156. },
  157. function () {
  158. var mesheses2 = null;
  159. if (transformNodex.getClassName() == "TransformNode") {
  160. mesheses2 = transformNodex.getChildMeshes(false);
  161. } else {
  162. mesheses2 = [];
  163. mesheses2.push(transformNodex);
  164. }
  165. for (var i = 0; i < mesheses2.length; i++) {
  166. try {
  167. h2.removeMesh(mesheses2[i]);
  168. } catch (error) {
  169. // alert(error)
  170. }
  171. }
  172. if (transformNodex.name.indexOf("yangan") >= 0) {
  173. if (transformNodex.baojing == true) {
  174. var location = transformNodex.absolutePosition;
  175. var xd = scene.getMeshByName("tapred");
  176. // x = x-0.6;; y = y+0.3 z=z+0.5
  177. xd.setEnabled(false);
  178. } else {
  179. var location = transformNodex.absolutePosition;
  180. var xd = scene.getMeshByName("tapblue");
  181. // x = x-0.6;; y = y+0.3 z=z+0.5
  182. xd.setEnabled(false);
  183. }
  184. }
  185. }
  186. )
  187. );
  188. //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));
  189. } catch (error) {
  190. //alert(error)
  191. }
  192. }
  193. var clickbegin = false;
  194. mesheses[i].actionManager.registerAction(
  195. new BABYLON.ExecuteCodeAction({
  196. trigger: BABYLON.ActionManager.OnPickTrigger,
  197. parameter: ""
  198. },
  199. function () {
  200. cameraClick(transformNodex)
  201. }
  202. )
  203. );
  204. }
  205. }
  206. var camera05 = scene.getTransformNodeByName("Camera05");
  207. var camera06 = scene.getTransformNodeByName("Camera06");
  208. camera05.name = "camera05";
  209. camera06.name = "camera06";
  210. camera05.nameID = "ZLS_MO_CAM_001";
  211. camera06.nameID = "ZLS_MO_CAM_002";
  212. camera05.baojing = false;
  213. camera06.baojing = false;
  214. var yangan05 = scene.getTransformNodeByName("yangan_4");
  215. yangan05.name = "yangan05"
  216. yangan05.nameID = "ZLS_MO_OAO_001"
  217. yangan05.wendu = 0;
  218. yangan05.sidu = 0;
  219. prepareGroupButtonOther(yangan05, new BABYLON.Color3(0, 0, 1))
  220. prepareGroupButtonOther(camera06, new BABYLON.Color3(0, 0, 1))
  221. prepareGroupButtonOther(camera05, new BABYLON.Color3(0, 0, 1))
  222. var x = scene.getMeshByName("立方体_2_17_primitive0");
  223. x.overlayColor = BABYLON.Color3.White()
  224. x.renderOverlay = true;
  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. 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: 10, height: 10 }, scene);
  323. plane.position = new BABYLON.Vector3(0.270, 1.96, -0.28);
  324. plane.rotation = new BABYLON.Vector3(90 * Math.PI / 180, 0, 0);
  325. plane.scaling = new BABYLON.Vector3(0.6, 0.55, 1);
  326. var vxd4 = scene.getMeshByName("平面_3_2");
  327. vxd4.material = mat4;
  328. scene.getMeshByName("tapblue").setEnabled(false);
  329. scene.getMeshByName("tapred").setEnabled(false);
  330. var material2d = scene.getMaterialByName("材质.16");
  331. material2d.metallic = 0.52;
  332. material2d.roughness = 0;
  333. //material2.metallicReflectanceColor=new BABYLON.Color3(1,0,0);
  334. material2d.albedoColor = new BABYLON.Color3(0.8, 0.8, 0.8);
  335. scene.getMaterialByName("Desk.010").metallic = 0.80;
  336. scene.getMaterialByName("Desk.010").roughness = 0.72;
  337. scene.getMaterialByName("Desk.011").metallic = 0.80;
  338. scene.getMaterialByName("Desk.011").roughness = 0.72;
  339. scene.getMaterialByName("Desk.012").metallic = 0.80;
  340. scene.getMaterialByName("Desk.012").roughness = 0.72;
  341. scene.getMaterialByName("Desk.013").metallic = 0.80;
  342. scene.getMaterialByName("Desk.013").roughness = 0.72;
  343. scene.getMaterialByName("Desk.014").metallic = 0.80;
  344. scene.getMaterialByName("Desk.014").roughness = 0.72;
  345. scene.getMaterialByName("Desk.015").metallic = 0.80;
  346. scene.getMaterialByName("Desk.015").roughness = 0.72;
  347. scene.getMaterialByName("Desk.016").metallic = 0.80;
  348. scene.getMaterialByName("Desk.016").roughness = 0.72;
  349. scene.getMaterialByName("Desk.017").metallic = 0.80;
  350. scene.getMaterialByName("Desk.017").roughness = 0.72;
  351. scene.getMaterialByName("Desk.018").metallic = 0.80;
  352. scene.getMaterialByName("Desk.018").roughness = 0.72;
  353. scene.getMaterialByName("材质.29").metallic = 0.80;
  354. // 给vue页面传值,加载完成之后
  355. parent.getIframeLoading("false")
  356. }
  357. // createScene function that creates and return the scene
  358. var createScene = function () {
  359. engine.displayLoadingUI();
  360. // create a basic BJS Scene object
  361. var scene = new BABYLON.Scene(engine);
  362. //scene.debugLayer.show();
  363. var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 5, new BABYLON.Vector3(0, -1, 0), scene);
  364. camera.setTarget(new BABYLON.Vector3(0, 2.5, 0));
  365. camera.attachControl(canvas, true);
  366. camera.lowerRadiusLimit = 2.0; // 这里是最大的位置,值越大,物体越小
  367. camera.upperRadiusLimit = 40;
  368. camera.radius = 8.888;
  369. camera.alpha = Math.PI * -240.2 / 180;
  370. camera.beta = Math.PI * 66 / 180;;
  371. camera.inertia = 0.1; // 缩放的快慢
  372. camera.useAutoRotationBehavior = true; // 自动旋转
  373. camera.panningDistanceLimit = 2; //平移半径
  374. camera.panningInertia = 0;
  375. camera.autoTransitionRange = 1;
  376. camera.pinchToPanMaxDistance = 0.1;
  377. camera.pinchDeltaPercentage = 0.001;
  378. camera.useAutoRotationBehavior = false;
  379. scene.activeCamera = camera;
  380. // 改变场景背景颜色 - 背景颜色opacity值设为0,达到透明背景的效果
  381. scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
  382. scene.activeCamera.useInputToRestoreState = true;
  383. var camera1_status = scene.activeCamera.storeState();
  384. var light = new BABYLON.HemisphericLight("HemiLight", new BABYLON.Vector3(0, 1, 0), scene);
  385. light.intensity = 2;
  386. light.diffuse = new BABYLON.Color3(0.92, 0.92, 0.92);
  387. var assetsManager = new BABYLON.AssetsManager(scene);
  388. var meshTask = assetsManager.addMeshTask("skull task", "", "asset/", "B4.glb");
  389. meshTask.onSuccess = function (task) {
  390. task.loadedMeshes[0].scaling = new BABYLON.Vector3(0.2, 0.2, -0.2);
  391. task.loadedMeshes[0].position = new BABYLON.Vector3(0.000, 2, 0);
  392. }
  393. meshTask.onError = function (task, message, exception) {
  394. console.log(message, exception);
  395. }
  396. var meshTask_tapblue = assetsManager.addMeshTask("skull task", "", "asset/", "tapBlue.glb");
  397. meshTask_tapblue.onSuccess = function (task) {
  398. task.loadedMeshes[0].scaling = new BABYLON.Vector3(0.2, 0.2, -0.2);
  399. task.loadedMeshes[0].position = new BABYLON.Vector3(0, 0, 0);
  400. //-2.5,3.77,1.45
  401. // x = x-0.6;; y = y+0.3 z=z+0.5
  402. task.loadedMeshes[0].rotation = new BABYLON.Vector3(0, 0, 0);
  403. task.loadedMeshes[0].name = "tapblue";
  404. var vx = scene.getTransformNodeByName("蓝");
  405. vx.position = new BABYLON.Vector3(0, 0, 0);
  406. vx.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);
  407. vx.scaling = new BABYLON.Vector3(0.015, 0.015, 0.015);
  408. }
  409. meshTask_tapblue.onError = function (task, message, exception) {
  410. console.log(message, exception);
  411. }
  412. var meshTask_tapred = assetsManager.addMeshTask("skull task", "", "asset/", "tapRed.glb");
  413. meshTask_tapred.onSuccess = function (task) {
  414. task.loadedMeshes[0].scaling = new BABYLON.Vector3(0.2, 0.2, -0.2);
  415. task.loadedMeshes[0].position = new BABYLON.Vector3(-1.929, 4.029, 0.968);
  416. //-2.5,3.77,1.45
  417. // x = x-0.6;; y = y+0.3 z=z+0.5
  418. task.loadedMeshes[0].rotation = new BABYLON.Vector3(0, 0, 0);
  419. task.loadedMeshes[0].name = "tapred";
  420. var vx = scene.getTransformNodeByName("红");
  421. vx.position = new BABYLON.Vector3(0, 0, 0);
  422. vx.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);
  423. vx.scaling = new BABYLON.Vector3(0.015, 0.015, 0.015);
  424. }
  425. meshTask_tapred.onError = function (task, message, exception) {
  426. console.log(message, exception);
  427. }
  428. var hdrTexture = new BABYLON.CubeTexture.CreateFromPrefilteredData("textures/environmentSpecular.env", scene);
  429. //var hdrTexture = new BABYLON.CubeTexture.CreateFromPrefilteredData("textures/environment.env", scene);
  430. scene.environmentTexture = hdrTexture;
  431. // renderCanvas.style.backgroundImage = 'url("./textures/' + '4' + '.jpg")';
  432. assetsManager.load();
  433. drag = new BABYLON.PointerDragBehavior({
  434. dragPlaneNormal: new BABYLON.Vector3(0, 0, 1)
  435. });
  436. //drag.useObjectOrienationForDragging = false;
  437. drag.validateDrag = (targetPosition) => {
  438. console.log(targetPosition)
  439. if (targetPosition.x > 10.5 || targetPosition.x < -10.5) {
  440. return false;
  441. }
  442. if (targetPosition.z > 10.5 || targetPosition.z < -10.5) {
  443. return false;
  444. }
  445. if (oldtransformNodex != null) {
  446. return true;
  447. }
  448. }
  449. drag.onDragEndObservable.add((event) => {
  450. console.log("dragEnd");
  451. //console.log(event);
  452. //console.log(line03_position)
  453. })
  454. //GUI
  455. h1 = new BABYLON.HighlightLayer("hl1", scene);
  456. h2 = new BABYLON.HighlightLayer("hl2", scene);
  457. h3 = new BABYLON.HighlightLayer("hl3", scene);
  458. var step = 0.1;
  459. var currentx = 1;
  460. var step2 = 0.1;
  461. var currentx2 = 0.1;
  462. h1.blurHorizontalSize = 0.1;
  463. var showx = 0;
  464. var showx2 = 2;
  465. scene.registerAfterRender(() => {
  466. h1.blurHorizontalSize = h1.blurVerticalSize + currentx;
  467. h2.blurHorizontalSize = h2.blurVerticalSize + currentx2;
  468. h3.blurHorizontalSize = h3.blurVerticalSize + currentx2;
  469. var nodealert = scene.getTransformNodeByName("yangan05");
  470. if (nodealert != null) {
  471. var mesheses3 = null;
  472. if (nodealert.getClassName() == "TransformNode") {
  473. mesheses3 = nodealert.getChildMeshes(false);
  474. } else {
  475. mesheses3 = [];
  476. mesheses3.push(nodealert);
  477. }
  478. for (var i = 0; i < mesheses3.length; i++) {
  479. try {
  480. if (nodealert.baojing == true) {
  481. h3.addMesh(mesheses3[i], new BABYLON.Color3(1, 0, 0));
  482. } else {
  483. h3.removeMesh(mesheses3[i]);
  484. }
  485. } catch (error) {
  486. // alert(error)
  487. }
  488. }
  489. }
  490. var nodealert = scene.getTransformNodeByName("camera05");
  491. if (nodealert != null) {
  492. var mesheses3 = null;
  493. if (nodealert.getClassName() == "TransformNode") {
  494. mesheses3 = nodealert.getChildMeshes(false);
  495. } else {
  496. mesheses3 = [];
  497. mesheses3.push(nodealert);
  498. }
  499. for (var i = 0; i < mesheses3.length; i++) {
  500. try {
  501. if (nodealert.baojing == true) {
  502. h3.addMesh(mesheses3[i], new BABYLON.Color3(1, 0, 0));
  503. } else {
  504. h3.removeMesh(mesheses3[i]);
  505. }
  506. } catch (error) {
  507. // alert(error)
  508. }
  509. }
  510. }
  511. var nodealert = scene.getTransformNodeByName("camera06");
  512. if (nodealert != null) {
  513. var mesheses3 = null;
  514. if (nodealert.getClassName() == "TransformNode") {
  515. mesheses3 = nodealert.getChildMeshes(false);
  516. } else {
  517. mesheses3 = [];
  518. mesheses3.push(nodealert);
  519. }
  520. for (var i = 0; i < mesheses3.length; i++) {
  521. try {
  522. if (nodealert.baojing == true) {
  523. h3.addMesh(mesheses3[i], new BABYLON.Color3(1, 0, 0));
  524. } else {
  525. h3.removeMesh(mesheses3[i]);
  526. }
  527. } catch (error) {
  528. // alert(error)
  529. }
  530. }
  531. }
  532. var a = scene.getMaterialByName("carpaint_baseRed");
  533. if (a != null) {
  534. if (a.albedoColor == b) {
  535. b = new BABYLON.Color3(0, 1, 0);
  536. a.albedoColor = b;
  537. }
  538. }
  539. var v2 = scene.getMeshByName("tapblue");
  540. if (v2 != null) {
  541. v2.lookAt(camera.globalPosition, 0, 0, Math.PI);
  542. }
  543. var v3 = scene.getMeshByName("tapred");
  544. if (v3 != null) {
  545. v3.lookAt(camera.globalPosition, 0, 0, Math.PI);
  546. }
  547. if (currentx > 0.5) {
  548. step *= -1;
  549. }
  550. if (currentx < 0) {
  551. step *= -1;
  552. }
  553. currentx += step;
  554. if (currentx2 > 5) {
  555. step2 *= -1;
  556. }
  557. if (currentx2 < 0) {
  558. step2 *= -1;
  559. }
  560. currentx2 += step2;
  561. if (dynamicTexture != null && PointerOverYangan != null) {
  562. var textx = scene.getTransformNodeByName(PointerOverYangan).wendu
  563. var font_size = 36;
  564. var font = "bold " + font_size + "px Arial";
  565. dynamicTexture.drawText(textx + "°C", null, null, font, "#FFFFFF", "#000000", true);
  566. showx++;
  567. show = 50;
  568. }
  569. if (dynamicTexture2 != null && PointerOverYangan != null) {
  570. var textx = scene.getTransformNodeByName(PointerOverYangan).sidu;
  571. var font_size = 36;
  572. var font = "bold " + font_size + "px Arial";
  573. dynamicTexture2.drawText(textx + "%", null, null, font, "#FFFFFF", "#000000", true);
  574. }
  575. if (dynamicTexture3 != null && PointerOverYangan != null) {
  576. var textx = scene.getTransformNodeByName(PointerOverYangan).wendu
  577. var font_size = 36;
  578. var font = "bold " + font_size + "px Arial";
  579. dynamicTexture3.drawText(textx + "°C", null, null, font, "#FFFFFF", "#000000", true);
  580. }
  581. if (dynamicTexture4 != null && PointerOverYangan != null) {
  582. var textx = scene.getTransformNodeByName(PointerOverYangan).sidu;
  583. var font_size = 36;
  584. var font = "bold " + font_size + "px Arial";
  585. dynamicTexture4.drawText(textx + "%", null, null, font, "#FFFFFF", "#000000", true);
  586. }
  587. /*show--;
  588. showdd--;*/
  589. });
  590. return scene;
  591. }
  592. var canvas = document.getElementById('renderCanvas');
  593. // load the 3D engine
  594. var engine = new BABYLON.Engine(canvas, true, {
  595. stencil: true
  596. });
  597. // call the createScene function
  598. var scene = createScene();
  599. scene.autoClear = true;
  600. scene.imageProcessingConfiguration.exposure = 1;
  601. scene.imageProcessingConfiguration.contrast = 1;
  602. scene.environmentIntensity = 0.4;
  603. engine.runRenderLoop(function () {
  604. scene.render();
  605. });
  606. window.addEventListener('resize', function () {
  607. engine.resize();
  608. });
  609. function HashMap () {
  610. //定义长度
  611. var length = 0;
  612. //创建一个对象
  613. var obj = new Object();
  614. //判断Map是否为空
  615. this.isEmpty = function () {
  616. return length == 0;
  617. }
  618. //判断对象中是否包含给定Key
  619. this.containsKey = function (key) {
  620. return (key in obj);
  621. }
  622. //判断对象中是否包含给定的Value
  623. this.containsValue = function (value) {
  624. for (var key in obj) {
  625. if (obj[key] == value) {
  626. return true;
  627. }
  628. }
  629. return false;
  630. }
  631. //向map中添加数据
  632. this.put = function (key, value) {
  633. if (!this.containsKey(key)) {
  634. length++;
  635. }
  636. obj[key] = value;
  637. }
  638. //根据给定的key获取Value
  639. this.get = function (key) {
  640. return this.containsKey(key) ? obj[key] : null;
  641. }
  642. //根据给定的Key删除一个值
  643. this.remove = function (key) {
  644. if (this.containsKey(key) && (delete obj[key])) {
  645. length--;
  646. }
  647. }
  648. //获得Map中所有的value
  649. this.values = function () {
  650. var _values = new Array();
  651. for (var key in obj) {
  652. _values.push(obj[key]);
  653. }
  654. return _values;
  655. }
  656. //获得Map中的所有key
  657. this.keySet = function () {
  658. var _keys = new Array();
  659. for (var key in obj) {
  660. _keys.push(key);
  661. }
  662. return _keys;
  663. }
  664. //获得Map的长度
  665. this.size = function () {
  666. return length;
  667. }
  668. //清空Map
  669. this.clear = function () {
  670. length = 0;
  671. obj = new Object();
  672. }
  673. }
  674. var yangans = new HashMap();
  675. yangans.put('ZLS_MO_OAO_001', 'yangan05');
  676. yangans.put('ZLS_MO_CAM_001', 'camera05');
  677. yangans.put('ZLS_MO_CAM_002', 'camera06');
  678. //功能转入报警
  679. function Myalert (MathineID, baojing) {
  680. scene.getMeshByName("tapblue").setEnabled(false);
  681. scene.getMeshByName("tapred").setEnabled(false);
  682. var theName = yangans.get(MathineID);
  683. if (theName == "yangan05") {
  684. scene.getTransformNodeByName("yangan05").baojing = baojing;
  685. }
  686. if (theName == "camera05") {
  687. scene.getTransformNodeByName("camera05").baojing = baojing;
  688. }
  689. if (theName == "camera06") {
  690. scene.getTransformNodeByName("camera06").baojing = baojing;
  691. }
  692. }
  693. //报警 true:表示报警, false :表示不报警
  694. // Myalert("DAK_MO_OAO_001",true)
  695. //设置温湿度
  696. function setAlertValue (MathineID, wendu, sidu) {
  697. var theName = yangans.get(MathineID);
  698. if (theName == "yangan05") {
  699. scene.getTransformNodeByName("yangan05").wendu = wendu;
  700. scene.getTransformNodeByName("yangan05").sidu = sidu;
  701. }
  702. }
  703. //设置温湿度: setAlertValue("DAK_MO_OAO_001",4,5)
  704. // 设置是否显示
  705. function setYangGanCanshow (MathineID, canshow) {
  706. var theName = yangans.get(MathineID);
  707. if (theName == "yangan05") {
  708. scene.getTransformNodeByName("yangan05").canshow = canshow;
  709. }
  710. }
  711. // setYangGanCanshow("DAK_MO_OAO_001",false)
  712. // function cameraClick(TheCamera) {
  713. // alert(TheCamera.nameID);
  714. // }
  715. function cameraClick (TheCamera) {
  716. window.parent.postMessage(
  717. {
  718. data: TheCamera.nameID
  719. },
  720. "*"
  721. );
  722. }
  723. // 监测父页面传来得初始化得温度湿度值
  724. window.addEventListener(
  725. "message",
  726. function (e) {
  727. deviceData = e.data.data;
  728. },
  729. false
  730. );