[solved] When to load the models?

Started by indigo, December 01, 2012, 11:24:00 PM

Previous topic - Next topic

indigo

Hi all,
My question would basically be when it is a good idea to load the models? I am playing around with a very small test App (just the MainActivity and a MyRenderer implementing Renderer). Right now, I trying to create my Object3Ds in MyRenderer's OnSurfaceCreated method. This works fine as long as I do something primitive like
model = Primitives.getBox(1.f, 1.f);

However, if I try and load an actual model like this:
InputStream in = Resources.getSystem().openRawResource(R.raw.model);
model = Loader.load3DS(in, 1.f)[0];


I run into problems:
Exception android.content.res.Resources$NotFoundException(<No current context>)
  breakpoint hit in android.opengl.GLSurfaceView$GLThread at line 1244 by thread <11> GLThread 81.


Apparently, this is the case because the Resources are only available from the Activity, not from the Renderer. On the other hand, the Renderer is where my World and all the other goodness is at, so loading it from the Activity is not viable either. What is the preferred way of going about this?

Thanks in advance.

EgonOlsen

I tend to do it either in the Activity itself for simple cases or wrap resource loading methods into some class that gets the current context injected from the Activity.

indigo

Ah, thanks. I forgot I could just pass the context around. :)