示例#1
0
 public void Serialize(FArchiveWriter Ar)
 {
     Ar.Write(R);
     Ar.Write(G);
     Ar.Write(B);
     Ar.Write(A);
 }
示例#2
0
 public void Serialize(FArchiveWriter Ar)
 {
     Ar.Write(ChunkId, 20);
     Ar.Write(TypeFlag);
     Ar.Write(DataSize);
     Ar.Write(DataCount);
 }
示例#3
0
 public void Serialize(FArchiveWriter Ar)
 {
     Ar.Write(Name, 64);
     Ar.Write(Flags);
     Ar.Write(NumChildren);
     Ar.Write(ParentIndex);
     BonePos.Serialize(Ar);
 }
示例#4
0
        private void ExportSkeletalMeshLod(CSkelMeshLod lod, List <CSkelMeshBone> bones, FArchiveWriter Ar, List <MaterialExporter>?materialExports, ETexturePlatform platform = ETexturePlatform.DesktopMobile)
        {
            var share  = new CVertexShare();
            var infHdr = new VChunkHeader();

            share.Prepare(lod.Verts);
            foreach (var vert in lod.Verts)
            {
                var weightsHash = vert.PackedWeights;
                for (var i = 0; i < vert.Bone.Length; i++)
                {
                    weightsHash ^= (uint)vert.Bone[i] << i;
                }

                share.AddVertex(vert.Position, vert.Normal, weightsHash);
            }

            ExportCommonMeshData(Ar, lod.Sections.Value, lod.Verts, lod.Indices.Value, share, materialExports, platform);
            ExportSkeletonData(Ar, bones);

            var numInfluences = 0;

            for (var i = 0; i < share.Points.Count; i++)
            {
                for (var j = 0; j < Constants.NUM_INFLUENCES_UE4; j++)
                {
                    if (lod.Verts[share.VertToWedge.Value[i]].Bone[j] < 0)
                    {
                        break;
                    }
                    numInfluences++;
                }
            }
            infHdr.DataCount = numInfluences;
            infHdr.DataSize  = 12;
            Ar.SerializeChunkHeader(infHdr, "RAWWEIGHTS");
            for (var i = 0; i < share.Points.Count; i++)
            {
                var v = lod.Verts[share.VertToWedge.Value[i]];
                var unpackedWeights = v.UnpackWeights();

                for (var j = 0; j < Constants.NUM_INFLUENCES_UE4; j++)
                {
                    if (v.Bone[j] < 0)
                    {
                        break;
                    }

                    Ar.Write(unpackedWeights[j]);
                    Ar.Write(i);
                    Ar.Write((int)v.Bone[j]);
                }
            }

            ExportVertexColors(Ar, lod.VertexColors, lod.NumVerts);
            ExportExtraUV(Ar, lod.ExtraUV.Value, lod.NumVerts, lod.NumTexCoords);
        }
示例#5
0
 public void Serialize(FArchiveWriter Ar)
 {
     Orientation.Serialize(Ar);
     Position.Serialize(Ar);
     Ar.Write(Length);
     Size.Serialize(Ar);
 }
示例#6
0
        public void Save(EMeshFormat meshFormat, FArchiveWriter Ar)
        {
            switch (meshFormat)
            {
            case EMeshFormat.Gltf2:
                Ar.Write(Model.WriteGLB());
                break;

            case EMeshFormat.OBJ:
                Ar.Write(SaveAsWavefront());     // this can be supported after new release of SharpGltf
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(meshFormat), meshFormat, null);
            }
        }
示例#7
0
        public static void Write(this FArchiveWriter Ar, string value, int len)
        {
            var padded = new byte[len];
            var bytes  = Encoding.UTF8.GetBytes(value);

            Buffer.BlockCopy(bytes, 0, padded, 0, bytes.Length);
            Ar.Write(padded);
        }
示例#8
0
 public void Serialize(FArchiveWriter Ar)
 {
     Ar.Write(MaterialName, 64);
     Ar.Write(TextureIndex);
     Ar.Write(PolyFlags);
     Ar.Write(AuxMaterial);
     Ar.Write(AuxFlags);
     Ar.Write(LodBias);
     Ar.Write(LodStyle);
 }
示例#9
0
 public void Serialize(FArchiveWriter Ar)
 {
     Ar.Write(WedgeIndex[0]);
     Ar.Write(WedgeIndex[1]);
     Ar.Write(WedgeIndex[2]);
     Ar.Write(MatIndex);
     Ar.Write(AuxMatIndex);
     Ar.Write(SmoothingGroups);
 }
示例#10
0
 public void Serialize(FArchiveWriter Ar)
 {
     Ar.Write(PointIndex);
     Ar.Write(UV.U);
     Ar.Write(UV.V);
     Ar.Write(MatIndex);
     Ar.Write(Reserved);
     Ar.Write(Pad);
 }
示例#11
0
        public void Serialize(FArchiveWriter writer)
        {
            var materialName = new byte[64];
            var material     = Encoding.UTF8.GetBytes(MaterialName);

            Buffer.BlockCopy(material, 0, materialName, 0, material.Length);

            writer.Write(materialName);
            writer.Write(TextureIndex);
            writer.Write(PolyFlags);
            writer.Write(AuxMaterial);
            writer.Write(AuxFlags);
            writer.Write(LodBias);
            writer.Write(LodStyle);
        }
示例#12
0
 public void Serialize(FArchiveWriter Ar)
 {
     Position.Serialize(Ar);
     Orientation.Serialize(Ar);
     Ar.Write(Time);
 }
示例#13
0
        private void ExportCommonMeshData(FArchiveWriter Ar, CMeshSection[] sections, CMeshVertex[] verts,
                                          FRawStaticIndexBuffer indices, CVertexShare share, List <MaterialExporter>?materialExports, ETexturePlatform platform = ETexturePlatform.DesktopMobile)
        {
            var mainHdr  = new VChunkHeader();
            var ptsHdr   = new VChunkHeader();
            var wedgHdr  = new VChunkHeader();
            var facesHdr = new VChunkHeader();
            var matrHdr  = new VChunkHeader();
            var normHdr  = new VChunkHeader();

            mainHdr.TypeFlag = Constants.PSK_VERSION;
            Ar.SerializeChunkHeader(mainHdr, "ACTRHEAD");

            var numPoints = share.Points.Count;

            ptsHdr.DataCount = numPoints;
            ptsHdr.DataSize  = 12;
            Ar.SerializeChunkHeader(ptsHdr, "PNTS0000");
            for (var i = 0; i < numPoints; i++)
            {
                var point = share.Points[i];
                point.Y = -point.Y; // MIRROR_MESH
                point.Serialize(Ar);
            }

            var numFaces    = 0;
            var numVerts    = verts.Length;
            var numSections = sections.Length;
            var wedgeMat    = new int[numVerts];

            for (var i = 0; i < numSections; i++)
            {
                var faces = sections[i].NumFaces;
                numFaces += faces;
                for (var j = 0; j < faces * 3; j++)
                {
                    wedgeMat[indices[j + sections[i].FirstIndex]] = i;
                }
            }

            wedgHdr.DataCount = numVerts;
            wedgHdr.DataSize  = 16;
            Ar.SerializeChunkHeader(wedgHdr, "VTXW0000");
            for (var i = 0; i < numVerts; i++)
            {
                Ar.Write(share.WedgeToVert[i]);
                Ar.Write(verts[i].UV.U);
                Ar.Write(verts[i].UV.V);
                Ar.Write((byte)wedgeMat[i]);
                Ar.Write((byte)0);
                Ar.Write((short)0);
            }

            facesHdr.DataCount = numFaces;
            if (numVerts <= 65536)
            {
                facesHdr.DataSize = 12;
                Ar.SerializeChunkHeader(facesHdr, "FACE0000");
                for (var i = 0; i < numSections; i++)
                {
                    for (var j = 0; j < sections[i].NumFaces; j++)
                    {
                        var wedgeIndex = new ushort[3];
                        for (var k = 0; k < wedgeIndex.Length; k++)
                        {
                            wedgeIndex[k] = (ushort)indices[sections[i].FirstIndex + j * 3 + k];
                        }

                        Ar.Write(wedgeIndex[1]); // MIRROR_MESH
                        Ar.Write(wedgeIndex[0]); // MIRROR_MESH
                        Ar.Write(wedgeIndex[2]);
                        Ar.Write((byte)i);
                        Ar.Write((byte)0);
                        Ar.Write((uint)1);
                    }
                }
            }
            else
            {
                facesHdr.DataSize = 18;
                Ar.SerializeChunkHeader(facesHdr, "FACE3200");
                for (var i = 0; i < numSections; i++)
                {
                    for (var j = 0; j < sections[i].NumFaces; j++)
                    {
                        var wedgeIndex = new int[3];
                        for (var k = 0; k < wedgeIndex.Length; k++)
                        {
                            wedgeIndex[k] = indices[sections[i].FirstIndex + j * 3 + k];
                        }

                        Ar.Write(wedgeIndex[1]); // MIRROR_MESH
                        Ar.Write(wedgeIndex[0]); // MIRROR_MESH
                        Ar.Write(wedgeIndex[2]);
                        Ar.Write((byte)i);
                        Ar.Write((byte)0);
                        Ar.Write((uint)1);
                    }
                }
            }

            matrHdr.DataCount = numSections;
            matrHdr.DataSize  = 88;
            Ar.SerializeChunkHeader(matrHdr, "MATT0000");
            for (var i = 0; i < numSections; i++)
            {
                string materialName;
                if (sections[i].Material?.Load <UMaterialInterface>() is { } tex)
                {
                    materialName = tex.Name;
                    materialExports?.Add(new MaterialExporter(tex, true, platform));
                }
示例#14
0
 public void Serialize(FArchiveWriter Ar)
 {
     Ar.Write(U);
     Ar.Write(V);
 }
示例#15
0
 public void Serialize(FArchiveWriter Ar)
 {
     Ar.Write(Name, 64);
     Ar.Write(Group, 64);
     Ar.Write(TotalBones);
     Ar.Write(RootInclude);
     Ar.Write(KeyCompressionStyle);
     Ar.Write(KeyQuotum);
     Ar.Write(KeyReduction);
     Ar.Write(TrackTime);
     Ar.Write(AnimRate);
     Ar.Write(StartBone);
     Ar.Write(FirstRawFrame);
     Ar.Write(NumRawFrames);
 }