Unsupported texture width

Started by oetzi, August 16, 2013, 04:51:34 PM

Previous topic - Next topic

oetzi

Hello,

I am very new to the general work with 3D objects as well as to jPCT.
Nevertheless, I got an app running, which displays a 3DS object, which I simply downloaded from http://archive3d.net/?a=download&id=527694d7 (I thought it might be a good idea to start with a very simple 3D object :) )

After being happy about this simple 3D object on my screen I have tried to load the related texture, but failed so far.
The error I get is "ERROR: Unsupported Texture width: 800"
I found several posts in this forum which deal with similar issues, but most of them were related to the use of drawables, which is not applicable for my case.

inputStream = masterContext.getAssets().open("3d-objects/ball/Ball N280313.3DS");
Texture texture = new Texture(masterContext.getAssets().open("3d-objects/ball/main_product_133750009413897300.jpg"));
TextureManager.getInstance().addTexture("main_product_133750009413897300.jpg", texture);


So, could anyone tell me, what I am doing wrong here?

Greetings,
oetzi





Yerst

Your texture sizes need to be a power of two. (2^n)
So just scale your texture to 512*512 for example, and it should work.

oetzi

Thanks Yerst, that solved indeed the problem. Although I am now a bit confused that only square textures can be used. Anyway.

Now that the texture is loaded sucessfully, I am facing the next problem. It is a bit off-topic, but hopefully you can help me with this too.
The texture is still not displayed and I assume that it simply has to do with the fact, that I do not use the correct name here for the first parameter:
TextureManager.getInstance().addTexture("main_product_133750009413897300.jpg", texture);
As mentioned before, I downloaded this 3D object from a website. That means that I do not know how the creator named the texture. I downloaded a zip file, which contains:
- Ball N280313.3DS
- Ball N280313.gsm
- main_product_133750009413897300.jpg

So the question is: How do I know which name I have to choose as first parameter in the addTexture() method?

Yerst

You need to assign the texture to the Object.
It doesn't matter how you name the texture, it just needs to be the same name you called it in the TextureManager.
yourBallModel.setTexture("ballTexture");
Or for your Current Name:
yourBallModel.setTexture("main_product_133750009413897300.jpg");

oetzi

Ah, now I see the logic. Thanks a lot!
And if my object consists of more than one part, I probably have to choose the correct order of the textures. I will try it now.

oetzi

mhh, I don't get it...

I took another 3DS object which contains of 3 parts.
Therefore I registered the following 3 textures:

inputStream = masterContext.getAssets().open("3d-objects/RackForFlowers/Rack for flowers N020813.3DS");
TextureManager.getInstance().addTexture("dirt", new Texture(masterContext.getAssets().open("3d-objects/RackForFlowers/textures/Archmodels66_dirt_1.jpg")));
TextureManager.getInstance().addTexture("leaf", new Texture(masterContext.getAssets().open("3d-objects/RackForFlowers/textures/Archmodels66_leaf_30.jpg")));
TextureManager.getInstance().addTexture("paper", new Texture(masterContext.getAssets().open("3d-objects/RackForFlowers/textures/PaperDecorative0011_1_L.jpg")));


What I did so far afterwards is based on an example I found in the web:

Object3D newObject;
        Object3D[] objs = Loader.load3DS(inputStream, 1f);
        Log.i("MyRenderer", "## objs.length ## " + objs.length);

        newObject = new Object3D(0);
        Object3D temp = null;
        for (int i = 0; i < objs.length; i++) {
            temp = objs[i];
            temp.setCenter(SimpleVector.ORIGIN);
            temp.rotateX((float)( -.5*Math.PI));
            temp.rotateMesh();
            temp.setTexture("Ball"); ##### <-- this worked for the ball object, which consists only of 1 part
            temp.setRotationMatrix(new Matrix());
            newObject = Object3D.mergeObjects(newObject, temp);
            newObject.build();
        }
       
        return newObject;


I do not see a efficient way to set all the different textures now?!

Here you can see, how the 3D object should look like:
http://archive3d.net/?a=download&id=b16a1a40

Yerst

You could change the name of the textures in the TextureManager to something like "RackForFlowers0", "RackForFlowers1",... and just call temp.setTexture("RackForFlowers" + Integer.toString(i));

oetzi

That was a good idea!
However, unfortunately it does not work.
This is what I tried now:

inputStream = masterContext.getAssets().open("3d-objects/RackForFlowers/Rack for flowers N020813.3DS");
TextureManager.getInstance().addTexture("RackForFlowers0", new Texture(masterContext.getAssets().open("3d-objects/RackForFlowers/textures/Archmodels66_dirt_1.jpg")));
TextureManager.getInstance().addTexture("RackForFlowers1", new Texture(masterContext.getAssets().open("3d-objects/RackForFlowers/textures/Archmodels66_leaf_30.jpg")));
TextureManager.getInstance().addTexture("RackForFlowers2", new Texture(masterContext.getAssets().open("3d-objects/RackForFlowers/textures/PaperDecorative0011_1_L.jpg")));
TextureManager.getInstance().addTexture("RackForFlowers3", new Texture(masterContext.getAssets().open("3d-objects/RackForFlowers/textures/PaperDecorative0011_1_L.jpg")));

        Object3D newObject;
        Object3D[] objs = Loader.load3DS(inputStream, 1f);
        Log.i("MyRenderer", "## objs.length ## " + objs.length);

        newObject = new Object3D(0);
        Object3D temp = null;
        for (int i = 0; i < objs.length; i++) {
            temp = objs[i];
            temp.setCenter(SimpleVector.ORIGIN);
            temp.rotateX((float)( -.5*Math.PI));
            temp.rotateMesh();
            String tmpName = "RackForFlowers" + Integer.toString(i);
            Log.i("MyRenderer", "## tmpName ## " + tmpName);
            temp.setTexture(tmpName);
            temp.setRotationMatrix(new Matrix());
            newObject = Object3D.mergeObjects(newObject, temp);
            newObject.build();
        }


The output is:
Quote
08-19 10:26:48.985: I/MyRenderer(28308): ## objs.length ## 4
08-19 10:26:48.985: I/MyRenderer(28308): ## tmpName ## RackForFlowers0
08-19 10:26:49.015: E/AndroidRuntime(28308): FATAL EXCEPTION: GLThread 28178
08-19 10:26:49.015: E/AndroidRuntime(28308): java.lang.RuntimeException: [ 1376900808997 ] - ERROR: Tried to set an undefined texture!
08-19 10:26:49.015: E/AndroidRuntime(28308):    at com.threed.jpct.Logger.log(Logger.java:189)
08-19 10:26:49.015: E/AndroidRuntime(28308):    at com.threed.jpct.Object3D.setTexture(Object3D.java:3434)
08-19 10:26:49.015: E/AndroidRuntime(28308):    at de.oetzi.dreid_test.MyRenderer.loadMeshFile(MyRenderer.java:146)
08-19 10:26:49.015: E/AndroidRuntime(28308):    at de.oetzi.dreid_test.MyRenderer.onSurfaceChanged(MyRenderer.java:84)
08-19 10:26:49.015: E/AndroidRuntime(28308):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1505)
08-19 10:26:49.015: E/AndroidRuntime(28308):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)