Skip to content

Commit

Permalink
Fix T70298: FBX IO: Apply squared crease transform when importing/exp…
Browse files Browse the repository at this point in the history
…orting.

Blender maps crease sharpness from internal [0, 1] to OpenSubdiv's
[0, 10] by squaring the value (see `get_edge_sharpness()`).

Other software seems to treat FBX crease as linear times 10 using OpenSubdiv.

This commits attempts to make FBX exported by Blender consistent with the
results from FBX exported from Maya regarding crease intensity.

Differential Revision: https://developer.blender.org/D5930
  • Loading branch information
Samuli Raivio authored and Bastien Montagne committed Oct 3, 2019
1 parent a28145a commit 53e6613
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion io_scene_fbx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
bl_info = {
"name": "FBX format",
"author": "Campbell Barton, Bastien Montagne, Jens Restemeier",
"version": (4, 17, 2),
"version": (4, 17, 3),
"blender": (2, 81, 6),
"location": "File > Import-Export",
"description": "FBX IO meshes, UV's, vertex colors, materials, textures, cameras, lamps and actions",
Expand Down
4 changes: 3 additions & 1 deletion io_scene_fbx/export_fbx_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,9 @@ def _infinite_gen(val):
for e in me.edges:
if e.key not in edges_map:
continue # Only loose edges, in theory!
t_ec[edges_map[e.key]] = e.crease
# Blender squares those values before sending them to OpenSubdiv, when other softwares don't,
# so we need to compensate that to get similar results through FBX...
t_ec[edges_map[e.key]] = e.crease * e.crease

lay_crease = elem_data_single_int32(geom, b"LayerElementEdgeCrease", 0)
elem_data_single_int32(lay_crease, b"Version", FBX_GEOMETRY_CREASE_VERSION)
Expand Down
5 changes: 5 additions & 0 deletions io_scene_fbx/import_fbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,8 @@ def blen_read_geom_layer_smooth(fbx_obj, mesh):
return False

def blen_read_geom_layer_edge_crease(fbx_obj, mesh):
from math import sqrt

fbx_layer = elem_find_first(fbx_obj, b'LayerElementEdgeCrease')

if fbx_layer is None:
Expand Down Expand Up @@ -1151,6 +1153,9 @@ def blen_read_geom_layer_edge_crease(fbx_obj, mesh):
fbx_layer_data, None,
fbx_layer_mapping, fbx_layer_ref,
1, 1, layer_id,
# Blender squares those values before sending them to OpenSubdiv, when other softwares don't,
# so we need to compensate that to get similar results through FBX...
xform=sqrt,
)
else:
print("warning layer %r mapping type unsupported: %r" % (fbx_layer.id, fbx_layer_mapping))
Expand Down

0 comments on commit 53e6613

Please sign in to comment.