How to set texture importing settings from gdscript and how to set a default setting?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 2plus2makes5

I want pixel art looking sprite3d so i want textures to be loseless and unfiltered, how do i set that from gdscript?

If i use load/preload the result is almost always filtered.

Another thing, in the editor i set my default setting for importing images but when i want to import an image there are always godot’s default settings and i have to manually load my default settings, shouldn’t be automatic?

EDIT:

I’m talking about the import dock settings.

About the code I have investigated a little and the problem might be that in the .import folder there are 3 files for the same image, the s3tc.stex, etc2.stex and .stex, the .stex is the one with my settings while the other 2 have default settings, in fact only if from code i load the .stex instead instead of the .png(or the s3tc.tex or the etc2.tex) i get the result i want, otherwise the result is filtered, but i don’t want to deal with any of those stex files that have really long and complex names! I want to use the .png filenames in the code.

If i disable s3tc and etc2 in the settings and delete those files godot sometimes doesn’t debug because it says it needs them and when i try to use not yet imported files godot says they aren’t resources and doesn’t open them.

I’m on windows 10 64bits and godot 3.0.2 but i’m pretty sure i had the import dock problem on 3.0.0 too.

:bust_in_silhouette: Reply From: Zylann

This problem has been solved already: Disabling Filter for non-blurry pixel art not working in 3.0 - Archive - Godot Forum

However, on the question specifically, I would be curious myself to know how to set import settings, especially when images are generated by tools… but I’m not sure if that was your real intention.

I’m talking about the import dock settings.

About the code I have investigated a little and the problem might be that in the .import folder there are 3 files for the same image, the s3tc.stex, etc2.stex and .stex, the .stex is the one with my settings while the other 2 have default settings, in fact only if from code i load the .stex instead instead of the .png(or the s3tc.tex or the etc2.tex) i get the result i want, otherwise the result is filtered, but i don’t want to deal with any of those stex files that have really long and complex names! I want to use the .png filenames in the code.

If i disable s3tc and etc2 in the settings and delete those files godot sometimes doesn’t debug because it says it needs them and when i try to use not yet imported files godot says they aren’t resources and doesn’t open them.

2plus2makes5 | 2018-04-07 16:42

I don’t think you should be loading the .stex files manually, these are used depending on which platform you are exporting your game for.

For filtering, it’s a common option located in the .import file, which you can either set in the import dock, or make it the default preset for texture resources as I linked in my answer.
Note that making this option the default will not retroactively update all textures you already imported, so you will either need to clear their import files to trigger a reimport with defaults, or set the options yourself.

If after you do this you still have filtered images, then it’s a bug.

Zylann | 2018-04-08 16:24

It’s probably a bug because my preset settings show neither with old textures nor with new ones, i always have to choose the preset option to set the options i want.

In the .import files of the files with problems there are usually references first to .stex with godot settings and then to the one with my settings, the problem is probably that godot considers the first one that usually has godot settings.

I guess i could edit all the .import files but i would like a more streamlined and automatic process.

Thanks for the answer :slight_smile:

2plus2makes5 | 2018-04-12 11:21

:bust_in_silhouette: Reply From: jpate

I think you need to parse the .import file manually and update it…

e.g. read the import file:

func _get_import_settings() -> Dictionary:
	var import_settings = {}
	var f := File.new()
	var import_filename := "%s.import" % [get_source_file()]
	var err := f.open(import_filename, File.READ)
	var section = {}
	while !f.eof_reached():
		var l := f.get_line()
		if l.begins_with('[') && l.ends_with(']'):
			section = {}
			import_settings[l.substr(1, len(l) - 2)] = section
		else:
			var parts = l.split('=', true, 1)
			if len(parts) > 1:
				section[parts[0]] = parts[1]
	f.close()
	print(import_settings)
	return import_settings

And then update the setting and do the reverse to save it…

then if you want to auto-reimport you need super duper hack if you aren’t writing a plugin…

func re_import():
	if Engine.editor_hint:
		var mi := get_node_or_null(mesh_path) as MeshInstance
		if !mi:
			return
		var mesh := mi.mesh as ArrayMesh
		if !mesh:
			return
		var bc: Control
		for c in get_tree().root.get_node('EditorNode').get_children():
			if c.is_class('EditorInterface'):
				c.edit_resource(mesh)
				c.inspect_object(self)
				bc = c.get_base_control()
				break
		if bc:
			# super duper big hack
			var import = bc.find_node('Import', true, false)
			if import:
				import._reimport()