Exemplo n.º 1
0
        public void TestConstructCompressedStream()
        {
            foreach (var testData in Tests)
            {
                var compressedFileBytes = File.ReadAllBytes(testData.CompressedFilePath);

                using (var ms = new MemoryStream(compressedFileBytes))
                {
                    var resource = GeometryResourceCanonical.Create(testData.RecordInfo.VersionHash);
                    resource.InitFromStream(ms);

                    Assert.AreEqual(resource.Resource.Bytes, testData.ExpectedContentBytes);
                }
            }
        }
        protected override void CustomFileExport(ExportParameters exportParameters)
        {
            if (exportParameters.FileExtension == ".fbx")
            {
                var downloadManifestResult = FileRecordInfo.DownloadResourceAsync(
                    exportParameters.FileRecord.Info.Hash,
                    FileRecordInfo.ResourceType.GeometryResourceImport,
                    FileRecordInfo.PayloadType.Manifest,
                    FileRecordInfo.VariantType.NoVariants,
                    new LibSanBag.Providers.HttpClientProvider()
                    ).Result;

                var manifest = ManifestResource.Create();
                manifest.InitFromRawDecompressed(downloadManifestResult.Bytes);
                var sourceGeometryEntry = manifest.Entries.Find(n => n.Name.Contains("Canonical"));
                if (sourceGeometryEntry == default(ManifestResource.ManifestEntry))
                {
                    throw new Exception("Canonical resource not found in import manifest");
                }

                var downloadGeometryResult = FileRecordInfo.DownloadResourceAsync(
                    sourceGeometryEntry.HashString,
                    FileRecordInfo.ResourceType.GeometryResourceCanonical,
                    FileRecordInfo.PayloadType.Payload,
                    FileRecordInfo.VariantType.NoVariants,
                    new LibSanBag.Providers.HttpClientProvider()
                    ).Result;

                var geometryCanonical = GeometryResourceCanonical.Create(downloadGeometryResult.Version);
                geometryCanonical.InitFromRawCompressed(downloadGeometryResult.Bytes);

                var outputName = Path.GetFileName(sourceGeometryEntry.HashString + sourceGeometryEntry.Name + ".fbx");
                File.WriteAllBytes(
                    Path.Combine(exportParameters.OutputDirectory, outputName),
                    geometryCanonical.Resource.Bytes
                    );
            }
        }