exporting animated shapekeys as triangulated .OBJ files with default exporter cause invalid mesh result #76715

Open
opened 2020-05-13 11:12:10 +02:00 by (Deleted) · 11 comments
(Deleted) commented 2020-05-13 11:12:10 +02:00 (Migrated from localhost:3001)

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
reproducer1.blend

  • 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:

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

**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** [reproducer1.blend](https://archive.blender.org/developer/F8532573/reproducer1.blend) - 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. [bm_to_mesh_bug.blend](https://archive.blender.org/developer/F8535877/bm_to_mesh_bug.blend) The correct mesh data can be restored in the viewport to the original values by entering EditMode and then again changing back to ObjectMode.
(Deleted) commented 2020-05-13 11:12:11 +02:00 (Migrated from localhost:3001)
Author

Added subscriber: @(Deleted)

Added subscriber: @(Deleted)
blender-admin changed title from exporting .OBJ file with default exporter causes invalid result to exporting animated shapeleys as .OBJ file with default exporter causes invalid result 2020-05-13 11:13:21 +02:00
blender-admin changed title 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 2020-05-13 11:14:04 +02:00
blender-admin changed title 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 2020-05-13 23:30:53 +02:00
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Can confirm, checking...

Can confirm, checking...
Member

Added subscriber: @mano-wii

Added subscriber: @mano-wii
Member

Not sure from quick glance...

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

Not sure from quick glance... @mano-wii: does this ring a bell? (just thinking, because you authored [D6514](https://archive.blender.org/developer/D6514), [D6516](https://archive.blender.org/developer/D6516) -- which might be related?)

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

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

In #76715#931637, @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?

> In #76715#931637, @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?

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.

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.
(Deleted) commented 2020-05-15 04:04:24 +02:00 (Migrated from localhost:3001)
Author

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.

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.

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.

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.
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#76715
No description provided.