babylon.babylonFileLoader.js 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. var BABYLON;
  2. (function (BABYLON) {
  3. (function (Internals) {
  4. var loadCubeTexture = function (rootUrl, parsedTexture, scene) {
  5. var texture = new BABYLON.CubeTexture(rootUrl + parsedTexture.name, scene);
  6. texture.name = parsedTexture.name;
  7. texture.hasAlpha = parsedTexture.hasAlpha;
  8. texture.level = parsedTexture.level;
  9. texture.coordinatesMode = parsedTexture.coordinatesMode;
  10. return texture;
  11. };
  12. var loadTexture = function (rootUrl, parsedTexture, scene) {
  13. if (!parsedTexture.name && !parsedTexture.isRenderTarget) {
  14. return null;
  15. }
  16. if (parsedTexture.isCube) {
  17. return loadCubeTexture(rootUrl, parsedTexture, scene);
  18. }
  19. var texture;
  20. if (parsedTexture.mirrorPlane) {
  21. texture = new BABYLON.MirrorTexture(parsedTexture.name, parsedTexture.renderTargetSize, scene);
  22. texture._waitingRenderList = parsedTexture.renderList;
  23. texture.mirrorPlane = BABYLON.Plane.FromArray(parsedTexture.mirrorPlane);
  24. } else if (parsedTexture.isRenderTarget) {
  25. texture = new BABYLON.RenderTargetTexture(parsedTexture.name, parsedTexture.renderTargetSize, scene);
  26. texture._waitingRenderList = parsedTexture.renderList;
  27. } else {
  28. texture = new BABYLON.Texture(rootUrl + parsedTexture.name, scene);
  29. }
  30. texture.name = parsedTexture.name;
  31. texture.hasAlpha = parsedTexture.hasAlpha;
  32. texture.getAlphaFromRGB = parsedTexture.getAlphaFromRGB;
  33. texture.level = parsedTexture.level;
  34. texture.coordinatesIndex = parsedTexture.coordinatesIndex;
  35. texture.coordinatesMode = parsedTexture.coordinatesMode;
  36. texture.uOffset = parsedTexture.uOffset;
  37. texture.vOffset = parsedTexture.vOffset;
  38. texture.uScale = parsedTexture.uScale;
  39. texture.vScale = parsedTexture.vScale;
  40. texture.uAng = parsedTexture.uAng;
  41. texture.vAng = parsedTexture.vAng;
  42. texture.wAng = parsedTexture.wAng;
  43. texture.wrapU = parsedTexture.wrapU;
  44. texture.wrapV = parsedTexture.wrapV;
  45. // Animations
  46. if (parsedTexture.animations) {
  47. for (var animationIndex = 0; animationIndex < parsedTexture.animations.length; animationIndex++) {
  48. var parsedAnimation = parsedTexture.animations[animationIndex];
  49. texture.animations.push(parseAnimation(parsedAnimation));
  50. }
  51. }
  52. return texture;
  53. };
  54. var parseSkeleton = function (parsedSkeleton, scene) {
  55. var skeleton = new BABYLON.Skeleton(parsedSkeleton.name, parsedSkeleton.id, scene);
  56. for (var index = 0; index < parsedSkeleton.bones.length; index++) {
  57. var parsedBone = parsedSkeleton.bones[index];
  58. var parentBone = null;
  59. if (parsedBone.parentBoneIndex > -1) {
  60. parentBone = skeleton.bones[parsedBone.parentBoneIndex];
  61. }
  62. var bone = new BABYLON.Bone(parsedBone.name, skeleton, parentBone, BABYLON.Matrix.FromArray(parsedBone.matrix));
  63. if (parsedBone.animation) {
  64. bone.animations.push(parseAnimation(parsedBone.animation));
  65. }
  66. }
  67. return skeleton;
  68. };
  69. var parseFresnelParameters = function (parsedFresnelParameters) {
  70. var fresnelParameters = new BABYLON.FresnelParameters();
  71. fresnelParameters.isEnabled = parsedFresnelParameters.isEnabled;
  72. fresnelParameters.leftColor = BABYLON.Color3.FromArray(parsedFresnelParameters.leftColor);
  73. fresnelParameters.rightColor = BABYLON.Color3.FromArray(parsedFresnelParameters.rightColor);
  74. fresnelParameters.bias = parsedFresnelParameters.bias;
  75. fresnelParameters.power = parsedFresnelParameters.power || 1.0;
  76. return fresnelParameters;
  77. };
  78. var parseMaterial = function (parsedMaterial, scene, rootUrl) {
  79. var material;
  80. material = new BABYLON.StandardMaterial(parsedMaterial.name, scene);
  81. material.ambientColor = BABYLON.Color3.FromArray(parsedMaterial.ambient);
  82. material.diffuseColor = BABYLON.Color3.FromArray(parsedMaterial.diffuse);
  83. material.specularColor = BABYLON.Color3.FromArray(parsedMaterial.specular);
  84. material.specularPower = parsedMaterial.specularPower;
  85. material.emissiveColor = BABYLON.Color3.FromArray(parsedMaterial.emissive);
  86. material.alpha = parsedMaterial.alpha;
  87. material.id = parsedMaterial.id;
  88. BABYLON.Tags.AddTagsTo(material, parsedMaterial.tags);
  89. material.backFaceCulling = parsedMaterial.backFaceCulling;
  90. material.wireframe = parsedMaterial.wireframe;
  91. if (parsedMaterial.diffuseTexture) {
  92. material.diffuseTexture = loadTexture(rootUrl, parsedMaterial.diffuseTexture, scene);
  93. }
  94. if (parsedMaterial.diffuseFresnelParameters) {
  95. material.diffuseFresnelParameters = parseFresnelParameters(parsedMaterial.diffuseFresnelParameters);
  96. }
  97. if (parsedMaterial.ambientTexture) {
  98. material.ambientTexture = loadTexture(rootUrl, parsedMaterial.ambientTexture, scene);
  99. }
  100. if (parsedMaterial.opacityTexture) {
  101. material.opacityTexture = loadTexture(rootUrl, parsedMaterial.opacityTexture, scene);
  102. }
  103. if (parsedMaterial.opacityFresnelParameters) {
  104. material.opacityFresnelParameters = parseFresnelParameters(parsedMaterial.opacityFresnelParameters);
  105. }
  106. if (parsedMaterial.reflectionTexture) {
  107. material.reflectionTexture = loadTexture(rootUrl, parsedMaterial.reflectionTexture, scene);
  108. }
  109. if (parsedMaterial.reflectionFresnelParameters) {
  110. material.reflectionFresnelParameters = parseFresnelParameters(parsedMaterial.reflectionFresnelParameters);
  111. }
  112. if (parsedMaterial.emissiveTexture) {
  113. material.emissiveTexture = loadTexture(rootUrl, parsedMaterial.emissiveTexture, scene);
  114. }
  115. if (parsedMaterial.emissiveFresnelParameters) {
  116. material.emissiveFresnelParameters = parseFresnelParameters(parsedMaterial.emissiveFresnelParameters);
  117. }
  118. if (parsedMaterial.specularTexture) {
  119. material.specularTexture = loadTexture(rootUrl, parsedMaterial.specularTexture, scene);
  120. }
  121. if (parsedMaterial.bumpTexture) {
  122. material.bumpTexture = loadTexture(rootUrl, parsedMaterial.bumpTexture, scene);
  123. }
  124. return material;
  125. };
  126. var parseMaterialById = function (id, parsedData, scene, rootUrl) {
  127. for (var index = 0; index < parsedData.materials.length; index++) {
  128. var parsedMaterial = parsedData.materials[index];
  129. if (parsedMaterial.id === id) {
  130. return parseMaterial(parsedMaterial, scene, rootUrl);
  131. }
  132. }
  133. return null;
  134. };
  135. var parseMultiMaterial = function (parsedMultiMaterial, scene) {
  136. var multiMaterial = new BABYLON.MultiMaterial(parsedMultiMaterial.name, scene);
  137. multiMaterial.id = parsedMultiMaterial.id;
  138. BABYLON.Tags.AddTagsTo(multiMaterial, parsedMultiMaterial.tags);
  139. for (var matIndex = 0; matIndex < parsedMultiMaterial.materials.length; matIndex++) {
  140. var subMatId = parsedMultiMaterial.materials[matIndex];
  141. if (subMatId) {
  142. multiMaterial.subMaterials.push(scene.getMaterialByID(subMatId));
  143. } else {
  144. multiMaterial.subMaterials.push(null);
  145. }
  146. }
  147. return multiMaterial;
  148. };
  149. var parseLensFlareSystem = function (parsedLensFlareSystem, scene, rootUrl) {
  150. var emitter = scene.getLastEntryByID(parsedLensFlareSystem.emitterId);
  151. var lensFlareSystem = new BABYLON.LensFlareSystem("lensFlareSystem#" + parsedLensFlareSystem.emitterId, emitter, scene);
  152. lensFlareSystem.borderLimit = parsedLensFlareSystem.borderLimit;
  153. for (var index = 0; index < parsedLensFlareSystem.flares.length; index++) {
  154. var parsedFlare = parsedLensFlareSystem.flares[index];
  155. var flare = new BABYLON.LensFlare(parsedFlare.size, parsedFlare.position, BABYLON.Color3.FromArray(parsedFlare.color), rootUrl + parsedFlare.textureName, lensFlareSystem);
  156. }
  157. return lensFlareSystem;
  158. };
  159. var parseParticleSystem = function (parsedParticleSystem, scene, rootUrl) {
  160. var emitter = scene.getLastMeshByID(parsedParticleSystem.emitterId);
  161. var particleSystem = new BABYLON.ParticleSystem("particles#" + emitter.name, parsedParticleSystem.capacity, scene);
  162. if (parsedParticleSystem.textureName) {
  163. particleSystem.particleTexture = new BABYLON.Texture(rootUrl + parsedParticleSystem.textureName, scene);
  164. particleSystem.particleTexture.name = parsedParticleSystem.textureName;
  165. }
  166. particleSystem.minAngularSpeed = parsedParticleSystem.minAngularSpeed;
  167. particleSystem.maxAngularSpeed = parsedParticleSystem.maxAngularSpeed;
  168. particleSystem.minSize = parsedParticleSystem.minSize;
  169. particleSystem.maxSize = parsedParticleSystem.maxSize;
  170. particleSystem.minLifeTime = parsedParticleSystem.minLifeTime;
  171. particleSystem.maxLifeTime = parsedParticleSystem.maxLifeTime;
  172. particleSystem.emitter = emitter;
  173. particleSystem.emitRate = parsedParticleSystem.emitRate;
  174. particleSystem.minEmitBox = BABYLON.Vector3.FromArray(parsedParticleSystem.minEmitBox);
  175. particleSystem.maxEmitBox = BABYLON.Vector3.FromArray(parsedParticleSystem.maxEmitBox);
  176. particleSystem.gravity = BABYLON.Vector3.FromArray(parsedParticleSystem.gravity);
  177. particleSystem.direction1 = BABYLON.Vector3.FromArray(parsedParticleSystem.direction1);
  178. particleSystem.direction2 = BABYLON.Vector3.FromArray(parsedParticleSystem.direction2);
  179. particleSystem.color1 = BABYLON.Color4.FromArray(parsedParticleSystem.color1);
  180. particleSystem.color2 = BABYLON.Color4.FromArray(parsedParticleSystem.color2);
  181. particleSystem.colorDead = BABYLON.Color4.FromArray(parsedParticleSystem.colorDead);
  182. particleSystem.updateSpeed = parsedParticleSystem.updateSpeed;
  183. particleSystem.targetStopDuration = parsedParticleSystem.targetStopFrame;
  184. particleSystem.textureMask = BABYLON.Color4.FromArray(parsedParticleSystem.textureMask);
  185. particleSystem.blendMode = parsedParticleSystem.blendMode;
  186. particleSystem.start();
  187. return particleSystem;
  188. };
  189. var parseShadowGenerator = function (parsedShadowGenerator, scene) {
  190. var light = scene.getLightByID(parsedShadowGenerator.lightId);
  191. var shadowGenerator = new BABYLON.ShadowGenerator(parsedShadowGenerator.mapSize, light);
  192. for (var meshIndex = 0; meshIndex < parsedShadowGenerator.renderList.length; meshIndex++) {
  193. var mesh = scene.getMeshByID(parsedShadowGenerator.renderList[meshIndex]);
  194. shadowGenerator.getShadowMap().renderList.push(mesh);
  195. }
  196. if (parsedShadowGenerator.usePoissonSampling) {
  197. shadowGenerator.usePoissonSampling = true;
  198. } else {
  199. shadowGenerator.useVarianceShadowMap = parsedShadowGenerator.useVarianceShadowMap;
  200. }
  201. return shadowGenerator;
  202. };
  203. var parseAnimation = function (parsedAnimation) {
  204. var animation = new BABYLON.Animation(parsedAnimation.name, parsedAnimation.property, parsedAnimation.framePerSecond, parsedAnimation.dataType, parsedAnimation.loopBehavior);
  205. var dataType = parsedAnimation.dataType;
  206. var keys = [];
  207. for (var index = 0; index < parsedAnimation.keys.length; index++) {
  208. var key = parsedAnimation.keys[index];
  209. var data;
  210. switch (dataType) {
  211. case BABYLON.Animation.ANIMATIONTYPE_FLOAT:
  212. data = key.values[0];
  213. break;
  214. case BABYLON.Animation.ANIMATIONTYPE_QUATERNION:
  215. data = BABYLON.Quaternion.FromArray(key.values);
  216. break;
  217. case BABYLON.Animation.ANIMATIONTYPE_MATRIX:
  218. data = BABYLON.Matrix.FromArray(key.values);
  219. break;
  220. case BABYLON.Animation.ANIMATIONTYPE_VECTOR3:
  221. default:
  222. data = BABYLON.Vector3.FromArray(key.values);
  223. break;
  224. }
  225. keys.push({
  226. frame: key.frame,
  227. value: data
  228. });
  229. }
  230. animation.setKeys(keys);
  231. return animation;
  232. };
  233. var parseLight = function (parsedLight, scene) {
  234. var light;
  235. switch (parsedLight.type) {
  236. case 0:
  237. light = new BABYLON.PointLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.position), scene);
  238. break;
  239. case 1:
  240. light = new BABYLON.DirectionalLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.direction), scene);
  241. light.position = BABYLON.Vector3.FromArray(parsedLight.position);
  242. break;
  243. case 2:
  244. light = new BABYLON.SpotLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.position), BABYLON.Vector3.FromArray(parsedLight.direction), parsedLight.angle, parsedLight.exponent, scene);
  245. break;
  246. case 3:
  247. light = new BABYLON.HemisphericLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.direction), scene);
  248. light.groundColor = BABYLON.Color3.FromArray(parsedLight.groundColor);
  249. break;
  250. }
  251. light.id = parsedLight.id;
  252. BABYLON.Tags.AddTagsTo(light, parsedLight.tags);
  253. if (parsedLight.intensity !== undefined) {
  254. light.intensity = parsedLight.intensity;
  255. }
  256. if (parsedLight.range) {
  257. light.range = parsedLight.range;
  258. }
  259. light.diffuse = BABYLON.Color3.FromArray(parsedLight.diffuse);
  260. light.specular = BABYLON.Color3.FromArray(parsedLight.specular);
  261. if (parsedLight.excludedMeshesIds) {
  262. light._excludedMeshesIds = parsedLight.excludedMeshesIds;
  263. }
  264. if (parsedLight.includedOnlyMeshesIds) {
  265. light._includedOnlyMeshesIds = parsedLight.includedOnlyMeshesIds;
  266. }
  267. // Animations
  268. if (parsedLight.animations) {
  269. for (var animationIndex = 0; animationIndex < parsedLight.animations.length; animationIndex++) {
  270. var parsedAnimation = parsedLight.animations[animationIndex];
  271. light.animations.push(parseAnimation(parsedAnimation));
  272. }
  273. }
  274. if (parsedLight.autoAnimate) {
  275. scene.beginAnimation(light, parsedLight.autoAnimateFrom, parsedLight.autoAnimateTo, parsedLight.autoAnimateLoop, 1.0);
  276. }
  277. };
  278. var parseCamera = function (parsedCamera, scene) {
  279. var camera = new BABYLON.FreeCamera(parsedCamera.name, BABYLON.Vector3.FromArray(parsedCamera.position), scene);
  280. camera.id = parsedCamera.id;
  281. BABYLON.Tags.AddTagsTo(camera, parsedCamera.tags);
  282. // Parent
  283. if (parsedCamera.parentId) {
  284. camera._waitingParentId = parsedCamera.parentId;
  285. }
  286. // Target
  287. if (parsedCamera.target) {
  288. camera.setTarget(BABYLON.Vector3.FromArray(parsedCamera.target));
  289. } else {
  290. camera.rotation = BABYLON.Vector3.FromArray(parsedCamera.rotation);
  291. }
  292. // Locked target
  293. if (parsedCamera.lockedTargetId) {
  294. camera._waitingLockedTargetId = parsedCamera.lockedTargetId;
  295. }
  296. camera.fov = parsedCamera.fov;
  297. camera.minZ = parsedCamera.minZ;
  298. camera.maxZ = parsedCamera.maxZ;
  299. camera.speed = parsedCamera.speed;
  300. camera.inertia = parsedCamera.inertia;
  301. camera.checkCollisions = parsedCamera.checkCollisions;
  302. camera.applyGravity = parsedCamera.applyGravity;
  303. if (parsedCamera.ellipsoid) {
  304. camera.ellipsoid = BABYLON.Vector3.FromArray(parsedCamera.ellipsoid);
  305. }
  306. // Animations
  307. if (parsedCamera.animations) {
  308. for (var animationIndex = 0; animationIndex < parsedCamera.animations.length; animationIndex++) {
  309. var parsedAnimation = parsedCamera.animations[animationIndex];
  310. camera.animations.push(parseAnimation(parsedAnimation));
  311. }
  312. }
  313. if (parsedCamera.autoAnimate) {
  314. scene.beginAnimation(camera, parsedCamera.autoAnimateFrom, parsedCamera.autoAnimateTo, parsedCamera.autoAnimateLoop, 1.0);
  315. }
  316. // Layer Mask
  317. if (parsedCamera.layerMask && (!isNaN(parsedCamera.layerMask))) {
  318. camera.layerMask = Math.abs(parseInt(parsedCamera.layerMask));
  319. } else {
  320. camera.layerMask = 0xFFFFFFFF;
  321. }
  322. return camera;
  323. };
  324. var parseGeometry = function (parsedGeometry, scene) {
  325. var id = parsedGeometry.id;
  326. return scene.getGeometryByID(id);
  327. };
  328. var parseBox = function (parsedBox, scene) {
  329. if (parseGeometry(parsedBox, scene)) {
  330. return null;
  331. }
  332. var box = new BABYLON.Geometry.Primitives.Box(parsedBox.id, scene, parsedBox.size, parsedBox.canBeRegenerated, null);
  333. BABYLON.Tags.AddTagsTo(box, parsedBox.tags);
  334. scene.pushGeometry(box, true);
  335. return box;
  336. };
  337. var parseSphere = function (parsedSphere, scene) {
  338. if (parseGeometry(parsedSphere, scene)) {
  339. return null;
  340. }
  341. var sphere = new BABYLON.Geometry.Primitives.Sphere(parsedSphere.id, scene, parsedSphere.segments, parsedSphere.diameter, parsedSphere.canBeRegenerated, null);
  342. BABYLON.Tags.AddTagsTo(sphere, parsedSphere.tags);
  343. scene.pushGeometry(sphere, true);
  344. return sphere;
  345. };
  346. var parseCylinder = function (parsedCylinder, scene) {
  347. if (parseGeometry(parsedCylinder, scene)) {
  348. return null;
  349. }
  350. var cylinder = new BABYLON.Geometry.Primitives.Cylinder(parsedCylinder.id, scene, parsedCylinder.height, parsedCylinder.diameterTop, parsedCylinder.diameterBottom, parsedCylinder.tessellation, parsedCylinder.subdivisions, parsedCylinder.canBeRegenerated, null);
  351. BABYLON.Tags.AddTagsTo(cylinder, parsedCylinder.tags);
  352. scene.pushGeometry(cylinder, true);
  353. return cylinder;
  354. };
  355. var parseTorus = function (parsedTorus, scene) {
  356. if (parseGeometry(parsedTorus, scene)) {
  357. return null;
  358. }
  359. var torus = new BABYLON.Geometry.Primitives.Torus(parsedTorus.id, scene, parsedTorus.diameter, parsedTorus.thickness, parsedTorus.tessellation, parsedTorus.canBeRegenerated, null);
  360. BABYLON.Tags.AddTagsTo(torus, parsedTorus.tags);
  361. scene.pushGeometry(torus, true);
  362. return torus;
  363. };
  364. var parseGround = function (parsedGround, scene) {
  365. if (parseGeometry(parsedGround, scene)) {
  366. return null;
  367. }
  368. var ground = new BABYLON.Geometry.Primitives.Ground(parsedGround.id, scene, parsedGround.width, parsedGround.height, parsedGround.subdivisions, parsedGround.canBeRegenerated, null);
  369. BABYLON.Tags.AddTagsTo(ground, parsedGround.tags);
  370. scene.pushGeometry(ground, true);
  371. return ground;
  372. };
  373. var parsePlane = function (parsedPlane, scene) {
  374. if (parseGeometry(parsedPlane, scene)) {
  375. return null;
  376. }
  377. var plane = new BABYLON.Geometry.Primitives.Plane(parsedPlane.id, scene, parsedPlane.size, parsedPlane.canBeRegenerated, null);
  378. BABYLON.Tags.AddTagsTo(plane, parsedPlane.tags);
  379. scene.pushGeometry(plane, true);
  380. return plane;
  381. };
  382. var parseTorusKnot = function (parsedTorusKnot, scene) {
  383. if (parseGeometry(parsedTorusKnot, scene)) {
  384. return null;
  385. }
  386. var torusKnot = new BABYLON.Geometry.Primitives.TorusKnot(parsedTorusKnot.id, scene, parsedTorusKnot.radius, parsedTorusKnot.tube, parsedTorusKnot.radialSegments, parsedTorusKnot.tubularSegments, parsedTorusKnot.p, parsedTorusKnot.q, parsedTorusKnot.canBeRegenerated, null);
  387. BABYLON.Tags.AddTagsTo(torusKnot, parsedTorusKnot.tags);
  388. scene.pushGeometry(torusKnot, true);
  389. return torusKnot;
  390. };
  391. var parseVertexData = function (parsedVertexData, scene, rootUrl) {
  392. if (parseGeometry(parsedVertexData, scene)) {
  393. return null;
  394. }
  395. var geometry = new BABYLON.Geometry(parsedVertexData.id, scene);
  396. BABYLON.Tags.AddTagsTo(geometry, parsedVertexData.tags);
  397. if (parsedVertexData.delayLoadingFile) {
  398. geometry.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
  399. geometry.delayLoadingFile = rootUrl + parsedVertexData.delayLoadingFile;
  400. geometry._boundingInfo = new BABYLON.BoundingInfo(BABYLON.Vector3.FromArray(parsedVertexData.boundingBoxMinimum), BABYLON.Vector3.FromArray(parsedVertexData.boundingBoxMaximum));
  401. geometry._delayInfo = [];
  402. if (parsedVertexData.hasUVs) {
  403. geometry._delayInfo.push(BABYLON.VertexBuffer.UVKind);
  404. }
  405. if (parsedVertexData.hasUVs2) {
  406. geometry._delayInfo.push(BABYLON.VertexBuffer.UV2Kind);
  407. }
  408. if (parsedVertexData.hasColors) {
  409. geometry._delayInfo.push(BABYLON.VertexBuffer.ColorKind);
  410. }
  411. if (parsedVertexData.hasMatricesIndices) {
  412. geometry._delayInfo.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  413. }
  414. if (parsedVertexData.hasMatricesWeights) {
  415. geometry._delayInfo.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  416. }
  417. geometry._delayLoadingFunction = importVertexData;
  418. } else {
  419. importVertexData(parsedVertexData, geometry);
  420. }
  421. scene.pushGeometry(geometry, true);
  422. return geometry;
  423. };
  424. var parseMesh = function (parsedMesh, scene, rootUrl) {
  425. var mesh = new BABYLON.Mesh(parsedMesh.name, scene);
  426. mesh.id = parsedMesh.id;
  427. BABYLON.Tags.AddTagsTo(mesh, parsedMesh.tags);
  428. mesh.position = BABYLON.Vector3.FromArray(parsedMesh.position);
  429. if (parsedMesh.rotationQuaternion) {
  430. mesh.rotationQuaternion = BABYLON.Quaternion.FromArray(parsedMesh.rotationQuaternion);
  431. } else if (parsedMesh.rotation) {
  432. mesh.rotation = BABYLON.Vector3.FromArray(parsedMesh.rotation);
  433. }
  434. mesh.scaling = BABYLON.Vector3.FromArray(parsedMesh.scaling);
  435. if (parsedMesh.localMatrix) {
  436. mesh.setPivotMatrix(BABYLON.Matrix.FromArray(parsedMesh.localMatrix));
  437. } else if (parsedMesh.pivotMatrix) {
  438. mesh.setPivotMatrix(BABYLON.Matrix.FromArray(parsedMesh.pivotMatrix));
  439. }
  440. mesh.setEnabled(parsedMesh.isEnabled);
  441. mesh.isVisible = parsedMesh.isVisible;
  442. mesh.infiniteDistance = parsedMesh.infiniteDistance;
  443. mesh.showBoundingBox = parsedMesh.showBoundingBox;
  444. mesh.showSubMeshesBoundingBox = parsedMesh.showSubMeshesBoundingBox;
  445. if (parsedMesh.pickable !== undefined) {
  446. mesh.isPickable = parsedMesh.pickable;
  447. }
  448. mesh.receiveShadows = parsedMesh.receiveShadows;
  449. mesh.billboardMode = parsedMesh.billboardMode;
  450. if (parsedMesh.visibility !== undefined) {
  451. mesh.visibility = parsedMesh.visibility;
  452. }
  453. mesh.checkCollisions = parsedMesh.checkCollisions;
  454. mesh._shouldGenerateFlatShading = parsedMesh.useFlatShading;
  455. // Parent
  456. if (parsedMesh.parentId) {
  457. mesh.parent = scene.getLastEntryByID(parsedMesh.parentId);
  458. }
  459. // Geometry
  460. if (parsedMesh.delayLoadingFile) {
  461. mesh.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
  462. mesh.delayLoadingFile = rootUrl + parsedMesh.delayLoadingFile;
  463. mesh._boundingInfo = new BABYLON.BoundingInfo(BABYLON.Vector3.FromArray(parsedMesh.boundingBoxMinimum), BABYLON.Vector3.FromArray(parsedMesh.boundingBoxMaximum));
  464. if (parsedMesh._binaryInfo) {
  465. mesh._binaryInfo = parsedMesh._binaryInfo;
  466. }
  467. mesh._delayInfo = [];
  468. if (parsedMesh.hasUVs) {
  469. mesh._delayInfo.push(BABYLON.VertexBuffer.UVKind);
  470. }
  471. if (parsedMesh.hasUVs2) {
  472. mesh._delayInfo.push(BABYLON.VertexBuffer.UV2Kind);
  473. }
  474. if (parsedMesh.hasColors) {
  475. mesh._delayInfo.push(BABYLON.VertexBuffer.ColorKind);
  476. }
  477. if (parsedMesh.hasMatricesIndices) {
  478. mesh._delayInfo.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  479. }
  480. if (parsedMesh.hasMatricesWeights) {
  481. mesh._delayInfo.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  482. }
  483. mesh._delayLoadingFunction = importGeometry;
  484. if (BABYLON.SceneLoader.ForceFullSceneLoadingForIncremental) {
  485. mesh._checkDelayState();
  486. }
  487. } else {
  488. importGeometry(parsedMesh, mesh);
  489. }
  490. // Material
  491. if (parsedMesh.materialId) {
  492. mesh.setMaterialByID(parsedMesh.materialId);
  493. } else {
  494. mesh.material = null;
  495. }
  496. // Skeleton
  497. if (parsedMesh.skeletonId > -1) {
  498. mesh.skeleton = scene.getLastSkeletonByID(parsedMesh.skeletonId);
  499. }
  500. // Physics
  501. if (parsedMesh.physicsImpostor) {
  502. if (!scene.isPhysicsEnabled()) {
  503. scene.enablePhysics();
  504. }
  505. mesh.setPhysicsState({ impostor: parsedMesh.physicsImpostor, mass: parsedMesh.physicsMass, friction: parsedMesh.physicsFriction, restitution: parsedMesh.physicsRestitution });
  506. }
  507. // Animations
  508. if (parsedMesh.animations) {
  509. for (var animationIndex = 0; animationIndex < parsedMesh.animations.length; animationIndex++) {
  510. var parsedAnimation = parsedMesh.animations[animationIndex];
  511. mesh.animations.push(parseAnimation(parsedAnimation));
  512. }
  513. }
  514. if (parsedMesh.autoAnimate) {
  515. scene.beginAnimation(mesh, parsedMesh.autoAnimateFrom, parsedMesh.autoAnimateTo, parsedMesh.autoAnimateLoop, 1.0);
  516. }
  517. // Layer Mask
  518. if (parsedMesh.layerMask && (!isNaN(parsedMesh.layerMask))) {
  519. mesh.layerMask = Math.abs(parseInt(parsedMesh.layerMask));
  520. } else {
  521. mesh.layerMask = 0xFFFFFFFF;
  522. }
  523. // Instances
  524. if (parsedMesh.instances) {
  525. for (var index = 0; index < parsedMesh.instances.length; index++) {
  526. var parsedInstance = parsedMesh.instances[index];
  527. var instance = mesh.createInstance(parsedInstance.name);
  528. BABYLON.Tags.AddTagsTo(instance, parsedInstance.tags);
  529. instance.position = BABYLON.Vector3.FromArray(parsedInstance.position);
  530. if (parsedInstance.rotationQuaternion) {
  531. instance.rotationQuaternion = BABYLON.Quaternion.FromArray(parsedInstance.rotationQuaternion);
  532. } else if (parsedInstance.rotation) {
  533. instance.rotation = BABYLON.Vector3.FromArray(parsedInstance.rotation);
  534. }
  535. instance.scaling = BABYLON.Vector3.FromArray(parsedInstance.scaling);
  536. instance.checkCollisions = mesh.checkCollisions;
  537. if (parsedMesh.animations) {
  538. for (animationIndex = 0; animationIndex < parsedMesh.animations.length; animationIndex++) {
  539. parsedAnimation = parsedMesh.animations[animationIndex];
  540. instance.animations.push(parseAnimation(parsedAnimation));
  541. }
  542. }
  543. }
  544. }
  545. return mesh;
  546. };
  547. var isDescendantOf = function (mesh, names, hierarchyIds) {
  548. names = (names instanceof Array) ? names : [names];
  549. for (var i in names) {
  550. if (mesh.name === names[i]) {
  551. hierarchyIds.push(mesh.id);
  552. return true;
  553. }
  554. }
  555. if (mesh.parentId && hierarchyIds.indexOf(mesh.parentId) !== -1) {
  556. hierarchyIds.push(mesh.id);
  557. return true;
  558. }
  559. return false;
  560. };
  561. var importVertexData = function (parsedVertexData, geometry) {
  562. var vertexData = new BABYLON.VertexData();
  563. // positions
  564. var positions = parsedVertexData.positions;
  565. if (positions) {
  566. vertexData.set(positions, BABYLON.VertexBuffer.PositionKind);
  567. }
  568. // normals
  569. var normals = parsedVertexData.normals;
  570. if (normals) {
  571. vertexData.set(normals, BABYLON.VertexBuffer.NormalKind);
  572. }
  573. // uvs
  574. var uvs = parsedVertexData.uvs;
  575. if (uvs) {
  576. vertexData.set(uvs, BABYLON.VertexBuffer.UVKind);
  577. }
  578. // uv2s
  579. var uv2s = parsedVertexData.uv2s;
  580. if (uv2s) {
  581. vertexData.set(uv2s, BABYLON.VertexBuffer.UV2Kind);
  582. }
  583. // colors
  584. var colors = parsedVertexData.colors;
  585. if (colors) {
  586. vertexData.set(colors, BABYLON.VertexBuffer.ColorKind);
  587. }
  588. // matricesIndices
  589. var matricesIndices = parsedVertexData.matricesIndices;
  590. if (matricesIndices) {
  591. vertexData.set(matricesIndices, BABYLON.VertexBuffer.MatricesIndicesKind);
  592. }
  593. // matricesWeights
  594. var matricesWeights = parsedVertexData.matricesWeights;
  595. if (matricesWeights) {
  596. vertexData.set(matricesWeights, BABYLON.VertexBuffer.MatricesWeightsKind);
  597. }
  598. // indices
  599. var indices = parsedVertexData.indices;
  600. if (indices) {
  601. vertexData.indices = indices;
  602. }
  603. geometry.setAllVerticesData(vertexData, parsedVertexData.updatable);
  604. };
  605. var importGeometry = function (parsedGeometry, mesh) {
  606. var scene = mesh.getScene();
  607. // Geometry
  608. var geometryId = parsedGeometry.geometryId;
  609. if (geometryId) {
  610. var geometry = scene.getGeometryByID(geometryId);
  611. if (geometry) {
  612. geometry.applyToMesh(mesh);
  613. }
  614. } else if (parsedGeometry instanceof ArrayBuffer) {
  615. var binaryInfo = mesh._binaryInfo;
  616. if (binaryInfo.positionsAttrDesc && binaryInfo.positionsAttrDesc.count > 0) {
  617. var positionsData = new Float32Array(parsedGeometry, binaryInfo.positionsAttrDesc.offset, binaryInfo.positionsAttrDesc.count);
  618. mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positionsData, false);
  619. }
  620. if (binaryInfo.normalsAttrDesc && binaryInfo.normalsAttrDesc.count > 0) {
  621. var normalsData = new Float32Array(parsedGeometry, binaryInfo.normalsAttrDesc.offset, binaryInfo.normalsAttrDesc.count);
  622. mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normalsData, false);
  623. }
  624. if (binaryInfo.uvsAttrDesc && binaryInfo.uvsAttrDesc.count > 0) {
  625. var uvsData = new Float32Array(parsedGeometry, binaryInfo.uvsAttrDesc.offset, binaryInfo.uvsAttrDesc.count);
  626. mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvsData, false);
  627. }
  628. if (binaryInfo.uvs2AttrDesc && binaryInfo.uvs2AttrDesc.count > 0) {
  629. var uvs2Data = new Float32Array(parsedGeometry, binaryInfo.uvs2AttrDesc.offset, binaryInfo.uvs2AttrDesc.count);
  630. mesh.setVerticesData(BABYLON.VertexBuffer.UV2Kind, uvs2Data, false);
  631. }
  632. if (binaryInfo.colorsAttrDesc && binaryInfo.colorsAttrDesc.count > 0) {
  633. var colorsData = new Float32Array(parsedGeometry, binaryInfo.colorsAttrDesc.offset, binaryInfo.colorsAttrDesc.count);
  634. mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colorsData, false);
  635. }
  636. if (binaryInfo.matricesIndicesAttrDesc && binaryInfo.matricesIndicesAttrDesc.count > 0) {
  637. var matricesIndicesData = new Int32Array(parsedGeometry, binaryInfo.matricesIndicesAttrDesc.offset, binaryInfo.matricesIndicesAttrDesc.count);
  638. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, matricesIndicesData, false);
  639. }
  640. if (binaryInfo.matricesWeightsAttrDesc && binaryInfo.matricesWeightsAttrDesc.count > 0) {
  641. var matricesWeightsData = new Float32Array(parsedGeometry, binaryInfo.matricesWeightsAttrDesc.offset, binaryInfo.matricesWeightsAttrDesc.count);
  642. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, matricesWeightsData, false);
  643. }
  644. if (binaryInfo.indicesAttrDesc && binaryInfo.indicesAttrDesc.count > 0) {
  645. var indicesData = new Int32Array(parsedGeometry, binaryInfo.indicesAttrDesc.offset, binaryInfo.indicesAttrDesc.count);
  646. mesh.setIndices(indicesData);
  647. }
  648. if (binaryInfo.subMeshesAttrDesc && binaryInfo.subMeshesAttrDesc.count > 0) {
  649. var subMeshesData = new Int32Array(parsedGeometry, binaryInfo.subMeshesAttrDesc.offset, binaryInfo.subMeshesAttrDesc.count * 5);
  650. mesh.subMeshes = [];
  651. for (var i = 0; i < binaryInfo.subMeshesAttrDesc.count; i++) {
  652. var materialIndex = subMeshesData[(i * 5) + 0];
  653. var verticesStart = subMeshesData[(i * 5) + 1];
  654. var verticesCount = subMeshesData[(i * 5) + 2];
  655. var indexStart = subMeshesData[(i * 5) + 3];
  656. var indexCount = subMeshesData[(i * 5) + 4];
  657. var subMesh = new BABYLON.SubMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh);
  658. }
  659. }
  660. return;
  661. } else if (parsedGeometry.positions && parsedGeometry.normals && parsedGeometry.indices) {
  662. mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, parsedGeometry.positions, false);
  663. mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, parsedGeometry.normals, false);
  664. if (parsedGeometry.uvs) {
  665. mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, parsedGeometry.uvs, false);
  666. }
  667. if (parsedGeometry.uvs2) {
  668. mesh.setVerticesData(BABYLON.VertexBuffer.UV2Kind, parsedGeometry.uvs2, false);
  669. }
  670. if (parsedGeometry.colors) {
  671. mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, parsedGeometry.colors, false);
  672. }
  673. if (parsedGeometry.matricesIndices) {
  674. if (!parsedGeometry.matricesIndices._isExpanded) {
  675. var floatIndices = [];
  676. for (var i = 0; i < parsedGeometry.matricesIndices.length; i++) {
  677. var matricesIndex = parsedGeometry.matricesIndices[i];
  678. floatIndices.push(matricesIndex & 0x000000FF);
  679. floatIndices.push((matricesIndex & 0x0000FF00) >> 8);
  680. floatIndices.push((matricesIndex & 0x00FF0000) >> 16);
  681. floatIndices.push(matricesIndex >> 24);
  682. }
  683. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, floatIndices, false);
  684. } else {
  685. delete parsedGeometry.matricesIndices._isExpanded;
  686. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, parsedGeometry.matricesIndices, false);
  687. }
  688. }
  689. if (parsedGeometry.matricesWeights) {
  690. mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, parsedGeometry.matricesWeights, false);
  691. }
  692. mesh.setIndices(parsedGeometry.indices);
  693. }
  694. // SubMeshes
  695. if (parsedGeometry.subMeshes) {
  696. mesh.subMeshes = [];
  697. for (var subIndex = 0; subIndex < parsedGeometry.subMeshes.length; subIndex++) {
  698. var parsedSubMesh = parsedGeometry.subMeshes[subIndex];
  699. var subMesh = new BABYLON.SubMesh(parsedSubMesh.materialIndex, parsedSubMesh.verticesStart, parsedSubMesh.verticesCount, parsedSubMesh.indexStart, parsedSubMesh.indexCount, mesh);
  700. }
  701. }
  702. // Flat shading
  703. if (mesh._shouldGenerateFlatShading) {
  704. mesh.convertToFlatShadedMesh();
  705. delete mesh._shouldGenerateFlatShading;
  706. }
  707. // Update
  708. mesh.computeWorldMatrix(true);
  709. // Octree
  710. if (scene._selectionOctree) {
  711. scene._selectionOctree.addMesh(mesh);
  712. }
  713. };
  714. BABYLON.SceneLoader.RegisterPlugin({
  715. extensions: ".babylon",
  716. importMesh: function (meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons) {
  717. var parsedData = JSON.parse(data);
  718. var loadedSkeletonsIds = [];
  719. var loadedMaterialsIds = [];
  720. var hierarchyIds = [];
  721. for (var index = 0; index < parsedData.meshes.length; index++) {
  722. var parsedMesh = parsedData.meshes[index];
  723. if (!meshesNames || isDescendantOf(parsedMesh, meshesNames, hierarchyIds)) {
  724. if (meshesNames instanceof Array) {
  725. // Remove found mesh name from list.
  726. delete meshesNames[meshesNames.indexOf(parsedMesh.name)];
  727. }
  728. // Material ?
  729. if (parsedMesh.materialId) {
  730. var materialFound = (loadedMaterialsIds.indexOf(parsedMesh.materialId) !== -1);
  731. if (!materialFound) {
  732. for (var multimatIndex = 0; multimatIndex < parsedData.multiMaterials.length; multimatIndex++) {
  733. var parsedMultiMaterial = parsedData.multiMaterials[multimatIndex];
  734. if (parsedMultiMaterial.id == parsedMesh.materialId) {
  735. for (var matIndex = 0; matIndex < parsedMultiMaterial.materials.length; matIndex++) {
  736. var subMatId = parsedMultiMaterial.materials[matIndex];
  737. loadedMaterialsIds.push(subMatId);
  738. parseMaterialById(subMatId, parsedData, scene, rootUrl);
  739. }
  740. loadedMaterialsIds.push(parsedMultiMaterial.id);
  741. parseMultiMaterial(parsedMultiMaterial, scene);
  742. materialFound = true;
  743. break;
  744. }
  745. }
  746. }
  747. if (!materialFound) {
  748. loadedMaterialsIds.push(parsedMesh.materialId);
  749. parseMaterialById(parsedMesh.materialId, parsedData, scene, rootUrl);
  750. }
  751. }
  752. // Skeleton ?
  753. if (parsedMesh.skeletonId > -1 && scene.skeletons) {
  754. var skeletonAlreadyLoaded = (loadedSkeletonsIds.indexOf(parsedMesh.skeletonId) > -1);
  755. if (!skeletonAlreadyLoaded) {
  756. for (var skeletonIndex = 0; skeletonIndex < parsedData.skeletons.length; skeletonIndex++) {
  757. var parsedSkeleton = parsedData.skeletons[skeletonIndex];
  758. if (parsedSkeleton.id === parsedMesh.skeletonId) {
  759. skeletons.push(parseSkeleton(parsedSkeleton, scene));
  760. loadedSkeletonsIds.push(parsedSkeleton.id);
  761. }
  762. }
  763. }
  764. }
  765. var mesh = parseMesh(parsedMesh, scene, rootUrl);
  766. meshes.push(mesh);
  767. }
  768. }
  769. // Particles
  770. if (parsedData.particleSystems) {
  771. for (index = 0; index < parsedData.particleSystems.length; index++) {
  772. var parsedParticleSystem = parsedData.particleSystems[index];
  773. if (hierarchyIds.indexOf(parsedParticleSystem.emitterId) !== -1) {
  774. particleSystems.push(parseParticleSystem(parsedParticleSystem, scene, rootUrl));
  775. }
  776. }
  777. }
  778. return true;
  779. },
  780. load: function (scene, data, rootUrl) {
  781. var parsedData = JSON.parse(data);
  782. // Scene
  783. scene.useDelayedTextureLoading = parsedData.useDelayedTextureLoading && !BABYLON.SceneLoader.ForceFullSceneLoadingForIncremental;
  784. scene.autoClear = parsedData.autoClear;
  785. scene.clearColor = BABYLON.Color3.FromArray(parsedData.clearColor);
  786. scene.ambientColor = BABYLON.Color3.FromArray(parsedData.ambientColor);
  787. scene.gravity = BABYLON.Vector3.FromArray(parsedData.gravity);
  788. // Fog
  789. if (parsedData.fogMode && parsedData.fogMode !== 0) {
  790. scene.fogMode = parsedData.fogMode;
  791. scene.fogColor = BABYLON.Color3.FromArray(parsedData.fogColor);
  792. scene.fogStart = parsedData.fogStart;
  793. scene.fogEnd = parsedData.fogEnd;
  794. scene.fogDensity = parsedData.fogDensity;
  795. }
  796. for (var index = 0; index < parsedData.lights.length; index++) {
  797. var parsedLight = parsedData.lights[index];
  798. parseLight(parsedLight, scene);
  799. }
  800. for (index = 0; index < parsedData.cameras.length; index++) {
  801. var parsedCamera = parsedData.cameras[index];
  802. parseCamera(parsedCamera, scene);
  803. }
  804. if (parsedData.activeCameraID) {
  805. scene.setActiveCameraByID(parsedData.activeCameraID);
  806. }
  807. // Materials
  808. if (parsedData.materials) {
  809. for (index = 0; index < parsedData.materials.length; index++) {
  810. var parsedMaterial = parsedData.materials[index];
  811. parseMaterial(parsedMaterial, scene, rootUrl);
  812. }
  813. }
  814. if (parsedData.multiMaterials) {
  815. for (index = 0; index < parsedData.multiMaterials.length; index++) {
  816. var parsedMultiMaterial = parsedData.multiMaterials[index];
  817. parseMultiMaterial(parsedMultiMaterial, scene);
  818. }
  819. }
  820. // Skeletons
  821. if (parsedData.skeletons) {
  822. for (index = 0; index < parsedData.skeletons.length; index++) {
  823. var parsedSkeleton = parsedData.skeletons[index];
  824. parseSkeleton(parsedSkeleton, scene);
  825. }
  826. }
  827. // Geometries
  828. var geometries = parsedData.geometries;
  829. if (geometries) {
  830. // Boxes
  831. var boxes = geometries.boxes;
  832. if (boxes) {
  833. for (index = 0; index < boxes.length; index++) {
  834. var parsedBox = boxes[index];
  835. parseBox(parsedBox, scene);
  836. }
  837. }
  838. // Spheres
  839. var spheres = geometries.spheres;
  840. if (spheres) {
  841. for (index = 0; index < spheres.length; index++) {
  842. var parsedSphere = spheres[index];
  843. parseSphere(parsedSphere, scene);
  844. }
  845. }
  846. // Cylinders
  847. var cylinders = geometries.cylinders;
  848. if (cylinders) {
  849. for (index = 0; index < cylinders.length; index++) {
  850. var parsedCylinder = cylinders[index];
  851. parseCylinder(parsedCylinder, scene);
  852. }
  853. }
  854. // Toruses
  855. var toruses = geometries.toruses;
  856. if (toruses) {
  857. for (index = 0; index < toruses.length; index++) {
  858. var parsedTorus = toruses[index];
  859. parseTorus(parsedTorus, scene);
  860. }
  861. }
  862. // Grounds
  863. var grounds = geometries.grounds;
  864. if (grounds) {
  865. for (index = 0; index < grounds.length; index++) {
  866. var parsedGround = grounds[index];
  867. parseGround(parsedGround, scene);
  868. }
  869. }
  870. // Planes
  871. var planes = geometries.planes;
  872. if (planes) {
  873. for (index = 0; index < planes.length; index++) {
  874. var parsedPlane = planes[index];
  875. parsePlane(parsedPlane, scene);
  876. }
  877. }
  878. // TorusKnots
  879. var torusKnots = geometries.torusKnots;
  880. if (torusKnots) {
  881. for (index = 0; index < torusKnots.length; index++) {
  882. var parsedTorusKnot = torusKnots[index];
  883. parseTorusKnot(parsedTorusKnot, scene);
  884. }
  885. }
  886. // VertexData
  887. var vertexData = geometries.vertexData;
  888. if (vertexData) {
  889. for (index = 0; index < vertexData.length; index++) {
  890. var parsedVertexData = vertexData[index];
  891. parseVertexData(parsedVertexData, scene, rootUrl);
  892. }
  893. }
  894. }
  895. for (index = 0; index < parsedData.meshes.length; index++) {
  896. var parsedMesh = parsedData.meshes[index];
  897. parseMesh(parsedMesh, scene, rootUrl);
  898. }
  899. for (index = 0; index < scene.cameras.length; index++) {
  900. var camera = scene.cameras[index];
  901. if (camera._waitingParentId) {
  902. camera.parent = scene.getLastEntryByID(camera._waitingParentId);
  903. delete camera._waitingParentId;
  904. }
  905. if (camera instanceof BABYLON.FreeCamera) {
  906. var freecamera = camera;
  907. if (freecamera._waitingLockedTargetId) {
  908. freecamera.lockedTarget = scene.getLastEntryByID(freecamera._waitingLockedTargetId);
  909. delete freecamera._waitingLockedTargetId;
  910. }
  911. }
  912. }
  913. // Particles Systems
  914. if (parsedData.particleSystems) {
  915. for (index = 0; index < parsedData.particleSystems.length; index++) {
  916. var parsedParticleSystem = parsedData.particleSystems[index];
  917. parseParticleSystem(parsedParticleSystem, scene, rootUrl);
  918. }
  919. }
  920. // Lens flares
  921. if (parsedData.lensFlareSystems) {
  922. for (index = 0; index < parsedData.lensFlareSystems.length; index++) {
  923. var parsedLensFlareSystem = parsedData.lensFlareSystems[index];
  924. parseLensFlareSystem(parsedLensFlareSystem, scene, rootUrl);
  925. }
  926. }
  927. // Shadows
  928. if (parsedData.shadowGenerators) {
  929. for (index = 0; index < parsedData.shadowGenerators.length; index++) {
  930. var parsedShadowGenerator = parsedData.shadowGenerators[index];
  931. parseShadowGenerator(parsedShadowGenerator, scene);
  932. }
  933. }
  934. // Finish
  935. return true;
  936. }
  937. });
  938. })(BABYLON.Internals || (BABYLON.Internals = {}));
  939. var Internals = BABYLON.Internals;
  940. })(BABYLON || (BABYLON = {}));
  941. //# sourceMappingURL=babylon.babylonFileLoader.js.map