阅行客电子档案
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.

1006 lines
31 KiB

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