app.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. var BABYLON = require("../../dist/preview release/babylon.max");
  2. var LOADERS = require("../../dist/preview release/loaders/babylonjs.loaders");
  3. global.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
  4. var engine = new BABYLON.NullEngine();
  5. var scene = new BABYLON.Scene(engine);
  6. // //Create a light
  7. // var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(-60, 60, 80), scene);
  8. // //Create an Arc Rotate Camera - aimed negative z this time
  9. // var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, 1.0, 110, BABYLON.Vector3.Zero(), scene);
  10. // //Creation of 6 spheres
  11. // var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 10.0, 9.0, scene);
  12. // var sphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 2.0, 9.0, scene);//Only two segments
  13. // var sphere3 = BABYLON.Mesh.CreateSphere("Sphere3", 10.0, 9.0, scene);
  14. // var sphere4 = BABYLON.Mesh.CreateSphere("Sphere4", 10.0, 9.0, scene);
  15. // var sphere5 = BABYLON.Mesh.CreateSphere("Sphere5", 10.0, 9.0, scene);
  16. // var sphere6 = BABYLON.Mesh.CreateSphere("Sphere6", 10.0, 9.0, scene);
  17. // //Position the spheres
  18. // sphere1.position.x = 40;
  19. // sphere2.position.x = 25;
  20. // sphere3.position.x = 10;
  21. // sphere4.position.x = -5;
  22. // sphere5.position.x = -20;
  23. // sphere6.position.x = -35;
  24. // //Creation of a plane
  25. // var plane = BABYLON.Mesh.CreatePlane("plane", 120, scene);
  26. // plane.position.y = -5;
  27. // plane.rotation.x = Math.PI / 2;
  28. // //Creation of a material with wireFrame
  29. // var materialSphere1 = new BABYLON.StandardMaterial("texture1", scene);
  30. // materialSphere1.wireframe = true;
  31. // //Creation of a red material with alpha
  32. // var materialSphere2 = new BABYLON.StandardMaterial("texture2", scene);
  33. // materialSphere2.diffuseColor = new BABYLON.Color3(1, 0, 0); //Red
  34. // materialSphere2.alpha = 0.3;
  35. // //Creation of a material with an image texture
  36. // var materialSphere3 = new BABYLON.StandardMaterial("texture3", scene);
  37. // materialSphere3.diffuseTexture = new BABYLON.Texture("textures/misc.jpg", scene);
  38. // //Creation of a material with translated texture
  39. // var materialSphere4 = new BABYLON.StandardMaterial("texture4", scene);
  40. // materialSphere4.diffuseTexture = new BABYLON.Texture("textures/misc.jpg", scene);
  41. // materialSphere4.diffuseTexture.vOffset = 0.1;//Vertical offset of 10%
  42. // materialSphere4.diffuseTexture.uOffset = 0.4;//Horizontal offset of 40%
  43. // //Creation of a material with an alpha texture
  44. // var materialSphere5 = new BABYLON.StandardMaterial("texture5", scene);
  45. // materialSphere5.diffuseTexture = new BABYLON.Texture("textures/tree.png", scene);
  46. // materialSphere5.diffuseTexture.hasAlpha = true;//Has an alpha
  47. // //Creation of a material and show all the faces
  48. // var materialSphere6 = new BABYLON.StandardMaterial("texture6", scene);
  49. // materialSphere6.diffuseTexture = new BABYLON.Texture("textures/tree.png", scene);
  50. // materialSphere6.diffuseTexture.hasAlpha = true;//Have an alpha
  51. // materialSphere6.backFaceCulling = false;//Show all the faces of the element
  52. // //Creation of a repeated textured material
  53. // var materialPlane = new BABYLON.StandardMaterial("texturePlane", scene);
  54. // materialPlane.diffuseTexture = new BABYLON.Texture("textures/grass.jpg", scene);
  55. // materialPlane.diffuseTexture.uScale = 5.0;//Repeat 5 times on the Vertical Axes
  56. // materialPlane.diffuseTexture.vScale = 5.0;//Repeat 5 times on the Horizontal Axes
  57. // materialPlane.backFaceCulling = false;//Always show the front and the back of an element
  58. // //Apply the materials to meshes
  59. // sphere1.material = materialSphere1;
  60. // sphere2.material = materialSphere2;
  61. // sphere3.material = materialSphere3;
  62. // sphere4.material = materialSphere4;
  63. // sphere5.material = materialSphere5;
  64. // sphere6.material = materialSphere6;
  65. // plane.material = materialPlane;
  66. //Adding a light
  67. var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 20, 100), scene);
  68. //Adding an Arc Rotate Camera
  69. var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 100, BABYLON.Vector3.Zero(), scene);
  70. // The first parameter can be used to specify which mesh to import. Here we import all meshes
  71. BABYLON.SceneLoader.ImportMesh("", "https://playground.babylonjs.com/scenes/", "skull.babylon", scene, function (newMeshes) {
  72. // Set the target of the camera to the first imported mesh
  73. camera.target = newMeshes[0];
  74. console.log("Meshes loaded from babylon file: " + newMeshes.length);
  75. for (var index = 0; index < newMeshes.length; index++) {
  76. console.log(newMeshes[index].toString());
  77. }
  78. BABYLON.SceneLoader.ImportMesh("", "https://www.babylonjs.com/Assets/DamagedHelmet/glTF/", "DamagedHelmet.gltf", scene, function (meshes) {
  79. console.log("Meshes loaded from gltf file: " + meshes.length);
  80. for (var index = 0; index < meshes.length; index++) {
  81. console.log(meshes[index].toString());
  82. }
  83. });
  84. console.log("render started")
  85. engine.runRenderLoop(function() {
  86. scene.render();
  87. })
  88. });