public List <uint> m_Indices = new List <uint>(); //use a list because I don't always know the facecount for triangle strips public Mesh(ObjectReader reader) : base(reader) { if (version[0] < 3 || (version[0] == 3 && version[1] < 5)) //3.5 down { m_Use16BitIndices = reader.ReadInt32() > 0; } if (version[0] == 2 && version[1] <= 5) //2.5 and down { int m_IndexBuffer_size = reader.ReadInt32(); if (m_Use16BitIndices) { m_IndexBuffer = new uint[m_IndexBuffer_size / 2]; for (int i = 0; i < m_IndexBuffer_size / 2; i++) { m_IndexBuffer[i] = reader.ReadUInt16(); } reader.AlignStream(); } else { m_IndexBuffer = reader.ReadUInt32Array(m_IndexBuffer_size / 4); } } int m_SubMeshesSize = reader.ReadInt32(); m_SubMeshes = new SubMesh[m_SubMeshesSize]; for (int i = 0; i < m_SubMeshesSize; i++) { m_SubMeshes[i] = new SubMesh(reader); } if (version[0] > 4 || (version[0] == 4 && version[1] >= 1)) //4.1 and up { m_Shapes = new BlendShapeData(reader); } if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up { m_BindPose = reader.ReadMatrixArray(); m_BoneNameHashes = reader.ReadUInt32Array(); var m_RootBoneNameHash = reader.ReadUInt32(); } if (version[0] > 2 || (version[0] == 2 && version[1] >= 6)) //2.6.0 and later { var m_MeshCompression = reader.ReadByte(); if (version[0] >= 4) { if (version[0] < 5) { var m_StreamCompression = reader.ReadByte(); } var m_IsReadable = reader.ReadBoolean(); var m_KeepVertices = reader.ReadBoolean(); var m_KeepIndices = reader.ReadBoolean(); } reader.AlignStream(); //Unity fixed it in 2017.3.1p1 and later versions if ((version[0] > 2017 || (version[0] == 2017 && version[1] >= 4)) || //2017.4 ((version[0] == 2017 && version[1] == 3 && version[2] == 1) && buildType.IsPatch) || //fixed after 2017.3.1px ((version[0] == 2017 && version[1] == 3) && m_MeshCompression == 0)) //2017.3.xfx with no compression { var m_IndexFormat = reader.ReadInt32(); } int m_IndexBuffer_size = reader.ReadInt32(); if (m_Use16BitIndices) { m_IndexBuffer = new uint[m_IndexBuffer_size / 2]; for (int i = 0; i < m_IndexBuffer_size / 2; i++) { m_IndexBuffer[i] = reader.ReadUInt16(); } reader.AlignStream(); } else { m_IndexBuffer = reader.ReadUInt32Array(m_IndexBuffer_size / 4); } } if (version[0] < 3 || (version[0] == 3 && version[1] < 5)) //3.4.2 and earlier { m_VertexCount = reader.ReadInt32(); m_Vertices = reader.ReadSingleArray(m_VertexCount * 3); //Vector3 m_Skin = new BoneWeights4[reader.ReadInt32()]; for (int s = 0; s < m_Skin.Length; s++) { m_Skin[s] = new BoneWeights4(reader); } m_BindPose = reader.ReadMatrixArray(); m_UV0 = reader.ReadSingleArray(reader.ReadInt32() * 2); //Vector2 m_UV1 = reader.ReadSingleArray(reader.ReadInt32() * 2); //Vector2 if (version[0] == 2 && version[1] <= 5) //2.5 and down { int m_TangentSpace_size = reader.ReadInt32(); m_Normals = new float[m_TangentSpace_size * 3]; m_Tangents = new float[m_TangentSpace_size * 4]; for (int v = 0; v < m_TangentSpace_size; v++) { m_Normals[v * 3] = reader.ReadSingle(); m_Normals[v * 3 + 1] = reader.ReadSingle(); m_Normals[v * 3 + 2] = reader.ReadSingle(); m_Tangents[v * 3] = reader.ReadSingle(); m_Tangents[v * 3 + 1] = reader.ReadSingle(); m_Tangents[v * 3 + 2] = reader.ReadSingle(); m_Tangents[v * 3 + 3] = reader.ReadSingle(); //handedness } } else //2.6.0 and later { m_Tangents = reader.ReadSingleArray(reader.ReadInt32() * 4); //Vector4 m_Normals = reader.ReadSingleArray(reader.ReadInt32() * 3); //Vector3 } } else { if (version[0] < 2018 || (version[0] == 2018 && version[1] < 2)) //2018.2 down { m_Skin = new BoneWeights4[reader.ReadInt32()]; for (int s = 0; s < m_Skin.Length; s++) { m_Skin[s] = new BoneWeights4(reader); } } if (version[0] == 3 || (version[0] == 4 && version[1] <= 2)) //4.2 and down { m_BindPose = reader.ReadMatrixArray(); } m_VertexData = new VertexData(reader); } if (version[0] > 2 || (version[0] == 2 && version[1] >= 6)) //2.6.0 and later { m_CompressedMesh = new CompressedMesh(reader); } reader.Position += 24; //AABB m_LocalAABB if (version[0] < 3 || (version[0] == 3 && version[1] <= 4)) //3.4.2 and earlier { int m_Colors_size = reader.ReadInt32(); m_Colors = new float[m_Colors_size * 4]; for (int v = 0; v < m_Colors_size * 4; v++) { m_Colors[v] = (float)reader.ReadByte() / 0xFF; } int m_CollisionTriangles_size = reader.ReadInt32(); reader.Position += m_CollisionTriangles_size * 4; //UInt32 indices int m_CollisionVertexCount = reader.ReadInt32(); } int m_MeshUsageFlags = reader.ReadInt32(); if (version[0] >= 5) //5.0 and up { var m_BakedConvexCollisionMesh = reader.ReadBytes(reader.ReadInt32()); reader.AlignStream(); var m_BakedTriangleCollisionMesh = reader.ReadBytes(reader.ReadInt32()); reader.AlignStream(); } if (version[0] > 2018 || (version[0] == 2018 && version[1] >= 2)) //2018.2 and up { var m_MeshMetrics = new float[2]; m_MeshMetrics[0] = reader.ReadSingle(); m_MeshMetrics[1] = reader.ReadSingle(); } if (version[0] > 2018 || (version[0] == 2018 && version[1] >= 3)) //2018.3 and up { reader.AlignStream(); m_StreamData = new StreamingInfo(reader); } ProcessData(); }
public SpriteRenderData(ObjectReader reader) { var version = reader.version; texture = new PPtr <Texture2D>(reader); if (version[0] > 5 || (version[0] == 5 && version[1] >= 2)) //5.2 and up { alphaTexture = new PPtr <Texture2D>(reader); } if (version[0] >= 2019) //2019 and up { var secondaryTexturesSize = reader.ReadInt32(); secondaryTextures = new SecondarySpriteTexture[secondaryTexturesSize]; for (var i = 0; i < secondaryTexturesSize; i++) { secondaryTextures[i] = new SecondarySpriteTexture(reader); } } if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up { var m_SubMeshesSize = reader.ReadInt32(); m_SubMeshes = new SubMesh[m_SubMeshesSize]; for (var i = 0; i < m_SubMeshesSize; i++) { m_SubMeshes[i] = new SubMesh(reader); } m_IndexBuffer = reader.ReadBytes(reader.ReadInt32()); reader.AlignStream(); m_VertexData = new VertexData(reader); } else { var verticesSize = reader.ReadInt32(); vertices = new SpriteVertex[verticesSize]; for (var i = 0; i < verticesSize; i++) { vertices[i] = new SpriteVertex(reader); } indices = reader.ReadUInt16Array(); reader.AlignStream(); } if (version[0] >= 2018) //2018 and up { m_Bindpose = reader.ReadMatrixArray(); if (version[0] == 2018 && version[1] < 2) //2018.2 down { var m_SourceSkinSize = reader.ReadInt32(); for (var i = 0; i < m_SourceSkinSize; i++) { m_SourceSkin[i] = new BoneWeights4(reader); } } } textureRect = reader.ReadRectangleF(); textureRectOffset = reader.ReadVector2(); if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up { atlasRectOffset = reader.ReadVector2(); } settingsRaw = new SpriteSettings(reader); if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up { uvTransform = reader.ReadVector4(); } if (version[0] >= 2017) //2017 and up { downscaleMultiplier = reader.ReadSingle(); } }
public List <uint> m_Indices = new List <uint>(); //use a list because I don't always know the facecount for triangle strips public Mesh(ObjectReader reader) : base(reader) { if (version[0] < 3 || (version[0] == 3 && version[1] < 5)) //3.5 down { m_Use16BitIndices = reader.ReadInt32() > 0; } if (version[0] == 2 && version[1] <= 5) //2.5 and down { int m_IndexBuffer_size = reader.ReadInt32(); if (m_Use16BitIndices) { m_IndexBuffer = new uint[m_IndexBuffer_size / 2]; for (int i = 0; i < m_IndexBuffer_size / 2; i++) { m_IndexBuffer[i] = reader.ReadUInt16(); } reader.AlignStream(); } else { m_IndexBuffer = new uint[m_IndexBuffer_size / 4]; for (int i = 0; i < m_IndexBuffer_size / 4; i++) { m_IndexBuffer[i] = reader.ReadUInt32(); } } } int m_SubMeshesSize = reader.ReadInt32(); m_SubMeshes = new SubMesh[m_SubMeshesSize]; for (int i = 0; i < m_SubMeshesSize; i++) { m_SubMeshes[i] = new SubMesh(reader); } if (version[0] == 4 && ((version[1] == 1 && !buildType.IsAlpha) || (version[1] > 1 && version[1] <= 2))) //4.1.0 to 4.2.x, excluding 4.1.0 alpha { int m_Shapes_size = reader.ReadInt32(); if (m_Shapes_size > 0) { //bool stop = true; } for (int s = 0; s < m_Shapes_size; s++) //untested { var shape_name = reader.ReadAlignedString(); reader.Position += 36; //uint firstVertex, vertexCount; Vector3f aabbMinDelta, aabbMaxDelta; bool hasNormals, hasTangents } int m_ShapeVertices_size = reader.ReadInt32(); reader.Position += m_ShapeVertices_size * 40; //vertex positions, normals, tangents & uint index } else if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3.0 and later { m_Shapes = new BlendShapeData(reader); m_BindPose = new float[reader.ReadInt32()][, ]; for (int i = 0; i < m_BindPose.Length; i++) { m_BindPose[i] = new[, ] { { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() } }; } m_BoneNameHashes = reader.ReadUInt32Array(); var m_RootBoneNameHash = reader.ReadUInt32(); } if (version[0] > 2 || (version[0] == 2 && version[1] >= 6)) //2.6.0 and later { var m_MeshCompression = reader.ReadByte(); if (version[0] >= 4) { if (version[0] < 5) { var m_StreamCompression = reader.ReadByte(); } var m_IsReadable = reader.ReadBoolean(); var m_KeepVertices = reader.ReadBoolean(); var m_KeepIndices = reader.ReadBoolean(); } reader.AlignStream(); //Unity fixed it in 2017.3.1p1 and later versions if ((version[0] > 2017 || (version[0] == 2017 && version[1] >= 4)) || //2017.4 ((version[0] == 2017 && version[1] == 3 && version[2] == 1) && buildType.IsPatch) || //fixed after 2017.3.1px ((version[0] == 2017 && version[1] == 3) && m_MeshCompression == 0)) //2017.3.xfx with no compression { var m_IndexFormat = reader.ReadInt32(); } int m_IndexBuffer_size = reader.ReadInt32(); if (m_Use16BitIndices) { m_IndexBuffer = new uint[m_IndexBuffer_size / 2]; for (int i = 0; i < m_IndexBuffer_size / 2; i++) { m_IndexBuffer[i] = reader.ReadUInt16(); } reader.AlignStream(); } else { m_IndexBuffer = new uint[m_IndexBuffer_size / 4]; for (int i = 0; i < m_IndexBuffer_size / 4; i++) { m_IndexBuffer[i] = reader.ReadUInt32(); } reader.AlignStream(); } } if (version[0] < 3 || (version[0] == 3 && version[1] < 5)) //3.4.2 and earlier { m_VertexCount = reader.ReadInt32(); m_Vertices = new float[m_VertexCount * 3]; for (int v = 0; v < m_VertexCount * 3; v++) { m_Vertices[v] = reader.ReadSingle(); } m_Skin = new BoneWeights4[reader.ReadInt32()]; for (int s = 0; s < m_Skin.Length; s++) { m_Skin[s] = new BoneWeights4(reader); } m_BindPose = new float[reader.ReadInt32()][, ]; for (int i = 0; i < m_BindPose.Length; i++) { m_BindPose[i] = new[, ] { { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() } }; } m_UV0 = reader.ReadSingleArray(reader.ReadInt32() * 2); //Vector2 m_UV1 = reader.ReadSingleArray(reader.ReadInt32() * 2); //Vector2 if (version[0] == 2 && version[1] <= 5) //2.5 and down { int m_TangentSpace_size = reader.ReadInt32(); m_Normals = new float[m_TangentSpace_size * 3]; for (int v = 0; v < m_TangentSpace_size; v++) { m_Normals[v * 3] = reader.ReadSingle(); m_Normals[v * 3 + 1] = reader.ReadSingle(); m_Normals[v * 3 + 2] = reader.ReadSingle(); reader.Position += 16; //Vector3f tangent & float handedness } } else //2.6.0 and later { m_Tangents = reader.ReadSingleArray(reader.ReadInt32() * 4); //Vector4 m_Normals = reader.ReadSingleArray(reader.ReadInt32() * 3); //Vector3 } } else { if (version[0] < 2018 || (version[0] == 2018 && version[1] < 2)) //2018.2 down { m_Skin = new BoneWeights4[reader.ReadInt32()]; for (int s = 0; s < m_Skin.Length; s++) { m_Skin[s] = new BoneWeights4(reader); } } if (version[0] == 3 || (version[0] == 4 && version[1] <= 2)) //4.2 and down { m_BindPose = new float[reader.ReadInt32()][, ]; for (int i = 0; i < m_BindPose.Length; i++) { m_BindPose[i] = new[, ] { { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }, { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() } }; } } m_VertexData = new VertexData(reader); } if (version[0] > 2 || (version[0] == 2 && version[1] >= 6)) //2.6.0 and later { m_CompressedMesh = new CompressedMesh(reader); } reader.Position += 24; //AABB m_LocalAABB if (version[0] < 3 || (version[0] == 3 && version[1] <= 4)) //3.4.2 and earlier { int m_Colors_size = reader.ReadInt32(); m_Colors = new float[m_Colors_size * 4]; for (int v = 0; v < m_Colors_size * 4; v++) { m_Colors[v] = (float)reader.ReadByte() / 0xFF; } int m_CollisionTriangles_size = reader.ReadInt32(); reader.Position += m_CollisionTriangles_size * 4; //UInt32 indices int m_CollisionVertexCount = reader.ReadInt32(); } int m_MeshUsageFlags = reader.ReadInt32(); if (version[0] >= 5) //5.0 and up { var m_BakedConvexCollisionMesh = reader.ReadBytes(reader.ReadInt32()); reader.AlignStream(); var m_BakedTriangleCollisionMesh = reader.ReadBytes(reader.ReadInt32()); reader.AlignStream(); } if (version[0] > 2018 || (version[0] == 2018 && version[1] >= 2)) //2018.2 and up { var m_MeshMetrics = new float[2]; m_MeshMetrics[0] = reader.ReadSingle(); m_MeshMetrics[1] = reader.ReadSingle(); } if (version[0] > 2018 || (version[0] == 2018 && version[1] >= 3)) //2018.3 and up { reader.AlignStream(); m_StreamData = new StreamingInfo(reader); } ProcessData(); }