stuartcaunt / isgl3d

iOS Scene Graph Library: a 3D framework for the iPhone, iPad and iPod touch
http://isgl3d.com
Other
108 stars 46 forks source link

Isgl3dPODImporter: Support loading textures from outside Main Bundle #42

Open DavidYKay opened 12 years ago

DavidYKay commented 12 years ago

Use Case

Downloading models(POD) and textures(PNG) over the network.

Originally, I had the problem of loading POD models with an absolute path in #10. @HolgerW1 since fixed model loading in 972f0c8831de1bfd68db7e56e0d362407570e404 (see podImporterWithResource), but textures do not yet work with absolute paths.

The Problem

modifyTexture calls all the way down to [[NSBundle mainBundle] pathForResource:fileName ofType:extension], which only looks inside the bundle folder.

Meanwhile, I can't download and save my textures to the bundle, only to Documents/.

The call stack, for reference:

These are not the final word, but what I've thought of so far.

Either:

  1. Allow user to pass in an absolute path to modifyTexture:withTexture
    • This is a bit messy, since we'll have to modify TONS of code going down the stack to use absolute paths.
  2. Allow user to pass in a texture to modifyTexture:withTexture
    • since Isgl3dTextureMaterial can be created with a UIImage, I could create a UIImage from my Documents/ folder and pass that into Isgl3dTextureMaterial.
    • This would result in less code changed, but it'd complicate the Isgl3dPODImporter API.
  3. ?

    Conclusion

Once we agree on a strategy, I'd be happy to implement the code. In fact, I think I might start playing around with the second option right now to see how tricky it will be.

HolgerW1 commented 12 years ago

I would suggest to modify and extend the Isgl3dGLTextureFactory, Isgl3dTextureMaterial and Isgl3dPODImporter class to support both loading textures from absolute file paths and from the bundle resource files. The current methods involved could need some refactoring anyways because the naming isn't very intuitive and self explaining.

Even though the method "loadImage:(NSString )path" is private and thus not visible a better name would be "loadImageFromPath:(NSString )filePath" to clearly indicate that it expects a full path name as the first parameter. An additional method "loadIamgeFromResource:(NSString *)name" could be added to provide a mechanism to load bundle resources for which the full path name is determined via [NSBundle pathForResource:ofType:]

Same rule applies to "createTextureFromFile" / "createTextureFromCompressedFile" and all corresponding methods of "Isgl3dTextureMaterial" which should take absolute file paths instead of resource names.

I'm gonna add this to my todo list but feel free to start implementing / sending a pull request.

DavidYKay commented 12 years ago

Great!

I should be sitting down with this on Monday.

Thanks again for a wonderful library.

graylikeme commented 12 years ago

Is anyone working on this? If not I'm on to the task

DavidYKay commented 12 years ago

Stanislav,

Priorities at work moved in a different direction so I haven't been able to tackle it. If you're able to, please be my guest!

David Young-Chan Kay http://gravatar.com/DavidYKay DavidYKay@gmail.com

On Tuesday, May 15, 2012 at 10:37 AM, Stanislav Ageev wrote:

Is anyone working on this? If not I'm on to the task


Reply to this email directly or view it on GitHub: https://github.com/isgl3d/isgl3d/issues/42#issuecomment-5717402