Log in or register to post comments

Changing Texture in ImageTarget Sample

April 5, 2013 - 12:51am #1

Hi,

i change the sourceCode of ImageTargets.cpp to get my own 3D Model.

with mymodelVerts, mymodelNormals, and myModelTexCoords.....

I also put the pictures (png) in the assets folder.

When i start my 3d model after running ndk. I see my model  with the textures of the Teapot.

What did i wrong?

I made UV Mapping with Blender.

Changing Texture in ImageTarget Sample

April 5, 2013 - 4:39am #9

Glad that you managed to sort it out!

Changing Texture in ImageTarget Sample

April 5, 2013 - 3:30am #8

Hi,

now i made my 3D Model UV Mapping with just one png includes all 4 colors.

I just use one png in the sourceCode and it works.

I think i have to think in an other way for UV Mapping :-)

Thanks

Changing Texture in ImageTarget Sample

April 5, 2013 - 2:58am #7

I put 4 png Files in the assetsFolder, each of them are in an other color ( yellow, blue, red, green). Like = red.png, blue.png......

And i want to set each color to one side of the Cube. Like i made it in Blender with UVMapping.

And now the Cube in my App just have the blue.png for every Side.

I think this line

const Texture* const thisTexture = textures[0];

just take one png, how can i put all pngs in the model.

When i write: textures[2];

It takes my 3rd pngFile from the assetsFolder for the whole Cube.

Changing Texture in ImageTarget Sample

April 5, 2013 - 2:24am #6

How can i put 4 colors to my model?

Not sure what exactly you mean; a texture is an image which can contains thousands of colors... can you clarify ?

 

Changing Texture in ImageTarget Sample

April 5, 2013 - 2:20am #5

Hi Alessandro,

now i changed the size to 128 * 128.

And i saw the first png its blue.

But i have 4 Colors.

How can i put 4 colors to my model?

Changing Texture in ImageTarget Sample

April 5, 2013 - 2:06am #4

What is the width and height of your textures ? (myone.png, etc.);

on most devices you need to use power-of-two sizes, i.e. acceptable sizes are for instance 128 x 128, or 256 x 256, or 512 x 512, or 512 x 256, 256 x 128, etc...

That could explain the black effect..

 

Changing Texture in ImageTarget Sample

April 5, 2013 - 2:01am #3

Hi,

i made:

 

private void loadTextures()
    {
        mTextures.add(Texture.loadTextureFromApk("myone.png",
                                                 getAssets()));
        mTextures.add(Texture.loadTextureFromApk("mytwo.png",
                                                 getAssets()));
        mTextures.add(Texture.loadTextureFromApk("mythree.png",
                getAssets()));
        mTextures.add(Texture.loadTextureFromApk("myfour.png",
                getAssets()));
    }

 

And than:

 

int textureIndex;
        if (strcmp(trackable.getName(), "chips") == 0)
        {
            textureIndex = 0;
        }
        else if (strcmp(trackable.getName(), "stones") == 0)
        {
            textureIndex = 1;
        }
        else
        {
            textureIndex = 2;
        }

        const Texture* const thisTexture = textures[0];

 

But after starting my app my model is Black.

What did i wrong?

Changing Texture in ImageTarget Sample

April 5, 2013 - 1:21am #2

Hi,

in the renderFrame() function in ImageTargets.cpp, you can find this code:

 int textureIndex;
        if (strcmp(trackable.getName(), "chips") == 0)
        {
            textureIndex = 0;
        }
        else if (strcmp(trackable.getName(), "stones") == 0)
        {
            textureIndex = 1;
        }
        else
        {
            textureIndex = 2;
        }

        const Texture* const thisTexture = textures[textureIndex];

That code is responsible for selecting the texture in the array of textures (i.e. if index is 0, it will pick the first texture, if index is 1, it will picke the second texture, etc.)

So, you need to change that so to make sure that you select the texture that you want for your model.

Note that the order in which textures are added to the array is defined in the Java code in ImageTargets.java:

private void loadTextures()
    {
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",
                                                 getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png",
                                                 getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotRed.png",
                getAssets()));
    }

I would suggest to also take a look at this tutorial about adding textures in Image targets:

https://developer.vuforia.com/resources/dev-guide/adding-textures

 

Log in or register to post comments