Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose load/import methods for use with file from user directory #17748

Closed
bartosz-m opened this issue Mar 24, 2018 · 16 comments
Closed

Expose load/import methods for use with file from user directory #17748

bartosz-m opened this issue Mar 24, 2018 · 16 comments
Labels

Comments

@bartosz-m
Copy link

Godot version:
3.0.2

Issue description:

I was trying to import audio "resources" from user directory using user:// but I could find how to do that from gdscript. load functions generates error for ogg,wav,opus

No loader found for resource: user://sample.ogg

I can successfully load file content as a PoolByteArray but I wasn't able to find a way to create from it usable resource.
I'm guessing that there are method that could import those file as resource at runtime, but are living in c++, so maybe they could get bindings for the gdscript side?

Steps to reproduce:
var user_sample = load("user://sample.ogg")

@LinuxUserGD
Copy link
Contributor

LinuxUserGD commented Mar 24, 2018

You could try to import the audio file under res:// and move the audio file together with the .import file to user://.
This may require editing the .import file manually.

@bartosz-m
Copy link
Author

Those files are generated at runtime so i don't think it is possible to import it that way (I'm new to godot so correct me if I'm wrong). But could it be possible to manually generate import files?

@LinuxUserGD
Copy link
Contributor

LinuxUserGD commented Mar 24, 2018

Ok, think that this is impossible now. The .import files are generated from the Godot Editor while tragging a file into the project directory, e. g. https://github.com/godotengine/godot-demo-projects/blob/master/2d/physics_platformer/music.ogg.import
But it seems like the .import file links to a .oggstr ressource that is only available on runtime.

@bartosz-m
Copy link
Author

Tell me if I understand correctly. Importing and resource generation is implemented as part of editor functionality and not game engine so it cannot be done at the runtime?

@hubslave
Copy link

hubslave commented Mar 26, 2018

In v3 you can't use any resource without first importing them (a process that loosy re-compresses the asset and put's it in the .import folder by default/recommended procedure) by design and from what I've seen the authors won't implement the direct access to assets as was the norm in v2 and requested multiple times here for no good reason they could give other than the ease of use by users (the developers needs don't matter) ...

In addition they are ignoring major bugs in the import system and not even notifying the users of them - for example: godotengine/godot-docs#1256 & #17726

Let's see how long are they going to take to fix or notify the developers about that "little" bug. And don't get me started on some other "features" they don't intend to even consider implementing alternatives of like this one here ...

@LinuxUserGD
Copy link
Contributor

LinuxUserGD commented Mar 26, 2018

Is it possible to initialize the import procedure at runtime via GDNative so the generated .import files could be saved in the user:// directory? Not sure about shortcuts...

This could solve #14954 because it won't be necessary anymore to package videos which makes the .pck smaller --> download and use assets at runtime

@mrcdk
Copy link
Contributor

mrcdk commented Mar 26, 2018

What you are trying to import isn't a resource that godot recognizes. Resources for godot are files that have been imported via any of the import mechanism there are and have extra information and metadata that the original file doesn't have.

For example, a imported .png will not only import it with whatever import options you give it but it will be automatically compressed and prepared for the different compress formats you select in the project settings. It doesn't modify the original .png file.

If you need to load a external file a successful loading will depend on what the file is but you will have to do it manually. The old 2.x import system wouldn't let you load it either.

You can load an external ogg file like:

func load_ogg(file):
	var path = "Z:\\godot_projects\\%s.ogg" % file
	var ogg_file = File.new()
	ogg_file.open(path, File.READ)
	var bytes = ogg_file.get_buffer(ogg_file.get_len())
	var stream = AudioStreamOGGVorbis.new()
	stream.data = bytes
	$AudioStreamPlayer.stream = stream
	ogg_file.close()

@bartosz-m
Copy link
Author

This is really helpful piece of code stream.data =. Base on that I was able to load .wav file. Thanks!

@hubslave
Copy link

hubslave commented Mar 27, 2018

@mrcdk For example, a imported .png will not only import it with whatever import options you give it but it will be automatically compressed and prepared for the different compress formats you select in the project settings. It doesn't modify the original .png file.

You should definitely double check you're comment because right now I can't use PNG files without importing them, and when I do using "Compress Lossless (PNG)" method the result is a Loosy compressed PNG file with data and quality lost during the import process (described with proof in 17726) ...

P.S. The decision to add extra data to each asset instead of using the obligatory extra files generated by the import process was probably the second biggest mistake in the new version right after changing the video engine without fallback method - they both need one and so far only one is getting such.

@LinuxUserGD
Copy link
Contributor

LinuxUserGD commented Mar 27, 2018

@bartosz-m Is this issue solved now? Maybe it's better to change the title to make clear if it's a feature request (@hubslave 's comment)

@bartosz-m
Copy link
Author

I've been able to overcome my problem and it looks like the main issue was different than that in the title I wrote. Problem was missing documentation for data property of audiostreams.
Now I've got a question should I change title of this issue or create new one.

@hubslave
Copy link

@LinuxUserGD The code provided by @mrcdk is just a solution for a part of the problem the author's are not willing to fix and labeling as "feature" and not a missing documentation problem - this will not be listed there unless the Godot engine policy changes. I'll not be surprised if this solution stops working in a future version and the reason is code labeled as bugfix ...

@LinuxUserGD
Copy link
Contributor

LinuxUserGD commented Mar 27, 2018

@hubslave There isn't just one solution for all assets, e. g. a video can't be compressed like a png but needs much space in the exported .pck #14954
So it's better to seperate documentation issues from issues in the engine's code.

And @mrcdk (contributor) fixed @bartosz-m problem two hours after your comment (--> documentation issue)

Image artifacts (#17726) should be an engine's issue.

And dynamically importing assets (media/ meshes) is a feature request, because Godot doesn't support it yet (--> Waiting for Godot)

Conclusion: Better close this issue and create seperate ones

@bartosz-m
Copy link
Author

Before closing this issue I would like to ask where create new one about missing documentation: here or on godot-docs?

@LinuxUserGD
Copy link
Contributor

godot-docs (not engine code specific)

@bartosz-m
Copy link
Author

As advised I'm closing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants