FBX: Apply Modifiers in the export settings causes mesh data block names to change for meshes with applied modifier #51856

Closed
opened 2017-06-20 19:36:25 +02:00 by Henrik Berglund · 9 comments

System Information
Win 8.1, GTX1070

Blender Version
Broken: 2.78c (e92f235283) and 2.79 test 1

Short description of error
The Apply Modifiers checkbox in the FBX export settings causes mesh data block names to change if the mesh had a modifier that was applied. This can be bad if other applications (in my case UE4) uses the mesh data block name for the mesh instead of the object name. If you apply the modifier in the viewport the data block name doesn't change so I don't see a reason for it to change in the FBX export. Even if it needs to change once in the export process because of some behind the scene magic the mesh data block name should be changed back to its original name before the final export.

Exact steps for others to reproduce the error

  1. Create two cubes.
  2. Change the mesh data block names to custom names. In my test file the FancyCube object has the mesh data block name FancyCube and the NotFancyCube object has the mesh data block name NotFancyCube.
  3. Add a solidify modifier to one of the cubes.
  4. Export the scene to a .fbx with the Apply Modifiers checkbox ticked.
  5. Create a new scene and import the .fbx.

Result: The FancyCube object that had the modifier applied on FBX export has its mesh data block name changed to Mesh from FancyCube. The NotFancyCube has its original NotFancyCube mesh data block name since it didn't have any modifiers applied.

Expected: Both objects should keep their original mesh data block names.
bug_on_export_wrong_mesh_data_name.blend

**System Information** Win 8.1, GTX1070 **Blender Version** Broken: 2.78c (e92f235283) and 2.79 test 1 **Short description of error** The Apply Modifiers checkbox in the FBX export settings causes mesh data block names to change if the mesh had a modifier that was applied. This can be bad if other applications (in my case UE4) uses the mesh data block name for the mesh instead of the object name. If you apply the modifier in the viewport the data block name doesn't change so I don't see a reason for it to change in the FBX export. Even if it needs to change once in the export process because of some behind the scene magic the mesh data block name should be changed back to its original name before the final export. **Exact steps for others to reproduce the error** 1. Create two cubes. 2. Change the mesh data block names to custom names. In my test file the FancyCube object has the mesh data block name FancyCube and the NotFancyCube object has the mesh data block name NotFancyCube. 3. Add a solidify modifier to one of the cubes. 4. Export the scene to a .fbx with the Apply Modifiers checkbox ticked. 5. Create a new scene and import the .fbx. Result: The FancyCube object that had the modifier applied on FBX export has its mesh data block name changed to Mesh from FancyCube. The NotFancyCube has its original NotFancyCube mesh data block name since it didn't have any modifiers applied. Expected: Both objects should keep their original mesh data block names. [bug_on_export_wrong_mesh_data_name.blend](https://archive.blender.org/developer/F636950/bug_on_export_wrong_mesh_data_name.blend)
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @cyaoeu

Added subscriber: @cyaoeu
Author
Member

Note that this also happens when using linked mesh data. For example you create a sphere, add a subdivision modifier, create a bunch of (let's say 3) linked copies with Alt+D. Now when you import this into UE4 using the scene import you will end up with 3 meshes instead of one because the links were effectively broken during export.

Note that this also happens when using linked mesh data. For example you create a sphere, add a subdivision modifier, create a bunch of (let's say 3) linked copies with Alt+D. Now when you import this into UE4 using the scene import you will end up with 3 meshes instead of one because the links were effectively broken during export.

Added subscriber: @mont29

Added subscriber: @mont29
Bastien Montagne self-assigned this 2017-06-21 09:58:54 +02:00

This is not as simple to solve as it may look, we cannot apply modifiers to original mesh, that would modify existing Blender scene itself! So we have to make a temp copy of the mesh, and apply modifiers on it. Thing is, in Blender two datablocks of same type are not allowed to have same name. Will see if we can work around that in exporter somehow…

Note that this also happens when using linked mesh data. For example you create a sphere, add a subdivision modifier, create a bunch of (let's say 3) linked copies with Alt+D. Now when you import this into UE4 using the scene import you will end up with 3 meshes instead of one because the links were effectively broken during export.

This has absolutely nothing related, and no bug here at all. Modifiers are Object-level data, not Mesh-level data, so quite obviously three different objects with modifiers will produce three different meshes when exported, even if their base mesh is the same. You have to apply modifiers yourself before exporting in that case.

This is not as simple to solve as it may look, we cannot apply modifiers to original mesh, that would modify existing Blender scene itself! So we have to make a temp copy of the mesh, and apply modifiers on it. Thing is, in Blender two datablocks of same type are not allowed to have same name. Will see if we can work around that in exporter somehow… > Note that this also happens when using linked mesh data. For example you create a sphere, add a subdivision modifier, create a bunch of (let's say 3) linked copies with Alt+D. Now when you import this into UE4 using the scene import you will end up with 3 meshes instead of one because the links were effectively broken during export. This has absolutely nothing related, and no bug here at all. Modifiers are Object-level data, not Mesh-level data, so quite obviously three different objects with modifiers will produce three different meshes when exported, even if their base mesh is the same. You have to apply modifiers yourself before exporting in that case.

In fact, initial report is not solvable either, for pretty much same reasons: imagine you have two objects using same mesh, with at least one object with a modifier. Then we have to produce two different meshes in FBX, and we have to give them different names for consistency…

Only issue here is that temp copy gets stupid default mesh name, whereas it should get a named derived from actual obdata, will fix that.

In fact, initial report is not solvable either, for pretty much same reasons: imagine you have two objects using same mesh, with at least one object with a modifier. Then we **have** to produce two different meshes in FBX, and we **have** to give them different names for consistency… Only issue here is that temp copy gets stupid default mesh name, whereas it should get a named derived from actual obdata, will fix that.

This issue was referenced by blender/blender@af35455912

This issue was referenced by blender/blender@af3545591228b9de135b0726a63835dd36b2e982

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Author
Member

Thanks for the fix.

TLDR-warning:

Even if modifiers are object-level data, if the modifiers for different linked objects are identical they could be treated as having linked modifiers too. Because if you apply those modifiers at the same time (by for example selecting them and doing Alt-C - Mesh) you will end up with what you want, linked meshes with applied modifiers. For a real example, if you're making a bunch of identical crates in a level for UE4 using linked data and modifiers (mirror modifier, subsurf etc), when you import this into UE4 you'll want to end up with 1 mesh instead of 90. The concept of object-level modifiers is useful in Blender but not too useful when actually exported.

I can see why this wouldn't work in some cases where you've got different modifiers, in that case you can't apply them at the same time, and you can't apply them one after another with linked data because applying modifiers the first time will affect the other mesh with different modifiers. The way I would solve this is use the same data for the meshes with identical modifiers, and on export compare the modifiers with other meshes, if they are different they could be added to a pile for each modifier configuration, then made into new unique mesh data before applying the modifiers.

For example you've got 10 crate objects with linked mesh data (crate), all with modifiers. There are three different types: 4 crate objects have mirror and subsurf modifiers. 3 crate objects have mirror/subsurf and array modifiers. 2 crate objects have mirror/subsurf and array modifiers with a different setup than the previous one.

On export you create copies of the meshes, so now you have 10 crate objects with mesh data crate.001. Then you check the modifiers, first looping through each object and adding each unique configuration to unique arrays (maybe a 2D array of objects), then populating these arrays with all objects with the same configuration that didn't get added in the first loop. It might be a good idea to check these configurations in a certain order so you always get the same result on export, using some suffix in the object name or whatever. Then for each array you select an object and make a single user copy, then for the rest of the objects in the same array you set them to use the new mesh data.

After the arrays have unique mesh data you can apply the modifiers, so loop through each array again, select the objects and convert to mesh. Then do the actual FBX export, then delete the temporary meshes. In UE4 you should end up with 3 object types, 4 crate objects named crate_002 (using the same mesh) with applied mirror/subsurf (periods are automatically converted to underscores, this actually breaks reimport of meshes so in the FBX exporter I replace periods with underscores already), 3 crate objects named crate_003 with mirror/subsurf/array modifiers applied, and 2 crate objects named crate_004 with mirror/subsurf and a different array modifier applied. So with this method you would have 3 truly unique meshes imported instead of 10 that are sometimes identical.

Then you probably clear orphan data so you get rid of any non used mesh data so the names don't get messed up if you export twice in a row.

In the .blend file all of the meshes should still have the same crate mesh data so you can edit the mesh instances non-destructively which is what you want, and then just export everything and the instancing should still work. I just made this technique up so I don't know if it works but I guess it should, and it is what you want if you're using Blender for level design. Even if it's not very Blendery it gives better results than what we've got by default for use in game engines. Until something like this exists in Blender by default (if it ever will) I'll be using an export script to accomplish this.

Thanks for the fix. TLDR-warning: Even if modifiers are object-level data, if the modifiers for different linked objects are identical they could be treated as having linked modifiers too. Because if you apply those modifiers at the same time (by for example selecting them and doing Alt-C - Mesh) you will end up with what you want, linked meshes with applied modifiers. For a real example, if you're making a bunch of identical crates in a level for UE4 using linked data and modifiers (mirror modifier, subsurf etc), when you import this into UE4 you'll want to end up with 1 mesh instead of 90. The concept of object-level modifiers is useful in Blender but not too useful when actually exported. I can see why this wouldn't work in some cases where you've got different modifiers, in that case you can't apply them at the same time, and you can't apply them one after another with linked data because applying modifiers the first time will affect the other mesh with different modifiers. The way I would solve this is use the same data for the meshes with identical modifiers, and on export compare the modifiers with other meshes, if they are different they could be added to a pile for each modifier configuration, then made into new unique mesh data before applying the modifiers. For example you've got 10 crate objects with linked mesh data (crate), all with modifiers. There are three different types: 4 crate objects have mirror and subsurf modifiers. 3 crate objects have mirror/subsurf and array modifiers. 2 crate objects have mirror/subsurf and array modifiers with a different setup than the previous one. On export you create copies of the meshes, so now you have 10 crate objects with mesh data crate.001. Then you check the modifiers, first looping through each object and adding each unique configuration to unique arrays (maybe a 2D array of objects), then populating these arrays with all objects with the same configuration that didn't get added in the first loop. It might be a good idea to check these configurations in a certain order so you always get the same result on export, using some suffix in the object name or whatever. Then for each array you select an object and make a single user copy, then for the rest of the objects in the same array you set them to use the new mesh data. After the arrays have unique mesh data you can apply the modifiers, so loop through each array again, select the objects and convert to mesh. Then do the actual FBX export, then delete the temporary meshes. In UE4 you should end up with 3 object types, 4 crate objects named crate_002 (using the same mesh) with applied mirror/subsurf (periods are automatically converted to underscores, this actually breaks reimport of meshes so in the FBX exporter I replace periods with underscores already), 3 crate objects named crate_003 with mirror/subsurf/array modifiers applied, and 2 crate objects named crate_004 with mirror/subsurf and a different array modifier applied. So with this method you would have 3 truly unique meshes imported instead of 10 that are sometimes identical. Then you probably clear orphan data so you get rid of any non used mesh data so the names don't get messed up if you export twice in a row. In the .blend file all of the meshes should still have the same crate mesh data so you can edit the mesh instances non-destructively which is what you want, and then just export everything and the instancing should still work. I just made this technique up so I don't know if it works but I guess it should, and it is what you want if you're using Blender for level design. Even if it's not very Blendery it gives better results than what we've got by default for use in game engines. Until something like this exists in Blender by default (if it ever will) I'll be using an export script to accomplish this.
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#51856
No description provided.