Topic locked

Replace 3D model with different 3D model

June 26, 2012 - 1:36pm #68

Hi guys!

I ve browsed the forum but havent found any satisfying solution on how to replace 3D model with another 3D model in ImageTargets project. A lot of you managed to do this somehow, so could you pls tell me (or show a sample) which exact steps are needed to do it ? 

Thanks a lot.

Replace 3D model with different 3D model

June 26, 2012 - 7:39pm #67

after changed the .obj to .h file, you will find there is no XXXIndices variables in the code

Replace 3D model with different 3D model

June 26, 2012 - 7:56pm #66

A common approach is to utilize this script ( http://heikobehrens.net/2009/08/27/obj2opengl/ ) to convert your model to the header file format used by the samples (see Teapot.h in the ImageTargets sample for an example ). The model must be in OBJ format to do this. It will be converted to a set of arrays defined within a header file - e.g. vertices, normals, and texture coordinates. You'll include that header file in your project - see the ImageTargets sample's use of the Teapot header file for an example.

To replace the model used in ImageTargets, revise the renderFrame method to utilze your arrays, rather than those of the Teapot.

Find ..

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotVertices[0]);

glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotNormals[0]);

glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotTexCoords[0]);

 

You need to switch out the teapotVertices, teapotNormals, teapotTexCoords, and teapotIndices variables in the code above with your own. You'll also need to use glDrawArrays rather than glDrawElements as such -  glDrawArrays(GL_TRIANGLES, 0, numVertices);

Give that a try and post any further questions.

 

Replace 3D model with different 3D model

June 27, 2012 - 8:58am #65

Hello,

I just also try do change the teapot with an other model from the "ImageTargets"Sample. The 3D Object I try to use is a banana.h. I downloaded the file here: http://heikobehrens.net/2009/08/27/obj2opengl/
Now I`m confusied because I tried different ways to modifie the "- (void)renderFrameQCAR" method from the sample. But I always fail!

I followed the instruductions from this thread and also tried to add the model the way it is described in the blog where I downloaded the files.

Currently I looking for a example how to add the banana model. Could someone help me? How does the "- (void)renderFrameQCARmethod needs to look like? 

Thanks and kindest regards from lake constance

Replace 3D model with different 3D model

June 28, 2012 - 2:09am #64

Guys, its working! I couldnt believe it, when I saw a banana floating over my table Smile Thank you so much for your help!

I used a solution that DavidBeard suggested:

       

1. Modify renderframe method in ImageTargets.cpp:

Replace this:

        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotVertices[0]);

        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotNormals[0]);

        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotTexCoords[0]);

with this:

 glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaVerts[0]);

 glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaNormals[0]);

 glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaTexCoords[0]);

 

And also replace this line:

glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &teapotIndices[0]);

with this one:

glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);

 

2. Modify loadTextures method in ImageTargets.java by adding a texture of banana:

    private void loadTextures()

    {

       mTextures.add(Texture.loadTextureFromApk("banana.jpg", getAssets())); 

        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png", getAssets()));

        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png", getAssets()));

        mTextures.add(Texture.loadTextureFromApk("TextureTeapotRed.png", getAssets()));        

    }

 

3. If you want your 3D model to be clearly visible, I recommend you to set kObjectScale = 120.f; (ImageTargets.cpp) 

4. Run the NDK-build and there you go. You will see a banana too! Smile

 

Working solution: http://interaktivnydokument.sk/download/ImageTargets.zip

<banana.h and banana.jpg download from http://heikobehrens.net/2009/08/27/obj2opengl/>

Replace 3D model with different 3D model

June 28, 2012 - 2:51am #63

Thumbs up! This also worked for me using iOS! 

Replace 3D model with different 3D model

July 2, 2012 - 9:07am #62

Hi,

I could do this, I create my own 3d object(an sphere), but I have 2 problem:

1-The sphere shown very strange:

http://www.subirimagenes.net/show-image.php?id=3d8139077b4e04f14edaf3d43a1923cb

2-I could't manage with my own trackable. Where is the code that link the trackable with the 3d object which have to be deploy?

Replace 3D model with different 3D model

July 5, 2012 - 11:21pm #61

Hi! I hope someone help me. 

 

I did the instructions as what stated here. But unlike most of you, my result was not as expected.

 

My result was still a teapot  but with the texture of the banana. I don't know what went wrong. I hope someone help me.

 

Thank you.

Replace 3D model with different 3D model

July 10, 2012 - 9:27am #60

Could anyone help me with the second issue?

I had checked all the ImageTarget.cpp and ImageTarget.java codes and I could do it, my trackable don't show the teapot nor the bannana.

Thanks

Replace 3D model with different 3D model

July 10, 2012 - 11:08am #59

2-I could't manage with my own trackable. Where is the code that link the trackable with the 3d object which have to be deploy?

This occurs within _renderFrame in ImageTargets.cpp ( ln 338 - 427 )

Here's how you identify which target has been detected..

 

            for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
    {

        if (strcmp(trackable->getName(), "chips") == 0)
        {
            // do something
        }
        else if (strcmp(trackable->getName(), "stones") == 0)
        {
            // do something
        }
        else
        {
            // do something else
        }

...

this is the code that is drawing the teapot. Revise this for the arrays in your header file..

        glUseProgram(shaderProgramID);

        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &teapotVertices[0]);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &teapotNormals[0]);
        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &teapotTexCoords[0]);

        glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(textureCoordHandle);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );
        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &teapotIndices[0]);

 

Also be sure that your dataset is loaded and activated within loadTrackerData

ln 181

Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_loadTrackerData

 

-----------

 

Regarding your sphere, make sure you have triangulated the model, any 3D modeling software should be able to do this. It is also possible the model has triangles winding in different directions (some clockwise, some counter-clockwise). This can happen when the normals are incorrect in the modeling software. In this case, try turning off culling: glDisable(GL_CULL_FACE);

Replace 3D model with different 3D model

July 11, 2012 - 8:13am #58

I load my own trackable (Meninas.xml) and it worked because when it appear on the screen a toast come with the name. Here is the loadTrackerData:

Quote:
JNIEXPORT int JNICALL Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_loadTrackerData(JNIEnv *, jobject) { LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_loadTrackerData"); // Get the image tracker: QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance(); QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>( trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER)); if (imageTracker == NULL) { LOG("Failed to load tracking data set because the ImageTracker has not" " been initialized."); return 0; } dataSetMeninas = imageTracker->createDataSet(); if (dataSetMeninas == 0) { LOG("Failed to create a new tracking data."); return 0; } if (!dataSetMeninas->load("Meninas.xml", QCAR::DataSet::STORAGE_APPRESOURCE)) { LOG("Failed to load data set."); return 0; } // Activate the data set: if (!imageTracker->activateDataSet(dataSetMeninas)) { LOG("Failed to activate data set."); return 0; } LOG("Successfully loaded and activated data set."); return 1; }

The renderFrame(I know the first part with the 'stones' have no sense because I never load his tracker):

Quote:
// Choose the texture based on the target name: int textureIndex; if (strcmp(trackable->getName(), "stones") == 0) { textureIndex = 0; } else if (strcmp(trackable->getName(), "meninas") == 0) { textureIndex = 1; } else { textureIndex = 2; } const Texture* const thisTexture = textures[textureIndex]; #ifdef USE_OPENGL_ES_1_1 // Load projection matrix: glMatrixMode(GL_PROJECTION); glLoadMatrixf(projectionMatrix.data); // Load model view matrix: glMatrixMode(GL_MODELVIEW); glLoadMatrixf(modelViewMatrix.data); glTranslatef(0.f, 0.f, kObjectScale); glScalef(kObjectScale, kObjectScale, kObjectScale); // Draw object: glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID); glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &pruebaTexCoords[0]); glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &pruebaVertices[0]); glNormalPointer(GL_FLOAT, 0, (const GLvoid*) &pruebaNormals[0]); // glVertexPointer(3, GL_FLOAT, 0, pruebaVerts); // glNormalPointer(GL_FLOAT, 0, pruebaNormals); // glTexCoordPointer(2, GL_FLOAT, 0, pruebaTexCoords); glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &teapotIndices[0]); #else QCAR::Matrix44F modelViewProjection; SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]); SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &modelViewMatrix.data[0]); SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix.data[0] , &modelViewProjection.data[0]); glUseProgram(shaderProgramID); glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &pruebaVerts[0]); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &pruebaNormals[0]); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &pruebaTexCoords[0]); // glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, // (const GLvoid*) &teapotVertices[0]); // glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, // (const GLvoid*) &teapotNormals[0]); // glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, // (const GLvoid*) &teapotTexCoords[0]); glEnableVertexAttribArray(vertexHandle); glEnableVertexAttribArray(normalHandle); glEnableVertexAttribArray(textureCoordHandle); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjection.data[0] ); glDrawArrays(GL_TRIANGLES, 0, pruebaNumVerts); SampleUtils::checkGlError("ImageTargets renderFrame"); #endif }

 

Replace 3D model with different 3D model

July 12, 2012 - 5:38am #57

Hi, 

 

as for iyasatuito, the same appened in my case.

 

I could see the teapot with the texture of a banana.... why is that? 

 

I guess we did not properly compile the C code with ndk-build, but I cannot understand what I am doing wrong. Any idea? 

 

thanks

Replace 3D model with different 3D model

July 13, 2012 - 10:34am #56

Cheers, Works !!!

Replace 3D model with different 3D model

July 13, 2012 - 11:18am #55

If you've compiled and cleaned the project, and are still seeing this, it's likely the texture assignment.

The textures are added in ImageTargets.java and their order is significant..

@ ln 294

    /** We want to load specific textures from the APK, which we will later
    use for rendering. */
    private void loadTextures()
    {
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",
                                                 getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png",
                                                 getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureTeapotRed.png",
                getAssets()));       
    }

 

because they are assigned by indes in ImageTargets.cpp

@ ln 347

        // Choose the texture based on the target name:
        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];

 

It's likely that the banana texture is at the texture index being used by the teapot. You can restore the teapot texture to the Teapot by subtituting the loadTextures method above for the one you're currently using.

Replace 3D model with different 3D model

July 23, 2012 - 3:47am #54

werther wrote:

Working solution: http://interaktivnydokument.sk/download/ImageTargets.zip

Hello and thanks for posting an example. Correct me if I'm wrong, but I'm not sure your example is a trully working one. If I can build with no issues, I have a flying banana that does not have a propperly mapped texture.

banana

I tried to rotate the texture but it did not work (and won't be a good solution either). I wasn't sure if the problem came from the model or the vuforia code, so I made a custom susanne monkey from blender with a baked rendering texture. Still in Blender, I re-applied the baked texture itself to susanne to be sure that it matched the vertices with UV mapping (and it did), exported it to .obj (modifiers, edges, normals, UVs, Keep Vertex Order) passed it the obj2opengl.pl script and I was close to get the texture perfectly mapped but some huge problems remain.

Am I the only one to get that weird banana?
Thanks for your answer.

 

EDIT : it seems that the forum does not embed images very well : here is a link to the capture I made : http://penumbra.me/uploads/vuforia_banana.png

Replace 3D model with different 3D model

July 23, 2012 - 8:02pm #53

Greeting all,

     I using obj2opengl.pl to convert a obj file to a .h file.

The problem is in the example given(http://heikobehrens.net/2009/08/27/obj2opengl/), there are a .jpg file.

when i convert my .obj file, there doesnt give me the jpg file.

May I know where or how I can get it? 

Replace 3D model with different 3D model

July 23, 2012 - 11:45pm #52

Hello lovebean. The things you need to do is called baking, if you use Blender, you can get more infos here : http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Bake. Exporting an obj will only export the mesh. There is also a lot of tutorials on Youtube (baking involves UV unwrap).

Replace 3D model with different 3D model

July 24, 2012 - 12:48am #51

Hi,

Thanks for the reply.

So do I just replace the teapot.png with the generated png? anyone coordination work?

Replace 3D model with different 3D model

July 24, 2012 - 7:17am #50

Hm, it's a little more complicated. If you have your texture generated from a teapot without having exported the teapot mesh itself, you'll have to check that your UV unwrap texture matches one of the example (in the assets folder -> TextureTeapot [Blue / Barss / Red]. png). Then it should probably do the job. But once that is done, you will not be so advanced, as did those who managed to run the example of the banana. I guess if you have a project, you will not do that from teapots and bananasUndecided no? So, unless you are using the extension for Unity, you will want to make a set of objects in a 3D external software, render with textures of your choice, bake, export to image file, export the objects of your scene in. obj, convert it to .h (or use a c parser). Currently, this is where I'm stuck (see my post below), I have a problem of coordination (as you say) between the texture coordinates of my object and the texture itself ...

Replace 3D model with different 3D model

July 29, 2012 - 7:51pm #49

Hi Guys,, !!!

i just want to load my 3D Object  to marker, any body help me how to do this???

Replace 3D model with different 3D model

July 29, 2012 - 7:55pm #48

i build it with Java native, and until now i still dont know how to load my 3D Object to my marker....

Replace 3D model with different 3D model

July 31, 2012 - 11:36am #47

Hello,

Have you followed David's instructions below? Do you have a 3D model converted to a .h file?

Thank you,

-Peter

Replace 3D model with different 3D model

July 31, 2012 - 10:14pm #46

i've read and still don't know,, can you tell me step by step how to load 3D object from zero until success? help me please, i wanna learn more about it... :)

Replace 3D model with different 3D model

August 14, 2012 - 5:36am #45

I have been stuck on the same thing for last 1 and half days, I try compiling Heinko's script obj2opengl with my triangulated 3dmodel, which I exported for mac, but I get this error:

Illegal division by zero at ./obj2opengl.pl line 294.

So I hard coded scalefac = 1 and commented out line 294. Then I tried ndk-build in ImageTarget folder after making changes in ImageTarget.cpp I get following in Terminal:

Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi-v7a/gdbserver
Gdbsetup : libs/armeabi-v7a/gdb.setup
Install : libImageTargets.so => libs/armeabi/libImageTargets.so
Install : libQCAR.so => libs/armeabi/libQCAR.so
Compile++ arm : ImageTargets <= ImageTargets.cpp
In file included from jni/ImageTargets.cpp:45:0:
jni/./posefour.h:33941:9: error: "vertices" is not a valid filename
jni/./posefour.h:67851:9: error: "vertex" is not a valid filename
jni/./posefour.h:135608:9: error: "faces" is not a valid filename
jni/./posefour.h:169532:9: error: "vertices" is not a valid filename
jni/./posefour.h:203442:9: error: "vertex" is not a valid filename
jni/./posefour.h:271199:9: error: "faces" is not a valid filename
In file included from jni/ImageTargets.cpp:15:0:
/Users/harshvardhan/Documents/Work/app/android-ndk-r8b/platforms/android-14/arch-arm/usr/include/jni.h:592:13: note: the mangling of 'va_list' has changed in GCC 4.4
In file included from jni/ImageTargets.cpp:45:0:
jni/./posefour.h:27:1: error: 'mtllib' was not declared in this scope
jni/./posefour.h:27:8: error: expected '}' before 'posefour'
jni/./posefour.h:27:8: error: expected ',' or ';' before 'posefour'
jni/./posefour.h:135613:1: error: expected declaration before '}' token
make: *** [obj/local/armeabi-v7a/objs-debug/ImageTargets/ImageTargets.o] Error 1

Here link to my 3dModel Files:
https://www.dropbox.com/sh/mz2ac79wnormm6d/zTHAem-y2W

Can you please suggest me how to get over these errors..?

Thanks

Replace 3D model with different 3D model

August 14, 2012 - 8:03am #44

From my point of view, I think your .obj file is not compatible with the script, or maybe there is an error somewhere (I can not import it into Blender). I advise you first to look closely at the export panel in MAX and make sure that you export only vertices and normals (forget the export of the material .mtl file, it will not be taken into account in the script). The fact that you changed the script itself may be the cause of your second problem. In fact all the other problems:
1 - posefourNumVerts variable should contain the total number of vertices of your model (therefor it should not be equal to 3).
2 - Description of vertices should be in this format: posefourVerts float [] = {V1X, V1Y, V1Z, V2X, V2Y, V2Z, etc ...} but you end up with a copy/paste of the .obj file where vertices are described in this way:
v x1 y1 z1
v x2 y2 z2
etc ...
3 - your .h file has lines of comments from the max exporter ("#") which trigger errors (for instance line 33941 = # 33908 vertices)

Replace 3D model with different 3D model

August 14, 2012 - 8:16am #43

It appears that the header file is corrupted. I notice that there is a reference to the MTL file, and the format is incorrect. Try Franck's advice, to make sure that you are exporting your model correctly. And uncomment line 294.

Take a look at the banana.h file that comes with the examples version of the script to see what these files should look like.

Replace 3D model with different 3D model

August 14, 2012 - 8:40am #42

I'm not sure but it definitely comes from your obj file which come from DOS while the obj2opengl.pl script is intended to be used in unix. More specifically it comes from the line breaking and the presence of the "^M" hidden caracter. So for the perl script, it's like your .obj file is a long single line of text (on my Mac in any case). Try to find a utility that could change the file format or get rid of every "^M" (if you can get your hands on vim -> http://vim.wikia.com/wiki/File_format#Converting_the_current_file). Good luck.

Replace 3D model with different 3D model

August 15, 2012 - 9:37am #41

Hey, thanks Frano and DavidBeard.

I exported the 3d model as explained i.e. with the vertices and normals only. But I get the same .h file. Except that I dont get any error on line 294 in obj2openpl file.

Here the output of ndk-build:

Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver

Gdbsetup       : libs/armeabi/gdb.setup

Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi-v7a/gdbserver

Gdbsetup       : libs/armeabi-v7a/gdb.setup

Compile++ arm    : ImageTargets <= ImageTargets.cpp

In file included from jni/ImageTargets.cpp:45:0:

jni/./posefour.h:33941:9: error: "vertices" is not a valid filename

jni/./posefour.h:67851:9: error: "vertex" is not a valid filename

jni/./posefour.h:135608:9: error: "faces" is not a valid filename

jni/./posefour.h:169532:9: error: "vertices" is not a valid filename

jni/./posefour.h:203442:9: error: "vertex" is not a valid filename

jni/./posefour.h:271199:9: error: "faces" is not a valid filename

In file included from jni/ImageTargets.cpp:15:0:

/Users/harshvardhan/Documents/Work/app/android-ndk-r8b/platforms/android-14/arch-arm/usr/include/jni.h:592:13: note: the mangling of 'va_list' has changed in GCC 4.4

In file included from jni/ImageTargets.cpp:45:0:

jni/./posefour.h:27:1: error: 'mtllib' was not declared in this scope

jni/./posefour.h:27:8: error: expected '}' before 'posefour'

jni/./posefour.h:27:8: error: expected ',' or ';' before 'posefour'

jni/./posefour.h:135613:1: error: expected declaration before '}' token

make: *** [obj/local/armeabi/objs-debug/ImageTargets/ImageTargets.o] Error 1


I still think that something is wrong with the 3d model only. Heinko mentioned a problem with 3ds max exporting script.

Should I delete the gw_objexp.ini or something else..any clue would be a great help..??

Replace 3D model with different 3D model

August 15, 2012 - 6:58pm #40

Do you have another 3D environment, or a model conversion utility, that you can try with? - i.e. to generate the obj version from software other than 3DS Max.

But I wouldn't delete anything just yet. You might want to check on a 3D forum w/ 3DS Max users. The header file format that we use is used for native iPhone app development as well. So others have probably encountered this problem.

Replace 3D model with different 3D model

August 15, 2012 - 8:55pm #39

Hi Its Done...:)

My 3d max guy wasn't converting the mesh into triangle. Once it was done it worked !!

Thanks guys..:)

I want to display no of models one by one in my project and chnge them on touch event.
Can some one guide me how to change my model to some other on tapping the screen in myImageTarget Project..?

I have tried changing bring teapot after my own model on touch event by calling a new function in ImageTarget.cpp

 

Heres the link to my ImageTarget.cpp.

Replace 3D model with different 3D model

August 15, 2012 - 10:17pm #38

Forgot to mention the function name in ImageTarget.cpp:

Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_getCallFromJava.

 

Replace 3D model with different 3D model

August 15, 2012 - 10:51pm #37

how are u guys getting your own model ? I am still getting the teapot on both the stones and chips image targets...I have tried the code posted by muhammadgyan over here : https://ar.qualcomm.at/content/createreplace-object#top  ...still i m not getting it..please can someone tell me how to load the banana object provided i have the .h file and .png files already in my android project...where do we need to make the change in the ImageTargets.cpp file?

Replace 3D model with different 3D model

August 23, 2012 - 6:38am #36

I've been looking for a solution to change this 3D object for whole day, and i've read every comment on this page but still i have nothing. I've got banana object and banana.h from http://heikobehrens.net/2009/08/27/obj2opengl/

 

In ImageTarget.java, i've added this line into loadTexture method:

mTextures.add(Texture.loadTextureFromApk("banana.jpg", getAssets()));

 

And then i've changed these lines in ImageTarget.cpp:

for USE_OPENGL_ES_1_1:

glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &bananaTexCoords[0]);

glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &bananaVerts[0]);

glNormalPointer(GL_FLOAT, 0,  (const GLvoid*) &bananaNormals[0]);

 

glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);

 

and for the rest:

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaVerts[0]);

glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaNormals[0]);

glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaTexCoords[0]);

 

glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);

 

I mean i've done everything as suggested, but now it draws nothing..? What am i missing? Thanks in advance...

Replace 3D model with different 3D model

August 23, 2012 - 5:15pm #35

Hello,

Try setting the kObjectScale in ImageTargets.cpp to something larger.

Thank you,

-Peter

Replace 3D model with different 3D model

August 23, 2012 - 11:13pm #34

werther mentioned about that but i thought that was just a suggestion, not a must...

Can't believe that was the case :) I set "kObjectScale=120" now it works :)

Thanks a lot ppreuss, you saved my day :)

Replace 3D model with different 3D model

September 5, 2012 - 6:13am #33

Just to add some important spots..

Download the obj2opengl file. Unzip this and use the files as follows.

Paste the header file  banana.h  into the ImageTargets project.  location:ImageTargets/

Paste the jpg file banana.jpg into assets folder. location:ImageTargets/assets/

 

Find the ImageTargets.cpp INSIDE the jni folder and change this according to werther's advice! location:ImageTargets/jni/

 

 

werther wrote:

Guys, its working! I couldnt believe it, when I saw a banana floating over my table Smile Thank you so much for your help!

I used a solution that DavidBeard suggested:

       

1. Modify renderframe method in ImageTargets.cpp:

Replace this:

        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotVertices[0]);

        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotNormals[0]);

        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &teapotTexCoords[0]);

with this:

 glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaVerts[0]);

 glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaNormals[0]);

 glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaTexCoords[0]);

 

And also replace this line:

glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &teapotIndices[0]);

with this one:

glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);

 

2. Modify loadTextures method in ImageTargets.java by adding a texture of banana:

    private void loadTextures()

    {

       mTextures.add(Texture.loadTextureFromApk("banana.jpg", getAssets())); 

        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png", getAssets()));

        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png", getAssets()));

        mTextures.add(Texture.loadTextureFromApk("TextureTeapotRed.png", getAssets()));        

    }

 

3. If you want your 3D model to be clearly visible, I recommend you to set kObjectScale = 120.f; (ImageTargets.cpp) 

4. Run the NDK-build and there you go. You will see a banana too! Smile

 

Working solution: http://interaktivnydokument.sk/download/ImageTargets.zip

<banana.h and banana.jpg download from http://heikobehrens.net/2009/08/27/obj2opengl/>

Replace 3D model with different 3D model

September 18, 2012 - 10:02am #32

for anyone who see a weird banana, 

you need to change

private void loadTextures()    {

        mTextures.add(Texture.loadTextureFromApk("banana.jpg",getAssets()));

        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",                                                 getAssets()));

        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png",                                                 getAssets()));

        mTextures.add(Texture.loadTextureFromApk("TextureTeapotRed.png",                getAssets()));

    }

to 

    private void loadTextures()    {

        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",                                                 getAssets()));

        mTextures.add(Texture.loadTextureFromApk("banana.jpg",getAssets()));

        mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png",                                                 getAssets()));

        mTextures.add(Texture.loadTextureFromApk("TextureTeapotRed.png",                getAssets()));

    }

the texture are loaded from ImageTargets.cpp line 351

        }        else if (strcmp(trackable->getName(), "stones") == 0)        {

            textureIndex = 1;

the weird banana is result from loading TextureTeapotBrass.png instead of banna.jpg

hope help anyone stuck with weird banana

 

 

Replace 3D model with different 3D model

September 27, 2012 - 7:07am #31

Hello,you seem not to mention that  we should add "banana.h" into ImaginationTargets.cppCool

Replace 3D model with different 3D model

September 27, 2012 - 7:07am #30

Hello,you seem not to mention that  we should add "banana.h" into ImaginationTargets.cppCool

Replace 3D model with different 3D model

October 17, 2012 - 1:27am #29

Hi there, i have a problem here when i want to convert .obj to .h with obj2opengl.pl

when i tried to convert banana.obj, i got my banana.h file, i checked its code and i got:
Array bananaVerts []
Array bananaNormals [] and
Array bananaTexCoords []
i modified the ImageTarget.cpp, compile and install it on my android, and the banana was successful appear on my android,

So, i tried my own object, i created it in blender, export into .obj (named nyancat.obj), then i convert into nyancat.h,
but when i checked the code, i can't find Array nyancatNormals [] and Array nyancatTexCoords [],
i only have Array of nyancatVerts []

first i ignored it, then i tried to modified the ImageTarget.cpp (and because of there was no texture for my nyancat, i didn't modify the ImageTarget.java). I compile and install it, i can't see my nyancat there..

is the problem is on my nyancat.h?

Replace 3D model with different 3D model

October 17, 2012 - 8:06am #28

Hi hoaxman,

if you only have vertices (and no tex coords), it is expected that you won't be able to see your mesh;

if you want to see your mesh anyway, you'll need to to modify the shader code in CubeShader.h (I'm referring to ImageTargets sample), replacing the line:

gl_FragColor = texture2D(texSampler2D, texCoord);

with a line like:

gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);

This should show your mesh in a flat red color (but it will look flat, i.e. not shaded), so you can verify that it is actually drawn; then if you want to have texture coordinates, please check that your .obj file (as exported by Blender) does have texture coordinates, before you convert it to a .h file.

 

 

 

 

Replace 3D model with different 3D model

October 17, 2012 - 10:08am #27

Hi again hoaxman,
so I tried to replicate your issue, creating a mesh in Blender (a simple cube in my case), then exporting the mesh to OBJ,
and finally converting the OBJ to an OpenGL header file (.h) using the obj2opengl.pl script, same procedure you did, if I understand right.

So, indeed the perl script did produce (like in your case) a mesh containing only vertices and no texture coordinates (no normals either);
this happens because the .OBJ file exported by Blender also only contains vertices (and no texture coordinates).

Now, suppose we don't care about the texture coordinates, and you want to show your model in QCAR any way, then you'll need to do the following things:

- remove the line glVertexAttribPointer(normalHandle, ...) as we don't have normals

- remove the line glVertexAttribPointer(textureCoordHandle, ...) as we don't have texture coordinates

- VERY IMPORTANT: remove the line glEnableVertexAttribArray(normalHandle); as we don't have normals

- VERY IMPORTANT: remove the line glEnableVertexAttribArray(textureCoordHandle); as we don't have texture coordinates

- call glDrawArrays(GL_TRIANGLES, 0, MyMeshNumVerts);   instead of glDrawElements(...), as already explained in a previous message in this thread

- make sure that the scale kObjectScale value is appropriate for your mesh (as already explained in previous messages in this thread)

If you follow the above you'll be able to see your mesh somehow (as I was able too).

Another thing: sometime the perl script will produce triangles with vertices in clock-wise order; if that is the case, you will also need to remove the line glEnable(GL_CULL_FACE);

Of course a much better solution would be to make sure that your .OBJ exported from Blender also contains texture coodinates and normals up front,
so that the.h header will also do (but that's related to Blender export settings or so).

 

Replace 3D model with different 3D model

October 21, 2012 - 11:02am #26

thx for reply alesandro :D
and i have followed your instruction..

same with you, i tried to make a simple cube on blender,
exported it to .obj - just give me an cubeVerts[]
then removed the line glVertexAttribPointer(normalHandle, ...) & glVertexAttribPointer(textureCoordHandle, ...)
also removed the line glEnableVertexAttribArray(normalHandle) & glEnableVertexAttribArray(textureCoordHandle)
and not forget to change glDrawElements(...) to glDrawArrays(...)

now it give me a strange cube, a cube with a triangle shapes for each faces instead of square shapes. i know it's because we put triangulate method to draw the object, but i don't how to make my cube as a cube as well..

 

Replace 3D model with different 3D model

October 22, 2012 - 1:24am #25

Hi hoaxman, you see triangles and not squares because you did not disable GL_CULL_FACE;

so make sure you disable GL_CULL_FACE, by either commenting out the line of code "glEnable(GL_CULL_FACE)" at the beginning of the renderFrame method, or otheriwse by calling explicitly  "glDisable(GL_CULL_FACE);"  right before drawing your vertex array.

That should fix it (let me know then).

 

 

Hi all,  thanks to everybody

January 11, 2013 - 1:41am #24

Hi all, 

thanks to everybody for the useful help. 

I followed all the suggestions in this thread and I got my simple 3D object on screen.

Unfortunately, the UV mapping procedure (and then the baking) in Blender for objects more complex than a simple cube is very difficult, and I did not get any texture working on my object.

Do you have any idea on how I could achieve at least to get it coloured? I simply need to visualize some text on the frame marker, so nothing that should be very difficult per se.

Hi, if you are fine with some

January 11, 2013 - 2:13am #23

Hi, if you are fine with some "flat" solid colouring, you can achieve this by doing the following:

- open the CubeShader.h file

- replace this line:

   gl_FragColor = texture2D(texSampler2D, texCoord);

   with this:

   gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);

Note: the line above will set the four components as RGBA, with R (red) = 1.0, G (green) = 0, B (blue) = 0, and A (opacity) = 1.0; so this will make your objects look red, but use the RGBA values that you prefer.

Let me know if that would be sufficient or not; if you need more shaded colors (such as "diffuse" color effect, there is also a solution, but it requires many more code changes....)

 

Replace 3D model with different 3D model

January 11, 2013 - 3:15am #22

Hi, thanks for your  andwer. 

Yes, i already tried that solution but I would actually need something a bit nicer (such as lighting, material, diffusion). I know here the problem is that I'm not good at all with OpenGL.

Anywya, if you had some suggestion, they would be mooore than welcome :)

 Hi, in order to enable

January 11, 2013 - 4:46am #21

 

Hi, in order to enable basic lighting (diffuse) effects, the vertex and fragment shaders must be modified as follows:

static const char* cubeMeshVertexShader = " \

attribute vec4 vertexPosition; \

attribute vec4 vertexNormal; \

attribute vec2 vertexTexCoord; \

varying vec2 texCoord; \

varying vec4 normal; \

uniform mat4 modelViewMatrix; \

uniform mat4 modelViewProjectionMatrix; \

void main() { \

   gl_Position = modelViewProjectionMatrix * vertexPosition; \

   normal = modelViewMatrix * vec4(vertexNormal.xyz, 0.0); \

   texCoord = vertexTexCoord; \

}";

 

static const char* cubeFragmentShader = " \

precision mediump float; \

varying vec2 texCoord; \

varying vec4 normal; \

uniform sampler2D texSampler2D; \

void main() { \

   vec3 n = normalize(normal.xyz); \

   vec3 lightDir = normalize(vec3(0.0, 0.0, -1.0)); \

   vec3 ambientLight = vec3(0.5, 0.5, 0.5); \

   vec3 ambientMaterial = vec3(0.3, 0.3, 0.3); \

   vec3 ambient = ambientMaterial * ambientLight; \

   vec3 diffuseLight = vec3(1.0, 1.0, 1.0); \

   vec3 diffuseMaterial = vec3(0.9, 0.9, 0.9); \

   float diffuseFactor = max(0.0, dot(n, lightDir)); \

   vec3 diffuse = diffuseFactor * diffuseMaterial * diffuseLight; \

   vec3 shadedColor = ambient + diffuse; \

   gl_FragColor = vec4(shadedColor, 1.0); \

}";

It is important to note that some of the variables defined in the fragment shaders, such as lightDir, ambientLight, diffuseLight and diffuseMaterial, would be better declared as uniform parameters, so that their values could be set from outside the shader (i.e. controlled from the application code); for simplicity reasons, this has not been done in the code above.

Also, a new uniform matrix, namely the “modelViewMatrix”, has been introduced in the vertex shader code; like for any other uniform parameters, the modelViewMatrix values must be set from the application code; this can be done in ImageTargets.cpp by simply adding the following line of code in the initRendering function:

modelViewMatrixHandle = glGetUniformLocation(shaderProgramID,

                                                "modelViewMatrix");

as well as adding the following line in the renderFrame function (just before calling glDrawElements):

glUniformMatrix4fv(modelViewMatrixHandle, 1, GL_FALSE,

                                   (GLfloat*)&modelViewMatrix.data[0] );

 

Let me know if something is not clear.

 

Replace 3D model with different 3D model

June 27, 2013 - 4:59am #20

hi Al, i follow all instrution below, and i changed my objek to banana.

i did this :

// Constants:
static const float kObjectScale = 120.f;

QCAR::DataSet* dataSetStonesAndChips    = 0;
QCAR::DataSet* dataSetTarmac            = 0;

but my banana.png just too small like a dot in image target

 

thanks,

 

regards

Replace 3D model with different 3D model

June 27, 2013 - 5:11am #19

Hi, have a look here, everything is explained in detail:

https://developer.vuforia.com/forum/faq/android-how-do-i-replace-teapot

Also, if a model appears too small or too big, this is because you need to:

- adjust the scale to a different value

- rebuild the code with ndk-build and make sure the build was successfull

- refresh the project in Eclipse so that it picks the changes

 

 

 

Replace 3D model with different 3D model

June 27, 2013 - 5:33am #18

i've done with the instruction you gave me.

1. i set the USE_OPENGL_ES_1_1 flag to true

# The variable USE_OPENGL_ES_1_1 determines the OpenGL ES API version
# to use. If set to true, OpenGL ES 1.1 is used, otherwise OpenGL ES 2.0.

USE_OPENGL_ES_1_1 := true

# Set OpenGL ES version-specific settings.

2. rebuild with dos command

3. refresh the project.

 

and now my banana disapear

 

could you tell me why ?

 

thanks

regards

me

Topic locked