babylon.sceneLoader.tests.ts 27 KB

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