babylon.sceneLoader.tests.ts 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /**
  2. * Describes the test suite.
  3. */
  4. describe('Babylon Scene Loader', function () {
  5. let subject: BABYLON.Engine;
  6. this.timeout(10000);
  7. /**
  8. * Loads the dependencies.
  9. */
  10. before(function (done) {
  11. this.timeout(180000);
  12. (BABYLONDEVTOOLS).Loader
  13. .useDist()
  14. .load(function () {
  15. // Force apply promise polyfill for consistent behavior between PhantomJS, IE11, and other browsers.
  16. BABYLON.PromisePolyfill.Apply(true);
  17. BABYLON.Engine.audioEngine = new BABYLON.AudioEngine();
  18. done();
  19. });
  20. });
  21. /**
  22. * Create a new engine subject before each test.
  23. */
  24. beforeEach(function () {
  25. subject = new BABYLON.NullEngine({
  26. renderHeight: 256,
  27. renderWidth: 256,
  28. textureSize: 256,
  29. deterministicLockstep: false,
  30. lockstepMaxSteps: 1
  31. });
  32. // Avoid creating normals in PBR materials.
  33. subject.getCaps().standardDerivatives = true;
  34. });
  35. /**
  36. * Integration tests for loading glTF assets.
  37. */
  38. describe('#glTF', () => {
  39. it('Load BoomBox', () => {
  40. const scene = new BABYLON.Scene(subject);
  41. return BABYLON.SceneLoader.AppendAsync("/Playground/scenes/BoomBox/", "BoomBox.gltf", scene).then(scene => {
  42. expect(scene.meshes.length, "scene.meshes.length").to.equal(2);
  43. expect(scene.materials.length, "scene.materials.length").to.equal(1);
  44. });
  45. });
  46. it('Load BoomBox GLB', () => {
  47. const scene = new BABYLON.Scene(subject);
  48. return BABYLON.SceneLoader.AppendAsync("/Playground/scenes/", "BoomBox.glb", scene).then(scene => {
  49. expect(scene.meshes.length, "scene.meshes.length").to.equal(2);
  50. expect(scene.materials.length, "scene.materials.length").to.equal(1);
  51. });
  52. });
  53. it('Load BoomBox with ImportMesh', () => {
  54. const scene = new BABYLON.Scene(subject);
  55. return BABYLON.SceneLoader.ImportMeshAsync(null, "/Playground/scenes/BoomBox/", "BoomBox.gltf", scene).then(result => {
  56. expect(result.meshes.length, "meshes.length").to.equal(scene.meshes.length);
  57. expect(result.particleSystems.length, "particleSystems.length").to.equal(0);
  58. expect(result.skeletons.length, "skeletons.length").to.equal(0);
  59. expect(result.animationGroups.length, "animationGroups.length").to.equal(0);
  60. });
  61. });
  62. it('Load TwoQuads with ImportMesh and one node name', () => {
  63. const scene = new BABYLON.Scene(subject);
  64. return BABYLON.SceneLoader.ImportMeshAsync("node0", "http://models.babylonjs.com/Tests/TwoQuads/", "TwoQuads.gltf", scene).then(() => {
  65. expect(scene.getMeshByName("node0"), "node0").to.exist;
  66. expect(scene.getMeshByName("node1"), "node1").to.not.exist;
  67. });
  68. });
  69. it('Load TwoQuads with ImportMesh and two node names', () => {
  70. const scene = new BABYLON.Scene(subject);
  71. return BABYLON.SceneLoader.ImportMeshAsync(["node0", "node1"], "http://models.babylonjs.com/Tests/TwoQuads/", "TwoQuads.gltf", scene).then(() => {
  72. expect(scene.getMeshByName("node0"), "node0").to.exist;
  73. expect(scene.getMeshByName("node1"), "node1").to.exist;
  74. });
  75. });
  76. it('Load BoomBox with callbacks', () => {
  77. let parsedCount = 0;
  78. let meshCount = 0;
  79. let materialCount = 0;
  80. let textureCounts: { [name: string]: number } = {};
  81. let ready = false;
  82. const promises = new Array<Promise<void>>();
  83. BABYLON.SceneLoader.OnPluginActivatedObservable.addOnce((loader: BABYLON.GLTFFileLoader) => {
  84. loader.onParsed = data => {
  85. parsedCount++;
  86. };
  87. loader.onMeshLoaded = mesh => {
  88. meshCount++;
  89. };
  90. loader.onMaterialLoaded = material => {
  91. materialCount++;
  92. };
  93. loader.onTextureLoaded = texture => {
  94. textureCounts[texture.name] = textureCounts[texture.name] || 0;
  95. textureCounts[texture.name]++;
  96. };
  97. promises.push(loader.whenCompleteAsync().then(() => {
  98. expect(ready, "ready").to.be.true;
  99. }));
  100. });
  101. const scene = new BABYLON.Scene(subject);
  102. promises.push(BABYLON.SceneLoader.AppendAsync("/Playground/scenes/BoomBox/", "BoomBox.gltf", scene).then(() => {
  103. ready = true;
  104. expect(parsedCount, "parsedCount").to.equal(1);
  105. expect(meshCount, "meshCount").to.equal(scene.meshes.length);
  106. expect(materialCount, "materialCount").to.equal(scene.materials.length);
  107. const expectedTextureLoadCounts = {
  108. "baseColor": 1,
  109. "occlusionRoughnessMetallic": 2,
  110. "normal": 1,
  111. "emissive": 1
  112. };
  113. expect(Object.keys(textureCounts), "Object.keys(textureCounts)").to.have.lengthOf(Object.keys(expectedTextureLoadCounts).length);
  114. for (const textureName in expectedTextureLoadCounts) {
  115. expect(textureCounts, "textureCounts").to.have.property(textureName, expectedTextureLoadCounts[textureName]);
  116. }
  117. }));
  118. return Promise.all(promises);
  119. });
  120. it('Load BoomBox with dispose', () => {
  121. let ready = false;
  122. let disposed = false;
  123. const promises = new Array<Promise<void>>();
  124. BABYLON.SceneLoader.OnPluginActivatedObservable.addOnce((loader: BABYLON.GLTFFileLoader) => {
  125. loader.onDispose = () => {
  126. disposed = true;
  127. };
  128. promises.push(BABYLON.Tools.DelayAsync(50).then(() => {
  129. loader.dispose();
  130. expect(ready, "ready").to.be.false;
  131. expect(disposed, "disposed").to.be.true;
  132. }));
  133. });
  134. const scene = new BABYLON.Scene(subject);
  135. promises.push(BABYLON.SceneLoader.AppendAsync("/Playground/scenes/BoomBox/", "BoomBox2.gltf", scene).then(() => {
  136. ready = true;
  137. }));
  138. return Promise.race(promises);
  139. });
  140. it('Load BoomBox with mesh.isEnabled check', () => {
  141. const scene = new BABYLON.Scene(subject);
  142. subject.runRenderLoop(() => {
  143. for (const mesh of scene.meshes) {
  144. if (mesh.getTotalVertices() !== 0) {
  145. expect(mesh.isEnabled(), "mesh.isEnabled").to.be.false;
  146. }
  147. }
  148. });
  149. return BABYLON.SceneLoader.AppendAsync("/Playground/scenes/BoomBox/", "BoomBox.gltf", scene).then(scene => {
  150. subject.stopRenderLoop();
  151. for (const mesh of scene.meshes) {
  152. if (mesh.getTotalVertices() !== 0) {
  153. expect(mesh.isEnabled(), "mesh.isEnabled").to.be.true;
  154. }
  155. }
  156. });
  157. });
  158. it('Load CompileMaterials', () => {
  159. const scene = new BABYLON.Scene(subject);
  160. const promises = new Array<Promise<void>>();
  161. let createShaderProgramSpy: sinon.SinonSpy;
  162. subject.runRenderLoop(() => {
  163. for (const mesh of scene.meshes) {
  164. if (mesh.material && mesh.isEnabled()) {
  165. expect(mesh.material.isReady(mesh), "mesh material is ready").to.be.true;
  166. }
  167. }
  168. });
  169. BABYLON.SceneLoader.OnPluginActivatedObservable.addOnce((loader: BABYLON.GLTFFileLoader) => {
  170. loader.compileMaterials = true;
  171. promises.push(loader.whenCompleteAsync().then(() => {
  172. const called = createShaderProgramSpy.called;
  173. createShaderProgramSpy.restore();
  174. expect(called, "createShaderProgramCalled").to.be.false;
  175. }));
  176. });
  177. promises.push(BABYLON.SceneLoader.AppendAsync("http://models.babylonjs.com/Tests/CompileMaterials/", "Test.gltf", scene).then(() => {
  178. createShaderProgramSpy = sinon.spy(subject, "createShaderProgram");
  179. }));
  180. return Promise.all(promises);
  181. });
  182. it('Load BrainStem with compileMaterials', () => {
  183. const scene = new BABYLON.Scene(subject);
  184. const promises = new Array<Promise<void>>();
  185. let createShaderProgramSpy: sinon.SinonSpy;
  186. subject.runRenderLoop(() => {
  187. for (const mesh of scene.meshes) {
  188. if (mesh.material && mesh.isEnabled()) {
  189. expect(mesh.material.isReady(mesh), "mesh material is ready").to.be.true;
  190. }
  191. }
  192. });
  193. BABYLON.SceneLoader.OnPluginActivatedObservable.addOnce((loader: BABYLON.GLTFFileLoader) => {
  194. loader.compileMaterials = true;
  195. promises.push(loader.whenCompleteAsync().then(() => {
  196. const called = createShaderProgramSpy.called;
  197. createShaderProgramSpy.restore();
  198. expect(called, "createShaderProgramCalled").to.be.false;
  199. }));
  200. });
  201. promises.push(BABYLON.SceneLoader.AppendAsync("/Playground/scenes/BrainStem/", "BrainStem.gltf", scene).then(() => {
  202. createShaderProgramSpy = sinon.spy(subject, "createShaderProgram");
  203. }));
  204. return Promise.all(promises);
  205. });
  206. it('Load Alien', () => {
  207. const scene = new BABYLON.Scene(subject);
  208. return BABYLON.SceneLoader.ImportMeshAsync(null, "/Playground/scenes/Alien/", "Alien.gltf", scene).then(result => {
  209. const skeletonsMapping = {
  210. "AlienHead": "skeleton0",
  211. "Collar": "skeleton1",
  212. "LeftEye": "skeleton2",
  213. "RightEye": "skeleton3",
  214. "CollarClasp": "skeleton1",
  215. "Shirt": "skeleton1",
  216. "ShirtPlate": "skeleton1",
  217. "Teeth": "skeleton1",
  218. };
  219. expect(scene.skeletons, "scene.skeletons").to.have.lengthOf(4);
  220. expect(result.skeletons, "skeletons").to.have.lengthOf(4);
  221. for (const meshName in skeletonsMapping) {
  222. const skeletonName = skeletonsMapping[meshName];
  223. expect(scene.getMeshByName(meshName).skeleton.name, `skeleton name of mesh '${meshName}'`).to.equal(skeletonName);
  224. }
  225. const alienHeadMesh = scene.getMeshByName("AlienHead") as BABYLON.Mesh;
  226. expect(alienHeadMesh.morphTargetManager.numTargets, "alienHeadMesh.morphTargetManager.numTargets").to.equal(2);
  227. expect(scene.animationGroups, "scene.animationGroups").to.have.lengthOf(1);
  228. expect(result.animationGroups, "animationGroups").to.have.lengthOf(1);
  229. const animationGroup = result.animationGroups[0];
  230. expect(animationGroup.name, "animationGroup.name").to.equal("TwoTargetBlend");
  231. expect(animationGroup.targetedAnimations, "animationGroup.targetedAnimations").to.have.lengthOf(7);
  232. const influenceAnimations = animationGroup.targetedAnimations.filter(_ => _.animation.targetProperty === "influence");
  233. expect(influenceAnimations, "influenceAnimations").to.have.lengthOf(2);
  234. const rotationAnimations = animationGroup.targetedAnimations.filter(_ => _.animation.targetProperty === "rotationQuaternion");
  235. expect(rotationAnimations, "rotationAnimations").to.have.lengthOf(4);
  236. const positionAnimations = animationGroup.targetedAnimations.filter(_ => _.animation.targetProperty === "position");
  237. expect(positionAnimations, "positionAnimations").to.have.lengthOf(1);
  238. });
  239. });
  240. it('Load TwoQuads with LODs', () => {
  241. const scene = new BABYLON.Scene(subject);
  242. const promises = new Array<Promise<void>>();
  243. subject.runRenderLoop(() => {
  244. for (const mesh of scene.meshes) {
  245. if (mesh.material && mesh.isEnabled()) {
  246. expect(mesh.material.isReady(mesh), "mesh material is ready").to.be.true;
  247. }
  248. }
  249. });
  250. BABYLON.SceneLoader.OnPluginActivatedObservable.addOnce((loader: BABYLON.GLTFFileLoader) => {
  251. loader.compileMaterials = true;
  252. promises.push(loader.whenCompleteAsync().then(() => {
  253. const meshes = [
  254. scene.getMeshByName("node0"),
  255. scene.getMeshByName("node1")
  256. ];
  257. expect(meshes[0].material.name, "Material for node 0").to.equal("LOD0");
  258. expect(meshes[1].material.name, "Material for node 1").to.equal("LOD0");
  259. expect(scene.materials, "scene.materials").to.have.lengthOf(1);
  260. const materials = [
  261. scene.getMaterialByName("LOD0")
  262. ];
  263. expect(materials[0].isReady(meshes[0]), "Material of LOD 0 is ready for node 0").to.be.true;
  264. expect(materials[0].isReady(meshes[1]), "Material of LOD 0 is ready for node 1").to.be.true;
  265. }));
  266. });
  267. promises.push(BABYLON.SceneLoader.AppendAsync("http://models.babylonjs.com/Tests/TwoQuads/", "TwoQuads.gltf", scene).then(() => {
  268. const meshes = [
  269. scene.getMeshByName("node0"),
  270. scene.getMeshByName("node1")
  271. ];
  272. expect(meshes[0].material.name, "Material for node 0").to.equal("LOD2");
  273. expect(meshes[1].material.name, "Material for node 1").to.equal("LOD2");
  274. expect(scene.materials, "scene.materials").to.have.lengthOf(3);
  275. const materials = [
  276. scene.getMaterialByName("LOD0"),
  277. scene.getMaterialByName("LOD1"),
  278. scene.getMaterialByName("LOD2")
  279. ];
  280. expect(materials[0].isReady(meshes[0]), "Material of LOD 0 is ready for node 0").to.be.false;
  281. expect(materials[0].isReady(meshes[1]), "Material of LOD 0 is ready for node 1").to.be.false;
  282. expect(materials[1].isReady(meshes[0]), "Material of LOD 1 is ready for node 0").to.be.false;
  283. expect(materials[1].isReady(meshes[1]), "Material of LOD 1 is ready for node 1").to.be.false;
  284. expect(materials[2].isReady(meshes[0]), "Material of LOD 2 is ready for node 0").to.be.true;
  285. expect(materials[2].isReady(meshes[1]), "Material of LOD 2 is ready for node 1").to.be.true;
  286. }));
  287. return Promise.all(promises);
  288. });
  289. it('Load TwoQuads with LODs and onMaterialLODsLoadedObservable', () => {
  290. const scene = new BABYLON.Scene(subject);
  291. const promises = new Array<Promise<void>>();
  292. BABYLON.SceneLoader.OnPluginActivatedObservable.addOnce((loader: BABYLON.GLTFFileLoader) => {
  293. const observer = loader.onExtensionLoadedObservable.add(extension => {
  294. if (extension instanceof BABYLON.GLTF2.Loader.Extensions.MSFT_lod) {
  295. loader.onExtensionLoadedObservable.remove(observer);
  296. extension.onMaterialLODsLoadedObservable.add(indexLOD => {
  297. const expectedMaterialName = `LOD${2 - indexLOD}`;
  298. expect(scene.getMeshByName("node0").material.name, "Material for node 0").to.equal(expectedMaterialName);
  299. expect(scene.getMeshByName("node1").material.name, "Material for node 1").to.equal(expectedMaterialName);
  300. });
  301. }
  302. });
  303. promises.push(loader.whenCompleteAsync());
  304. });
  305. promises.push(BABYLON.SceneLoader.AppendAsync("http://models.babylonjs.com/Tests/TwoQuads/", "TwoQuads.gltf", scene).then(() => {
  306. // do nothing
  307. }));
  308. return Promise.all(promises);
  309. });
  310. it('Load TwoQuads with LODs and dispose when onMaterialLODsLoadedObservable', () => {
  311. const scene = new BABYLON.Scene(subject);
  312. const promises = new Array<Promise<void>>();
  313. BABYLON.SceneLoader.OnPluginActivatedObservable.addOnce((loader: BABYLON.GLTFFileLoader) => {
  314. const observer = loader.onExtensionLoadedObservable.add(extension => {
  315. if (extension instanceof BABYLON.GLTF2.Loader.Extensions.MSFT_lod) {
  316. loader.onExtensionLoadedObservable.remove(observer);
  317. extension.onMaterialLODsLoadedObservable.add(indexLOD => {
  318. expect(indexLOD, "indexLOD").to.equal(0);
  319. loader.dispose();
  320. });
  321. }
  322. });
  323. promises.push(new Promise(resolve => {
  324. loader.onDisposeObservable.addOnce(() => {
  325. resolve();
  326. });
  327. }));
  328. });
  329. promises.push(BABYLON.SceneLoader.AppendAsync("http://models.babylonjs.com/Tests/TwoQuads/", "TwoQuads.gltf", scene).then(() => {
  330. // do nothing
  331. }));
  332. return Promise.all(promises);
  333. });
  334. it('Load TwoQuadsNoTextures with LODs', () => {
  335. const scene = new BABYLON.Scene(subject);
  336. const promises = new Array<Promise<any>>();
  337. BABYLON.SceneLoader.OnPluginActivatedObservable.addOnce((loader: BABYLON.GLTFFileLoader) => {
  338. promises.push(loader.whenCompleteAsync());
  339. });
  340. promises.push(BABYLON.SceneLoader.AppendAsync("http://models.babylonjs.com/Tests/TwoQuads/", "TwoQuadsNoTextures.gltf", scene));
  341. return Promise.all(promises);
  342. });
  343. it('Load MultiPrimitive', () => {
  344. const scene = new BABYLON.Scene(subject);
  345. return BABYLON.SceneLoader.ImportMeshAsync(null, "http://models.babylonjs.com/Tests/MultiPrimitive/", "MultiPrimitive.gltf", scene).then(result => {
  346. expect(result.meshes, "meshes").to.have.lengthOf(4);
  347. const node = scene.getMeshByName("node");
  348. expect(node, "node").to.exist;
  349. expect(node, "node").to.be.an.instanceof(BABYLON.Mesh);
  350. const mesh = node as BABYLON.Mesh;
  351. expect(mesh.geometry).to.not.exist;
  352. expect(mesh.material).to.not.exist;
  353. expect(mesh.getChildren(), "mesh children").to.have.lengthOf(2);
  354. for (const childNode of mesh.getChildren()) {
  355. expect(childNode, "child node").to.be.an.instanceof(BABYLON.Mesh);
  356. const childMesh = childNode as BABYLON.Mesh;
  357. expect(childMesh.geometry).to.exist;
  358. expect(childMesh.material).to.exist;
  359. }
  360. });
  361. });
  362. it('Load BrainStem', () => {
  363. const scene = new BABYLON.Scene(subject);
  364. return BABYLON.SceneLoader.ImportMeshAsync(null, "/Playground/scenes/BrainStem/", "BrainStem.gltf", scene).then(result => {
  365. expect(result.skeletons, "skeletons").to.have.lengthOf(1);
  366. const node1 = scene.getMeshByName("node1");
  367. for (const childMesh of node1.getChildMeshes()) {
  368. expect(childMesh.skeleton, "mesh skeleton").to.exist;
  369. expect(childMesh.skeleton.name, "mesh skeleton name").to.equal(result.skeletons[0].name);
  370. }
  371. });
  372. });
  373. it('Load BoomBox with transparencyAsCoverage', () => {
  374. const scene = new BABYLON.Scene(subject);
  375. const promises = new Array<Promise<any>>();
  376. BABYLON.SceneLoader.OnPluginActivatedObservable.addOnce((loader: BABYLON.GLTFFileLoader) => {
  377. var specularOverAlpha = false;
  378. var radianceOverAlpha = false;
  379. loader.transparencyAsCoverage = true;
  380. loader.onMaterialLoaded = material => {
  381. specularOverAlpha = specularOverAlpha || (material as BABYLON.PBRMaterial).useSpecularOverAlpha;
  382. radianceOverAlpha = radianceOverAlpha || (material as BABYLON.PBRMaterial).useRadianceOverAlpha;
  383. };
  384. promises.push(loader.whenCompleteAsync().then(() => {
  385. expect(specularOverAlpha, "specularOverAlpha").to.be.false;
  386. expect(radianceOverAlpha, "radianceOverAlpha").to.be.false;
  387. }));
  388. });
  389. promises.push(BABYLON.SceneLoader.AppendAsync("/Playground/scenes/BoomBox/", "BoomBox.gltf", scene));
  390. return Promise.all(promises);
  391. });
  392. it('Load BoomBox without transparencyAsCoverage', () => {
  393. const scene = new BABYLON.Scene(subject);
  394. const promises = new Array<Promise<any>>();
  395. BABYLON.SceneLoader.OnPluginActivatedObservable.addOnce((loader: BABYLON.GLTFFileLoader) => {
  396. var specularOverAlpha = true;
  397. var radianceOverAlpha = true;
  398. loader.transparencyAsCoverage = false;
  399. loader.onMaterialLoaded = material => {
  400. specularOverAlpha = specularOverAlpha && (material as BABYLON.PBRMaterial).useSpecularOverAlpha;
  401. radianceOverAlpha = radianceOverAlpha && (material as BABYLON.PBRMaterial).useRadianceOverAlpha;
  402. };
  403. promises.push(loader.whenCompleteAsync().then(() => {
  404. expect(specularOverAlpha, "specularOverAlpha").to.be.true;
  405. expect(radianceOverAlpha, "radianceOverAlpha").to.be.true;
  406. }));
  407. });
  408. promises.push(BABYLON.SceneLoader.AppendAsync("/Playground/scenes/BoomBox/", "BoomBox.gltf", scene));
  409. return Promise.all(promises);
  410. });
  411. it('Load BoomBox twice and check texture instancing', () => {
  412. const scene = new BABYLON.Scene(subject);
  413. return BABYLON.SceneLoader.AppendAsync("/Playground/scenes/BoomBox/", "BoomBox.gltf", scene).then(() => {
  414. const createTextureSpy = sinon.spy(subject, "createTexture");
  415. return BABYLON.SceneLoader.AppendAsync("/Playground/scenes/BoomBox/", "BoomBox.gltf", scene).then(() => {
  416. const called = createTextureSpy.called;
  417. createTextureSpy.restore();
  418. expect(called, "createTextureSpyCalled").to.be.false;
  419. });
  420. });
  421. });
  422. it('Load UFO with MSFT_audio_emitter', () => {
  423. const scene = new BABYLON.Scene(subject);
  424. return BABYLON.SceneLoader.ImportMeshAsync(null, "/Playground/scenes/", "ufo.glb", scene).then(result => {
  425. expect(result.meshes.length, "meshes.length").to.equal(scene.meshes.length);
  426. expect(result.particleSystems.length, "particleSystems.length").to.equal(0);
  427. expect(result.animationGroups.length, "animationGroups.length").to.equal(3);
  428. expect(scene.soundTracks.length, "scene.soundTracks.length").to.equal(1);
  429. expect(scene.soundTracks[0].soundCollection.length, "scene.soundTracks[0].soundCollection.length").to.equal(3);
  430. expect(scene.soundTracks[0].soundCollection[0].onEndedObservable.hasObservers(), "scene.soundTracks[0].soundCollection[0].onEndedObservable.hasObservers()").to.be.true;
  431. });
  432. });
  433. // TODO: test animation group callback
  434. // TODO: test material instancing
  435. // TODO: test KHR_materials_pbrSpecularGlossiness
  436. // TODO: test KHR_lights
  437. });
  438. describe('#AssetContainer', () => {
  439. it('should be loaded from BoomBox GLTF', () => {
  440. var scene = new BABYLON.Scene(subject);
  441. return BABYLON.SceneLoader.LoadAssetContainerAsync("/Playground/scenes/BoomBox/", "BoomBox.gltf", scene).then(container => {
  442. expect(container.meshes.length).to.eq(2);
  443. });
  444. });
  445. it('should be adding and removing objects from scene', () => {
  446. // Create a scene with some assets
  447. var scene = new BABYLON.Scene(subject);
  448. var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
  449. var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
  450. var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene);
  451. var ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene);
  452. // Move all the assets from the scene into a container
  453. var container = new BABYLON.AssetContainer(scene);
  454. var keepAssets = new BABYLON.KeepAssets();
  455. keepAssets.cameras.push(camera);
  456. container.moveAllFromScene(keepAssets);
  457. expect(scene.cameras.length).to.eq(1);
  458. expect(scene.meshes.length).to.eq(0);
  459. expect(scene.lights.length).to.eq(0);
  460. expect(container.cameras.length).to.eq(0);
  461. expect(container.meshes.length).to.eq(2);
  462. expect(container.lights.length).to.eq(1);
  463. // Add them back and then remove again
  464. container.addAllToScene();
  465. expect(scene.cameras.length).to.eq(1);
  466. expect(scene.meshes.length).to.eq(2);
  467. expect(scene.lights.length).to.eq(1);
  468. container.removeAllFromScene();
  469. expect(scene.cameras.length).to.eq(1);
  470. expect(scene.meshes.length).to.eq(0);
  471. expect(scene.lights.length).to.eq(0);
  472. });
  473. });
  474. });