babylon.sceneLoader.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var SceneLoader = (function () {
  4. function SceneLoader() {
  5. }
  6. Object.defineProperty(SceneLoader, "ForceFullSceneLoadingForIncremental", {
  7. get: function () {
  8. return SceneLoader._ForceFullSceneLoadingForIncremental;
  9. },
  10. set: function (value) {
  11. SceneLoader._ForceFullSceneLoadingForIncremental = value;
  12. },
  13. enumerable: true,
  14. configurable: true
  15. });
  16. SceneLoader._getPluginForFilename = function (sceneFilename) {
  17. var dotPosition = sceneFilename.lastIndexOf(".");
  18. var extension = sceneFilename.substring(dotPosition).toLowerCase();
  19. for (var index = 0; index < this._registeredPlugins.length; index++) {
  20. var plugin = this._registeredPlugins[index];
  21. if (plugin.extensions.indexOf(extension) !== -1) {
  22. return plugin;
  23. }
  24. }
  25. return this._registeredPlugins[this._registeredPlugins.length - 1];
  26. };
  27. // Public functions
  28. SceneLoader.RegisterPlugin = function (plugin) {
  29. plugin.extensions = plugin.extensions.toLowerCase();
  30. SceneLoader._registeredPlugins.push(plugin);
  31. };
  32. SceneLoader.ImportMesh = function (meshesNames, rootUrl, sceneFilename, scene, onsuccess, progressCallBack, onerror) {
  33. var _this = this;
  34. var manifestChecked = function (success) {
  35. scene.database = database;
  36. var plugin = _this._getPluginForFilename(sceneFilename);
  37. var importMeshFromData = function (data) {
  38. var meshes = [];
  39. var particleSystems = [];
  40. var skeletons = [];
  41. if (!plugin.importMesh(meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons)) {
  42. if (onerror) {
  43. onerror(scene);
  44. }
  45. return;
  46. }
  47. if (onsuccess) {
  48. scene.importedMeshesFiles.push(rootUrl + sceneFilename);
  49. onsuccess(meshes, particleSystems, skeletons);
  50. }
  51. };
  52. if (sceneFilename.substr && sceneFilename.substr(0, 5) === "data:") {
  53. // Direct load
  54. importMeshFromData(sceneFilename.substr(5));
  55. return;
  56. }
  57. BABYLON.Tools.LoadFile(rootUrl + sceneFilename, function (data) {
  58. importMeshFromData(data);
  59. }, progressCallBack, database);
  60. };
  61. // Checking if a manifest file has been set for this scene and if offline mode has been requested
  62. var database = new BABYLON.Database(rootUrl + sceneFilename, manifestChecked);
  63. };
  64. /**
  65. * Load a scene
  66. * @param rootUrl a string that defines the root url for scene and resources
  67. * @param sceneFilename a string that defines the name of the scene file. can start with "data:" following by the stringified version of the scene
  68. * @param engine is the instance of BABYLON.Engine to use to create the scene
  69. */
  70. SceneLoader.Load = function (rootUrl, sceneFilename, engine, onsuccess, progressCallBack, onerror) {
  71. SceneLoader.Append(rootUrl, sceneFilename, new BABYLON.Scene(engine), onsuccess, progressCallBack, onerror);
  72. };
  73. /**
  74. * Append a scene
  75. * @param rootUrl a string that defines the root url for scene and resources
  76. * @param sceneFilename a string that defines the name of the scene file. can start with "data:" following by the stringified version of the scene
  77. * @param scene is the instance of BABYLON.Scene to append to
  78. */
  79. SceneLoader.Append = function (rootUrl, sceneFilename, scene, onsuccess, progressCallBack, onerror) {
  80. var plugin = this._getPluginForFilename(sceneFilename.name || sceneFilename);
  81. var database;
  82. var loadSceneFromData = function (data) {
  83. scene.database = database;
  84. if (!plugin.load(scene, data, rootUrl)) {
  85. if (onerror) {
  86. onerror(scene);
  87. }
  88. return;
  89. }
  90. if (onsuccess) {
  91. onsuccess(scene);
  92. }
  93. };
  94. var manifestChecked = function (success) {
  95. BABYLON.Tools.LoadFile(rootUrl + sceneFilename, loadSceneFromData, progressCallBack, database);
  96. };
  97. if (sceneFilename.substr && sceneFilename.substr(0, 5) === "data:") {
  98. // Direct load
  99. loadSceneFromData(sceneFilename.substr(5));
  100. return;
  101. }
  102. if (rootUrl.indexOf("file:") === -1) {
  103. // Checking if a manifest file has been set for this scene and if offline mode has been requested
  104. database = new BABYLON.Database(rootUrl + sceneFilename, manifestChecked);
  105. } else {
  106. BABYLON.Tools.ReadFile(sceneFilename, loadSceneFromData, progressCallBack);
  107. }
  108. };
  109. SceneLoader._ForceFullSceneLoadingForIncremental = false;
  110. SceneLoader._registeredPlugins = new Array();
  111. return SceneLoader;
  112. })();
  113. BABYLON.SceneLoader = SceneLoader;
  114. ;
  115. })(BABYLON || (BABYLON = {}));
  116. //# sourceMappingURL=babylon.sceneLoader.js.map