Hellkero,
it's very simple (depending on your model):
I used a model generated from a "special" software; the problem was, that this model used more than one mesh and therefore more than one texture.
I imported the model in 3DSMAX (use "Merge to one mesh") and exported the model again (without any further modifications) as "*.obj". Bute there were again more than one texture. I used then DAZ Studio 3D to import the model.
There is a plugin "Texture Atlas" (29 $), which merges the textures to one.
Exported again as Wavefront .obj.
These steps are only necessary if the model has more than one mesh and/or more than one texture.
Now the part for QCAR: (assuming jour model has the name "model.obj" and the texture has the name "texture.png" - OK ?)
use the script "obj2opengl.pl" (I'm using a Mac w. Snow Leo):
Invoke "perl obj2opengl.pl model.obj".
This will generate a file "model.h". Save this to your "ImageTargets/jni" Folder.
Now edit "ImageTargets.cpp":
include this line
#include "model.h"
right after
#include "teapot.h".
Now replace the lines from
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotVertices[0]);
to
glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &teapotIndices[0]);
with these:
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &modelVerts[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &modelNormals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &modelTexCoords[0]);
glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);
glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjection.data[0] );
glDrawArrays(GL_TRIANGLES, 0, modelNumVerts);
Save it and invoke "ndk-build" in the folder "ImageTargets". If everything is fine the you should "Clean" your project in Eclipse and then "Build Project" and run it on your device.
If your model looks too small, you should set the scaling like this (factor 3.0):
SampleUtils::scalePoseMatrix(3.0f, 3.0f, 3.0f, &modelViewMatrix.data[0]);
If you want to replace the texture (assuming your target is "stones") the you should copy the file "texture.png" (by draggin' into the "assets" folder).
Now include this line
mTextures.add(Texture.loadTextureFromApk("model.png", getAssets()));
BEFORE the line
mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",
getAssets()));
in "ImageTargets.java" in the procedure "private void loadTextures()"
This will load the texture "model.png" as Texture with the index 0;
I hope this helps you (and others).
Frank
Have you added that texture to the project?