babylon.sceneloader.tests.ts 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Describes the test suite.
  3. */
  4. describe('Babylon SceneLoader', () => {
  5. var subject : BABYLON.Engine;
  6. /**
  7. * Loads the dependencies.
  8. */
  9. before(function (done) {
  10. this.timeout(180000);
  11. (BABYLONDEVTOOLS).Loader
  12. .useDist()
  13. .load(function () {
  14. done();
  15. });
  16. });
  17. /**
  18. * Create a nu engine subject before each test.
  19. */
  20. beforeEach(function () {
  21. subject = new BABYLON.NullEngine({
  22. renderHeight: 256,
  23. renderWidth: 256,
  24. textureSize: 256,
  25. deterministicLockstep: false,
  26. lockstepMaxSteps: 1
  27. });
  28. });
  29. /**
  30. * This test is more an integration test than a regular unit test but highlights how to rely
  31. * on the BABYLON.NullEngine in order to create complex test cases.
  32. */
  33. describe('#GLTF', () => {
  34. it('should load BoomBox GLTF', (done) => {
  35. mocha.timeout(10000);
  36. var scene = new BABYLON.Scene(subject);
  37. BABYLON.SceneLoader.Append("/Playground/scenes/BoomBox/", "BoomBox.gltf", scene, function () {
  38. scene.meshes.length.should.be.equal(2);
  39. scene.materials.length.should.be.equal(1);
  40. scene.multiMaterials.length.should.be.equal(0);
  41. done();
  42. });
  43. });
  44. });
  45. describe('#AssetContainer', () => {
  46. it('should be loaded from BoomBox GLTF', (done) => {
  47. var scene = new BABYLON.Scene(subject);
  48. BABYLON.SceneLoader.LoadAssetContainer("/Playground/scenes/BoomBox/", "BoomBox.gltf", scene, function (container) {
  49. expect(container.meshes.length).to.eq(2);
  50. done();
  51. });
  52. });
  53. it('should be adding and removing objects from scene', () => {
  54. // Create a scene with some assets
  55. var scene = new BABYLON.Scene(subject);
  56. var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
  57. var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
  58. var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene);
  59. var ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene);
  60. // Move all the assets from the scene into a container
  61. var container = new BABYLON.AssetContainer(scene);
  62. var keepAssets = new BABYLON.KeepAssets();
  63. keepAssets.cameras.push(camera)
  64. container.moveAllFromScene(keepAssets)
  65. expect(scene.cameras.length).to.eq(1)
  66. expect(scene.meshes.length).to.eq(0)
  67. expect(scene.lights.length).to.eq(0)
  68. expect(container.cameras.length).to.eq(0)
  69. expect(container.meshes.length).to.eq(2)
  70. expect(container.lights.length).to.eq(1)
  71. // Add them back and then remove again
  72. container.addAllToScene();
  73. expect(scene.cameras.length).to.eq(1)
  74. expect(scene.meshes.length).to.eq(2)
  75. expect(scene.lights.length).to.eq(1)
  76. container.removeAllFromScene();
  77. expect(scene.cameras.length).to.eq(1)
  78. expect(scene.meshes.length).to.eq(0)
  79. expect(scene.lights.length).to.eq(0)
  80. });
  81. });
  82. });