Skip to content

Commit 490a53b

Browse files
authored
Blender 5.1 support: fix vertex colors import and bump max version in README (Fast-64#711)
* Readme: bump max blender to 5.1.2 * fix vertex color importing in blender 5.1 * Use color_attributes API for Blender 3.2+ too
1 parent 832e80b commit 490a53b

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Fast64
22

3-
This requires Blender 3.2 - 5.0.1. Blender 4.0+ is recommended.
3+
This requires Blender 3.2 - 5.1.2. Blender 4.0+ is recommended.
44

55
Forked from [kurethedead/fast64 on BitBucket](https://bitbucket.org/kurethedead/fast64/src).
66

fast64_internal/f3d/f3d_parser.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ def deleteMaterialContext(self):
18641864
raise PluginError("Attempting to delete material context that is None.")
18651865

18661866
# if deleteMaterialContext is False, then manually call self.deleteMaterialContext() later.
1867-
def createMesh(self, obj, removeDoubles, importNormals, callDeleteMaterialContext: bool):
1867+
def createMesh(self, obj: bpy.types.Object, removeDoubles, importNormals, callDeleteMaterialContext: bool):
18681868
mesh = obj.data
18691869
if len(self.verts) % 3 != 0:
18701870
print(len(self.verts))
@@ -1902,13 +1902,26 @@ def createMesh(self, obj, removeDoubles, importNormals, callDeleteMaterialContex
19021902
# There will be one loop for every vertex
19031903
uv_layer[i].uv = self.verts[i].uv
19041904

1905-
color_layer = mesh.vertex_colors.new(name="Col").data
1906-
for i in range(len(mesh.loops)):
1907-
color_layer[i].color = self.verts[i].rgb.to_4d()
1908-
1909-
alpha_layer = mesh.vertex_colors.new(name="Alpha").data
1910-
for i in range(len(mesh.loops)):
1911-
alpha_layer[i].color = [self.verts[i].alpha] * 3 + [1]
1905+
# The mesh.vertex_colors API is deprecated since Blender 3.2,
1906+
# and its usage by fast64 here breaks in Blender 5.1 somehow.
1907+
# (can't replicate in simple cases)
1908+
if bpy.app.version < (3, 2, 0):
1909+
color_layer = mesh.vertex_colors.new(name="Col").data
1910+
for i in range(len(mesh.loops)):
1911+
color_layer[i].color = self.verts[i].rgb.to_4d()
1912+
1913+
alpha_layer = mesh.vertex_colors.new(name="Alpha").data
1914+
for i in range(len(mesh.loops)):
1915+
alpha_layer[i].color = [self.verts[i].alpha] * 3 + [1]
1916+
else:
1917+
col_attr = mesh.color_attributes.new("Col", "BYTE_COLOR", "CORNER")
1918+
for i in range(len(mesh.loops)):
1919+
col_attr.data[i].color = (*self.verts[i].rgb, 1)
1920+
1921+
alpha_attr = mesh.color_attributes.new("Alpha", "BYTE_COLOR", "CORNER")
1922+
for i in range(len(mesh.loops)):
1923+
a = self.verts[i].alpha
1924+
alpha_attr.data[i].color = (a, a, a, 1)
19121925

19131926
if bpy.context.mode != "OBJECT":
19141927
bpy.ops.object.mode_set(mode="OBJECT")

0 commit comments

Comments
 (0)