Skip to content

fix mesh export error for unity2017.4 - #36

Merged
K0lb3 merged 7 commits into
K0lb3:masterfrom
jesliwang:master
Mar 9, 2021
Merged

K0lb3 merged 7 commits into
K0lb3:masterfrom
jesliwang:master

Conversation

@jesliwang

Copy link
Copy Markdown
Contributor
  1. Change indent_style to space。 All project files indent with space, .editorconfig's indent_style make it hard for edit
  2. Change 'except:' to 'except Exception as e: \n print(traceback.format_exc())'. With 'Except:', it's hard to decide the reason of failure
  3. Update 'AnimationClip.py' and 'Mesh.py' Refer to ’Perfare/AssetStudio‘

@K0lb3 K0lb3 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.
I still have some comments about some parts, but it looks good overall.

  1. 👍
  2. I've kept it without traceback because the normal user likely won't investigate it deeper and would simply open a new issue if it's important, but it's probably better with traceback so that the issue would contain the traceback as well.
  3. in the code comments

Comment thread UnityPy/classes/AnimationClip.py Outdated
bitPos %= 8

scale: float = 1.0 / self.m_Range
scale: float = 1.0 / self.m_Range if self.m_Range != 0 else 0.0001

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C#'s division by 0 results in infinity.
This isn't correctly reflected in your version.
scale = (1.0 / self.m_Range) if self.m_Range else float("inf") would be better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infinity is a better choice. I'll fix it

Comment thread UnityPy/classes/AnimationClip.py Outdated

x &= uint((1 << self.m_BitSize) - 1) # (uint)(1 << m_BitSize) - 1u
data.append(x / (scale * ((1 << self.m_BitSize) - 1)) + self.m_Start)
data.append(x / (scale * ((1 << self.m_BitSize) - 1) if self.m_BitSize != 0 else 1 ) + self.m_Start)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above - float("inf").

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infinity is a better choice. I'll fix it

bits = 0
entry = 0
while bits << m_BitSize:
while bits < m_BitSize:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you investigated this?

AssetStudio also uses <.
AnimationClip - line 112

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misread it ? This fix is from << to <

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, you're right.

Comment thread UnityPy/classes/Mesh.py
if m_Channel.dimension > 0:
m_Stream = m_VertexData.m_Streams[m_Channel.stream]
channelMask = bin(m_Stream.channelMask)[::-1]
if channelMask[chn] == "1":

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                var channelMask = new BitArray(new[] { (int)m_Stream.channelMask });
                byte offset = 0;
                for (int i = 0; i < 6; i++)
                {
                    if (channelMask.Get(i))

The channelMask in AssetStudio "gets" a boolean value.
Since BitArray isn't natively available in python bin is used to convert the mask into bits.

The original .get(i) wouldn't fulfill the requirement if a 0 was returned,
but in your variant, a 0 would do, as "0" is True in python.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for correcting the mistake!!! I I confused bin with byte

Comment thread UnityPy/classes/Mesh.py Outdated
else:
self.m_UV0 = m_CompressedMesh.m_UV.UnpackFloats(
2, 2*4, 0, m_VertexCount)
if m_CompressedMesh.m_UV.m_NumItems >= m_VertexCount * 4: #

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also belongs to the else previous branch,
-> indent

@jesliwang
jesliwang requested a review from K0lb3 March 9, 2021 17:08

@K0lb3 K0lb3 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now.

Thanks again for the hard work.

@K0lb3
K0lb3 merged commit 704d3ab into K0lb3:master Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants