Maniphest T76715

exporting animated shapekeys as triangulated .OBJ files with default exporter cause invalid mesh result
Confirmed, NormalBUG

Assigned To
None
Authored By
Unknown Object (User)
May 13 2020, 11:12 AM
Tags
  • Add-ons (Community)
  • Import/Export
Subscribers
Germano Cavalcante (mano-wii)
Philipp Oeser (lichtwerk)

Description

System Information
Operating system: Win10PRO 64bit
Graphics card:

Blender Version
2.82
2.83

Short description of error
When exporting it as .OBJ files (with "Animation" and "Triangulate Faces" options) then the output is invalid and also the viewport shows the invalid mesh after export.
This does not happen, when "Triangulate Faces" is not selected;

Exact steps for others to reproduce the error

  • Open File
  • export as OBJ
  • enable Animation
  • enable Triangulate Faces
  • export

The object in the scene is changed as if the shapekey was applied multiple times

bmesh used together with "relative shape keys" seems to be the reason.
Written OBJs are false though.

In this other file, the code that brings the problem was copied in the Text Editor.
To reproduce the same problem just:

  • run the script.

The correct mesh data can be restored in the viewport to the original values by entering EditMode and then again changing back to ObjectMode.

Event Timeline

Unknown Object (User) renamed this task from exporting .OBJ file with default exporter causes invalid result to exporting animated shapeleys as .OBJ file with default exporter causes invalid result .May 13 2020, 11:12 AM
Unknown Object (User) renamed this task from exporting animated shapeleys as .OBJ file with default exporter causes invalid result to exporting animated shapeleys as triangulated .OBJ files with default exporter causes invalid result .
Unknown Object (User) created this task.
Unknown Object (User) updated the task description.
Unknown Object (User) updated the task description.May 13 2020, 11:20 AM
Unknown Object (User) renamed this task from exporting animated shapeleys as triangulated .OBJ files with default exporter causes invalid result to exporting animated shapekeys as triangulated .OBJ files with default exporter cause invalid mesh result .May 13 2020, 11:30 PM
Unknown Object (User) updated the task description.
Unknown Object (User) updated the task description.May 13 2020, 11:43 PM
Philipp Oeser (lichtwerk) changed the task status from Needs Triage to Confirmed.May 14 2020, 3:17 PM
Philipp Oeser (lichtwerk) edited projects, added Add-ons (Community), Import/Export; removed BF Blender.
Philipp Oeser (lichtwerk) changed the subtype of this task from "Report" to "Bug".
Philipp Oeser (lichtwerk) added a subscriber: Philipp Oeser (lichtwerk).

Can confirm, checking...

Philipp Oeser (lichtwerk) added a subscriber: Germano Cavalcante (mano-wii).May 14 2020, 4:21 PM

Not sure from quick glance...

@Germano Cavalcante (mano-wii): does this ring a bell? (just thinking, because you authored D6514, D6516 -- which might be related?)

Germano Cavalcante (mano-wii) added a comment.May 14 2020, 4:39 PM

I am having trouble following the steps to reproduce the problem.
Can these steps be more detailed?

Philipp Oeser (lichtwerk) updated the task description.May 14 2020, 4:53 PM
In T76715#931637, @Germano Cavalcante (mano-wii) wrote:

I am having trouble following the steps to reproduce the problem.
Can these steps be more detailed?

updated the report description, does this help?

Germano Cavalcante (mano-wii) added a comment.EditedMay 14 2020, 8:17 PM

I can confirm the problem.
It happens along these lines: https://developer.blender.org/diffusion/BA/browse/master/io_scene_obj/export_obj.py$40-46

The code to convert bmesh to mesh always "rebases" the shapekey by taking the difference between the bmesh and the original coordinates of the shapekey that is active.
But in my opinion this "rebase" should only be done when toogle edit mode and object mode.

I'm not sure if the problem is in bm.from_mesh(me) or if it is with bm.to_mesh(me).
There may be something wrong there, but I find it redundant to use the bmesh.ops.triangulate(bm, faces=bm.faces) to triangulate the mesh.
The mesh already informs the triangles through mesh.loop_triangles.
Perhaps this conversion can be disregarded.

Germano Cavalcante (mano-wii) updated the task description.May 14 2020, 8:47 PM
Unknown Object (User) added a comment.May 15 2020, 4:04 AM

thanks for confirming my report as bug.

using mesh.loop_triangles would be tempting, but in this line:
https://developer.blender.org/diffusion/BA/browse/master/io_scene_obj/export_obj.py$376
"polygons" of type MeshPolygons are needed to build the face/UV pairs.
Is there a conversion from "MeshLoopTriangles" to "MeshPolygons" possible throught the bpy API ?
that would help a lot.

Germano Cavalcante (mano-wii) added a comment.EditedMay 15 2020, 2:02 PM

We could do something like this to fix it:

diff --git a/source/blender/bmesh/intern/bmesh_mesh_conv.c b/source/blender/bmesh/intern/bmesh_mesh_conv.c
index de32d7881b0..8832a93c792 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_conv.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_conv.c
@@ -812,7 +812,7 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
 
   /* See comment below, this logic is in twice. */
 
-  if (me->key) {
+  if (me->key && me->runtime.is_original) {
     KeyBlock *currkey;
     KeyBlock *actkey = BLI_findlink(&me->key->block, bm->shapenr - 1);

I believe there is no problem but I am not sure.
I will propose this patch for review and see with the developers later.