Author Topic: [solved] When to load the models?  (Read 2387 times)

Offline indigo

  • byte
  • *
  • Posts: 4
    • View Profile
[solved] When to load the models?
« on: December 01, 2012, 11:24:00 pm »
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
Code: [Select]
model = Primitives.getBox(1.f, 1.f);
However, if I try and load an actual model like this:
Code: [Select]
InputStream in = Resources.getSystem().openRawResource(R.raw.model);
model = Loader.load3DS(in, 1.f)[0];

I run into problems:
Code: [Select]
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.
« Last Edit: December 01, 2012, 11:38:38 pm by indigo »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: When to load the models?
« Reply #1 on: December 01, 2012, 11:28:55 pm »
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.

Offline indigo

  • byte
  • *
  • Posts: 4
    • View Profile
Re: When to load the models?
« Reply #2 on: December 01, 2012, 11:38:26 pm »
Ah, thanks. I forgot I could just pass the context around. :)