[bug] island_margin in bpy.ops.uv.smart_project seems to have no effect
Open, Needs TriagePublic

Description

System Information
Windows 10X64, GTX1080

Blender Version
Broken: 2.79 (+a)
Worked: previous version (2.76 ?)

The island_margin value seems to have no/minor effect in the new version of Blender when using a command line python script (to add a lightmap to meshes in a fbx file).
bpy.ops.uv.smart_project(angle_limit=66.0, island_margin=0.0, user_area_weight=0.0, use_aspect=True)
When importing the fbx in Unreal, compared to an earlier version of Blender, changing the value for island_margin from 0 to 1 has no to really minor effect.

Exact steps for others to reproduce the error
on the command line using a python script; open an fbx, add a 2nd uv channel, use the smart_project command from above, save as a new fbx file and open in a fbx viewer where you can see the uv layout.

Details

Type
Bug

By default it uses units as a measurement so in Blender default scale island_margin 0.0 means 0m and island_margin 1 means 1m. You mentioned UE4 so I'm assuming you're using a scene scale of 0.01 for skeletal mesh compatibility.

If you use a scene scale of 0.01 Blender assumes all of your typed units are now in centimeters instead of meters. This means that in this operator island_margin 0.0 now means 0cm and island_margin 1 means 1cm. So, in other terms, where in default scale it would be 0 and 100cm it is now 0 and 1cm meaning you get a 100 times smaller margin.

It's hard to say whether this is a bug or not, it could be a design (bad design) issue instead. But you can fix it with a workaround by opening the file (located in your Blender software folder\2.79\scripts\startup\bl_operators\uvcalc_smart_project.py) and search for "Island Margin" until you find the FloatProperty. Inside it you can change the max value from 1.0 to 100.0. That way it will behave as the Blender default even in the changed scene scale.

This was caused by fix for T53678.

Not sure this should be considered a bug though.

Since the value is in distance units - applying those using the scenes settings makes sense.

However, the value being modified when called from a script isn't great - perhaps we should only apply scene scaling from the UI, not Python execution. Needs investigation.

Note that the issue was minor, if it's causing problems it might be best to revert it.

This was caused by fix for T53678.

Not sure this should be considered a bug though.

Since the value is in distance units - applying those using the scenes settings makes sense.

However, the value being modified when called from a script isn't great - perhaps we should only apply scene scaling from the UI, not Python execution. Needs investigation.

Note that the issue was minor, if it's causing problems it might be best to revert it.

Are you sure this is caused by that fix? I'm not seeing any difference in behavior with that fix or commenting it out. The 0.01 scene still gives a tiny 1cm margin instead of 1m.

You can test these files, first with 0.01 scene unit scale and second with 1 scene unit scale. Ideally they should give the same result.

Hi Henrik and Campbell, thanks for looking into this issue. I'm puzzled by the logic of using real units instead of a percentage. Seems strange to me (using lightmap texture sizes of 64/128/256/512).
I modified the uvcalc_smart_project.py and that works for me. Thanks! Should make a note of it in case of future updates of Blender.

There seems to be some inconsistency in the uv scaling in the python methods anyway because yesterday I 'fixed' this issue in the python script by adding to;
bpy.ops.uv.smart_project(angle_limit=66.0, island_margin=myMargin, user_area_weight=0.0, use_aspect=True)

bpy.ops.uv.select_all(action='SELECT')
bpy.ops.uv.pack_islands(rotate=True, margin=myMargin)

By adding those two lines, the scaling of the uvs (even witm small numbers) seems to be as before.