babylon.glTFFileLoader.js 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  1. var BABYLON;
  2. (function (BABYLON) {
  3. /**
  4. * Enums
  5. */
  6. (function (EComponentType) {
  7. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  8. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  9. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  10. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  11. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  12. })(BABYLON.EComponentType || (BABYLON.EComponentType = {}));
  13. var EComponentType = BABYLON.EComponentType;
  14. (function (EShaderType) {
  15. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  16. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  17. })(BABYLON.EShaderType || (BABYLON.EShaderType = {}));
  18. var EShaderType = BABYLON.EShaderType;
  19. (function (EParameterType) {
  20. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  21. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  22. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  23. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  24. EParameterType[EParameterType["INT"] = 5124] = "INT";
  25. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  26. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  27. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  28. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  29. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  30. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  31. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  32. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  33. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  34. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  35. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  36. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  37. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  38. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  39. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  40. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  41. })(BABYLON.EParameterType || (BABYLON.EParameterType = {}));
  42. var EParameterType = BABYLON.EParameterType;
  43. (function (ETextureWrapMode) {
  44. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  45. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  46. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  47. })(BABYLON.ETextureWrapMode || (BABYLON.ETextureWrapMode = {}));
  48. var ETextureWrapMode = BABYLON.ETextureWrapMode;
  49. (function (ETextureFilterType) {
  50. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  51. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  52. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  53. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  54. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  55. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  56. })(BABYLON.ETextureFilterType || (BABYLON.ETextureFilterType = {}));
  57. var ETextureFilterType = BABYLON.ETextureFilterType;
  58. (function (ETextureFormat) {
  59. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  60. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  61. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  62. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  63. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  64. })(BABYLON.ETextureFormat || (BABYLON.ETextureFormat = {}));
  65. var ETextureFormat = BABYLON.ETextureFormat;
  66. (function (ECullingType) {
  67. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  68. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  69. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  70. })(BABYLON.ECullingType || (BABYLON.ECullingType = {}));
  71. var ECullingType = BABYLON.ECullingType;
  72. (function (EBlendingFunction) {
  73. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  74. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  75. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  76. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  77. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  78. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  79. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  80. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  81. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  82. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  83. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  84. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  85. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  86. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  87. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  88. })(BABYLON.EBlendingFunction || (BABYLON.EBlendingFunction = {}));
  89. var EBlendingFunction = BABYLON.EBlendingFunction;
  90. /**
  91. * Tokenizer. Used for shaders compatibility
  92. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  93. */
  94. var ETokenType;
  95. (function (ETokenType) {
  96. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  97. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  98. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  99. })(ETokenType || (ETokenType = {}));
  100. var Tokenizer = (function () {
  101. function Tokenizer(toParse) {
  102. this._pos = 0;
  103. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  104. this._toParse = toParse;
  105. this._maxPos = toParse.length;
  106. }
  107. Tokenizer.prototype.getNextToken = function () {
  108. if (this.isEnd())
  109. return ETokenType.END_OF_INPUT;
  110. this.currentString = this.read();
  111. this.currentToken = ETokenType.UNKNOWN;
  112. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  113. this.currentToken = ETokenType.IDENTIFIER;
  114. this.currentIdentifier = this.currentString;
  115. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  116. this.currentIdentifier += this.currentString;
  117. this.forward();
  118. }
  119. }
  120. return this.currentToken;
  121. };
  122. Tokenizer.prototype.peek = function () {
  123. return this._toParse[this._pos];
  124. };
  125. Tokenizer.prototype.read = function () {
  126. return this._toParse[this._pos++];
  127. };
  128. Tokenizer.prototype.forward = function () {
  129. this._pos++;
  130. };
  131. Tokenizer.prototype.isEnd = function () {
  132. return this._pos >= this._maxPos;
  133. };
  134. return Tokenizer;
  135. })();
  136. /**
  137. * Values
  138. */
  139. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  140. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  141. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  142. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  143. /**
  144. * Parse
  145. */
  146. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  147. for (var buf in parsedBuffers) {
  148. var parsedBuffer = parsedBuffers[buf];
  149. gltfRuntime.buffers[buf] = parsedBuffer;
  150. gltfRuntime.buffersCount++;
  151. }
  152. };
  153. var parseShaders = function (parsedShaders, gltfRuntime) {
  154. for (var sha in parsedShaders) {
  155. var parsedShader = parsedShaders[sha];
  156. gltfRuntime.shaders[sha] = parsedShader;
  157. gltfRuntime.shaderscount++;
  158. }
  159. };
  160. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  161. for (var object in parsedObjects) {
  162. var parsedObject = parsedObjects[object];
  163. gltfRuntime[runtimeProperty][object] = parsedObject;
  164. }
  165. };
  166. /**
  167. * Utils
  168. */
  169. var getByteStrideFromType = function (accessor) {
  170. // Needs this function since "byteStride" isn't requiered in glTF format
  171. var type = accessor.type;
  172. switch (type) {
  173. case "VEC2": return 2;
  174. case "VEC3": return 3;
  175. case "VEC4": return 4;
  176. case "MAT2": return 4;
  177. case "MAT3": return 9;
  178. case "MAT4": return 16;
  179. default: return 1;
  180. }
  181. };
  182. var setMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  183. var mat = null;
  184. if (parameter.semantic === "MODEL") {
  185. mat = source.getWorldMatrix();
  186. }
  187. else if (parameter.semantic === "PROJECTION") {
  188. mat = scene.getProjectionMatrix();
  189. }
  190. else if (parameter.semantic === "VIEW") {
  191. mat = scene.getViewMatrix();
  192. }
  193. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  194. mat = BABYLON.Matrix.Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  195. }
  196. else if (parameter.semantic === "MODELVIEW") {
  197. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  198. }
  199. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  200. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  201. }
  202. else if (parameter.semantic === "MODELINVERSE") {
  203. mat = source.getWorldMatrix().invert();
  204. }
  205. else if (parameter.semantic === "VIEWINVERSE") {
  206. mat = scene.getViewMatrix().invert();
  207. }
  208. else if (parameter.semantic === "PROJECTIONINVERSE") {
  209. mat = scene.getProjectionMatrix().invert();
  210. }
  211. else if (parameter.semantic === "MODELVIEWINVERSE") {
  212. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  213. }
  214. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  215. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  216. }
  217. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  218. mat = BABYLON.Matrix.Transpose(source.getWorldMatrix().invert());
  219. }
  220. else {
  221. debugger;
  222. }
  223. switch (parameter.type) {
  224. case EParameterType.FLOAT_MAT2:
  225. shaderMaterial.setMatrix2x2(uniformName, BABYLON.Matrix.GetAsMatrix2x2(mat));
  226. break;
  227. case EParameterType.FLOAT_MAT3:
  228. shaderMaterial.setMatrix3x3(uniformName, BABYLON.Matrix.GetAsMatrix3x3(mat));
  229. break;
  230. case EParameterType.FLOAT_MAT4:
  231. shaderMaterial.setMatrix(uniformName, mat);
  232. break;
  233. default: break;
  234. }
  235. };
  236. var setUniform = function (shaderMaterial, uniform, value, type) {
  237. switch (type) {
  238. case EParameterType.FLOAT:
  239. shaderMaterial.setFloat(uniform, value);
  240. return true;
  241. case EParameterType.FLOAT_VEC2:
  242. shaderMaterial.setVector2(uniform, BABYLON.Vector2.FromArray(value));
  243. return true;
  244. case EParameterType.FLOAT_VEC3:
  245. shaderMaterial.setVector3(uniform, BABYLON.Vector3.FromArray(value));
  246. return true;
  247. case EParameterType.FLOAT_VEC4:
  248. shaderMaterial.setVector4(uniform, BABYLON.Vector4.FromArray(value));
  249. return true;
  250. default: return false;
  251. }
  252. };
  253. var getWrapMode = function (mode) {
  254. switch (mode) {
  255. case ETextureWrapMode.CLAMP_TO_EDGE: return BABYLON.Texture.CLAMP_ADDRESSMODE;
  256. case ETextureWrapMode.MIRRORED_REPEAT: return BABYLON.Texture.MIRROR_ADDRESSMODE;
  257. case ETextureWrapMode.REPEAT: return BABYLON.Texture.WRAP_ADDRESSMODE;
  258. default: return BABYLON.Texture.WRAP_ADDRESSMODE;
  259. }
  260. };
  261. var getTextureFilterMode = function (mode) {
  262. switch (mode) {
  263. case ETextureFilterType.LINEAR:
  264. case ETextureFilterType.LINEAR_MIPMAP_NEAREST:
  265. case ETextureFilterType.LINEAR_MIPMAP_LINEAR: return BABYLON.Texture.TRILINEAR_SAMPLINGMODE;
  266. case ETextureFilterType.NEAREST:
  267. case ETextureFilterType.NEAREST_MIPMAP_NEAREST: return BABYLON.Texture.NEAREST_SAMPLINGMODE;
  268. default: return BABYLON.Texture.BILINEAR_SAMPLINGMODE;
  269. }
  270. };
  271. var getBufferFromAccessor = function (gltfRuntime, accessor) {
  272. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  273. var arrayBuffer = gltfRuntime.arrayBuffers[bufferView.buffer];
  274. var byteOffset = accessor.byteOffset + bufferView.byteOffset;
  275. var count = accessor.count * getByteStrideFromType(accessor);
  276. switch (accessor.componentType) {
  277. case EComponentType.BYTE: return new Int8Array(arrayBuffer, byteOffset, count);
  278. case EComponentType.UNSIGNED_BYTE: return new Uint8Array(arrayBuffer, byteOffset, count);
  279. case EComponentType.SHORT: return new Int16Array(arrayBuffer, byteOffset, count);
  280. case EComponentType.UNSIGNED_SHORT: return new Uint16Array(arrayBuffer, byteOffset, count);
  281. default: return new Float32Array(arrayBuffer, byteOffset, count);
  282. }
  283. };
  284. var normalizeUVs = function (buffer) {
  285. if (!buffer) {
  286. return;
  287. }
  288. for (var i = 0; i < buffer.length / 2; i++) {
  289. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  290. }
  291. };
  292. var replaceInString = function (str, searchValue, replaceValue) {
  293. while (str.indexOf(searchValue) !== -1) {
  294. str = str.replace(searchValue, replaceValue);
  295. }
  296. return str;
  297. };
  298. var getAttribute = function (attributeParameter) {
  299. if (attributeParameter.semantic === "NORMAL") {
  300. return "normal";
  301. }
  302. else if (attributeParameter.semantic === "POSITION") {
  303. return "position";
  304. }
  305. else if (attributeParameter.semantic === "JOINT") {
  306. return "matricesIndices";
  307. }
  308. else if (attributeParameter.semantic === "WEIGHT") {
  309. return "matricesWeights";
  310. }
  311. else if (attributeParameter.semantic === "COLOR") {
  312. return "color";
  313. }
  314. else if (attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  315. var channel = Number(attributeParameter.semantic.split("_")[1]);
  316. return "uv" + (channel === 0 ? "" : channel + 1);
  317. }
  318. };
  319. var isBase64 = function (uri) {
  320. return uri.length < 5 ? false : uri.substr(0, 5) === "data:";
  321. };
  322. /**
  323. * Returns the animation path (glTF -> Babylon)
  324. */
  325. var getAnimationPath = function (path) {
  326. var index = glTFAnimationPaths.indexOf(path);
  327. if (index !== -1) {
  328. return babylonAnimationPaths[index];
  329. }
  330. return path;
  331. };
  332. /**
  333. * Loads and creates animations
  334. */
  335. var loadAnimations = function (gltfRuntime) {
  336. for (var anim in gltfRuntime.animations) {
  337. var animation = gltfRuntime.animations[anim];
  338. for (var i = 0; i < animation.channels.length; i++) {
  339. // Get parameters and load buffers
  340. var channel = animation.channels[i];
  341. var sampler = animation.samplers[channel.sampler];
  342. if (!sampler) {
  343. continue;
  344. }
  345. var inputData = animation.parameters[sampler.input];
  346. var outputData = animation.parameters[sampler.output];
  347. var bufferInput = getBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  348. var bufferOutput = getBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  349. var targetID = channel.target.id;
  350. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  351. if (targetNode === null) {
  352. BABYLON.Tools.Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  353. continue;
  354. }
  355. var isBone = targetNode instanceof BABYLON.Bone;
  356. // Get target path (position, rotation or scaling)
  357. var targetPath = channel.target.path;
  358. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  359. if (targetPathIndex !== -1) {
  360. targetPath = babylonAnimationPaths[targetPathIndex];
  361. }
  362. // Determine animation type
  363. var animationType = BABYLON.Animation.ANIMATIONTYPE_MATRIX;
  364. if (!isBone) {
  365. if (targetPath === "rotationQuaternion") {
  366. animationType = BABYLON.Animation.ANIMATIONTYPE_QUATERNION;
  367. targetNode.rotationQuaternion = new BABYLON.Quaternion();
  368. }
  369. else {
  370. animationType = BABYLON.Animation.ANIMATIONTYPE_VECTOR3;
  371. }
  372. }
  373. // Create animation and key frames
  374. var babylonAnimation = new BABYLON.Animation(anim, isBone ? "_matrix" : targetPath, 1, animationType, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
  375. var keys = [];
  376. var arrayOffset = 0;
  377. // For each frame
  378. for (var j = 0; j < bufferInput.length; j++) {
  379. var value = null;
  380. if (targetPath === "rotationQuaternion") {
  381. value = BABYLON.Quaternion.FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  382. arrayOffset += 4;
  383. }
  384. else {
  385. value = BABYLON.Vector3.FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  386. arrayOffset += 3;
  387. }
  388. if (isBone) {
  389. var bone = targetNode;
  390. var translation = BABYLON.Vector3.Zero();
  391. var rotationQuaternion = new BABYLON.Quaternion();
  392. var scaling = BABYLON.Vector3.Zero();
  393. // Warning on decompose
  394. var mat = bone.getBaseMatrix();
  395. mat.decompose(scaling, rotationQuaternion, translation);
  396. if (targetPath === "position") {
  397. translation = value;
  398. }
  399. else if (targetPath === "rotationQuaternion") {
  400. rotationQuaternion = value;
  401. }
  402. else {
  403. scaling = value;
  404. }
  405. value = BABYLON.Matrix.Compose(scaling, rotationQuaternion, translation);
  406. }
  407. keys.push({
  408. frame: bufferInput[j],
  409. value: value
  410. });
  411. }
  412. // Finish
  413. babylonAnimation.setKeys(keys);
  414. targetNode.animations.push(babylonAnimation);
  415. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  416. }
  417. }
  418. };
  419. /**
  420. * Returns the bones transformation matrix
  421. */
  422. var configureBoneTransformation = function (node) {
  423. var mat = null;
  424. if (node.translation && node.rotation && node.scale) {
  425. var scale = BABYLON.Vector3.FromArray(node.scale);
  426. var rotation = BABYLON.Quaternion.FromArray(node.rotation);
  427. var position = BABYLON.Vector3.FromArray(node.translation);
  428. mat = BABYLON.Matrix.Compose(scale, rotation, position);
  429. }
  430. else {
  431. mat = BABYLON.Matrix.FromArray(node.matrix);
  432. }
  433. return mat;
  434. };
  435. /**
  436. * Returns the parent bone
  437. */
  438. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  439. // Try to find
  440. for (var i = 0; i < newSkeleton.bones.length; i++) {
  441. if (newSkeleton.bones[i].id === jointName) {
  442. return newSkeleton.bones[i];
  443. }
  444. }
  445. // Not found, search in gltf nodes
  446. var nodes = gltfRuntime.nodes;
  447. for (var nde in nodes) {
  448. var node = nodes[nde];
  449. if (!node.jointName) {
  450. continue;
  451. }
  452. var children = node.children;
  453. for (var i = 0; i < children.length; i++) {
  454. var child = gltfRuntime.nodes[children[i]];
  455. if (!child.jointName) {
  456. continue;
  457. }
  458. if (child.jointName === jointName) {
  459. var mat = configureBoneTransformation(node);
  460. var bone = new BABYLON.Bone(node.name, newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  461. bone.id = nde;
  462. return bone;
  463. }
  464. }
  465. }
  466. return null;
  467. };
  468. /**
  469. * Returns the appropriate root node
  470. */
  471. var getNodeToRoot = function (nodesToRoot, id) {
  472. for (var i = 0; i < nodesToRoot.length; i++) {
  473. var nodeToRoot = nodesToRoot[i];
  474. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  475. var child = nodeToRoot.node.children[j];
  476. if (child === id) {
  477. return nodeToRoot.bone;
  478. }
  479. }
  480. }
  481. return null;
  482. };
  483. /**
  484. * Returns the node with the joint name
  485. */
  486. var getJointNode = function (gltfRuntime, jointName) {
  487. var nodes = gltfRuntime.nodes;
  488. var node = nodes[jointName];
  489. if (node) {
  490. return {
  491. node: node,
  492. id: jointName
  493. };
  494. }
  495. for (var nde in nodes) {
  496. node = nodes[nde];
  497. if (node.jointName === jointName) {
  498. return {
  499. node: node,
  500. id: nde
  501. };
  502. }
  503. }
  504. return null;
  505. };
  506. /**
  507. * Checks if a nodes is in joints
  508. */
  509. var nodeIsInJoints = function (skins, id) {
  510. for (var i = 0; i < skins.jointNames.length; i++) {
  511. if (skins.jointNames[i] === id) {
  512. return true;
  513. }
  514. }
  515. return false;
  516. };
  517. /**
  518. * Fills the nodes to root for bones and builds hierarchy
  519. */
  520. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  521. // Creates nodes for root
  522. for (var nde in gltfRuntime.nodes) {
  523. var node = gltfRuntime.nodes[nde];
  524. var id = nde;
  525. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  526. continue;
  527. }
  528. // Create node to root bone
  529. var mat = configureBoneTransformation(node);
  530. var bone = new BABYLON.Bone(node.name, newSkeleton, null, mat);
  531. bone.id = id;
  532. nodesToRoot.push({ bone: bone, node: node, id: id });
  533. }
  534. // Parenting
  535. for (var i = 0; i < nodesToRoot.length; i++) {
  536. var nodeToRoot = nodesToRoot[i];
  537. var children = nodeToRoot.node.children;
  538. for (var j = 0; j < children.length; j++) {
  539. var child = null;
  540. for (var k = 0; k < nodesToRoot.length; k++) {
  541. if (nodesToRoot[k].id === children[j]) {
  542. child = nodesToRoot[k];
  543. break;
  544. }
  545. }
  546. if (child) {
  547. child.bone._parent = nodeToRoot.bone;
  548. nodeToRoot.bone.children.push(child.bone);
  549. }
  550. }
  551. }
  552. };
  553. /**
  554. * Imports a skeleton
  555. */
  556. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton) {
  557. if (!newSkeleton) {
  558. newSkeleton = new BABYLON.Skeleton(skins.name, "", gltfRuntime.scene);
  559. }
  560. if (!skins.babylonSkeleton) {
  561. return newSkeleton;
  562. }
  563. // Matrices
  564. var accessor = gltfRuntime.accessors[skins.inverseBindMatrices];
  565. var buffer = getBufferFromAccessor(gltfRuntime, accessor);
  566. var bindShapeMatrix = BABYLON.Matrix.FromArray(skins.bindShapeMatrix);
  567. newSkeleton._identity = bindShapeMatrix;
  568. // Find the root bones
  569. var nodesToRoot = [];
  570. var nodesToRootToAdd = [];
  571. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  572. newSkeleton.bones = [];
  573. // Joints
  574. for (var i = 0; i < skins.jointNames.length; i++) {
  575. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  576. var node = jointNode.node;
  577. if (!node) {
  578. BABYLON.Tools.Warn("Joint named " + skins.jointNames[i] + " does not exist");
  579. continue;
  580. }
  581. var id = jointNode.id;
  582. // Check if node already exists
  583. var foundBone = false;
  584. for (var j = 0; j < newSkeleton.bones.length; j++) {
  585. if (newSkeleton.bones[j].id === id) {
  586. foundBone = true;
  587. break;
  588. }
  589. }
  590. if (foundBone) {
  591. continue;
  592. }
  593. // Search for parent bone
  594. var parentBone = null;
  595. for (var j = 0; j < i; j++) {
  596. var joint = getJointNode(gltfRuntime, skins.jointNames[j]).node;
  597. if (!joint) {
  598. BABYLON.Tools.Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  599. continue;
  600. }
  601. var children = joint.children;
  602. foundBone = false;
  603. for (var k = 0; k < children.length; k++) {
  604. if (children[k] === id) {
  605. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  606. foundBone = true;
  607. break;
  608. }
  609. }
  610. if (foundBone) {
  611. break;
  612. }
  613. }
  614. // Create bone
  615. var mat = configureBoneTransformation(node);
  616. if (!parentBone) {
  617. parentBone = getNodeToRoot(nodesToRoot, id);
  618. if (parentBone) {
  619. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  620. nodesToRootToAdd.push(parentBone);
  621. }
  622. }
  623. }
  624. var bone = new BABYLON.Bone(node.name, newSkeleton, parentBone, mat);
  625. bone.id = id;
  626. }
  627. // Polish
  628. var bones = newSkeleton.bones;
  629. newSkeleton.bones = [];
  630. for (var i = 0; i < skins.jointNames.length; i++) {
  631. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  632. if (!jointNode) {
  633. continue;
  634. }
  635. for (var j = 0; j < bones.length; j++) {
  636. if (bones[j].id === jointNode.id) {
  637. newSkeleton.bones.push(bones[j]);
  638. break;
  639. }
  640. }
  641. }
  642. // Finish
  643. newSkeleton.prepare();
  644. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  645. newSkeleton.bones.push(nodesToRootToAdd[i]);
  646. }
  647. return newSkeleton;
  648. };
  649. /**
  650. * Imports a mesh and its geometries
  651. */
  652. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  653. if (!newMesh) {
  654. newMesh = new BABYLON.Mesh(node.name, gltfRuntime.scene);
  655. newMesh.id = id;
  656. }
  657. if (!node.babylonNode) {
  658. return newMesh;
  659. }
  660. var multiMat = new BABYLON.MultiMaterial("multimat" + id, gltfRuntime.scene);
  661. newMesh.material = multiMat;
  662. var vertexData = new BABYLON.VertexData();
  663. var geometry = new BABYLON.Geometry(id, gltfRuntime.scene, vertexData, false, newMesh);
  664. var verticesStarts = [];
  665. var verticesCounts = [];
  666. var indexStarts = [];
  667. var indexCounts = [];
  668. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  669. var meshID = meshes[meshIndex];
  670. var mesh = gltfRuntime.meshes[meshID];
  671. if (!mesh) {
  672. continue;
  673. }
  674. // Positions, normals and UVs
  675. for (var i = 0; i < mesh.primitives.length; i++) {
  676. // Temporary vertex data
  677. var tempVertexData = new BABYLON.VertexData();
  678. var primitive = mesh.primitives[i];
  679. if (primitive.mode !== 4) {
  680. }
  681. var attributes = primitive.attributes;
  682. var accessor = null;
  683. var buffer = null;
  684. // Set positions, normal and uvs
  685. for (var semantic in attributes) {
  686. // Link accessor and buffer view
  687. accessor = gltfRuntime.accessors[attributes[semantic]];
  688. buffer = getBufferFromAccessor(gltfRuntime, accessor);
  689. if (semantic === "NORMAL") {
  690. tempVertexData.normals = [];
  691. for (var j = 0; j < buffer.length; j++) {
  692. tempVertexData.normals.push(buffer[j]);
  693. }
  694. }
  695. else if (semantic === "POSITION") {
  696. tempVertexData.positions = [];
  697. for (var j = 0; j < buffer.length; j++) {
  698. tempVertexData.positions.push(buffer[j]);
  699. }
  700. verticesCounts.push(tempVertexData.positions.length);
  701. }
  702. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  703. var channel = Number(semantic.split("_")[1]);
  704. var uvKind = BABYLON.VertexBuffer.UVKind + (channel === 0 ? "" : (channel + 1));
  705. var uvs = [];
  706. for (var j = 0; j < buffer.length; j++) {
  707. uvs.push(buffer[j]);
  708. }
  709. normalizeUVs(uvs);
  710. tempVertexData.set(uvs, uvKind);
  711. }
  712. else if (semantic === "JOINT") {
  713. tempVertexData.matricesIndices = [];
  714. for (var j = 0; j < buffer.length; j++) {
  715. tempVertexData.matricesIndices.push(buffer[j]);
  716. }
  717. }
  718. else if (semantic === "WEIGHT") {
  719. tempVertexData.matricesWeights = [];
  720. for (var j = 0; j < buffer.length; j++) {
  721. tempVertexData.matricesWeights.push(buffer[j]);
  722. }
  723. }
  724. else if (semantic === "COLOR") {
  725. tempVertexData.colors = [];
  726. for (var j = 0; j < buffer.length; j++) {
  727. tempVertexData.colors.push(buffer[j]);
  728. }
  729. }
  730. }
  731. // Indices
  732. accessor = gltfRuntime.accessors[primitive.indices];
  733. buffer = getBufferFromAccessor(gltfRuntime, accessor);
  734. tempVertexData.indices = [];
  735. for (var j = 0; j < buffer.length; j++) {
  736. tempVertexData.indices.push(buffer[j]);
  737. }
  738. indexCounts.push(buffer.length);
  739. vertexData.merge(tempVertexData);
  740. tempVertexData = undefined;
  741. // Sub material
  742. var material = gltfRuntime.scene.getMaterialByID(primitive.material);
  743. multiMat.subMaterials.push(material === null ? gltfRuntime.scene.defaultMaterial : material);
  744. // Update vertices start and index start
  745. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  746. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  747. }
  748. }
  749. // Apply geometry
  750. geometry.setAllVerticesData(vertexData, false);
  751. newMesh.flipFaces(true);
  752. newMesh.computeWorldMatrix(true);
  753. // Apply submeshes
  754. newMesh.subMeshes = [];
  755. var index = 0;
  756. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  757. var meshID = meshes[meshIndex];
  758. var mesh = gltfRuntime.meshes[meshID];
  759. if (!mesh) {
  760. continue;
  761. }
  762. for (var i = 0; i < mesh.primitives.length; i++) {
  763. if (mesh.primitives[i].mode !== 4) {
  764. }
  765. var subMesh = new BABYLON.SubMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  766. index++;
  767. }
  768. }
  769. // Finish
  770. return newMesh;
  771. };
  772. /**
  773. * Configure node transformation from position, rotation and scaling
  774. */
  775. var configureNode = function (newNode, position, rotation, scaling) {
  776. if (newNode.position) {
  777. newNode.position = position;
  778. }
  779. if (newNode.rotationQuaternion || newNode.rotation) {
  780. newNode.rotationQuaternion = rotation;
  781. }
  782. if (newNode.scaling) {
  783. newNode.scaling = scaling;
  784. }
  785. };
  786. /**
  787. * Configures node from transformation matrix
  788. */
  789. var configureNodeFromMatrix = function (newNode, node) {
  790. if (node.matrix) {
  791. var position = new BABYLON.Vector3(0, 0, 0);
  792. var rotation = new BABYLON.Quaternion();
  793. var scaling = new BABYLON.Vector3(0, 0, 0);
  794. var mat = BABYLON.Matrix.FromArray(node.matrix);
  795. mat.decompose(scaling, rotation, position);
  796. // Y is Up
  797. if (GLTFFileLoader.MakeYUP) {
  798. rotation = rotation.multiply(new BABYLON.Quaternion(-0.707107, 0, 0, 0.707107));
  799. }
  800. configureNode(newNode, position, rotation, scaling);
  801. if (newNode instanceof BABYLON.TargetCamera) {
  802. newNode.setTarget(BABYLON.Vector3.Zero());
  803. }
  804. }
  805. else {
  806. configureNode(newNode, BABYLON.Vector3.FromArray(node.translation), BABYLON.Quaternion.FromArray(node.rotation), BABYLON.Vector3.FromArray(node.scale));
  807. }
  808. };
  809. /**
  810. * Imports a node
  811. */
  812. var importNode = function (gltfRuntime, node, id) {
  813. var lastNode = null;
  814. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  815. if (gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name) === -1) {
  816. return null;
  817. }
  818. }
  819. // Meshes
  820. if (node.skin) {
  821. if (node.meshes) {
  822. var skin = gltfRuntime.skins[node.skin];
  823. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  824. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  825. if (newMesh.skeleton === null) {
  826. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton);
  827. if (!skin.babylonSkeleton) {
  828. skin.babylonSkeleton = newMesh.skeleton;
  829. }
  830. }
  831. if (newMesh.skeleton !== null) {
  832. newMesh.useBones = true;
  833. }
  834. lastNode = newMesh;
  835. }
  836. }
  837. else if (node.meshes) {
  838. /**
  839. * Improve meshes property
  840. */
  841. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  842. lastNode = newMesh;
  843. }
  844. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  845. var light = gltfRuntime.lights[node.light];
  846. if (light) {
  847. if (light.type === "ambient") {
  848. var ambienLight = light[light.type];
  849. var hemiLight = new BABYLON.HemisphericLight(node.light, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  850. hemiLight.name = node.name;
  851. if (ambienLight.color) {
  852. hemiLight.diffuse = BABYLON.Color3.FromArray(ambienLight.color);
  853. }
  854. lastNode = hemiLight;
  855. }
  856. else if (light.type === "directional") {
  857. var directionalLight = light[light.type];
  858. var dirLight = new BABYLON.DirectionalLight(node.light, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  859. dirLight.name = node.name;
  860. if (directionalLight.color) {
  861. dirLight.diffuse = BABYLON.Color3.FromArray(directionalLight.color);
  862. }
  863. lastNode = dirLight;
  864. }
  865. else if (light.type === "point") {
  866. var pointLight = light[light.type];
  867. var ptLight = new BABYLON.PointLight(node.light, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  868. ptLight.name = node.name;
  869. if (pointLight.color) {
  870. ptLight.diffuse = BABYLON.Color3.FromArray(pointLight.color);
  871. }
  872. lastNode = ptLight;
  873. }
  874. else if (light.type === "spot") {
  875. var spotLight = light[light.type];
  876. var spLight = new BABYLON.SpotLight(node.light, BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), 0, 0, gltfRuntime.scene);
  877. spLight.name = node.name;
  878. if (spotLight.color) {
  879. spLight.diffuse = BABYLON.Color3.FromArray(spotLight.color);
  880. }
  881. if (spotLight.fallOfAngle) {
  882. spLight.angle = spotLight.fallOfAngle;
  883. }
  884. if (spotLight.fallOffExponent) {
  885. spLight.exponent = spotLight.fallOffExponent;
  886. }
  887. lastNode = spLight;
  888. }
  889. }
  890. }
  891. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  892. var camera = gltfRuntime.cameras[node.camera];
  893. if (camera) {
  894. if (camera.type === "orthographic") {
  895. var orthographicCamera = camera[camera.type];
  896. var orthoCamera = new BABYLON.FreeCamera(node.camera, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  897. orthoCamera.name = node.name;
  898. orthoCamera.mode = BABYLON.Camera.ORTHOGRAPHIC_CAMERA;
  899. orthoCamera.attachControl(gltfRuntime.scene.getEngine().getRenderingCanvas());
  900. lastNode = orthoCamera;
  901. }
  902. else if (camera.type === "perspective") {
  903. var perspectiveCamera = camera[camera.type];
  904. var persCamera = new BABYLON.FreeCamera(node.camera, BABYLON.Vector3.Zero(), gltfRuntime.scene);
  905. persCamera.name = node.name;
  906. persCamera.attachControl(gltfRuntime.scene.getEngine().getRenderingCanvas());
  907. if (!perspectiveCamera.aspectRatio) {
  908. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  909. }
  910. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  911. persCamera.maxZ = perspectiveCamera.zfar;
  912. persCamera.minZ = perspectiveCamera.znear;
  913. }
  914. lastNode = persCamera;
  915. }
  916. }
  917. }
  918. // Empty node
  919. if (!node.jointName) {
  920. if (node.babylonNode) {
  921. return node.babylonNode;
  922. }
  923. else if (lastNode === null) {
  924. var dummy = new BABYLON.Mesh(node.name, gltfRuntime.scene);
  925. node.babylonNode = dummy;
  926. lastNode = dummy;
  927. }
  928. }
  929. if (lastNode !== null) {
  930. if (node.matrix) {
  931. configureNodeFromMatrix(lastNode, node);
  932. }
  933. else {
  934. configureNode(lastNode, BABYLON.Vector3.FromArray(node.translation), BABYLON.Quaternion.RotationAxis(BABYLON.Vector3.FromArray(node.rotation).normalize(), node.rotation[3]), BABYLON.Vector3.FromArray(node.scale));
  935. }
  936. lastNode.updateCache(true);
  937. node.babylonNode = lastNode;
  938. }
  939. return lastNode;
  940. };
  941. /**
  942. * Traverses nodes and creates them
  943. */
  944. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  945. var node = gltfRuntime.nodes[id];
  946. var newNode = null;
  947. if (gltfRuntime.importOnlyMeshes && !meshIncluded) {
  948. if (gltfRuntime.importMeshesNames.indexOf(node.name) !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  949. meshIncluded = true;
  950. }
  951. else {
  952. meshIncluded = false;
  953. }
  954. }
  955. else {
  956. meshIncluded = true;
  957. }
  958. if (!node.jointName && meshIncluded) {
  959. newNode = importNode(gltfRuntime, node, id);
  960. if (newNode !== null) {
  961. newNode.id = id;
  962. newNode.parent = parent;
  963. }
  964. }
  965. for (var i = 0; i < node.children.length; i++) {
  966. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  967. }
  968. };
  969. /**
  970. * Buffers loaded, create nodes
  971. */
  972. var onBuffersLoaded = function (gltfRuntime) {
  973. // Nodes
  974. var currentScene = gltfRuntime.currentScene;
  975. for (var i = 0; i < currentScene.nodes.length; i++) {
  976. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  977. }
  978. // Set animations
  979. loadAnimations(gltfRuntime);
  980. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  981. var skeleton = gltfRuntime.scene.skeletons[i];
  982. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  983. }
  984. };
  985. /**
  986. * On a buffer is loaded
  987. */
  988. var onLoadBuffer = function (gltfRuntime, buf) {
  989. return function (data) {
  990. gltfRuntime.loadedBuffers++;
  991. if (!(data instanceof ArrayBuffer)) {
  992. BABYLON.Tools.Error("Buffer named " + buf + " is not an array buffer");
  993. }
  994. else if (data.byteLength != gltfRuntime.buffers[buf].byteLength) {
  995. BABYLON.Tools.Error("Buffer named " + buf + " is length " + data.byteLength + ". Expected: " + gltfRuntime.buffers[buf].byteLength); // Improve error message
  996. }
  997. gltfRuntime.arrayBuffers[buf] = data;
  998. if (gltfRuntime.loadedBuffers === gltfRuntime.buffersCount) {
  999. onBuffersLoaded(gltfRuntime);
  1000. }
  1001. };
  1002. };
  1003. /**
  1004. * Error when loaded buffer
  1005. */
  1006. var onLoadBufferError = function (gltfRuntime, buf) {
  1007. return function () {
  1008. BABYLON.Tools.Error("Error when loading buffer named " + buf + " located at " + gltfRuntime.buffers[buf].uri);
  1009. };
  1010. };
  1011. /**
  1012. * Decode array buffer from base64
  1013. */
  1014. var decodeArrayBuffer = function (base64) {
  1015. var decodedString = atob(base64);
  1016. var bufferLength = decodedString.length;
  1017. var arraybuffer = new Uint8Array(new ArrayBuffer(bufferLength));
  1018. for (var i = 0; i < bufferLength; i++) {
  1019. arraybuffer[i] = decodedString.charCodeAt(i);
  1020. }
  1021. return arraybuffer.buffer;
  1022. };
  1023. /**
  1024. * Loads buffers (geometries)
  1025. */
  1026. var loadBuffers = function (gltfRuntime) {
  1027. for (var buf in gltfRuntime.buffers) {
  1028. var buffer = gltfRuntime.buffers[buf];
  1029. if (buffer) {
  1030. if (isBase64(buffer.uri)) {
  1031. var arrayBuffer = decodeArrayBuffer(buffer.uri.split(",")[1]);
  1032. onLoadBuffer(gltfRuntime, buf)(arrayBuffer);
  1033. }
  1034. else {
  1035. BABYLON.Tools.LoadFile(gltfRuntime.rootUrl + buffer.uri, onLoadBuffer(gltfRuntime, buf), null, null, true, onLoadBufferError(gltfRuntime, buf));
  1036. }
  1037. }
  1038. else {
  1039. BABYLON.Tools.Error("No buffer named : " + buf);
  1040. }
  1041. }
  1042. };
  1043. /**
  1044. * onBind shaderrs callback to set uniforms and matrices
  1045. */
  1046. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material) {
  1047. for (var unif in unTreatedUniforms) {
  1048. var uniform = unTreatedUniforms[unif];
  1049. var type = uniform.type;
  1050. if (type === EParameterType.FLOAT_MAT2 || type === EParameterType.FLOAT_MAT3 || type === EParameterType.FLOAT_MAT4) {
  1051. if (uniform.semantic && !uniform.source && !uniform.node) {
  1052. setMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  1053. }
  1054. else if (uniform.semantic && (uniform.source || uniform.node)) {
  1055. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node);
  1056. if (source === null) {
  1057. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node);
  1058. }
  1059. if (source === null) {
  1060. continue;
  1061. }
  1062. setMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  1063. }
  1064. }
  1065. else {
  1066. var value = material.values[technique.uniforms[unif]];
  1067. if (!value) {
  1068. continue;
  1069. }
  1070. if (type === EParameterType.SAMPLER_2D) {
  1071. var texture = gltfRuntime.textures[value].babylonTexture;
  1072. if (texture === null) {
  1073. continue;
  1074. }
  1075. shaderMaterial.getEffect().setTexture(unif, texture);
  1076. }
  1077. else {
  1078. setUniform(shaderMaterial.getEffect(), unif, value, type);
  1079. }
  1080. }
  1081. }
  1082. };
  1083. /**
  1084. * Prepare uniforms to send the only one time
  1085. * Loads the appropriate textures
  1086. */
  1087. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  1088. var materialValues = material.values;
  1089. var techniqueUniforms = technique.uniforms;
  1090. /**
  1091. * Prepare values here (not matrices)
  1092. */
  1093. for (var unif in unTreatedUniforms) {
  1094. var uniform = unTreatedUniforms[unif];
  1095. var type = uniform.type;
  1096. var value = materialValues[techniqueUniforms[unif]] || uniform.value;
  1097. if (!value) {
  1098. continue;
  1099. }
  1100. // Texture (sampler2D)
  1101. if (type === EParameterType.SAMPLER_2D) {
  1102. var texture = gltfRuntime.textures[value];
  1103. var sampler = gltfRuntime.samplers[texture.sampler];
  1104. if (!texture || !texture.source) {
  1105. continue;
  1106. }
  1107. var source = gltfRuntime.images[texture.source];
  1108. var newTexture = null;
  1109. var createMipMaps = (sampler.minFilter === ETextureFilterType.NEAREST_MIPMAP_NEAREST) ||
  1110. (sampler.minFilter === ETextureFilterType.NEAREST_MIPMAP_LINEAR) ||
  1111. (sampler.minFilter === ETextureFilterType.LINEAR_MIPMAP_NEAREST) ||
  1112. (sampler.minFilter === ETextureFilterType.LINEAR_MIPMAP_LINEAR);
  1113. var samplingMode = BABYLON.Texture.BILINEAR_SAMPLINGMODE;
  1114. if (isBase64(source.uri)) {
  1115. newTexture = new BABYLON.Texture(source.uri, gltfRuntime.scene, !createMipMaps, true, samplingMode, null, null, source.uri, true);
  1116. }
  1117. else {
  1118. newTexture = new BABYLON.Texture(gltfRuntime.rootUrl + source.uri, gltfRuntime.scene, !createMipMaps, true, samplingMode);
  1119. }
  1120. newTexture.wrapU = getWrapMode(sampler.wrapS);
  1121. newTexture.wrapV = getWrapMode(sampler.wrapT);
  1122. newTexture.name = value;
  1123. texture.babylonTexture = newTexture;
  1124. if (uniform.value) {
  1125. // Static uniform
  1126. shaderMaterial.setTexture(unif, newTexture);
  1127. delete unTreatedUniforms[unif];
  1128. }
  1129. }
  1130. else {
  1131. if (uniform.value && setUniform(shaderMaterial, unif, value, type)) {
  1132. // Static uniform
  1133. delete unTreatedUniforms[unif];
  1134. }
  1135. }
  1136. }
  1137. };
  1138. /**
  1139. * Shader compilation failed
  1140. */
  1141. var onShaderCompileError = function (program, shaderMaterial) {
  1142. return function (effect, error) {
  1143. BABYLON.Tools.Error("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  1144. shaderMaterial.dispose(true);
  1145. };
  1146. };
  1147. /**
  1148. * Shader compilation success
  1149. */
  1150. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  1151. return function (_) {
  1152. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  1153. shaderMaterial.onBind = function (mat, mesh) {
  1154. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material);
  1155. };
  1156. };
  1157. };
  1158. /**
  1159. * Returns the appropriate uniform if already handled by babylon
  1160. */
  1161. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  1162. for (var unif in technique.uniforms) {
  1163. var uniform = technique.uniforms[unif];
  1164. var uniformParameter = technique.parameters[uniform];
  1165. if (tokenizer.currentIdentifier === unif) {
  1166. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  1167. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  1168. if (transformIndex !== -1) {
  1169. delete unTreatedUniforms[unif];
  1170. return babylonTransforms[transformIndex];
  1171. }
  1172. }
  1173. }
  1174. }
  1175. return tokenizer.currentIdentifier;
  1176. };
  1177. /**
  1178. * All shaders loaded. Create materials one by one
  1179. */
  1180. var onShadersLoaded = function (gltfRuntime) {
  1181. // Create materials
  1182. for (var mat in gltfRuntime.materials) {
  1183. var material = gltfRuntime.materials[mat];
  1184. var technique = gltfRuntime.techniques[material.technique];
  1185. var program = gltfRuntime.programs[technique.program];
  1186. var states = technique.states;
  1187. var vertexShader = BABYLON.Effect.ShadersStore[program.vertexShader + "VertexShader"];
  1188. var pixelShader = BABYLON.Effect.ShadersStore[program.fragmentShader + "PixelShader"];
  1189. var newVertexShader = "";
  1190. var newPixelShader = "";
  1191. var vertexTokenizer = new Tokenizer(vertexShader);
  1192. var pixelTokenizer = new Tokenizer(pixelShader);
  1193. var unTreatedUniforms = {};
  1194. var uniforms = [];
  1195. var attributes = [];
  1196. var samplers = [];
  1197. // Fill uniform, sampler2D and attributes
  1198. for (var unif in technique.uniforms) {
  1199. var uniform = technique.uniforms[unif];
  1200. var uniformParameter = technique.parameters[uniform];
  1201. unTreatedUniforms[unif] = uniformParameter;
  1202. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  1203. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  1204. if (transformIndex !== -1) {
  1205. uniforms.push(babylonTransforms[transformIndex]);
  1206. delete unTreatedUniforms[unif];
  1207. }
  1208. else {
  1209. uniforms.push(unif);
  1210. }
  1211. }
  1212. else if (uniformParameter.type === EParameterType.SAMPLER_2D) {
  1213. samplers.push(unif);
  1214. }
  1215. else {
  1216. uniforms.push(unif);
  1217. }
  1218. }
  1219. for (var attr in technique.attributes) {
  1220. var attribute = technique.attributes[attr];
  1221. var attributeParameter = technique.parameters[attribute];
  1222. if (attributeParameter.semantic) {
  1223. attributes.push(getAttribute(attributeParameter));
  1224. }
  1225. }
  1226. // Configure vertex shader
  1227. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  1228. var tokenType = vertexTokenizer.currentToken;
  1229. if (tokenType !== ETokenType.IDENTIFIER) {
  1230. newVertexShader += vertexTokenizer.currentString;
  1231. continue;
  1232. }
  1233. var foundAttribute = false;
  1234. for (var attr in technique.attributes) {
  1235. var attribute = technique.attributes[attr];
  1236. var attributeParameter = technique.parameters[attribute];
  1237. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  1238. newVertexShader += getAttribute(attributeParameter);
  1239. foundAttribute = true;
  1240. break;
  1241. }
  1242. }
  1243. if (foundAttribute) {
  1244. continue;
  1245. }
  1246. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  1247. }
  1248. // Configure pixel shader
  1249. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  1250. var tokenType = pixelTokenizer.currentToken;
  1251. if (tokenType !== ETokenType.IDENTIFIER) {
  1252. newPixelShader += pixelTokenizer.currentString;
  1253. continue;
  1254. }
  1255. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  1256. }
  1257. // Create shader material
  1258. var shaderPath = {
  1259. vertex: program.vertexShader + mat,
  1260. fragment: program.fragmentShader + mat
  1261. };
  1262. var options = {
  1263. attributes: attributes,
  1264. uniforms: uniforms,
  1265. samplers: samplers,
  1266. needAlphaBlending: states.functions && states.functions.blendEquationSeparate
  1267. };
  1268. BABYLON.Effect.ShadersStore[program.vertexShader + mat + "VertexShader"] = newVertexShader;
  1269. BABYLON.Effect.ShadersStore[program.fragmentShader + mat + "PixelShader"] = newPixelShader;
  1270. var shaderMaterial = new BABYLON.ShaderMaterial(material.name, gltfRuntime.scene, shaderPath, options);
  1271. shaderMaterial.id = mat;
  1272. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial);
  1273. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  1274. if (states.functions) {
  1275. var functions = states.functions;
  1276. if (functions.cullFace && functions.cullFace[0] !== ECullingType.BACK) {
  1277. shaderMaterial.backFaceCulling = false;
  1278. }
  1279. var blendFunc = functions.blendFuncSeparate;
  1280. if (blendFunc) {
  1281. if (blendFunc[0] === EBlendingFunction.SRC_ALPHA && blendFunc[1] === EBlendingFunction.ONE_MINUS_SRC_ALPHA && blendFunc[2] === EBlendingFunction.ONE && blendFunc[3] === EBlendingFunction.ONE) {
  1282. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_COMBINE;
  1283. }
  1284. else if (blendFunc[0] === EBlendingFunction.ONE && blendFunc[1] === EBlendingFunction.ONE && blendFunc[2] === EBlendingFunction.ZERO && blendFunc[3] === EBlendingFunction.ONE) {
  1285. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_ONEONE;
  1286. }
  1287. else if (blendFunc[0] === EBlendingFunction.SRC_ALPHA && blendFunc[1] === EBlendingFunction.ONE && blendFunc[2] === EBlendingFunction.ZERO && blendFunc[3] === EBlendingFunction.ONE) {
  1288. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_ADD;
  1289. }
  1290. else if (blendFunc[0] === EBlendingFunction.ZERO && blendFunc[1] === EBlendingFunction.ONE_MINUS_SRC_COLOR && blendFunc[2] === EBlendingFunction.ONE && blendFunc[3] === EBlendingFunction.ONE) {
  1291. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_SUBTRACT;
  1292. }
  1293. else if (blendFunc[0] === EBlendingFunction.DST_COLOR && blendFunc[1] === EBlendingFunction.ZERO && blendFunc[2] === EBlendingFunction.ONE && blendFunc[3] === EBlendingFunction.ONE) {
  1294. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_MULTIPLY;
  1295. }
  1296. else if (blendFunc[0] === EBlendingFunction.SRC_ALPHA && blendFunc[1] === EBlendingFunction.ONE_MINUS_SRC_COLOR && blendFunc[2] === EBlendingFunction.ONE && blendFunc[3] === EBlendingFunction.ONE) {
  1297. shaderMaterial.alphaMode = BABYLON.Engine.ALPHA_MAXIMIZED;
  1298. }
  1299. }
  1300. }
  1301. }
  1302. // Finish
  1303. loadBuffers(gltfRuntime);
  1304. };
  1305. /**
  1306. * Shader loaded
  1307. */
  1308. var onLoadShader = function (gltfRuntime, sha) {
  1309. return function (data) {
  1310. gltfRuntime.loadedShaders++;
  1311. BABYLON.Effect.ShadersStore[sha + (gltfRuntime.shaders[sha].type === EShaderType.VERTEX ? "VertexShader" : "PixelShader")] = data;
  1312. if (gltfRuntime.loadedShaders === gltfRuntime.shaderscount) {
  1313. onShadersLoaded(gltfRuntime);
  1314. }
  1315. };
  1316. };
  1317. /**
  1318. * Error callback when loading a shader
  1319. */
  1320. var onLoadShaderError = function (gltfRuntime, sha) {
  1321. return function () {
  1322. BABYLON.Tools.Error("Error when loading shader program named " + sha + " located at " + gltfRuntime.shaders[sha].uri);
  1323. };
  1324. };
  1325. /**
  1326. * Load shaders
  1327. */
  1328. var load = function (gltfRuntime) {
  1329. // Begin with shaders
  1330. for (var sha in gltfRuntime.shaders) {
  1331. var shader = gltfRuntime.shaders[sha];
  1332. if (shader) {
  1333. if (isBase64(shader.uri)) {
  1334. var shaderString = atob(shader.uri.split(",")[1]);
  1335. onLoadShader(gltfRuntime, sha)(shaderString);
  1336. }
  1337. else {
  1338. BABYLON.Tools.LoadFile(gltfRuntime.rootUrl + shader.uri, onLoadShader(gltfRuntime, sha), null, null, false, onLoadShaderError(gltfRuntime, sha));
  1339. }
  1340. }
  1341. else {
  1342. BABYLON.Tools.Error("No shader file named " + shader.uri);
  1343. }
  1344. }
  1345. };
  1346. /**
  1347. * glTF File Loader Plugin
  1348. */
  1349. var GLTFFileLoader = (function () {
  1350. function GLTFFileLoader() {
  1351. /**
  1352. * Public members
  1353. */
  1354. this.extensions = ".gltf";
  1355. }
  1356. /**
  1357. * Import meshes
  1358. */
  1359. GLTFFileLoader.prototype.importMesh = function (meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons) {
  1360. var parsedData = JSON.parse(data);
  1361. var gltfRuntime = this._createGlTFRuntime(parsedData, scene, rootUrl);
  1362. gltfRuntime.importOnlyMeshes = true;
  1363. if (meshesNames === "") {
  1364. gltfRuntime.importMeshesNames = [];
  1365. }
  1366. else if (typeof meshesNames === "string") {
  1367. gltfRuntime.importMeshesNames = [meshesNames];
  1368. }
  1369. else if (meshesNames && !(meshesNames instanceof Array)) {
  1370. gltfRuntime.importMeshesNames = [meshesNames];
  1371. }
  1372. else {
  1373. gltfRuntime.importMeshesNames = [];
  1374. BABYLON.Tools.Warn("Argument meshesNames must be of type string or string[]");
  1375. }
  1376. // Create nodes
  1377. this._createNodes(gltfRuntime);
  1378. // Fill arrays of meshes and skeletons
  1379. for (var nde in gltfRuntime.nodes) {
  1380. var node = gltfRuntime.nodes[nde];
  1381. if (node.babylonNode instanceof BABYLON.AbstractMesh) {
  1382. meshes.push(node.babylonNode);
  1383. }
  1384. }
  1385. for (var skl in gltfRuntime.skins) {
  1386. var skin = gltfRuntime.skins[skl];
  1387. if (skin.babylonSkeleton instanceof BABYLON.Skeleton) {
  1388. skeletons.push(skin.babylonSkeleton);
  1389. }
  1390. }
  1391. // Load shaders and buffers to apply
  1392. load(gltfRuntime);
  1393. return true;
  1394. };
  1395. /**
  1396. * Load scene
  1397. */
  1398. GLTFFileLoader.prototype.load = function (scene, data, rootUrl) {
  1399. var parsedData = JSON.parse(data);
  1400. var gltfRuntime = this._createGlTFRuntime(parsedData, scene, rootUrl);
  1401. // Create nodes
  1402. this._createNodes(gltfRuntime);
  1403. // Load shaders and buffers to apply
  1404. load(gltfRuntime);
  1405. // Finish
  1406. return true;
  1407. };
  1408. // Creates nodes before loading buffers and shaders
  1409. GLTFFileLoader.prototype._createNodes = function (gltfRuntime) {
  1410. var currentScene = gltfRuntime.currentScene;
  1411. for (var i = 0; i < currentScene.nodes.length; i++) {
  1412. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1413. }
  1414. };
  1415. // Creates the gltfRuntime
  1416. GLTFFileLoader.prototype._createGlTFRuntime = function (parsedData, scene, rootUrl) {
  1417. var gltfRuntime = {
  1418. accessors: {},
  1419. buffers: {},
  1420. bufferViews: {},
  1421. meshes: {},
  1422. lights: {},
  1423. cameras: {},
  1424. nodes: {},
  1425. images: {},
  1426. textures: {},
  1427. shaders: {},
  1428. programs: {},
  1429. samplers: {},
  1430. techniques: {},
  1431. materials: {},
  1432. animations: {},
  1433. skins: {},
  1434. currentScene: {},
  1435. buffersCount: 0,
  1436. shaderscount: 0,
  1437. scene: scene,
  1438. dummyNodes: [],
  1439. loadedBuffers: 0,
  1440. loadedShaders: 0,
  1441. rootUrl: rootUrl,
  1442. importOnlyMeshes: false,
  1443. arrayBuffers: []
  1444. };
  1445. // Parse
  1446. if (parsedData.buffers) {
  1447. parseBuffers(parsedData.buffers, gltfRuntime);
  1448. }
  1449. if (parsedData.bufferViews) {
  1450. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  1451. }
  1452. if (parsedData.accessors) {
  1453. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  1454. }
  1455. if (parsedData.meshes) {
  1456. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  1457. }
  1458. if (parsedData.lights) {
  1459. parseObject(parsedData.lights, "lights", gltfRuntime);
  1460. }
  1461. if (parsedData.cameras) {
  1462. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  1463. }
  1464. if (parsedData.nodes) {
  1465. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  1466. }
  1467. if (parsedData.images) {
  1468. parseObject(parsedData.images, "images", gltfRuntime);
  1469. }
  1470. if (parsedData.textures) {
  1471. parseObject(parsedData.textures, "textures", gltfRuntime);
  1472. }
  1473. if (parsedData.shaders) {
  1474. parseShaders(parsedData.shaders, gltfRuntime);
  1475. }
  1476. if (parsedData.programs) {
  1477. parseObject(parsedData.programs, "programs", gltfRuntime);
  1478. }
  1479. if (parsedData.samplers) {
  1480. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  1481. }
  1482. if (parsedData.techniques) {
  1483. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  1484. }
  1485. if (parsedData.materials) {
  1486. parseObject(parsedData.materials, "materials", gltfRuntime);
  1487. }
  1488. if (parsedData.animations) {
  1489. parseObject(parsedData.animations, "animations", gltfRuntime);
  1490. }
  1491. if (parsedData.skins) {
  1492. parseObject(parsedData.skins, "skins", gltfRuntime);
  1493. }
  1494. if (parsedData.scene && parsedData.scenes) {
  1495. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  1496. }
  1497. return gltfRuntime;
  1498. };
  1499. /**
  1500. * Private members
  1501. */
  1502. // None
  1503. /**
  1504. * Static members
  1505. */
  1506. GLTFFileLoader.MakeYUP = false;
  1507. return GLTFFileLoader;
  1508. })();
  1509. BABYLON.GLTFFileLoader = GLTFFileLoader;
  1510. ;
  1511. BABYLON.SceneLoader.RegisterPlugin(new GLTFFileLoader());
  1512. })(BABYLON || (BABYLON = {}));
  1513. //# sourceMappingURL=babylon.glTFFileLoader.js.map