glTF: use color attribute API instead of vertex color
This commit is contained in:
parent
83fa6728e5
commit
485b4ac569
|
@ -4,7 +4,7 @@
|
|||
bl_info = {
|
||||
'name': 'glTF 2.0 format',
|
||||
'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
|
||||
"version": (3, 2, 37),
|
||||
"version": (3, 2, 38),
|
||||
'blender': (3, 1, 0),
|
||||
'location': 'File > Import-Export',
|
||||
'description': 'Import-Export as glTF 2.0',
|
||||
|
|
|
@ -526,18 +526,11 @@ def __get_uvs(blender_mesh, uv_i):
|
|||
|
||||
|
||||
def __get_colors(blender_mesh, color_i):
|
||||
layer = blender_mesh.vertex_colors[color_i]
|
||||
colors = np.empty(len(blender_mesh.loops) * 4, dtype=np.float32)
|
||||
layer.data.foreach_get('color', colors)
|
||||
layer = blender_mesh.vertex_colors[color_i]
|
||||
blender_mesh.color_attributes[layer.name].data.foreach_get('color', colors)
|
||||
colors = colors.reshape(len(blender_mesh.loops), 4)
|
||||
|
||||
# sRGB -> Linear
|
||||
rgb = colors[:, :-1]
|
||||
not_small = rgb >= 0.04045
|
||||
small_result = np.where(rgb < 0.0, 0.0, rgb * (1.0 / 12.92))
|
||||
large_result = np.power((rgb + 0.055) * (1.0 / 1.055), 2.4, where=not_small)
|
||||
rgb[:] = np.where(not_small, large_result, small_result)
|
||||
|
||||
# colors are already linear, no need to switch color space
|
||||
return colors
|
||||
|
||||
|
||||
|
|
|
@ -250,9 +250,6 @@ def do_primitives(gltf, mesh_idx, skin_idx, mesh, ob):
|
|||
for uvs in loop_uvs:
|
||||
uvs_gltf_to_blender(uvs)
|
||||
|
||||
for cols in loop_cols:
|
||||
colors_linear_to_srgb(cols[:, :-1])
|
||||
|
||||
# ---------------
|
||||
# Start creating things
|
||||
|
||||
|
@ -292,7 +289,7 @@ def do_primitives(gltf, mesh_idx, skin_idx, mesh, ob):
|
|||
"reached.")
|
||||
break
|
||||
|
||||
layer.data.foreach_set('color', squish(loop_cols[col_i]))
|
||||
mesh.color_attributes[layer.name].data.foreach_set('color', squish(loop_cols[col_i]))
|
||||
|
||||
# Skinning
|
||||
# TODO: this is slow :/
|
||||
|
@ -468,16 +465,6 @@ def colors_rgb_to_rgba(rgb):
|
|||
rgba[:, :3] = rgb
|
||||
return rgba
|
||||
|
||||
|
||||
def colors_linear_to_srgb(color):
|
||||
assert color.shape[1] == 3 # only change RGB, not A
|
||||
|
||||
not_small = color >= 0.0031308
|
||||
small_result = np.where(color < 0.0, 0.0, color * 12.92)
|
||||
large_result = 1.055 * np.power(color, 1.0 / 2.4, where=not_small) - 0.055
|
||||
color[:] = np.where(not_small, large_result, small_result)
|
||||
|
||||
|
||||
def uvs_gltf_to_blender(uvs):
|
||||
# u,v -> u,1-v
|
||||
uvs[:, 1] *= -1
|
||||
|
|
Loading…
Reference in New Issue