Topic locked

Replace 3D model with different 3D model

July 24, 2012 - 12:48am #18

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 23, 2012 - 11:45pm #17

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 23, 2012 - 8:02pm #16

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 - 3:47am #15

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 13, 2012 - 11:18am #14

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 13, 2012 - 10:34am #13

Cheers, Works !!!

Replace 3D model with different 3D model

July 12, 2012 - 5:38am #12

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 11, 2012 - 8:13am #11

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 10, 2012 - 11:08am #10

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 10, 2012 - 9:27am #9

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 5, 2012 - 11:21pm #8

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 2, 2012 - 9:07am #7

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

June 28, 2012 - 2:51am #6

Thumbs up! This also worked for me using iOS! 

Replace 3D model with different 3D model

June 28, 2012 - 2:09am #5

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 27, 2012 - 8:58am #4

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 26, 2012 - 7:56pm #3

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 26, 2012 - 7:39pm #2

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

Pages

Topic locked