Hi All,
As Kim said the post could help me, but I could not open the page, who can help me?
https://ar.qualcomm.at/arforums/showpost.php?p=1596
Hi All,
As Kim said the post could help me, but I could not open the page, who can help me?
https://ar.qualcomm.at/arforums/showpost.php?p=1596
Hi,
I am a beginner started to work on drawing 2d image on target using openGL but I have faced the same error like discussed below. I have followed the instructions in the link: https://developer.vuforia.com/library/articles/Solution/How-To-Draw-a-2D-image-on-top-of-a-target-using-OpenGL-ES . It shows me the same casting error. What should I do to display 2d picture or texture on my Image Target.
Any advice or link to solve problem would be so helpfull. I appreciate for your support.
Check this updated version:
https://developer.vuforia.com/resources/dev-guide/replacing-teapot
This contains correct C++ code, as well as Java code if you use the Java API.
hi ,
i facing the problem like below when i compile the image target .cpp on the cygwin terminal .i modified the coding by follow ur instruction .i m not sure which part i have done wrong .
That article refers to C++ and JNI folder because it refers to the Android C++ native sample code (see the ImageTargetsNative sample in Vuforia 2.8).
It does not apply to Unity; in Unity, this is a task that can be really done by following the Unity developer guide... and this is not so relevant to Vuforia per-se.
hi Allesandro B ,
can i ask another question if i want to modify using vuforia by following this link :https://developer.vuforia.com/resources/dev-guide/textured-plane-target
but i saw that the sample is guide us in modify the c++ code in jni folder but i didnt see any c file there ..so where i can change the planes vertices ...
thank uu:)
Glad to hear that you solved it :-)
More in general, if you still meet similar issues, please check the migration guide (to port code from 1.5 to 2.0):
https://developer.vuforia.com/resources/dev-guide/migrating-your-android-sdk-project
I have the same error as Mita.
I did what Kim said on this forum post nr 3:
https://developer.vuforia.com/forum/qcar-api/understanding-getpose-function
But when i compile it with NDK i get a invalid cast error from QCAR Trackable to QCAR imageTarget.
I'm using Vuforia SDK 2.0
Can someone help me?
Best Regards.
I solved it:
Solution:
QCAR::Vec2F targetSize = (( QCAR::ImageTarget *) &trackable)->getSize();
Hi Mita, thanks for the link to your source code;
I downloaded it, but it actually looks like some code with some JS functions;
could you double check that the ImageTargets.cpp contains the right piece of code ?
Otherwise you can also copy-paste here the relevant code snippet that fails to compile, so I can verify it.
Thanks.
One question: are you using Vuforia 1.5 or 2.0 at the moment ?
hi AlessandroB,
Thanks for guidance
I had added plan coordinates on top of the ImageTarget.cpp.
You can find that file from
https://www.dropbox.com/sh/1665izr0v9tnf89/1pDFGyn75D
I had follow all the step used for 2d image in image target
But when I compile the code with ndk-build it will give following error.
invalid cast from type 'const QCAR::Trackable' to type 'QCAR: :ImageTarget*'
Please guide
Thanks & Regards
Mita
Hi, have you tried including the ImageTarget.h header ?
#include <QCAR/Trackable.h>
#include <QCAR/ImageTarget.h>
For the texPlaneCoords, that is just an example, but you need to define by yourself a simple rectangular geom with texture coordinates
to render the picture on top of it.
I hope this helps.
Hello AlessandroB
Thanks for suggestion,
now I have decided to use 2d picture instead of 3d object, but when I using the code given in below link
It will give following error,
jni/ImageTargets.cpp: In function 'void
Java_com_qualcomm_QCARSamples_ImageTarge
ts_ImageTargetsRenderer_renderFrame(JNIEnv*, jobject)':
invalid cast from type 'const QCAR::Trackable' to type 'QCAR::ImageTarget*'
'planeTexCoords' was not declared in this scope
Please guide,
Thanks & regards
mita
Hi, the suggested code and technique to display the model in OpenGL is correct in general,
however, for complex models it can happen that the model is not exported in a fully correct way using the conversion tool (we have seen this kind of issues also with other models in the past);
in such a case, honestly using a game engine like Unity is a much better option;
for the license you can check on the Unity3D website, as they have multiple license schemes.
Hello AlessandroB
Thanks for your quick reply, I change accordingly but it not looks good. I have doubt that is this a right way to display object or there is another way? Can u please advice which is the better for my requirement, can I have to use unity 3d to display 3d object? Is it free for commercial purpose? Or simply use jpg image instead of 3d object?
I tried to put 2d image. I followed the guide line given in below link
But gives error
jni/ImageTargets.cpp: In function 'void
Java_com_qualcomm_QCARSamples_ImageTarge
ts_ImageTargetsRenderer_renderFrame(JNIEnv*, jobject)':
invalid cast from type 'const QCAR::Trackable' to type 'QCAR::ImageTarget*'
'planeTexCoords' was not declared in this scope
What can I do? Please guide
Thanks & regards
Mita
Hi Mita,
I have tested your teapot.h (house model) and I checked your code in ImageTargets.cpp:
actually one of the problems is that about 50% of the triangles of the 3D model are culled away by OpenGL, so you only see half of the triangles (and you see holes for the missing ones);
to avoid this, you need to disable the OpenGL face culling right before calling glDrawArrays() and then re-enable it back after the draw call, i.e. your draw code should be modified as follows:
Hello,
Thanks for your continuous support
I had created sample application for 3d Augmentation of house view. now my problem is 3d object not create properly and blinking when camera focus on target image.
i have put my code in dropbox.
dropbox information
Email Id :mita.vaghela@gmail.com
password:mita3183
https://www.dropbox.com/home/3D%20Augmentation
here house.jpg is how 3d house will display.
image001.jpg is target image on which 3d house will display
ImageTargets.cpp for object settings
Teapot.h header file for house
houseF.obj object file for house.
kindly review the code and guide for the same.
thanks & Regards
Mita
Hi Mita,
if the size of your header file is too big to be handled by Eclipse, this is a clear indication that you should not use such a mesh;
even if you manage at some point to get Eclipse to pick up (without hanging) and compile your large header file, probably your Android device will not be able to render it, due to:
- memory constraints
- OpenGL-ES limitations in the size of the mesh that can be rendered (consider that the size of a vertex array cannot exceed 65,000 vertices/indices; so you should then split your mesh into several vertex arrays, each one containing less than 65,000 vertices)
What I would suggest is to first make a simnpler test by integrating relatively small 3D models (low polygon count), and if you are successfull with that, then you could verify if larger models work (maybe proceeding incrementally with 3 or 4 models of different sizes).
Hi,
about using the model without textures:
yes, it is possible, just remove (or comment out) these lines of code in the _renderFrame function in ImageTargets.cpp:
glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
Then, in the shader (see CubeShader.h ) you need to change this line:
gl_FragColor = texture2D(texSampler2D, texCoord);
replace it with:
gl_FragColor = vec4 (1.0, 1.0, 1.0, 1.0); //Note: (1.0, 1.0, 1.0, 1.0) is white color, => use your desired R,G,B,A values to get the color that you want
For your other question:
could you PM me the header file (.h) of your model, so that I can have a look and try to render it ?
Hello,
Thanks for reply,
I want to develop apps in that there is one house construction plan on paper and by this apps it will show 3d view of that house.
but when i generate 3d view with skechup and create .obj file with blender and convert in to .h file and use in my apps.the 3d object which is display is not showing properly and is it posible to use object with out texture?
please guide.
Thanks & Regards
Mita
Hi Mita,
have you followed the process described in this thread:
https://developer.vuforia.com/forum/faq/android-how-do-i-replace-teapot
?
Also, you may want to check in the FAQs section for other possible discussions related to this topic:
https://developer.vuforia.com/forum/faq/
If, after reading the above, you still have questions on the OBJ integration, you can post it here (but please try to describe your problem with sufficient detail, so that we can help effectively).
Hello,
I am using ImageTarget example for 3d augmention.
My requirement is to i have to create app like there is structure of house.and by app it shows house 3d view.
i have create .obj file of house. but it will not display currectly.i also have problem with its texture.
please guide
Thanks & Regards
Mita
I've read my post again and maybe it's confusing. The problem is not that the texture doesn't reder well, what isn't working well is the plane which must be reder over the trackable, the 2d plane which is replacing the 3d object.
I need only that to complet my project. could you help me?
Thanks
Ok. It's fixed the problem in the sample trackable I could see the image. Now I know that the image have to be 2x in width and height. But, on the other hand, when I tried with my trackable it isn't fixed and the 2d plane(in black) only appear when I'm closed to the image and not with some distance, I will tried to upload a screen capture.
Here it is. I put the camera in angle to see how in the nearest part of the trackabale (a Velazquez picture) we can see the plane built in black but in the farest part the plane isn't built.
http://www.freeimagehosting.net/newuploads/rpaqr.png
Thanks.
Is this picture in the /assets folder?
And you are using the correct texture index the C++ file?
private void loadTextures()
{
// textures[0]
mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",
getAssets()));
// textures[1]
mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png",
getAssets()));
// textures[2]
mTextures.add(Texture.loadTextureFromApk("TextureTeapotRed.png",
getAssets()));
}
Hi, I did what you say and I was able to see the teapot png picture in the plane but if the the loadTexture method I change that file for any other .png file the plane looks black.
I only change:
mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png",getAssets()));
for this other line whre Awesome.png is a random picture from the internet:
mTextures.add(Texture.loadTextureFromApk("Awesome.png", getAssets()));
Thanks
Can you post your renderFrame code? Also be sure that you're adding the texture that you want to use.
hi thanks for the instruction above and I've tried it in the ImageTargets sample, it does succeed but unfortunately, only shows up a black pic.
however, the teapot shows up too but the sharp is strange and not fully visiable seems been stretched.
Please help me. Now Im livin' hell...
you should mark the source code and replace like this:
quote :-----------------------------------------------------------------------------------------------------------------------
/*
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*) &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]);
*/
QCAR::Vec2F targetSize = ((QCAR::ImageTarget *) trackable)->getSize();
QCAR::Matrix44F modelViewProjection;
SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]);
SampleUtils::scalePoseMatrix(targetSize.data[0], targetSize.data[1], 1.0f, &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*) &planeVertices[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &planeNormals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &planeTexCoords[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, 6, GL_UNSIGNED_SHORT, (const GLvoid*) &planeIndices[0]);
-----------------------------------------------------------------------------------------------------------------------
and don't forget
#include <QCAR/ImageTarget.h>
These are the instructions that she was referring to. Basically you are going to define a plane and map your picture to that in the same way that you would map a texture to any other 3D model.
Start with the ImageTargets sample project. Open ImageTargets.cpp, located in the jni folder.
Add the following just after the includes at the top:
#include <QCAR/ImageTarget.h>
static const float planeVertices[] = { -0.5, -0.5, 0.0, 0.5, -0.5, 0.0, 0.5, 0.5, 0.0, -0.5, 0.5, 0.0, };
static const float planeTexcoords[] = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 };
static const float planeNormals[] = { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0 };
static const unsigned short planeIndices[] = { 0, 1, 2, 0, 2, 3 };
Now replace the OpenGL ES 2.0 rendering code in the renderFrame method with the following:
// assuming this is an image target
QCAR::Vec2F targetSize = ((QCAR::ImageTarget *) trackable)->getSize();
QCAR::Matrix44F modelViewProjection;
SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]);
SampleUtils::scalePoseMatrix(targetSize.data[0], targetSize.data[1], 1.0f, &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*) &planeVertices[0]); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &planeNormals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &planeTexcoords[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, 6, GL_UNSIGNED_SHORT, (const GLvoid*) &planeIndices[0]);
Build the native code, using ndk-build for Android, then refresh the Eclipse or XCode project and run the app. You should see the teapot texture stretched over the image target.
You can swap the texture by adding your image to the project's assets folder (png or jpg format). Then open ImageTargets.java and look for the loadTextures() method. Replace the teapot texture filenames with your own. Note that the order the textures are added set the order they are stored in the native textures array (the first texture is at position 0).
Hi, there
I solved my cast problem with this code
HTH
Navin