import.gd 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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(_path, 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_import_order():
  29. return ResourceImporter.IMPORT_ORDER_DEFAULT
  30. func _get_option_visibility(path, option, options):
  31. return true
  32. func _import(source_file, save_path, options, r_platform_variants, r_gen_files):
  33. var file = FileAccess.open(source_file, FileAccess.READ)
  34. var line = file.get_line()
  35. var channels = line.split(",")
  36. if channels.size() != 3:
  37. return ERR_PARSE_ERROR
  38. var color = Color8(int(channels[0]), int(channels[1]), int(channels[2]))
  39. var material = StandardMaterial3D.new()
  40. if options.use_red_anyway:
  41. color = Color8(255, 0, 0)
  42. material.albedo_color = color
  43. return ResourceSaver.save(material, "%s.%s" % [save_path, _get_save_extension()])