babylon.glTFLoaderUtils.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2. module BABYLON.GLTF2 {
  3. /**
  4. * Utils functions for GLTF
  5. */
  6. export class GLTFUtils {
  7. /**
  8. * If the uri is a base64 string
  9. * @param uri: the uri to test
  10. */
  11. public static IsBase64(uri: string): boolean {
  12. return uri.length < 5 ? false : uri.substr(0, 5) === "data:";
  13. }
  14. /**
  15. * Decode the base64 uri
  16. * @param uri: the uri to decode
  17. */
  18. public static DecodeBase64(uri: string): ArrayBuffer {
  19. const decodedString = atob(uri.split(",")[1]);
  20. const bufferLength = decodedString.length;
  21. const bufferView = new Uint8Array(new ArrayBuffer(bufferLength));
  22. for (let i = 0; i < bufferLength; i++) {
  23. bufferView[i] = decodedString.charCodeAt(i);
  24. }
  25. return bufferView.buffer;
  26. }
  27. public static ValidateUri(uri: string): boolean {
  28. return (uri.indexOf("..") === -1);
  29. }
  30. }
  31. }