3
$\begingroup$

I am currently trying to make a rollercoaster in OpenGL. To do this, I prepared the track in Blender (following a Bezier curve) and exported it along with the curve as .obj files in OpenGL.

My problem is that I can't find a way to export the normals (or TILT values) from Blender. What I have already done works fine but I also need to export some information concerning the orientation if I want the camera to point in the right direction in the final animation.

I know that a few questions concerning this issue have already been posted but I couldn't find an answer in any of these.

Could anyone help me with this? Thanks in advance!

$\endgroup$
  • 1
    $\begingroup$ You want to do this with a custom python script I assume? Each BezierSplinePoint has a tilt attribute, which you can access via script. docs.blender.org/api/blender_python_api_current/… $\endgroup$ – HENDRIX Dec 28 '17 at 12:21
  • $\begingroup$ Yes, I wanted to do that but ideally for every single point of the Bezier curve, not only the control points. $\endgroup$ – Oskar Dec 28 '17 at 12:36
  • $\begingroup$ You could interpolate the tilt between the handles. It would help if you show some code of how you're getting your points. Are those just vertices following a bezier, or are you trying to export the bezier directly? $\endgroup$ – HENDRIX Dec 28 '17 at 17:18
  • $\begingroup$ Yes, interpolating the points in OpenGL would actually be a great idea! I found some python scripts here and there to extract all the control points + handles from Blender, before importing them in OpenGL and recalculating the Bezier Curve. I wrote a code to estimate the Bezier Curve in OpenGL, so that's fine, but surprisingly none of the python scripts I tried previously (to export the control points) worked... I am not really familiar with python, how would you go and write a code like this one? $\endgroup$ – Oskar Dec 29 '17 at 7:09
  • $\begingroup$ First you'll need to gather your data, so get the curve object and iterate over all its BezierSplinePoints to get the tilt, handle_left & handle_right values for each. Then you'll need to write these to a file, presumably in a simple custom format. $\endgroup$ – HENDRIX Dec 29 '17 at 9:22
1
$\begingroup$

After quite some research, I am pretty sure it is not possible to directly extract the curve's normals from Blender, but it is possible to extract the control point's TILT values with a Python script. However, I found a solution to recalculate the normals in OpenGL which I will present here in case someone has the same issue in the future.

I realised that blender calculates the normals using an algorithm which minimises the twisting of the normals compared to the previous values (called "Minimum"). Since I didn't find a way to export these normals from Blender, nor a complete explanation of the algorithm, what I did first was to change the normals' calculation to "Z-UP" in Blender (which is simply another way of calculating normals). Then I imported the curve's control points and handles with a Python script and recalculated the normals in OpenGL as for a standard Bezier curve. Finally, I still had some issues with the twisting and especially where the end meets the beginning of the curve. This problem was solved by calculating the normals using the previous point's normal and adding a low and constant value to the latter's y component.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.