TextureType.hx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package hrt.impl;
  2. @:enum
  3. abstract TextureType(String) from String to String {
  4. var gradient;
  5. var path; // Not used as a type inside the json (the playload is a string), default value
  6. }
  7. class Utils {
  8. public static function getTextureFromValue(val : Any) : h3d.mat.Texture {
  9. if (Std.isOfType(val, String)) {
  10. var t = hxd.res.Loader.currentInstance.load(val).toTexture();
  11. t.wrap = Repeat;
  12. return t;
  13. }
  14. else if (Type.typeof(val) == TObject) {
  15. var val = (val:Dynamic);
  16. if (val.type != null && Std.isOfType(val.type, String)) {
  17. switch((val.type:String):TextureType) {
  18. case TextureType.gradient:
  19. {
  20. if (Reflect.hasField(val.data, "stops") && Reflect.hasField(val.data, "resolution")) {
  21. var t = Gradient.textureFromData(val.data);
  22. return t;
  23. }
  24. }
  25. default:
  26. }
  27. }
  28. }
  29. return null;
  30. }
  31. public static function copyTextureData(val : Any) : Any {
  32. if (Type.typeof(val) == TObject)
  33. return haxe.Json.parse(haxe.Json.stringify(val));
  34. return val;
  35. }
  36. }