1
$\begingroup$

I am attempting to export objects from blender into .obj format for use in an opengl program I am writing. Currently, I am attempting to create shape keys in blender, then export them, then interpolate between them as my program runs.

Below is the python command that I use to export the .obj file.

bpy.ops.export_scene.obj(
    filepath = temp.name,
    use_selection = True,
    use_edges = False,
    use_normals = True,
    use_uvs = True,
    use_materials = False,
    use_triangles = True,
    keep_vertex_order = True)

Both the initial and final steps of the animation look as expected, with the shape key either applied entirely, or not applied at all. However, in the interpolation between the two shape keys, there are graphical issues as shown below.

non-interpolation step interpolation step

This seems to be caused by inconsistent triangulation between the two different shape keys, since the diagonal between the corners of the rectangles goes in the opposite direction at the two ends of the animation. I would not have expected this, since I had passed the keep_vertex_order flag to the exporter. Am I understanding the issue correctly, and is there a way to keep consistent triangulation?

$\endgroup$
1
$\begingroup$

You could add a Triangulate Modifier, with either Fixed or Fixed Alternate as the Quad Method. Make sure to Apply modifier in the .obj exporter with:

for obj in bpy.context.selected_objects:
    if not 'Triangulate' in obj.modifiers:
        tri_mod = obj.modifiers.new(name='Triangulate', type = 'TRIANGULATE')
        tri_mod.quad_method = 'FIXED'

bpy.ops.export_scene.obj(
    filepath = temp.name,
    use_selection = True,
    use_edges = False,
    use_normals = True,
    use_uvs = True,
    use_materials = False,
    use_triangles = True,
    keep_vertex_order = True
    use_mesh_modifiers = True)
$\endgroup$
  • $\begingroup$ Hmmm, I'm getting an error that TriangulateModifier has no attribute quad_method. I was able to work around it by manually triangulating the output, but I would prefer your method if I can get it to work, as it is much cleaner. $\endgroup$ – Eldritch Cheese Jun 27 '14 at 21:11
  • $\begingroup$ Ah, I don't know when this was added, or if it was there from the start. If you see the Quad Method option in the Modifiers panel, you can hover over it to see the name of the attribute (eg. ...modifiers["Triangulate"].quad method in my build) and modify the script accordingly. Which version are you using? $\endgroup$ – Pisurquatre Jun 27 '14 at 22:54
  • $\begingroup$ Currently, using version 2.69, the version that is in the linux mint repository, and the option is not available from the GUI, either. On my other machine, a windows machine with 2.70, the option is available, so it looks like it was added at that point. Thank you. $\endgroup$ – Eldritch Cheese Jun 27 '14 at 23:45

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.