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

777 lines
35 KiB

3 years ago
  1. function IsPC() {
  2. var userAgentInfo = navigator.userAgent;
  3. var Agents = ["Android", "iPhone",
  4. "SymbianOS", "Windows Phone",
  5. "iPad", "iPod"];
  6. var flag = true;
  7. for (var v = 0; v < Agents.length; v++) {
  8. if (userAgentInfo.indexOf(Agents[v]) > 0) {
  9. flag = false;
  10. break;
  11. }
  12. }
  13. return flag;
  14. }
  15. if(IsPC()==true){
  16. // if(false){
  17. // alert("我是PC");
  18. }else{
  19. // alert("我是手机");
  20. let mains=document.getElementsByClassName("mains")[0];
  21. let contint=document.getElementsByClassName("contint")[0];
  22. mains.setAttribute("class","main2")
  23. contint.setAttribute("class","contint2")
  24. // renderCanvas.setAttribute("class","renderCanvas2")
  25. document.getElementById("renderCanvas").style.width="980px";
  26. document.getElementById("renderCanvas").style.height="960px";
  27. // console.log(document.getElementById("renderCanvas").style.with);
  28. //console.log(document.getElementsByClassName("mains").style.flexDirection);
  29. document.getElementsByClassName("title")[0].style.display = "none";
  30. }
  31. // const width = document.documentElement.clientWidth;
  32. // const height = document.documentElement.clientHeight;
  33. // if (width < height) {
  34. // console.log(width + " " + height);
  35. // const contentDOM = document.getElementById('divTransform');
  36. // contentDOM.style.width = height + 'px';
  37. // contentDOM.style.height = width + 'px';
  38. // contentDOM.style.top = (height - width) / 2 + 'px';
  39. // contentDOM.style.left = 0 - (height - width) / 2 + 'px';
  40. // //contentDOM.style.transform = 'rotate(90deg)';
  41. // }
  42. // const evt = "onorientationchange" in window ? "orientationchange" : "resize";
  43. // window.addEventListener(evt, function () {
  44. // const width = document.documentElement.clientWidth;
  45. // const height = document.documentElement.clientHeight;
  46. // const contentDOM = document.getElementById('content');
  47. // //alert('width: ' + width + ' height: ' + height)
  48. // if (width > height) { // 横屏
  49. // contentDOM.style.width = width + 'px';
  50. // contentDOM.style.height = height + 'px';
  51. // contentDOM.style.top = '0px';
  52. // contentDOM.style.left = '0px';
  53. // contentDOM.style.transform = 'none';
  54. // }
  55. // else { // 竖屏,这里微信应该由bug,我切换为竖屏的时候,width:375, height: 323, 导致不能旋转角度。 在safari、chrome上是正确的。
  56. // alert('change to portrait')
  57. // contentDOM.style.width = height + 'px';
  58. // contentDOM.style.height = width + 'px';
  59. // contentDOM.style.top = (height - width) / 2 + 'px';
  60. // contentDOM.style.left = 0 - (height - width) / 2 + 'px';
  61. // //contentDOM.style.transform = 'rotate(90deg)';
  62. // }
  63. // }, false);
  64. window.addEventListener('DOMContentLoaded', function(){
  65. BABYLON.DefaultLoadingScreen.prototype.displayLoadingUI = function () {
  66. if (document.getElementById("customLoadingScreenDiv")) {
  67. // Do not add a loading screen if there is already one
  68. document.getElementById("customLoadingScreenDiv").style.display = "initial";
  69. return;
  70. }
  71. this._loadingDiv = document.createElement("div");
  72. this._loadingDiv.id = "customLoadingScreenDiv";
  73. //this._loadingDiv.innerHTML = "模型正在加载....";
  74. this._loadingDiv.innerHTML = "<image src='./loading.gif' />";
  75. var customLoadingScreenCss = document.createElement('style');
  76. customLoadingScreenCss.type = 'text/css';
  77. customLoadingScreenCss.innerHTML = `
  78. #customLoadingScreenDiv{
  79. background-color: #3D4456cc;
  80. color: white;
  81. font-size:50px;
  82. text-align:center;
  83. }
  84. `;
  85. document.getElementsByTagName('head')[0].appendChild(customLoadingScreenCss);
  86. this._resizeLoadingUI();
  87. window.addEventListener("resize", this._resizeLoadingUI);
  88. document.body.appendChild(this._loadingDiv);
  89. };
  90. BABYLON.DefaultLoadingScreen.prototype.hideLoadingUI = function(){
  91. document.getElementById("customLoadingScreenDiv").style.display = "none";
  92. console.log("scene is now loaded");
  93. }
  94. function sleep(beginTime,endTime) {
  95. var exitTime = beginTime + 3000;
  96. while (true) {
  97. now = new Date();
  98. if (now.getTime() > exitTime)
  99. return;
  100. }
  101. }
  102. // get the canvas DOM element
  103. var canvas = document.getElementById('renderCanvas');
  104. var d = new Date();
  105. var n_Begin= d.getTime();
  106. console.log("n_Begin:"+n_Begin);
  107. // load the 3D engine
  108. var engine = new BABYLON.Engine(canvas, true);
  109. // createScene function that creates and return the scene
  110. var createScene = function(){
  111. engine.displayLoadingUI();
  112. // create a basic BJS Scene object
  113. var scene = new BABYLON.Scene(engine);
  114. //scene.debugLayer.show();
  115. var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 5, new BABYLON.Vector3(0, 0, 0), scene);
  116. console.log(camera);
  117. // camera.transforms.alpha = 85;
  118. //camea.transforms.beta=95;
  119. // target the camera to scene origin
  120. camera.setTarget(BABYLON.Vector3.Zero());
  121. //camera.setPosition(new BABYLON.Vector3(20, 200, 400));
  122. // attach the camera to the canvas
  123. camera.attachControl(canvas, true);
  124. camera.lowerRadiusLimit = 2.5 ;// 这里是最大的位置,值越大,物体越小
  125. camera.upperRadiusLimit = 20 ;
  126. camera.Radius = 2.5;
  127. camera.alpha = 1.5;
  128. camera.beta = 1;
  129. camera.inertia=0.1; // 缩放的快慢
  130. //scene.VRHelper = scene.createDefaultVRExperience({createDeviceOrientationCamera: false});
  131. //var VRHelper = scene.createDefaultVRExperience();
  132. //console.log(VRHelper);
  133. //VRHelper.onExitingVR.add(()=>{
  134. // scene.setActiveCameraByName("Camera");
  135. // console.log("abc");
  136. //console.log(scene);
  137. //})
  138. //scene.setActiveCameraByName("Camera");
  139. //console.log(VRHelper);
  140. // create a basic light, aiming 0,1,0 - meaning, to the sky
  141. var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0,1,0), scene);
  142. // Skybox
  143. var skybox = BABYLON.MeshBuilder.CreateBox("skyBox", {size:1000.0}, scene);
  144. var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
  145. skyboxMaterial.backFaceCulling = false;
  146. skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("textures/skybox", scene);
  147. skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  148. skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
  149. skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  150. skybox.material = skyboxMaterial;
  151. var myColor = BABYLON.Color3.Blue();
  152. var line03_position = BABYLON.Vector3(0,0,0);
  153. var line01_position = BABYLON.Vector3(0,0,0);
  154. var line17_position = BABYLON.Vector3(0,0,0);
  155. var line26_position = BABYLON.Vector3(0,0,0);
  156. console.log("position:"+line03_position);
  157. // Initialize GizmoManager
  158. var gizmoManager = new BABYLON.GizmoManager(scene)
  159. BABYLON.SceneLoader.Append("./asset/", "abc2.gltf", scene, function (scene) {
  160. //坐场
  161. line03 = scene.getMeshByName("Line03");
  162. line03_position = line03.position;
  163. Line03Mat = new BABYLON.StandardMaterial("ground", scene);
  164. Line03Mat.diffuseColor = new BABYLON.Color3(0.4, 0.4,0.4);
  165. Line03Mat.specularColor = new BABYLON.Color3(0.4, 0.4, 0.4);
  166. Line03Mat.emissiveColor = BABYLON.Color3.Blue();
  167. line03.material = Line03Mat;
  168. //左护版
  169. line01 = scene.getMeshByName("Line01");
  170. line01_position = line01.position;
  171. Line01Mat = new BABYLON.StandardMaterial("ground", scene);
  172. Line01Mat.diffuseColor = new BABYLON.Color3(0.4, 0.4, 0.4);
  173. Line01Mat.specularColor = new BABYLON.Color3(0.4, 0.4, 0.4);
  174. Line01Mat.emissiveColor = BABYLON.Color3.Blue();
  175. line01.material = Line01Mat;
  176. //左护版
  177. //line05 = scene.getMeshByName("Line05");
  178. //Line05Mat = new BABYLON.StandardMaterial("ground", scene);
  179. //Line05Mat.diffuseColor = new BABYLON.Color3(0.4, 0.4, 0.4);
  180. //Line05Mat.specularColor = new BABYLON.Color3(0.4, 0.4, 0.4);
  181. //Line05Mat.emissiveColor = BABYLON.Color3.Blue();
  182. //line05.material = Line05Mat;
  183. //右腿
  184. line17 = scene.getMeshByName("Line17");
  185. line17_position = line17.position;
  186. Line17Mat = new BABYLON.StandardMaterial("ground", scene);
  187. Line17Mat.diffuseColor = new BABYLON.Color3(0.4, 0.4, 0.4);
  188. Line17Mat.specularColor = new BABYLON.Color3(0.4, 0.4, 0.4);
  189. Line17Mat.emissiveColor = BABYLON.Color3.Blue();
  190. line17.material = Line17Mat;
  191. //line17.position.x =1;
  192. //右腿
  193. line26 = scene.getMeshByName("Cylinder56");
  194. line26_position = line26.position;
  195. Line26Mat = new BABYLON.StandardMaterial("ground", scene);
  196. Line26Mat.diffuseColor = new BABYLON.Color3(0.4, 0.4, 0.4);
  197. Line26Mat.specularColor = new BABYLON.Color3(0.4, 0.4, 0.4);
  198. Line26Mat.emissiveColor = BABYLON.Color3.Blue();
  199. line26.material = Line26Mat;
  200. //枪
  201. tube15 = scene.getMeshByName("Tube15");
  202. tube15_position = tube15.position;
  203. Tube15Mat = new BABYLON.StandardMaterial("ground", scene);
  204. Tube15Mat.diffuseColor = new BABYLON.Color3(0.4, 0.4, 0.4);
  205. Tube15Mat.specularColor = new BABYLON.Color3(0.4, 0.4, 0.4);
  206. Tube15Mat.emissiveColor = BABYLON.Color3.Blue();
  207. tube15.material = Tube15Mat;
  208. root = scene.getMeshByName("__root__");
  209. //console.log("abccc");
  210. //console.log(scene);
  211. //root.addRotation(0.01, 0, 0);
  212. //gizmoManager.boundingBoxGizmoEnabled=true
  213. // Restrict gizmos to only spheres
  214. gizmoManager.attachableMeshes =[line03,line01,tube15,line26,line17];
  215. // Toggle gizmos with keyboard buttons
  216. document.onkeydown = (e)=>{
  217. if(e.key == 'w'){
  218. gizmoManager.positionGizmoEnabled = !gizmoManager.positionGizmoEnabled
  219. }
  220. if(e.key == 'e'){
  221. gizmoManager.rotationGizmoEnabled = !gizmoManager.rotationGizmoEnabled
  222. }
  223. if(e.key == 'r'){
  224. gizmoManager.scaleGizmoEnabled = !gizmoManager.scaleGizmoEnabled
  225. }
  226. if(e.key == 'q'){
  227. gizmoManager.boundingBoxGizmoEnabled = !gizmoManager.boundingBoxGizmoEnabled
  228. }
  229. }
  230. var oldMeth = null;
  231. // On pick interpolations
  232. var prepareButton = function (mesh, color,strss) {
  233. //var goToColorAction = new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, light, "diffuse", color, 1000, null, true);
  234. mesh.actionManager = new BABYLON.ActionManager(scene);
  235. // mesh.actionManager.registerAction(new BABYLON.SetValueAction(BABYLON.ActionManager.OnPointerOutTrigger, mesh.material, "emissiveColor", mesh.material.emissiveColor));
  236. mesh.actionManager.registerAction(new BABYLON.SetValueAction(BABYLON.ActionManager.OnPickTrigger, mesh.material, "emissiveColor", BABYLON.Color3.Red()));
  237. // mesh.actionManager.registerAction(new BABYLON.SetValueAction(BABYLON.ActionManager.OnPickTrigger, mesh.material, "emissiveColor", BABYLON.Color3.Yellow()));
  238. mesh.actionManager.registerAction(new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPointerOutTrigger, mesh, "scaling", new BABYLON.Vector3(0.38, 0.38, 0.38), 100));
  239. mesh.actionManager.registerAction(new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPointerOverTrigger, mesh, "scaling", new BABYLON.Vector3(0.4, 0.4, 0.4), 100));
  240. //mesh.actionManager.registerAction(new BABYLON.SetValueAction(BABYLON.ActionManager.OnPickTrigger, mesh.material, "wireframe", true))
  241. mesh.actionManager.registerAction(
  242. new BABYLON.ExecuteCodeAction(
  243. {
  244. trigger:BABYLON.ActionManager.OnPickTrigger,
  245. parameter:""
  246. },
  247. function(){
  248. document.getElementById("show").innerHTML=strss;
  249. console.log(oldMeth);
  250. console.log(mesh);
  251. if(oldMeth != null && oldMeth.id != mesh.id){
  252. oldMeth.material.emissiveColor= myColor;
  253. }
  254. oldMeth = mesh;
  255. // mesh.material.emissiveColor= BABYLON.Color3.Red()
  256. //mesh.material.emissiveColor = myColor;
  257. //console.log(mesh.material.emissiveColor);
  258. //mesh.material = BABYLON.Color3.Yellow()
  259. //a.innerHTML ="这里是坐长的位置,可以坐人的."
  260. }
  261. )
  262. );
  263. }
  264. var prepareButton2 = function (mesh, color,strss) {
  265. //var goToColorAction = new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, light, "diffuse", color, 1000, null, true);
  266. mesh.actionManager = new BABYLON.ActionManager(scene);
  267. mesh.actionManager.registerAction(new BABYLON.SetValueAction(BABYLON.ActionManager.OnPointerOutTrigger, mesh.material, "emissiveColor", mesh.material.emissiveColor));
  268. mesh.actionManager.registerAction(new BABYLON.SetValueAction(BABYLON.ActionManager.OnPointerOverTrigger, mesh.material, "emissiveColor", BABYLON.Color3.Red()));
  269. mesh.actionManager.registerAction(new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPointerOutTrigger, mesh, "scaling", new BABYLON.Vector3(1,1, 1), 100));
  270. mesh.actionManager.registerAction(new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPointerOverTrigger, mesh, "scaling", new BABYLON.Vector3(1, 1, 1), 100));
  271. mesh.actionManager.registerAction(
  272. new BABYLON.ExecuteCodeAction(
  273. {
  274. trigger:BABYLON.ActionManager.OnPickTrigger,
  275. parameter:""
  276. },
  277. function(){
  278. document.getElementById("show").innerHTML=strss;
  279. //a.innerHTML ="这里是坐长的位置,可以坐人的."
  280. }
  281. )
  282. );
  283. }
  284. prepareButton(line03, BABYLON.Color3.Blue(),`<font size="20">坐舱:</font></br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;又叫驾驶舱(Cockpit)是操作员控制机器人的座舱,通常位于前端。除了早期的,如今大部分机器人的驾驶舱采用密闭式的设计。机器人驾驶舱内一般安装有各类控制系统。 驾驶舱是机器人的首脑元件,为太空船里下令及控制的中心。它是设计用来尽量让驾驶员感到操控舒适,并包含所有先进导航及各项操控的系统,就如同其他提供居住人员所有必需品的组件是一样重要的。</h2>`);
  285. prepareButton(line01, BABYLON.Color3.Blue(),`<font size="20">铠甲:</font><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;机械外骨骼或称动力外骨骼(Powered exoskeleton),是一种由钢铁的框架构成并且可让人穿上的机器装置,这个装备可以提供额外能量来供四肢运动。别称:强化服、动力服(Power Suit)、动力装甲(Power armor或Powered armor)、Exoframe、Hardsuit或Exosuit等。凭借这套“服装”,人类就可以成为所谓的“铁人”。
  286. <br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;动力外骨骼更倾向于军用除了能够增强人体能力的这一基本功能外还要具有良好的防护性对复杂环境的适应性以及辅助火力通信侦查支持等军用功能
  287. <br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;动力服是设计成用来保护穿戴者的例如为了保护士兵或建筑工而设计或设计用来进行救援身处险境的人员上广泛一些的用途则是用来做为义肢与帮助老弱者行动其它的用途则是用来进行救援行动就像在一栋要倒塌的建筑物里这个装置可以提供给工人很大的力量来举起重物同时保护它不被落下的碎石砸伤在日本有银行为需常搬运沉重钞票及硬币的员工配备外骨骼以降低身体负担`);
  288. //prepareButton(line05, BABYLON.Color3.Blue(),"右护版");
  289. prepareButton(line17, BABYLON.Color3.Blue(),`<font size="20">左脚:</font>
  290. <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用激光器作为辐射源的雷达激光雷达是激光技术与雷达技术相结合的产物 由发射机 天线 接收机 跟踪架及信息处理等部分组成发射机是各种形式的激光器如二氧化碳激光器掺钕钇铝石榴石激光器半导体激光器及波长可调谐的固体激光器等天线是光学望远镜接收机采用各种形式的光电探测器如光电倍增管半导体光电二极管雪崩光电二极管红外和可见光多元探测器件等激光雷达采用脉冲或连续波2种工作方式探测方法分直接探测与外差探测
  291. <br><img src='./img/2.jpg' height='400'>`);
  292. prepareButton(line26, BABYLON.Color3.Blue(),`<font size="20">机器关节:</font><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;机器人关节驱动器是一种集电液伺服阀及摆动缸于一体的液压或气动装置。关节机器人常见的有协作机器人(六轴、七轴)、外骨骼机器人、四足、双足、手术机器人等,里面用的东西基本都包含力矩电机、编码器、减速器、驱动器等,有的可能会用到抱闸、力矩传感器。但是每个应用匹配的方案不一样,用的产品也是多种多样。<br/><img src='./img/4.jpg'>`);
  293. prepareButton(tube15, BABYLON.Color3.Blue(),`<p class='p13'><font size="20">机枪:</font><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;机枪(Machine gun) 一种带有枪架或枪座,能实现连发射击的自动枪械。世界第一挺机枪是个叫伐商的比利时工程师(曾是拿破伦手下的上尉)于1851年设计的。该枪曾在1870、1871年的普法战争中用过。而普遍观点认为,现代机枪的鼻祖是加特林多管式机枪。1862年,由美国人理查德·杰丹·加特林发明,这种枪有几个枪筒,可以轮转。1883年,美国人海尔曼·S·马克沁进行革新,机枪变为单枪筒,利用后坐力,使上膛、射击和退弹能同时完成,枪身用枪筒上的水套降温,每分钟可射击650次,名为马克沁机枪.<br/></p><video src='a.mp4' controls='controls'></video> `);
  294. var d1 = new Date();
  295. var n_end= d1.getTime();
  296. console.log("n_end:"+n_end);
  297. console.log(n_end - n_Begin);
  298. sleep(n_Begin,n_end);
  299. engine.hideLoadingUI();
  300. });
  301. //GUI
  302. // Another GUI on the right
  303. var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
  304. advancedTexture.layer.layerMask = 2;
  305. var panel3 = new BABYLON.GUI.StackPanel();
  306. panel3.width = "800px";
  307. panel3.fontSize = "30px";
  308. panel3.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;
  309. panel3.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  310. advancedTexture.addControl(panel3);
  311. var button1 = BABYLON.GUI.Button.CreateSimpleButton("but1", "旋 转");
  312. button1.width = 0.2;
  313. button1.height = "80px";
  314. button1.color = "white";
  315. button1.cornerRadius = 20;
  316. button1.background = "green";
  317. button1.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;
  318. //button1.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  319. //button1.centerY=5;
  320. //console.log(button1);
  321. //button1.position.x = 300;
  322. //button1.position.y = 5;
  323. var aaab = false;
  324. button1.onPointerUpObservable.add(function() {
  325. // circle.scaleX += 0.1;
  326. if(aaab== false){
  327. scene.registerBeforeRender(function(){
  328. root.addRotation(0.00, 0.008, 0);
  329. button1.textBlock.text = "停 止";
  330. aaab = true;
  331. button1.background = "red";
  332. });
  333. }else{
  334. scene.registerBeforeRender(function(){
  335. root.addRotation(0.00, -0.008, 0);
  336. button1.textBlock.text = "旋 转";
  337. aaab = false;
  338. button1.background = "green";
  339. });
  340. }
  341. });
  342. var button3 = BABYLON.GUI.Button.CreateSimpleButton("but2", "展 开");
  343. button3.width = 0.2;
  344. button3.height = "80px";
  345. button3.color = "white";
  346. button3.cornerRadius = 20;
  347. button3.background = "green";
  348. var bob = false;
  349. button3.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;
  350. button3.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  351. button3.onPointerUpObservable.add(function() {
  352. // circle.scaleX += 0.1;
  353. //gizmoManager.positionGizmoEnabled = !gizmoManager.positionGizmoEnabled
  354. if(bob== false){
  355. bob = true;
  356. button3.textBlock.text = "合 体";
  357. button3.background = "red";
  358. var animationBox = new BABYLON.Animation("tutoAnimation", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
  359. BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  360. // Animation keys
  361. var keys = [];
  362. keys.push({
  363. frame: 0,
  364. value: line03_position
  365. });
  366. keys.push({
  367. frame: 20,
  368. value: new BABYLON.Vector3(line03_position.x+60,line03_position.y,line03_position.z)
  369. });
  370. animationBox.setKeys(keys);
  371. line03.animations.push(animationBox); //中间坐舱
  372. //scene.beginAnimation(line03, 0, 100, false);
  373. //左护版
  374. var animationBox2 = new BABYLON.Animation("Animation2", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
  375. BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  376. // Animation keys
  377. var keys1 = [];
  378. keys1.push({
  379. frame: 0,
  380. value: line01_position
  381. });
  382. keys1.push({
  383. frame: 20,
  384. value: new BABYLON.Vector3(line01_position.x-40,line01_position.y,line01_position.z)
  385. });
  386. animationBox2.setKeys(keys1);
  387. line01.animations.push(animationBox2); //中间坐舱
  388. //scene.beginAnimation(line01, 0, 100, true);
  389. //左脚
  390. var animationBox3 = new BABYLON.Animation("animationBox3", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
  391. BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  392. // Animation keys
  393. var keys2 = [];
  394. keys2.push({
  395. frame: 0,
  396. value: line17_position
  397. });
  398. keys2.push({
  399. frame: 20,
  400. value: new BABYLON.Vector3(line17_position.x-50,line17_position.y,line17_position.z)
  401. });
  402. animationBox3.setKeys(keys2);
  403. line17.animations.push(animationBox3); //中间坐舱
  404. //scene.beginAnimation(line17, 0, 100, true);
  405. //右脚
  406. var animationBox4 = new BABYLON.Animation("animationBox4", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
  407. BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  408. // Animation keys
  409. var keys4 = [];
  410. keys4.push({
  411. frame: 0,
  412. value: line26_position
  413. });
  414. keys4.push({
  415. frame: 20,
  416. value: new BABYLON.Vector3(line26_position.x+50,line26_position.y,line26_position.z)
  417. });
  418. animationBox4.setKeys(keys4);
  419. line26.animations.push(animationBox4); //中间坐舱
  420. //scene.beginAnimation(line26, 0, 100, true);
  421. //枪
  422. var animationBox5 = new BABYLON.Animation("animationBox5", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
  423. BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  424. // Animation keys
  425. var keys5 = [];
  426. keys5.push({
  427. frame: 0,
  428. value: new BABYLON.Vector3(-23,0,-47.5)
  429. });
  430. keys5.push({
  431. frame: 20,
  432. value:new BABYLON.Vector3(-2,0,-90)
  433. });
  434. animationBox5.setKeys(keys5);
  435. tube15.animations.push(animationBox5); //中间坐舱
  436. //scene.beginAnimation(tube15, 0, 100, true);
  437. setTimeout(async () => {
  438. var anim1 = scene.beginAnimation(line01, 0, 100, false);
  439. var anim2 = scene.beginAnimation(line03, 0, 100, false);
  440. var anim3 = scene.beginAnimation(line17, 0, 100, false);
  441. var anim4 = scene.beginAnimation(line26, 0, 100, false);
  442. var anim5 = scene.beginAnimation(tube15, 0, 100, false);
  443. console.log("ddd");
  444. //await anim1.waitAsync();
  445. //await anim2.waitAsync();
  446. //await anim3.waitAsync();
  447. //await anim4.waitAsync();
  448. await anim5.waitAsync();
  449. console.log("dd33d");
  450. scene.stopAnimation(line01);
  451. scene.stopAnimation(line03);
  452. scene.stopAnimation(line17);
  453. scene.stopAnimation(line26);
  454. scene.stopAnimation(tube15);
  455. });
  456. }else{
  457. bob = false;
  458. button3.background = "green";
  459. var animationBox = new BABYLON.Animation("tutoAnimation", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
  460. BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  461. // Animation keys
  462. var keys = [];
  463. keys.push({
  464. frame: 0,
  465. value: new BABYLON.Vector3(line03_position.x-60,line03_position.y,line03_position.z)
  466. });
  467. keys.push({
  468. frame: 20,
  469. value: line03_position
  470. });
  471. animationBox.setKeys(keys);
  472. line03.animations.push(animationBox); //中间坐舱
  473. //scene.beginAnimation(line03, 0, 100, true);
  474. //左护版
  475. var animationBox2 = new BABYLON.Animation("Animation2", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
  476. BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  477. // Animation keys
  478. var keys1 = [];
  479. keys1.push({
  480. frame: 0,
  481. value: new BABYLON.Vector3(line01_position.x+40,line01_position.y,line01_position.z)
  482. });
  483. keys1.push({
  484. frame: 20,
  485. value:line01_position
  486. });
  487. animationBox2.setKeys(keys1);
  488. line01.animations.push(animationBox2); //中间坐舱
  489. //scene.beginAnimation(line01, 0, 100, true);
  490. //左脚
  491. var animationBox3 = new BABYLON.Animation("animationBox3", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
  492. BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  493. // Animation keys
  494. var keys2 = [];
  495. keys2.push({
  496. frame: 0,
  497. value: new BABYLON.Vector3(line17_position.x+50,line17_position.y,line17_position.z)
  498. });
  499. keys2.push({
  500. frame: 20,
  501. value:line17_position
  502. });
  503. animationBox3.setKeys(keys2);
  504. line17.animations.push(animationBox3); //中间坐舱
  505. // scene.beginAnimation(line17, 0, 100, true);
  506. //右脚
  507. var animationBox4 = new BABYLON.Animation("animationBox4", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
  508. BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  509. // Animation keys
  510. var keys4 = [];
  511. keys4.push({
  512. frame: 0,
  513. value: new BABYLON.Vector3(line26_position.x-50,line26_position.y,line26_position.z)
  514. });
  515. keys4.push({
  516. frame: 20,
  517. value: line26_position
  518. });
  519. animationBox4.setKeys(keys4);
  520. line26.animations.push(animationBox4); //中间坐舱
  521. //scene.beginAnimation(line26, 0, 100, true);
  522. //枪
  523. var animationBox5 = new BABYLON.Animation("animationBox5", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
  524. BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  525. // Animation keys
  526. var keys5 = [];
  527. keys5.push({
  528. frame: 0,
  529. value:new BABYLON.Vector3(-2,0,-90)
  530. });
  531. keys5.push({
  532. frame: 20,
  533. value: new BABYLON.Vector3(-23,0,-47.5)
  534. });
  535. animationBox5.setKeys(keys5);
  536. tube15.animations.push(animationBox5); //中间坐舱
  537. button3.textBlock.text = "展 开";
  538. setTimeout(async () => {
  539. var anim1 = scene.beginAnimation(line01, 0, 100, false);
  540. var anim2 = scene.beginAnimation(line03, 0, 100, false);
  541. var anim3 = scene.beginAnimation(line17, 0, 100, false);
  542. var anim4 = scene.beginAnimation(line26, 0, 100, false);
  543. var anim5 = scene.beginAnimation(tube15, 0, 100, false);
  544. console.log("ddd");
  545. await anim1.waitAsync();
  546. await anim2.waitAsync();
  547. await anim3.waitAsync();
  548. await anim4.waitAsync();
  549. await anim5.waitAsync();
  550. console.log("dd33d");
  551. scene.stopAnimation(line01);
  552. scene.stopAnimation(line03);
  553. scene.stopAnimation(line17);
  554. scene.stopAnimation(line26);
  555. scene.stopAnimation(tube15);
  556. });
  557. }
  558. });
  559. var button2 = BABYLON.GUI.Button.CreateSimpleButton("but2", "拆 解");
  560. button2.width =0.2;
  561. button2.height = "80px";
  562. button2.color = "white";
  563. button2.cornerRadius = 20;
  564. button2.background = "green";
  565. button2.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;
  566. button2.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  567. var selectOne = false;
  568. button2.onPointerUpObservable.add(function() {
  569. // circle.scaleX += 0.1;
  570. gizmoManager.positionGizmoEnabled = !gizmoManager.positionGizmoEnabled
  571. if(selectOne== false){
  572. //scene.stopAnimation(line01);
  573. //scene.stopAnimation(line03);
  574. //scene.stopAnimation(line17);
  575. //scene.stopAnimation(line26);
  576. //scene.stopAnimation(tube15);
  577. selectOne = true;
  578. button2.background = "red";
  579. button2.textBlock.text = "取 消";
  580. }else{
  581. //window.location.reload(true);
  582. selectOne = false;
  583. button2.background = "green";
  584. button2.textBlock.text = "拆 解";
  585. }
  586. });
  587. var button4 = BABYLON.GUI.Button.CreateSimpleButton("but4", "还 原");
  588. //button4.fontSize = "26px";
  589. button4.width = 0.2;
  590. button4.height = "80px";
  591. button4.color = "white";
  592. button4.cornerRadius = 20;
  593. button4.background = "green";
  594. button4.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;
  595. button4.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  596. button4.onPointerUpObservable.add(function() {
  597. window.location.reload(true);
  598. });
  599. panel3.addControl(button1);
  600. panel3.addControl(button3);
  601. panel3.addControl(button2);
  602. panel3.addControl(button4);
  603. return scene;
  604. }
  605. // call the createScene function
  606. var scene = createScene();
  607. //var a = scene.getElementById("__root");
  608. // run the render loop
  609. /**/
  610. engine.runRenderLoop(function(){
  611. scene.render();
  612. });
  613. var abc1 = scene.getMeshByName("plane");
  614. window.addEventListener('resize', function(){
  615. engine.resize();
  616. });
  617. });