Author Topic: Adding a 3DS model with a texture  (Read 1918 times)

Offline OneManSitting

  • byte
  • *
  • Posts: 9
    • View Profile
Adding a 3DS model with a texture
« on: October 27, 2012, 11:52:55 pm »
 :P

I have the texture in jpctLoadModel02/res/drawable-hdpi called leaf1.jpg and the leaf1.3ds file in jpctLoadModel02 default folder.

Code: [Select]
String[] leafTexture = {"leaf1"};
String leafModelName = "leaf1.3ds";
InputStream isLeaf;
Object3D[] leafModel;

Then in the onSurfaceChanged method
Code: [Select]
Texture leafTex = new Texture(600,600);
        for (int i = 0; i < leafTexture.length; ++i) {
            TextureManager.getInstance().addTexture("res/"+leafTexture[i] + ".jpg");
        }
//Modelname string to inputstream
try {isLeaf = new ByteArrayInputStream(leafModelName.getBytes("UTF-8"));
      } catch (UnsupportedEncodingException e) {
         e.printStackTrace(); }

   leafModel = Loader.load3DS(isLeaf,1);
   Camera cam = world.getCamera();
   cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
   SimpleVector sv = new SimpleVector();
        for (int i = 0; i < leafModel.length; ++i) {
        leafModel[i].build();
world.addObject(leafModel[i]);
cam.lookAt(leafModel[i].getTransformedCenter());
sv.set(leafModel[i].getTransformedCenter());
        }

 In the logcat it shows as:
10-27 21:33:22.549: E/AndroidRuntime(401): FATAL EXCEPTION: main
10-27 21:33:22.549: E/AndroidRuntime(401): java.lang.NoClassDefFoundError: com.threed.jpct.RGBColor
10-27 21:33:22.549: E/AndroidRuntime(401):    at ian.capstone.JpctLoadModel02Activity.<init>(JpctLoadModel02Activity.java:54)
10-27 21:33:22.549: E/AndroidRuntime(401):    at java.lang.Class.newInstanceImpl(Native Method)
10-27 21:33:22.549: E/AndroidRuntime(401):    at java.lang.Class.newInstance(Class.java:1409)
10-27 21:33:22.549: E/AndroidRuntime(401):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
10-27 21:33:22.549: E/AndroidRuntime(401):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1536)
10-27 21:33:22.549: E/AndroidRuntime(401):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
10-27 21:33:22.549: E/AndroidRuntime(401):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-27 21:33:22.549: E/AndroidRuntime(401):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
10-27 21:33:22.549: E/AndroidRuntime(401):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-27 21:33:22.549: E/AndroidRuntime(401):    at android.os.Looper.loop(Looper.java:123)
10-27 21:33:22.549: E/AndroidRuntime(401):    at android.app.ActivityThread.main(ActivityThread.java:3647)
10-27 21:33:22.549: E/AndroidRuntime(401):    at java.lang.reflect.Method.invokeNative(Native Method)
10-27 21:33:22.549: E/AndroidRuntime(401):    at java.lang.reflect.Method.invoke(Method.java:507)
10-27 21:33:22.549: E/AndroidRuntime(401):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-27 21:33:22.549: E/AndroidRuntime(401):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-27 21:33:22.549: E/AndroidRuntime(401):    at dalvik.system.NativeStart.main(Native Method)

Am i suppose to use another kind of Loader method or am i just looping through them incorrectly. I thought i would only get one Object3d file and then add that into the world, but it always crashes on me.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Adding a 3DS model with a texture
« Reply #1 on: October 28, 2012, 12:13:02 am »
Problem is in ADB. This is solution http://www.jpct.net/forum2/index.php/topic,2663.0.html

Offline OneManSitting

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Adding a 3DS model with a texture
« Reply #2 on: November 08, 2012, 07:16:25 pm »
Ok i updated and changed the libs folder but now i get this error.

11-08 13:09:01.397: E/AndroidRuntime(370): java.lang.RuntimeException: [ 1352398141349 ] - ERROR: Not a valid 3DS file!
11-08 13:09:01.397: E/AndroidRuntime(370):    at com.threed.jpct.Logger.log(Logger.java:189)
11-08 13:09:01.397: E/AndroidRuntime(370):    at com.threed.jpct.Loader.load3DS(Loader.java:1462)

Anyone run into this before?


Offline OneManSitting

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Adding a 3DS model with a texture
« Reply #3 on: November 08, 2012, 09:23:34 pm »
Code: [Select]

TextureManager.getInstance().addTexture(leafTexture);

InputStream is = new ByteArrayInputStream(leafModelName.getBytes());
   
System.out.println("loaded");   
leafModel = Loader.load3DS(isLeaf,1);
       
        Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
SimpleVector sv = new SimpleVector();
        for (int i = 0; i < leafModel.length; ++i) {
        leafModel[i].build();
world.addObject(leafModel[i]);
cam.lookAt(leafModel[i].getTransformedCenter());
sv.set(leafModel[i].getTransformedCenter());
        }

11-08 15:18:30.797: E/AndroidRuntime(481): java.lang.RuntimeException: [ 1352405910765 ] - ERROR: Couldn't read file from InputStream

I tried to use a string but it wont let me, but i get an error that says only a string is allowed.

Do i need to create a jar file like in this post?
http://www.jpct.net/forum2/index.php/topic,475.0.html
« Last Edit: November 08, 2012, 09:33:32 pm by OneManSitting »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Adding a 3DS model with a texture
« Reply #4 on: November 08, 2012, 09:36:17 pm »
That's not how it works. You have to give it the inputstream to the file, not the one to the name if the file. Files belong to res or assets and you can get the stream to them by using the different means Android provides for this.

Offline OneManSitting

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Adding a 3DS model with a texture
« Reply #5 on: November 08, 2012, 10:04:15 pm »
Code: [Select]

 try {
InputStream isLeaf = new FileInputStream("C:/Users/Ian/workspace/jpctLoadModel02/3ds/lilacleaf1.3ds");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
     
leafModel = Loader.load3DS(isLeaf,1);

Like this? Oh well i will keep plugging away  :o

still getting the same thing in logcat
« Last Edit: November 08, 2012, 10:09:23 pm by OneManSitting »

Offline OneManSitting

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Adding a 3DS model with a texture
« Reply #6 on: November 08, 2012, 10:31:33 pm »
I guess there is something wrong with my file system now.... I get a little red x on my 3ds folder.

http://imgur.com/vJORL

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Adding a 3DS model with a texture
« Reply #7 on: November 08, 2012, 10:43:52 pm »
No, that's bogus on Android. You can't access your files that way. As said, you have to put them in res or assets in your Android project. Please have a look at the Android docs and tutorials to get an idea of how to deal with files on Android. It's different from what you do on the desktop.

Offline OneManSitting

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Adding a 3DS model with a texture
« Reply #8 on: November 09, 2012, 08:54:26 pm »
I found this example that makes the 3ds file into a xml file. Still cant get it to work properly though.

http://www.bayninestudios.com/2011/01/importing-3d-models-in-android/

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Adding a 3DS model with a texture
« Reply #9 on: November 09, 2012, 09:15:27 pm »
No, you are overcomplicating things...it actually drop dead simple. Copy your 3ds files into the assets directory of your project (if there is none, create one). Then, in your Activity, do

Code: [Select]
getResources().getAssets().open("yourfilename.3ds");

to get the InputStream for the file. You can also put the files into res/raw. Then, it goes like this:

Code: [Select]
getResources().openRawResource(R.raw.yourfilename);