From 90446bc1b561f05846b0ec1b1ed2f56263f3e92a Mon Sep 17 00:00:00 2001 From: rogangriffin Date: Fri, 22 Mar 2019 11:03:44 -0600 Subject: [PATCH 1/2] 2018.2 14 channel format support --- unitypack/export.py | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/unitypack/export.py b/unitypack/export.py index 5337bbb..ae334ca 100644 --- a/unitypack/export.py +++ b/unitypack/export.py @@ -87,6 +87,8 @@ def extract_indices(self): def extract_vertices(self): # unity 5+ has 8 channels (6 otherwise) v5_channel_count = 8 + # unity 2018 has 14 channels + v2018_channel_count = 14 buf = BinaryReader(BytesIO(self.mesh.vertex_data.data)) channels = self.mesh.vertex_data.channels # actual streams attribute 'm_Streams' may only exist in unity 4, @@ -105,25 +107,29 @@ def extract_vertices(self): raise NotImplementedError("(%r) 16 bit floats are not supported" % (self.mesh)) # read the appropriate vertex value into the correct list if ch and ch["dimension"] > 0 and ch["stream"] == s: - if j == 0: - self.vertices.append(OBJVector3().read(buf)) - elif j == 1: - self.normals.append(OBJVector3().read(buf)) - elif j == 2: - self.colors.append(OBJVector4().read_color(buf)) - elif j == 3: - self.uv1.append(OBJVector2().read(buf)) - elif j == 4: - self.uv2.append(OBJVector2().read(buf)) - elif j == 5: - if channel_count == v5_channel_count: - self.uv3.append(OBJVector2().read(buf)) - else: - self.tangents.append(OBJVector4().read(buf)) - elif j == 6: # for unity 5+ - self.uv4.append(OBJVector2().read(buf)) - elif j == 7: # for unity 5+ - self.tangents.append(OBJVector4().read(buf)) + if j == 0: + self.vertices.append(OBJVector3().read(buf)) + elif j == 1: + self.normals.append(OBJVector3().read(buf)) + elif j == 2: + if channel_count == v2018_channel_count: + self.tangents.append(OBJVector4().read(buf)) + else: + self.colors.append(OBJVector4().read_color(buf)) + elif j == 3: + self.uv1.append(OBJVector2().read(buf)) + elif j == 4: + self.uv2.append(OBJVector2().read(buf)) + elif j == 5: + if channel_count == v5_channel_count: + self.uv3.append(OBJVector2().read(buf)) + else: + self.tangents.append(OBJVector4().read(buf)) + elif j == 6: # for unity 5+ + self.uv4.append(OBJVector2().read(buf)) + elif j == 7: # for unity 5+ + if channel_count == v5_channel_count: + self.tangents.append(OBJVector4().read(buf)) # TODO investigate possible alignment here, after each stream def get_num_streams(self, channels): From ef4ee5da1e93ce46b89cb027313c81cd718736a5 Mon Sep 17 00:00:00 2001 From: rogangriffin Date: Fri, 22 Mar 2019 11:26:07 -0600 Subject: [PATCH 2/2] Another handling of 2018 channel count change --- unitypack/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unitypack/export.py b/unitypack/export.py index ae334ca..1b02842 100644 --- a/unitypack/export.py +++ b/unitypack/export.py @@ -121,7 +121,7 @@ def extract_vertices(self): elif j == 4: self.uv2.append(OBJVector2().read(buf)) elif j == 5: - if channel_count == v5_channel_count: + if channel_count == v5_channel_count || channel_count == v2018_channel_count: self.uv3.append(OBJVector2().read(buf)) else: self.tangents.append(OBJVector4().read(buf))