コード例 #1
0
        public static void Serialize(this SerializingContainer2 sc, ref SkeletalMeshVertexBuffer svb)
        {
            if (sc.IsLoading)
            {
                svb = new SkeletalMeshVertexBuffer();
            }

            if (sc.Game == MEGame.UDK)
            {
                sc.Serialize(ref svb.NumTexCoords);
            }
            sc.Serialize(ref svb.bUseFullPrecisionUVs);
            if (svb.bUseFullPrecisionUVs)
            {
                throw new Exception($"SkeletalMesh is using Full precision UVs! Mesh in: {sc.Pcc.FilePath}");
            }
            if (sc.Game >= MEGame.ME3)
            {
                sc.Serialize(ref svb.bUsePackedPosition);
                if (svb.bUseFullPrecisionUVs)
                {
                    throw new Exception($"SkeletalMesh is using PackedPosition vertices! Mesh in: {sc.Pcc.FilePath}");
                }
                sc.Serialize(ref svb.MeshExtension);
                sc.Serialize(ref svb.MeshOrigin);
            }
            int elementSize = 32;

            sc.Serialize(ref elementSize);
            sc.Serialize(ref svb.VertexData, Serialize);
        }
コード例 #2
0
        public static void Serialize(this SerializingContainer2 sc, ref SkeletalMeshVertexBuffer svb)
        {
            if (sc.IsLoading)
            {
                svb = new SkeletalMeshVertexBuffer();
            }

            if (sc.Game == MEGame.UDK)
            {
                svb.bUsePackedPosition = true;
            }
            else
            {
                svb.bUsePackedPosition   = false;
                svb.bUseFullPrecisionUVs = false;
            }

            if (sc.Game == MEGame.UDK)
            {
                svb.NumTexCoords = 1;
                sc.Serialize(ref svb.NumTexCoords);
            }
            else if (sc.IsLoading)
            {
                svb.NumTexCoords = 1;
            }
            sc.Serialize(ref svb.bUseFullPrecisionUVs);
            if (sc.Game >= MEGame.ME3)
            {
                sc.Serialize(ref svb.bUsePackedPosition);
                sc.Serialize(ref svb.MeshExtension);
                sc.Serialize(ref svb.MeshOrigin);
            }
            int elementSize = 32;

            sc.Serialize(ref elementSize);

            //vertexData
            int count = svb.VertexData?.Length ?? 0;

            sc.Serialize(ref count);
            if (sc.IsLoading)
            {
                svb.VertexData = new GPUSkinVertex[count];
            }

            for (int j = 0; j < count; j++)
            {
                ref GPUSkinVertex gsv = ref svb.VertexData[j];
                if (sc.IsLoading)
                {
                    gsv = new GPUSkinVertex();
                }

                if (sc.Game == MEGame.ME2)
                {
                    sc.Serialize(ref gsv.Position);
                }
                sc.Serialize(ref gsv.TangentX);
                sc.Serialize(ref gsv.TangentZ);
                for (int i = 0; i < 4; i++)
                {
                    sc.Serialize(ref gsv.InfluenceBones[i]);
                }
                for (int i = 0; i < 4; i++)
                {
                    sc.Serialize(ref gsv.InfluenceWeights[i]);
                }
                if (sc.Game >= MEGame.ME3)
                {
                    if (false)
                    {
                        if (sc.IsLoading)
                        {
                            uint packedPos = sc.ms.ReadUInt32();
                            gsv.Position = new Vector3(packedPos.bits(31, 21) / 1023f,
                                                       packedPos.bits(20, 10) / 1023f,
                                                       packedPos.bits(9, 0) / 1023f) * svb.MeshExtension + svb.MeshOrigin;
                        }
                        else
                        {
                            Vector3 pos = (gsv.Position - svb.MeshOrigin) - svb.MeshExtension; //puts values in -1.0 to 1.0 range
                            uint    x;
                            uint    y;
                            uint    z;
                            unchecked
                            {
                                x = (uint)Math.Truncate(pos.X * 1023.0).ToInt32().Clamp(-1023, 1023) << 21;
                                y = (uint)Math.Truncate(pos.Y * 1023.0).ToInt32().Clamp(-1023, 1023) << 21 >> 11;
                                z = (uint)Math.Truncate(pos.Z * 1023.0).ToInt32().Clamp(-1023, 1023) << 22 >> 22;
                            }
                            sc.ms.WriteUInt32(x | y | z);
                        }
                    }
                    else
                    {
                        sc.Serialize(ref gsv.Position);
                    }
                }

                if (svb.bUseFullPrecisionUVs)
                {
                    Vector2 fullUV = gsv.UV;
                    sc.Serialize(ref fullUV);
                    gsv.UV = fullUV;
                }
                else
                {
                    sc.Serialize(ref gsv.UV);
                }

                if (svb.NumTexCoords > 1)
                {
                    if (sc.IsLoading)
                    {
                        sc.ms.Skip((svb.NumTexCoords - 1) * (svb.bUseFullPrecisionUVs ? 8 : 4));
                    }
                    else
                    {
                        throw new Exception("Should never be saing more than one UV!");
                    }
                }
            }