import.gd 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. tool
  2. extends EditorImportPlugin
  3. enum Presets { PRESET_DEFAULT }
  4. func get_importer_name():
  5. return "demos.sillymaterial"
  6. func get_visible_name():
  7. return "Silly Material"
  8. func get_recognized_extensions():
  9. return ["mtxt"]
  10. func get_save_extension():
  11. return "res"
  12. func get_resource_type():
  13. return "Material"
  14. func get_preset_count():
  15. return Presets.size()
  16. func get_preset_name(preset):
  17. match preset:
  18. Presets.PRESET_DEFAULT: return "Default"
  19. _: return "Unknown"
  20. func get_import_options(preset):
  21. match preset:
  22. Presets.PRESET_DEFAULT:
  23. return [{
  24. "name": "use_red_anyway",
  25. "default_value": false
  26. }]
  27. _: return []
  28. func get_option_visibility(option, options):
  29. return true
  30. func import(source_file, save_path, options, r_platform_variants, r_gen_files):
  31. var file = File.new()
  32. var err = file.open(source_file, File.READ)
  33. if err != OK:
  34. return err
  35. var line = file.get_line()
  36. file.close()
  37. var channels = line.split(",")
  38. if channels.size() != 3:
  39. return ERR_PARSE_ERROR
  40. var color = Color8(int(channels[0]), int(channels[1]), int(channels[2]))
  41. var material = SpatialMaterial.new()
  42. if options.use_red_anyway:
  43. color = Color8(255, 0, 0)
  44. material.albedo_color = color
  45. return ResourceSaver.save("%s.%s" % [save_path, get_save_extension()], material)