Log in or register to post comments

[ASK]step-by-step building simple AR application

May 29, 2013 - 6:36pm #1

Hi everyone,
I have some question to ask about building simple AR app with my own 3D model...

#1
Can I integrate 3D model with (*.FBX) extension with eclipse like Unity do?

#2
What files need to imported when I start building simple AR app?

Actually I'm new with Android, Vuforia and openGL, so sorry for the dumb questions...

Thanks... :)

[ASK]step-by-step building simple AR application

July 12, 2013 - 11:54am #35

Have a look at ImageTargetsRenderer.java; that's where you can find the opengl rendering and initialization functions:

see in particular  the lines that call the initRendering() and updateRendering() functions.

[ASK]step-by-step building simple AR application

July 12, 2013 - 11:15am #34

Can you give me a clue?

I want to add some text when the GLView start to displaying the 3D object, but I don't have a clue which line of code in ImageTargets.java that start to init rendering code for the 3D object.

Thx.

[ASK]step-by-step building simple AR application

July 6, 2013 - 12:21am #33

Sure you can, this is basically just a matter of "duplicating" the relevant OpenGL code for one model (see for instance the teapot rendering code in the ImageTargets sample) so that it renders 2 models instead of one.

What you need is just plain OpenGL programming; 

and this article can be a useful read too:

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

 

 

[ASK]step-by-step building simple AR application

July 6, 2013 - 12:01am #32

Can I display 2 different 3D object in one Image?

e.g: Image A displaying car and cube.

Thx

[ASK]step-by-step building simple AR application

June 23, 2013 - 3:59am #31

Can I just call a code from jni which only handle for the rotation?
or I have to call several line of code to handle the render and the rotation?

[ASK]step-by-step building simple AR application

June 23, 2013 - 12:01am #30

Hi, how to implement a swipe/gesture handling is not Vuforia-specific, you can find this information in the Android developer guide.

About rotating the teapot (or other 3D model) in our sample, this article esplains that:

https://developer.vuforia.com/forum/faq/android-how-can-i-rotate-teapot

 

[ASK]step-by-step building simple AR application

June 22, 2013 - 8:07pm #29

Can I give Gesture/Swipe Event for the 3D model?

So when I swipe the screen after the model displayed, the model rotate and the value of the rotation depend on swipe event...

 

[ASK]step-by-step building simple AR application

June 22, 2013 - 8:03pm #28

ok solved...

The scale for teapot object is too big...

After I change to normal scale the target displayed the model...

[ASK]step-by-step building simple AR application

June 22, 2013 - 7:51pm #27

this my value for kObjectScale

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

I think that there's no problem with the rendering code, I have tried to log every single if clause and it succeed...

Or maybe the scale is to big for the teapot?

Let me try one more time with smaller scale....

[ASK]step-by-step building simple AR application

June 22, 2013 - 12:09pm #26

The code looks right, but you might need to change the kObjectScale value depending on which model you want to render; it could be that you don't see one of the 2 models because the kObjectScale is too small for it...

there might also be other reasons (for example have you verified that each target is actually detected, by logging some message to the console ??   This would be the first thing to verify, and then if you are sure that they are both detected, you can focus on the rendering issue...)

 

[ASK]step-by-step building simple AR application

June 22, 2013 - 9:35am #25

this is my renderImage() code after a modification...

JNIEXPORT void JNICALL
Java_com_ta_arbook3d_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject)
{
    //LOG("Java_com_ta_arbook3d_GLRenderer_renderFrame");

    // Clear color and depth buffer 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    
    // Explicitly render the Video Background
    QCAR::Renderer::getInstance().drawVideoBackground();
       
#ifdef USE_OPENGL_ES_1_1
    // Set GL11 flags:
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);
        
#endif

    glEnable(GL_DEPTH_TEST);

    // We must detect if background reflection is active and adjust the culling direction. 
    // If the reflection is active, this means the post matrix has been reflected as well,
    // therefore standard counter clockwise face culling will result in "inside out" models. 
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    if(QCAR::Renderer::getInstance().getVideoBackgroundConfig().mReflection == QCAR::VIDEO_BACKGROUND_REFLECTION_ON)
        glFrontFace(GL_CW);  //Front camera
    else
        glFrontFace(GL_CCW);   //Back camera


    // Did we find any trackables this frame?
    for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
    {
        // Get the trackable:
        const QCAR::TrackableResult* result = state.getTrackableResult(tIdx);
        const QCAR::Trackable& trackable = result->getTrackable();
        QCAR::Matrix44F modelViewMatrix =
            QCAR::Tool::convertPose2GLMatrix(result->getPose());        

        // Choose the texture based on the target name:
        int textureIndex;
        if (strcmp(trackable.getName(), "Earth") == 0)
        {
            textureIndex = 0;
        }
        else if (strcmp(trackable.getName(), "TestImage") == 0)
        {
            textureIndex = 1;
        }

        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*) &teapotTexCoords[0]);
        //glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &teapotVertices[0]);
        //glNormalPointer(GL_FLOAT, 0,  (const GLvoid*) &teapotNormals[0]);
        glVertexPointer(3, GL_FLOAT, 0, test_earthVerts);
        glNormalPointer(GL_FLOAT, 0, test_earthVerts);
        glTexCoordPointer(2, GL_FLOAT, 0, test_earthTexCoords);
        glDrawArrays(GL_TRIANGLES, 0, test_earthNumVerts);
        //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]);

        float angle = -180.0f; // YOUR ROTATION ANGLE HERE (in degrees)
        SampleUtils::rotatePoseMatrix(angle, 0.0f, 0.0f, 1.0f,
                                     &modelViewMatrix.data[0]);

        SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                                     &modelViewMatrix.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewMatrix.data[0] ,
                                    &modelViewProjection.data[0]);

        glUseProgram(shaderProgramID);
        
        if (strcmp(trackable.getName(), "Earth") == 0)
        {
			glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
					(const GLvoid*) &test_earthVerts[0]);
			glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
					(const GLvoid*) &test_earthVerts[0]);
			glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
					(const GLvoid*) &test_earthTexCoords[0]);
        }
        else if(strcmp(trackable.getName(), "TestImage") == 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);
        glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );
        if (strcmp(trackable.getName(), "Earth") == 0)
        {
			glDisable(GL_CULL_FACE);
			glDrawArrays(GL_TRIANGLES, 0, test_earthNumVerts);
			glEnable(GL_CULL_FACE);
        }
        else if(strcmp(trackable.getName(), "TestImage") == 0)
        {
        	glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
        			(const GLvoid*) &teapotIndices[0]);
        }
        //glDrawElements(GL_TRIANGLES, (faces_count[0]*3), GL_UNSIGNED_SHORT,
        //               (const GLvoid*) &indexes[0]);

        SampleUtils::checkGlError("ImageTargets renderFrame");
#endif

    }

    glDisable(GL_DEPTH_TEST);

#ifdef USE_OPENGL_ES_1_1        
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
    glDisableVertexAttribArray(vertexHandle);
    glDisableVertexAttribArray(normalHandle);
    glDisableVertexAttribArray(textureCoordHandle);
#endif

    QCAR::Renderer::getInstance().end();
}

it can load the earth model from earth image, but it can't load teapot model from TestImage image...

I have added #include "Teapot.h" above it

[ASK]step-by-step building simple AR application

June 21, 2013 - 10:47am #24

Yes, it is possible.

Have a look at the sample code in ImageTargets.cpp; the renderFrame() function contains the necessary code, which you can rearrange for your needs;

in particular, have a look at the OpenGL code around the lines glVertexAttribPointer() and following lines; that's the code that renders a model in OpenGL;

also, another useful code bit is the one which sets the texture depending on the name of the target (see textureIndex variable and how this is set to different values);

that's your starting point, you can easily re-use that code to achieve the rendering of different 3D models based on the specific target.

 

[ASK]step-by-step building simple AR application

June 21, 2013 - 10:11am #23

ok, solved.

Is it possible in 1 dataset, every target inside it displaying different 3d model?

e.g: dataset A(contains image1, image2, image3), image1 displaying teapot model, image2 displaying cube model, image3 displaying sphere model

If it's possible what code do I have to add?

Thx

[ASK]step-by-step building simple AR application

June 20, 2013 - 2:01am #22

You're welcome.

 

Concerning your second question, about increasing the heap memory size of your app, this is Android-specific, and you can find many threads over the internet, for instance this is one:

http://stackoverflow.com/questions/11275650/how-to-increase-heap-size-of-an-android-application

 

[ASK]step-by-step building simple AR application

June 19, 2013 - 8:04pm #21

it worked, thx :)

another problem, when I run my app in my device it can display the 3D model...

but not long after displayed the model it went crashed...

logcat said :

06-20 09:58:21.013: E/AndroidRuntime(17001): java.lang.OutOfMemoryError: (Heap Size=40611KB, Allocated=28131KB)

I was wondering how to make the memory bigger so I can run the app smoothly...

[ASK]step-by-step building simple AR application

June 19, 2013 - 11:43am #20

Hi, from the attached image I seem to see that the problem is with triangle culling;

what you can do is to add this line just BEFORE your glDrawArrays() line of code:

glDisable(GL_CULL_FACE);

and then add this line right AFTER the glDrawArrays():

glEnable(GL_CULL_FACE);

 
Let me know if that solves the issue
 

[ASK]step-by-step building simple AR application

June 19, 2013 - 11:33am #19

Hi AlessandroB,

I have a problem when my device render my 3D model,

#1 : I have followed the code in here : https://developer.vuforia.com/forum/rendering-opengl-es/convert-obj-h

       but the rendered model looked worst...

       Can you help me?

 

#2 : In my .h file it has testEarthVerts, testEarthTexCoords, but didn't have testEarthNormals... 

       How do I get it? I'm using Blender for my 3D model, I have Unwrapped it for the texCoords, 

       but when I convert .obj file into .h file it didn't have Normals inside it...

Thx

 

 

AttachmentSize
Image icon ARB3D200613-012128.jpg315.41 KB

[ASK]step-by-step building simple AR application

June 13, 2013 - 3:06am #18

Hi, about rotatign the model, you can check this article here:

https://developer.vuforia.com/forum/faq/android-how-can-i-rotate-teapot

Concerning the model texture rendering, this depends on the texture coordinates of the model, but it has nothing to do with Vuforia...

 

[ASK]step-by-step building simple AR application

June 13, 2013 - 1:03am #17

anyone can help my problem?

till now I'm stuck in here...

thx :)

[ASK]step-by-step building simple AR application

June 10, 2013 - 5:31am #16

So, is there a way to make my model rotate dynamically?

I have one more  question,

I have apply my own texture on my own model, but it's looks alike didn't fit with my model...

How do I fix it? here

AttachmentSize
Image icon ARB3D1.jpg302.04 KB

[ASK]step-by-step building simple AR application

June 10, 2013 - 2:30am #15

Hi,

an infinite loop will make your application block in that rendering code, as you never exit the loop...

[ASK]step-by-step building simple AR application

June 10, 2013 - 12:42am #14

Hi AlessandroB,

Can I add Infinite Loop code in ImageTarget.cpp?

just like this

QCAR::Matrix44F modelViewProjection;
 
SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale,
                                 &modelViewMatrix.data[0]);
 
float angle = 3.0f; // YOUR ROTATION ANGLE HERE (in degrees)
for(;;)
{
      SampleUtils::rotatePoseMatrix(angle, 0.0f, 0.0f, 1.0f,
                                  &modelViewMatrix.data[0]);
}
 
SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                             &modelViewMatrix.data[0]);
SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                            &modelViewMatrix.data[0] ,
                            &modelViewProjection.data[0]);

Cause I want to make the rotation dynamically. Is that possible?

[ASK]step-by-step building simple AR application

June 4, 2013 - 11:43pm #13

#1 : Can I display a TextView while in the Camera mode (while looking for the target)?

yes, you can. You need to simple add a TextView on top of the OpenGL View; if you look at the ImageTargets sample, in ImageTargets.java you can find some code to add a view in overlay on top of the mGLView (search the mUILayout variable in the sample code and see how it is added; in particular pay attention to the methods addContentView() and bringToFront() )

Note that the best is to create those TextView during the Activity creation phase, and then simply set them to VISIBLE or INVISIBLE when you want to show/hide them.

You may also want to look at this article, which explains how to perform some UI operations (such as showing a text message) in response to a target detection event:

https://developer.vuforia.com/forum/faq/android-how-can-i-update-my-ui-response-tracking-events

 

#2 : How do I make a simple animation(rotation) of a 3D model?

you may want to checked this page?

https://developer.vuforia.com/forum/faq/android-how-can-i-rotate-teapot

 

[ASK]step-by-step building simple AR application

June 4, 2013 - 9:40pm #12

Hi AlessandroB,

I have a questions about adding a feature in my AR app..

#1 : Can I display a TextView while in the Camera mode (while looking for the target)?

So the example is like this....

while getting 3D model of some target I can display a TextView with description of that 3D model...

3D model (Ball) -> Description in TextView(Used to play football)

3D model (earth) -> Description in TextView(bla bla bla)

 

#2 : How do I make a simple animation(rotation) of a 3D model?

example :

rotation of the planets

rotation of the wheels

 

Thx :)

[ASK]step-by-step building simple AR application

June 3, 2013 - 10:07am #11

I have replied in that thread.

[ASK]step-by-step building simple AR application

June 3, 2013 - 9:41am #10

AlessandroB wrote:

Hi,

how to add a different model for a different dataset is implicitly shown in the existing Image target sample (the sample sets different textures to the teapot model based on which target is detected, but you can also just adjust the OpenGL code to render a different mesh depending on which target is detected);

the relevant code is in renderFrame() function of ImageTargets.cpp;

every 3D model in your project should result in a header file (similar to teapot.h), so basically you just need to dupliacted the rendering code to use the vertices, normals and texture coordinates of your meshes (instead of teapotVerts, teapotNormals, teapotTexCoords), using some simple application logic similar to the one shown in the existing ImageTargets sample to select a different texture.

 

When using my own data set...my model look collision
for 
easy ,please answer in this thread mr.admin :https://developer.vuforia.com/forum/android/2-different-image-targets-and-2-objects#comment-2028032

[ASK]step-by-step building simple AR application

June 3, 2013 - 4:34am #9

Solved.

Sorry, my bad. :)

[ASK]step-by-step building simple AR application

June 3, 2013 - 3:27am #8

Hi AlessandroB,

I have export and import QCAR.jar file in Java Build Path, but I still have this error when I run my app on my device :

06-03 17:09:11.445: E/AndroidRuntime(19137): java.lang.NoSuchMethodError: no method with name='getTexture' signature='(I)Lcom/qualcomm/QCARSamples/ImageTargets/Texture;' in class Lcom/ta/arbook3d/ImageTargets;

and my app crashes after displaying camera overlay layout...

how do I fix it?

[ASK]step-by-step building simple AR application

June 3, 2013 - 2:24am #7

Hi,

how to add a different model for a different dataset is implicitly shown in the existing Image target sample (the sample sets different textures to the teapot model based on which target is detected, but you can also just adjust the OpenGL code to render a different mesh depending on which target is detected);

the relevant code is in renderFrame() function of ImageTargets.cpp;

every 3D model in your project should result in a header file (similar to teapot.h), so basically you just need to dupliacted the rendering code to use the vertices, normals and texture coordinates of your meshes (instead of teapotVerts, teapotNormals, teapotTexCoords), using some simple application logic similar to the one shown in the existing ImageTargets sample to select a different texture.

 

[ASK]step-by-step building simple AR application

June 3, 2013 - 12:36am #6

didithere wrote:

OK.

I get all the points so far.

Now I'm wondering how do we add different model for every target we have in dataset?

Target 1 : Stones -> Model : Teapot

Target 2 : Chips -> Model : Sphere

Thx.

 

i've same question....now im using SDK 2.0 , 

[ASK]step-by-step building simple AR application

May 31, 2013 - 10:46am #5

OK.

I get all the points so far.

Now I'm wondering how do we add different model for every target we have in dataset?

Target 1 : Stones -> Model : Teapot

Target 2 : Chips -> Model : Sphere

Thx.

[ASK]step-by-step building simple AR application

May 30, 2013 - 4:37am #4

One way of making your model work with your app (if you don't use Unity) is to convert the model to OBJ format, and then convert the OBJ model to a header file using some script;

the whole procedure is detailed in this article:

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

You can also find more articles on related topics in our FAQ page:

https://developer.vuforia.com/forum/faq/faq

 

[ASK]step-by-step building simple AR application

May 30, 2013 - 4:27am #3

Hi AlessandroB :)

Thx for you reply...

OK I think I got the point for question #2. Thx :)

Is there any best way that I can do to make my own 3D model works with my app?

[ASK]step-by-step building simple AR application

May 29, 2013 - 11:40pm #2

Hi,

if you want to import 3D models in .FBX, you will need to integarate some 3rd parties libraries that support that feature,

or to implement your own parser and renderer (the latter solution can be quite challenging, so I would not recommend it).

Concerning your question about which files to import to build an AR app, I would suggest to have a look at the ImageTargets sample and try to build and run it;

you can follow the instructions here:

https://developer.vuforia.com/resources/dev-guide/step-3-compiling-running-vuforia-sample-app

 

Log in or register to post comments