Page MenuHome

FBX Exporter: New feature "Export active UV map" to export the active (selected) UV map instead of exporting all UV maps.
Needs ReviewPublic

Authored by Henrik Berglund (cyaoeu) on Jan 14 2018, 11:39 PM.

Details

Summary

This is a feature to allow exporting the active (selected) UV map instead of exporting all UV maps in the file. Some software (like Substance Painter) at the moment only works with a single UV map and if you had several UV maps you wanted to use you would need to create a copy of the mesh, remove one UV map, make another copy of the original mesh, remove the other UV map and so on. This gets worse the more UV maps you have.

This patch attempts to solve this by adding an option (boolean) for enabling the feature of exporting the active UV map. That way you can keep your original mesh and just export it twice (after changing the active UV map) and this way it's a non destructive action, or at least saves you the trouble of copying your mesh a bunch of times and removing the UV maps.

This was made to improve the workflow for exporting a mesh with a single specified UV map for texture creation purposes, but could also be used for any other time you need to export a mesh with a single specific UV map.

Diff Detail

Repository
rBA Blender Add-ons
Branch
fbx_export_specify_exported_uvmap
Build Status
Buildable 1153
Build 1153: arc lint + arc unit

Event Timeline

  • Fix for wrong version.

    Accidently used wrong version of .py files (did make update but forgot to copy files to the actual testing build)
Henrik Berglund (cyaoeu) updated this revision to Diff 9822.EditedJan 16 2018, 12:08 AM
  • Remove uneccessary newline.
  • Put the new stuff on a new line so it's more obvious that it's new.
  • ... in all files.
  • Add space so it looks like the rest of the code.

Using an index won't work well for multiple objects.
Why not have an option to export only the active map index? - mesh.uv_layers.active_index

Using an index won't work well for multiple objects.
Why not have an option to export only the active map index? - mesh.uv_layers.active_index

Oh yeah, didn't really think of that. Technically it would work as long as they had the same amount of UV maps per object. But yeah it probably shouldn't stop working if you've got objects that don't have the UV map with a certain index.

That being said with this method you would no longer be able to specify the UV map you want to export within the FBX exporter menu directly and this means you would need to change the UV map yourself for all objects. Without scripting this is kind of annoying because you cannot alt+click a UV map in order to make that the active index for all objects. It is possible when clicking the camera icon (active render) so I'm wondering if this is by design or a bug that you can't do it when alt+clicking the UV map name instead? If alt+clicking a map changed the active index for all objects I would have no problem with your suggestion.

  • Temporary fix for UV map index range errors with multiple objects.

    Use last UV map index that exists for that mesh if the given index returns an IndexError.

Using an index won't work well for multiple objects.
Why not have an option to export only the active map index? - mesh.uv_layers.active_index

Oh yeah, didn't really think of that. Technically it would work as long as they had the same amount of UV maps per object. But yeah it probably shouldn't stop working if you've got objects that don't have the UV map with a certain index.

That being said with this method you would no longer be able to specify the UV map you want to export within the FBX exporter menu directly and this means you would need to change the UV map yourself for all objects. Without scripting this is kind of annoying because you cannot alt+click a UV map in order to make that the active index for all objects. It is possible when clicking the camera icon (active render) so I'm wondering if this is by design or a bug that you can't do it when alt+clicking the UV map name instead? If alt+clicking a map changed the active index for all objects I would have no problem with your suggestion.

Think using the index like this isn't a good workflow since it assumes all your meshes UV layers are aligned.

Did you report this problem to Substance Painter? Maybe it's best they resolve on their end.

If a single UV is being exported I think it's quite reasonable to export the active / render UV layer.
If we need a way to set this on all meshes at once, then it can be added.

How to other programs that support multiple UV's handle this?

Using an index won't work well for multiple objects.
Why not have an option to export only the active map index? - mesh.uv_layers.active_index

Oh yeah, didn't really think of that. Technically it would work as long as they had the same amount of UV maps per object. But yeah it probably shouldn't stop working if you've got objects that don't have the UV map with a certain index.

That being said with this method you would no longer be able to specify the UV map you want to export within the FBX exporter menu directly and this means you would need to change the UV map yourself for all objects. Without scripting this is kind of annoying because you cannot alt+click a UV map in order to make that the active index for all objects. It is possible when clicking the camera icon (active render) so I'm wondering if this is by design or a bug that you can't do it when alt+clicking the UV map name instead? If alt+clicking a map changed the active index for all objects I would have no problem with your suggestion.

Think using the index like this isn't a good workflow since it assumes all your meshes UV layers are aligned.

Did you report this problem to Substance Painter? Maybe it's best they resolve on their end.

If a single UV is being exported I think it's quite reasonable to export the active / render UV layer.
If we need a way to set this on all meshes at once, then it can be added.

How to other programs that support multiple UV's handle this?

I haven't reported it personally but it's been a feature request over there since 2016. I don't really think getting the UV by index is a problem with the alignment because if they're not aligned they will screw up things when finally exported to a game engine anyway. Not aligning the UVs shouldn't happen too often and if it does you can fix it by creating a copy, renaming the UV map and joining it to your mesh again.

Then again I agree that it's reasonable to export the active UV layer if there's a way to easily select one for multiple meshes. It would save space in the UI too. I don't know how to add this though, I looked through the code for the ALLSELECT stuff but I didn't really understand it, I don't know C. I did notice that alt+click doesn't work for any of those UI elements though, like UV maps, vertex groups and vertex colors.

Changed behavior to export the active (selected) UV map as per Campbell's suggestion.

  • Changed behavior to export the active (selected) UV map as per
  • Fix prop in UI.
  • Fix typo.
  • Fix wrong prop in if statement.
  • Fix missing space in description.

    The new code being an if statement before the old code (now in an else: statement) looks a bit ugly, not sure how to fix. Also there's still the problem of users not being able to "batch change" the active UV map without using scripting.
Henrik Berglund (cyaoeu) retitled this revision from FBX Exporter: New feature "Specify single exported UV map" to specify a single UV map index that will be exported instead of exporting all UV maps. to FBX Exporter: New feature "Export active UV map" to export the active (selected) UV map instead of exporting all UV maps..Jan 26 2018, 7:20 PM
Henrik Berglund (cyaoeu) edited the summary of this revision. (Show Details)
io_scene_fbx/__init__.py
51

Not needed.

io_scene_fbx/export_fbx_bin.py
1104

This can be done without copy-pasting UV exporting block.

eg:

for uvindex, uvlayer in enumerate(
    me.uv_layers if not scene_data.settings.export_active_uvmap else 
    (me.uv_layers.active,)
):

Probably neater to assign a variable, but you see the difference.

Update. Hopefully nothing went wrong...

  • Remove no longer used IntProperty import.
  • Remove code duplication by adding uv_enumerate function that either
  • Remove unneccesary comment.
  • Remove whitespace.
  • Remove more whitespace.
Henrik Berglund (cyaoeu) marked 2 inline comments as done.Feb 3 2018, 3:05 AM

Added function that replaces enumerate(), by default mimics enumerate but when export_active_uvmap is true it returns the active uv layer index and active uv map instead. Keeps the code the same which looks nicer.

With some edits, patch seems OK,

Even so its a bit arbitrary - why not another option only to export active vertex color layers too?
(We could have a single option to use active UV's and Colors).


@Bastien Montagne (mont29), what do you think?

io_scene_fbx/__init__.py
360

Name isn't good, sounds like you dont get active UV map if it's disabled.

Maybe call "Only Active UV Map" or "Single UV Map"

io_scene_fbx/export_fbx_bin.py
824–829

If the function is defined on execution, better define two functions, based on scene_data.settings.export_active_uvmap setting.

With some edits, patch seems OK,

Even so its a bit arbitrary - why not another option only to export active vertex color layers too?
(We could have a single option to use active UV's and Colors).


@Bastien Montagne (mont29), what do you think?

Yes, "only active UV map" is better. I personally didn't use multiple vertex color layers for texturing but yes it sounds like it could be useful, that way you could do a different ID map bake (from vertex colors) on your other UV layer, or a single UV map with several vertex color layers (exported one at a time) for different material setups. I will look into adding the vertex color part.

Also I don't really understand the second comment regarding multiple functions.

  • Change name to "Only...", add active vertex color layer to export.
  • Remove whitespace.
  • Fix mistake in tspace argument.
Henrik Berglund (cyaoeu) marked an inline comment as done.Feb 5 2018, 3:43 PM

Any updates on this topic?

Another feature "in review" which I'd need but it seem never got into master. I also need to specify, which UV Map Layout is used for export. Like I'd also like to have the option to choose which material output branch is used for export.