Example #1
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);
            }
        }
Example #2
0
        public MeshExporter(UStaticMesh originalMesh, ELodFormat lodFormat = ELodFormat.FirstLod, bool exportMaterials = true, EMeshFormat meshFormat = EMeshFormat.ActorX, ETexturePlatform platform = ETexturePlatform.DesktopMobile)
        {
            MeshLods = new List <Mesh>();
            MeshName = originalMesh.Owner?.Name ?? originalMesh.Name;

            if (!originalMesh.TryConvert(out var convertedMesh) || convertedMesh.LODs.Count == 0)
            {
                Log.Logger.Warning($"Mesh '{MeshName}' has no LODs");
                return;
            }

            var i = 0;

            foreach (var lod in convertedMesh.LODs)
            {
                if (lod.SkipLod)
                {
                    Log.Logger.Warning($"LOD {i} in mesh '{MeshName}' should be skipped");
                    continue;
                }

                using var Ar = new FArchiveWriter();
                var    materialExports = exportMaterials ? new List <MaterialExporter>() : null;
                string ext;
                switch (meshFormat)
                {
                case EMeshFormat.ActorX:
                    ext = "pskx";
                    ExportStaticMeshLods(lod, Ar, materialExports);
                    break;

                case EMeshFormat.Gltf2:
                    ext = "glb";
                    new Gltf(MeshName.SubstringAfterLast("/"), lod, materialExports).Save(meshFormat, Ar);
                    break;

                case EMeshFormat.OBJ:
                    ext = "obj";
                    new Gltf(MeshName.SubstringAfterLast("/"), lod, materialExports).Save(meshFormat, Ar);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(meshFormat), meshFormat, null);
                }

                MeshLods.Add(new Mesh($"{MeshName}_LOD{i}.{ext}", Ar.GetBuffer(), materialExports ?? new List <MaterialExporter>()));
                if (lodFormat == ELodFormat.FirstLod)
                {
                    break;
                }
                i++;
            }
        }