I downloaded sample Vuforia iOS project. Instead of teapot, I want to rotate a Cube with texture. To create a cube having texture, I used blender and created a OBJ file with its UV mapping image as below:
In blender, it renders perfect and I can see the cube object with its texture perfectly.
Then I converted OBJ file to .h file using perl script and replaced that Teapot.h file and also replaced teapot image with PNG I attached above.
While I run the project, the cube is seen with its texture but triangles are cut for each side as below:
I am desperate to create custom squares, cubes having textures in existing iOS project but, I am not getting success in checking feasibility.
NOTE: My project is already developed with lots of frameworks and libraries and in one screen, I need to integrate this function.
I could achieve it by having add-on to Blender and then export .h
file directly from Blender. There is no need to do triangulate before exporting as Unity
already does the triangulation for us.
Prepare the 3D object that you want in Blender. Check this tutorial which explains how to use Blender and make a simple 3D object having a texture around it.
Once you have the model that you want, go to File
> Export
> Vuforia OpenGL C Include
as shown in below image. Save the .h
file at some location
In Vuforia iOS sample project, add this .h
file and UV-mapping
image (which we used to render our object) same way Teapot.h
and its UV-mapping
image.
Import the header file.
Replace Teapot:
Replace
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)teapotVertices); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)teapotNormals); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)teapotTexCoords);
with
BlenderExportedObject object = rectObject; glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)object.vertices); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)object.normals); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)object.texCoords);
where rectObject
is object name. In my case, my Blender object name was rect
so it created rectObject
name in .h
file. Check your .h
file for find that name.
Replace
glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*)teapotIndices);
with
glDrawElements(GL_TRIANGLES, NUM_RECT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*)object.indices);
Refer to .h
file to find NUM_RECT_OBJECT_INDEX
.