Skip to content

Commit 530a9e3

Browse files
committed
MeshHelper - fix get_streams and m_Channel.dimension usage (&0xF)
1 parent 3c4c89d commit 530a9e3

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

UnityPy/helpers/MeshHelper.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,7 @@ def copy_from_spriterenderdata(self):
252252
def get_streams(
253253
self, m_Channels: list[ChannelInfo], m_VertexCount: int
254254
) -> list[StreamInfo]:
255-
streamCount = 1
256-
if m_Channels:
257-
streamCount += max(x.stream for x in m_Channels)
258-
255+
streamCount = 1 + max(x.stream for x in m_Channels)
259256
m_Streams: list[StreamInfo] = []
260257
offset = 0
261258
for s in range(streamCount):
@@ -266,7 +263,7 @@ def get_streams(
266263
if m_Channel.dimension > 0:
267264
chnMask |= 1 << chn
268265
component_size = self.get_channel_component_size(m_Channel)
269-
stride += m_Channel.dimension * component_size
266+
stride += (m_Channel.dimension & 0xF) * component_size
270267

271268
m_Streams.append(
272269
StreamInfo(
@@ -358,6 +355,7 @@ def read_vertex_data(
358355
# channel_byte_size = m_Channel.dimension * component_byte_size
359356

360357
swap = self.endianess == "<" and component_byte_size > 1
358+
channel_dimension = m_Channel.dimension & 0xF
361359

362360
if UnityPyBoost:
363361
componentBytes = UnityPyBoost.unpack_vertexdata(
@@ -367,22 +365,22 @@ def read_vertex_data(
367365
m_Stream.offset,
368366
m_Stream.stride,
369367
m_Channel.offset,
370-
m_Channel.dimension,
368+
channel_dimension,
371369
swap,
372370
)
373371
else:
374372
componentBytes = bytearray(
375-
m_VertexCount * m_Channel.dimension * component_byte_size
373+
m_VertexCount * channel_dimension * component_byte_size
376374
)
377375

378376
vertexBaseOffset = m_Stream.offset + m_Channel.offset
379377
for v in range(m_VertexCount):
380378
vertexOffset = vertexBaseOffset + m_Stream.stride * v
381-
for d in range(m_Channel.dimension):
379+
for d in range(channel_dimension):
382380
componentOffset = vertexOffset + component_byte_size * d
383381
vertexDataSrc = componentOffset
384382
componentDataSrc = component_byte_size * (
385-
v * m_Channel.dimension + d
383+
v * channel_dimension + d
386384
)
387385
buff = m_VertexData.m_DataSize[
388386
vertexDataSrc : vertexDataSrc + component_byte_size
@@ -399,7 +397,7 @@ def read_vertex_data(
399397
f">{count}{component_dtype}", componentBytes
400398
)
401399
component_data = flat_list_to_tuples(
402-
component_data, m_Channel.dimension
400+
component_data, channel_dimension
403401
)
404402

405403
self.assign_channel_vertex_data(chn, component_data)

0 commit comments

Comments
 (0)