Author Topic: No success with importing 3ds into Project  (Read 1289 times)

Offline higgs

  • byte
  • *
  • Posts: 6
    • View Profile
No success with importing 3ds into Project
« on: August 14, 2013, 12:51:14 pm »
Hi,
im an absolute beginner with jpct-ae and now trying to import a .3ds file, which i made in blender (its already got a texture).

I was reading in this forum for quite some time and in the API of jpct but didnt succeed to get it work.

I already managed to get my app run, showing a cube, that can be turned by touch, now i just want to replace this cube by my .3ds file.

I read a comment somewhere in this forum, that the .3ds file should be in res/raw folder, is this correct?
And what code do i have to use to import the .3ds?

Till now, my code looks like this (excerpt)

Code: [Select]
[...]
Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(masterContext.getResources().getDrawable(R.drawable.ic_launcher)), 64, 64));
TextureManager.getInstance().addTexture("ic_launcher", texture);
cube = Primitives.getCube(10);
cube.calcTextureWrapSpherical();
cube.setTexture("ic_launcher");
cube.strip();
cube.build();
world.addObject(cube);
[...]

I tried to load the file via the loadModel-method from the API:

Code: [Select]
private Object3D loadModel(String filename, float scale) throws IOException {

InputStream stream = mContext.getAssets().open("cube.3ds");
     Object3D[] model = Loader.load3DS(stream, scale);
     Object3D o3d = new Object3D(0);
     Object3D temp = null;
     for (int i = 0; i < model.length; i++) {
         temp = model[i];
         temp.setCenter(SimpleVector.ORIGIN);
         temp.rotateX((float)( -.5*Math.PI));
         temp.rotateMesh();
         temp.setRotationMatrix(new Matrix());
         o3d = Object3D.mergeObjects(o3d, temp);
         o3d.build();
     }
     return o3d;
 }

I have no clue, if this is the right approach.
   
My .3ds file is very small, I think like 1KB (its just a cube also), so it should work without renaming it to .mp3.

Thanks for the help.

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: No success with importing 3ds into Project
« Reply #1 on: August 14, 2013, 02:47:44 pm »
This is what you need to load a .3ds file (in res/raw):

Code: [Select]
Object3D model = Object3D.mergeAll(Loader.load3DS(res.openRawResource(R.raw.model), scale));
world.addObject(model);
It it has a Texture:
Textures aren't packed in a .3ds file. You need to save the Texture (as a .png for example) and copy it in the assets or res/raw.
This should work then:
Code: [Select]
TextureManager tm = TextureManager.getInstance();
Object3D model = Object3D.mergeAll(Loader.load3DS(res.openRawResource(R.raw.model), scale));
tm.addTexture("model_texture",new Texture(res.openRawResource(R.raw.model_texture)));
model.setTexture("model_texture");
world.addObject(model);

Offline higgs

  • byte
  • *
  • Posts: 6
    • View Profile
Re: No success with importing 3ds into Project
« Reply #2 on: August 16, 2013, 11:40:06 am »
Thanks for the quick reply.
This code seems to work but I got the problem that res cannot be resolved. I tried to define it with
Code: [Select]
Resources res = getResources();
right before the Loader and importing

Code: [Select]
import android.content.res.Resources;
Then he suggests to create a method "getRessource". I dont think, that this is the right way.

Is there anything I forgot to import? Whats to do?

Thanks again.

Offline Yerst

  • byte
  • *
  • Posts: 38
    • View Profile
Re: No success with importing 3ds into Project
« Reply #3 on: August 16, 2013, 12:54:16 pm »
sry, i forgot about the resources.
You need the application context to get the resources.
You can get the application Context by calling this.getApplicationContext() in your (Main)Activity.
I hand over the Context to every class where i need it, not only the Resources, because they cannont access the assets folder.
To get the Resources do the following just call
Code: [Select]
Resources res = context.getResources() in your class.

P.S.: If you didn't already know, just press Strg+Shift+O and eclipse will import everything you need.
« Last Edit: August 16, 2013, 01:27:07 pm by Yerst »

Offline higgs

  • byte
  • *
  • Posts: 6
    • View Profile
Re: No success with importing 3ds into Project
« Reply #4 on: August 26, 2013, 04:35:01 pm »
Hi,
sorry for the late reply, but I dont get it managed.

I tried to get the Context by writing this.getApplicationContext(), but I just get a proposal to built a so called method.
My MyRenderer - method is looking like this:
Code: [Select]
public MyRenderer(JPCTAESkeletonActivity master, Context context) {

this.masterActivity=master;
this.masterContext=context;

 }

I hope this is the right method.

Also, the "res"-fault disappears, putting  "Resources res = context.getResources();" in front of my import-code. Only fault left is that "context" cant be resolved. Any last ideas how to fix it?
Thanks a lot.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: No success with importing 3ds into Project
« Reply #5 on: August 26, 2013, 09:02:32 pm »
Try to explicitly import android.content.Context

Offline higgs

  • byte
  • *
  • Posts: 6
    • View Profile
Re: No success with importing 3ds into Project
« Reply #6 on: August 27, 2013, 01:18:16 pm »
already got that from the beginning.

Here is what I got

Code: [Select]
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.content.res.Resources;
import android.opengl.GLSurfaceView;

import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Light;
import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.MemoryHelper;

I got my code partially from a sample code and Im wondering whats the difference between context and masterContext. So Im asking myself if masterContext is necessary or if it "constricts" the "normal" context.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: No success with importing 3ds into Project
« Reply #7 on: August 27, 2013, 03:29:07 pm »
I think that i lost track somehow...what *exactly* is the actual problem here?

Offline higgs

  • byte
  • *
  • Posts: 6
    • View Profile
Re: No success with importing 3ds into Project
« Reply #8 on: August 27, 2013, 05:53:19 pm »
originally I wanted to import a 3ds-modell.

Yerst gave me some code that seems to work, but I cant access my 3ds file in res/raw (res can not be resolved) (context has to get resources). Now, Yerst told me to put Resources res = context.getResources() in front of my 3ds import. Now, context cant be resolved. In Addition, he told me to call  this.getApplicationContext() in my main activity, but that doesnt seem to work neither.

So now, my only fault is that context cant be resolved in Resources res = context.getResources().

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: No success with importing 3ds into Project
« Reply #9 on: August 27, 2013, 05:58:45 pm »
this.getApplicationContext().getResources();