app.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. var BABYLON = require("../../dist/preview release/babylon.max");
  2. var LOADERS = require("../../dist/preview release/loaders/babylonjs.loaders");
  3. global.XMLHttpRequest = require('xhr2').XMLHttpRequest;
  4. var engine = new BABYLON.NullEngine();
  5. // //Adding a light
  6. // var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 20, 100), scene);
  7. // //Adding an Arc Rotate Camera
  8. // var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 100, BABYLON.Vector3.Zero(), scene);
  9. // // The first parameter can be used to specify which mesh to import. Here we import all meshes
  10. // BABYLON.SceneLoader.ImportMesh("", "https://playground.babylonjs.com/scenes/", "skull.babylon", scene, function (newMeshes) {
  11. // // Set the target of the camera to the first imported mesh
  12. // camera.target = newMeshes[0];
  13. // console.log("Meshes loaded from babylon file: " + newMeshes.length);
  14. // for (var index = 0; index < newMeshes.length; index++) {
  15. // console.log(newMeshes[index].toString());
  16. // }
  17. // BABYLON.SceneLoader.ImportMesh("", "https://www.babylonjs.com/Assets/DamagedHelmet/glTF/", "DamagedHelmet.gltf", scene, function (meshes) {
  18. // console.log("Meshes loaded from gltf file: " + meshes.length);
  19. // for (var index = 0; index < meshes.length; index++) {
  20. // console.log(meshes[index].toString());
  21. // }
  22. // });
  23. // console.log("render started")
  24. // engine.runRenderLoop(function() {
  25. // scene.render();
  26. // })
  27. // });
  28. // Setup environment
  29. // var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 90, BABYLON.Vector3.Zero(), scene);
  30. // camera.lowerBetaLimit = 0.1;
  31. // camera.upperBetaLimit = (Math.PI / 2) * 0.9;
  32. // camera.lowerRadiusLimit = 30;
  33. // camera.upperRadiusLimit = 150;
  34. // // light1
  35. // var light = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(-1, -2, -1), scene);
  36. // light.position = new BABYLON.Vector3(20, 40, 20);
  37. // light.intensity = 0.5;
  38. // var lightSphere = BABYLON.Mesh.CreateSphere("sphere", 10, 2, scene);
  39. // lightSphere.position = light.position;
  40. // lightSphere.material = new BABYLON.StandardMaterial("light", scene);
  41. // lightSphere.material.emissiveColor = new BABYLON.Color3(1, 1, 0);
  42. // // light2
  43. // var light2 = new BABYLON.SpotLight("spot02", new BABYLON.Vector3(30, 40, 20),
  44. // new BABYLON.Vector3(-1, -2, -1), 1.1, 16, scene);
  45. // light2.intensity = 0.5;
  46. // var lightSphere2 = BABYLON.Mesh.CreateSphere("sphere", 10, 2, scene);
  47. // lightSphere2.position = light2.position;
  48. // lightSphere2.material = new BABYLON.StandardMaterial("light", scene);
  49. // lightSphere2.material.emissiveColor = new BABYLON.Color3(1, 1, 0);
  50. // // Ground
  51. // var ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene);
  52. // var groundMaterial = new BABYLON.StandardMaterial("ground", scene);
  53. // groundMaterial.diffuseTexture = new BABYLON.Texture("textures/ground.jpg", scene);
  54. // groundMaterial.diffuseTexture.uScale = 6;
  55. // groundMaterial.diffuseTexture.vScale = 6;
  56. // groundMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  57. // ground.position.y = -2.05;
  58. // ground.material = groundMaterial;
  59. // // Torus
  60. // var torus = BABYLON.Mesh.CreateTorus("torus", 4, 2, 30, scene, false);
  61. // // Box
  62. // var box = BABYLON.Mesh.CreateBox("box", 3);
  63. // box.parent = torus;
  64. // // Shadows
  65. // var shadowGenerator = new BABYLON.ShadowGenerator(1024, light);
  66. // shadowGenerator.addShadowCaster(torus);
  67. // shadowGenerator.useExponentialShadowMap = true;
  68. // var shadowGenerator2 = new BABYLON.ShadowGenerator(1024, light2);
  69. // shadowGenerator2.addShadowCaster(torus);
  70. // shadowGenerator2.usePoissonSampling = true;
  71. // ground.receiveShadows = true;
  72. // // Animations
  73. // var alpha = 0;
  74. // scene.registerBeforeRender(function () {
  75. // torus.rotation.x += 0.01;
  76. // torus.rotation.z += 0.02;
  77. // torus.position = new BABYLON.Vector3(Math.cos(alpha) * 30, 10, Math.sin(alpha) * 30);
  78. // alpha += 0.01;
  79. // });
  80. // //Adding a light
  81. // var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 20, 100), scene);
  82. // //Adding an Arc Rotate Camera
  83. // var camera = new BABYLON.ArcRotateCamera("Camera", -0.5, 2.2, 100, BABYLON.Vector3.Zero(), scene);
  84. // // The first parameter can be used to specify which mesh to import. Here we import all meshes
  85. // BABYLON.SceneLoader.ImportMesh("", "https://www.babylonjs-playground.com/scenes/", "skull.babylon", scene, function (newMeshes) {
  86. // // Set the target of the camera to the first imported mesh
  87. // camera.target = newMeshes[0];
  88. // newMeshes[0].material = new BABYLON.StandardMaterial("skull", scene);
  89. // newMeshes[0].material.emissiveColor = new BABYLON.Color3(0.2, 0.2, 0.2);
  90. // });
  91. // // Create the "God Rays" effect (volumetric light scattering)
  92. // var godrays = new BABYLON.VolumetricLightScatteringPostProcess('godrays', 1.0, camera, null, 100, BABYLON.Texture.BILINEAR_SAMPLINGMODE, engine, false);
  93. // // By default it uses a billboard to render the sun, just apply the desired texture
  94. // // position and scale
  95. // godrays.mesh.material.diffuseTexture = new BABYLON.Texture('https://www.babylonjs-playground.com/textures/sun.png', scene, true, false, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
  96. // godrays.mesh.material.diffuseTexture.hasAlpha = true;
  97. // godrays.mesh.position = new BABYLON.Vector3(-150, 150, 150);
  98. // godrays.mesh.scaling = new BABYLON.Vector3(350, 350, 350);
  99. // light.position = godrays.mesh.position;
  100. // engine.runRenderLoop(function() {
  101. // scene.render();
  102. // })
  103. // new BABYLON.Scene(engine).dispose()
  104. // BABYLON.SceneLoader.Load("https://playground.babylonjs.com/scenes/", "skull.babylon", engine, (scene) => {
  105. // console.log('scene loaded!');
  106. // for (var index = 0; index < scene.meshes.length; index++) {
  107. // console.log(scene.meshes[index].name);
  108. // }
  109. // engine.dispose();
  110. // // engine.runRenderLoop(function() {
  111. // // scene.render();
  112. // //});
  113. // }, progress => {}, (scene, err) => console.error('error:', err));
  114. var scene = new BABYLON.Scene(engine);
  115. var camera = new BABYLON.ArcRotateCamera("camera", 0, 0, 0, BABYLON.Vector3.Zero(), scene);
  116. scene.render();
  117. var pos = BABYLON.Vector3.Project(
  118. new BABYLON.Vector3(0.5, 0.5, 0.5),
  119. BABYLON.Matrix.Identity(),
  120. scene.getTransformMatrix(),
  121. scene.activeCamera.viewport.toGlobal(
  122. engine.getRenderWidth(),
  123. engine.getRenderHeight()
  124. ));;
  125. console.log(pos);