Adding a 3DS model with a texture

Started by OneManSitting, October 27, 2012, 11:52:55 PM

Previous topic - Next topic

OneManSitting

 :P

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

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


Then in the onSurfaceChanged method
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.


OneManSitting

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?


OneManSitting

#3

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

EgonOlsen

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.

OneManSitting

#5

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

OneManSitting

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

EgonOlsen

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.

OneManSitting

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/

EgonOlsen

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


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:


getResources().openRawResource(R.raw.yourfilename);