Log in or register to post comments

Normal, Texture, and Index

December 21, 2011 - 2:20pm #1

Hello, I'm using Blender to make my 3D models and exporting them as .obj files. Then, I'm using the .pl code given here to convert the .obj to a .h, but when I do, all I get is the objectVerts array. I'm missing all the other ones. I tried commenting out the lines for the normal array and texture array in the ImageTargets.cpp but the cube would come out missing bits and pieces. I tried using the cube that is given to us in the zip file that only has the verts and normal and this one comes out fine, albeit in pure black.

So, question is, why am I missing the normal and texture arrays on my .h file when I convert it through the .pl code. Am I forgetting to do something in Blender to get the normals or is there anything else? I've read this thread but there doesn't seem to be anything on how to obtain the missing arrays.

Re: Normal, Texture, and Index

January 10, 2012 - 12:08pm #8

Is there a modeling program that would be better to use other than Blender for this? What software was used to make the teapot and the dominoes cube?

Re: Normal, Texture, and Index

January 4, 2012 - 7:03am #7

Hi Natzely,

This size problem sounds strange to me...
Looking in the config.xml of the default trackables, the size of the "stones" tracker is 270.
I did never used that script to convert .obj to .h, but could it be the cause of your problem?
You can look at the vertices value inside the .obj AND .h. The values should have an order of magnitude similar to the "stones" image target. This means that at least some vertices should have a value near to 270 (assuming that your model is as wide as the trackable). If you can't see a vertex value greater than, let's say, 0.1 units, then it would be suspicious.

So, you can check this out on both .obj and .h files. If you see too small values on the .obj, it would mean that your export from blender applies some undesired scaling, or maybe that the model is just too small (in this case you can just scale it on blender). If, on the other hand, the .obj is fine and the .h seems wrong, maybe the undesired scaling is on the conversion from .obj to .h and you should check this .pl script converter.

Reading .obj files is easy, you just need to open the file on a text editor and look at the numbers after a "v": these are the vertices values.
For the .h file, there is an array called "vertices" or something like that, which contains all the vertex data.

Hope it helps.


Re: Normal, Texture, and Index

January 3, 2012 - 9:22am #6

Thanks Infaust, I found the option to change the up and forward directions on Blender before you export it to a .obj file. The rotation is perfect now.

But the size doesn't seem to be doing anything. I've set it up so that is shows the metric measurements (cm, m, km) and it showed that my model was a couple of m's in the dimensions but it was still very small when it came up on the trackable. I'm using the default stones trackable for testing. I've tried to change the scale variable on both the build window and on the export window.

Well, nevermind the stuff below, which I'll leave on for reference, but it seemed that the slow rotation works if you put the static double prevTime = getCurrentTime(); inside the function. I didn't try this earlier because of the prevTime = time; . It seemed weird to have that line as both prevTime and time were being initialized and set everytime the function was being called, but I can see why setting them up each time helps the slow rotation as the rotation angle increases slower.

---Older post left for reference---
Also, I'm having troubles with stopping the rotation of the matrix at a certain angle. If I want the rotation to stop when the angle is 90 degrees, I have it set so that if the rotateBowlAngle goes over 90 it is fixed to back to 90. But what I see is a short duration of slow rotation as it should look like but then it is instantly changed to the 90 degree rotation. I'm guessing it has something to do with the rotation over time but I can't figure it out. Here is my code:

animateBowl(QCAR::Matrix44F& modelViewMatrix)
    double time = getCurrentTime();             // Get real time difference
    float dt = (float)(time-prevTime);          // from frame to frame

    if(rotateBowlAngle < 90.0f) <- To check for angle
    	rotateBowlAngle += dt * 180.0f/3.1415f;     // Animate angle based on time

    if(rotateBowlAngle > 90.0f) <- if it goes over 90 set it to 90
    	rotateBowlAngle = 90.0f;                   &modelViewMatrix.data[0]);

    SampleUtils::rotatePoseMatrix(rotateBowlAngle, 1.0f, 0.0f, 0.0f,

    prevTime = time;


This does make the model rotate the 90 and stop, but does it instantly instead of the slow rotation.

Re: Normal, Texture, and Index

January 2, 2012 - 4:46am #5


The size which your model will be rendered depends on the trackable size and the model size itself.
When you create your trackable, you need to define a size for it (e.g. in centimeters or inches). Then you need to use the same measurement unit on Blender. This means that if you want a teapot covering the entire marker, and the marker measures 100 cm, on Blender the teapot must be also 100 cm wide.

And you say also that your model is displayed side ways. You have to consider that on QCAR, the Z-Axis points out from the center of the Image Marker (I don't know how it works exactly with the "Cereal Box" marker, but probably it's similar). So you need to rotate your model on Blender in a way that the Z-Axis point in the direction that you consider "upwards". There is also an option on the Blender OBJ exporter that does this automatically (Rotate X90).


Re: Normal, Texture, and Index

December 23, 2011 - 9:44am #4

Thanks praetoriax, I found the check marks on in blender and those gave me the necessary arrays. Another question though, what size should my models be in blender for them to match the teapots with out having to change the kObjectScale. Also, the model comes out side ways and since it's smaller than the teapot, it's going around in a circle with the animateBowl function instead of standing still and doing some awsome spins.

I noticed that the bigger the model, the smaller the circle it goes around so maybe matching teapot's size in blender would help solve this problem, not sure about the sideways thing though.

Re: Normal, Texture, and Index

December 21, 2011 - 10:48pm #3

Hello. Check your export options in Blender. When exporting the model in Blender at the left side in "Export OBJ" section must be checked: Apply Modifiers, Edges, Normals, UVs, Triangulate, Keep Vertex Order, Objects as OBJ Objects.
Something like that. To use obj2opengl script model must be triangulated.
And you need Normals only for light in the shaders. If you not using light - you may forget about Normals.

Re: Normal, Texture, and Index

December 21, 2011 - 5:21pm #2

We don't provide support for external scripts. That said, you should be able to open your .obj file with a text editor and make sure the texcoords and normals are in there. In Blender, you might have to check a box somewhere on export to include these.

Note that our sample code doesn't really make use of the normals, so you can probably leave those out. The texcoords are important, however.

- Kim

Log in or register to post comments