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

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