import.gd 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. @tool
  2. extends EditorImportPlugin
  3. enum Preset {
  4. PRESET_DEFAULT,
  5. }
  6. func _get_importer_name() -> String:
  7. return "demos.sillymaterial"
  8. func _get_visible_name() -> String:
  9. return "Silly Material"
  10. func _get_recognized_extensions() -> PackedStringArray:
  11. return ["mtxt"]
  12. func _get_save_extension() -> String:
  13. return "res"
  14. func _get_resource_type() -> String:
  15. return "Material"
  16. func _get_preset_count() -> int:
  17. return Preset.size()
  18. func _get_preset_name(preset: Preset) -> String:
  19. match preset:
  20. Preset.PRESET_DEFAULT:
  21. return "Default"
  22. _:
  23. return "Unknown"
  24. func _get_import_options(_path: String, preset: Preset) -> Array[Dictionary]:
  25. match preset:
  26. Preset.PRESET_DEFAULT:
  27. return [{
  28. "name": "use_red_anyway",
  29. "default_value": false,
  30. }]
  31. _:
  32. return []
  33. func _get_import_order() -> int:
  34. return ResourceImporter.IMPORT_ORDER_DEFAULT
  35. func _get_option_visibility(path: String, option: StringName, options: Dictionary) -> bool:
  36. return true
  37. func _import(source_file: String, save_path: String, options: Dictionary, r_platform_variants: Array[String], r_gen_files: Array[String]) -> Error:
  38. var file := FileAccess.open(source_file, FileAccess.READ)
  39. var line := file.get_line()
  40. var channels := line.split(",")
  41. if channels.size() != 3:
  42. return ERR_PARSE_ERROR
  43. var color := Color8(int(channels[0]), int(channels[1]), int(channels[2]))
  44. var material := StandardMaterial3D.new()
  45. if options.use_red_anyway:
  46. color = Color8(255, 0, 0)
  47. material.albedo_color = color
  48. return ResourceSaver.save(material, "%s.%s" % [save_path, _get_save_extension()])