Browse Source

Updated nugets.
Added method to retrieve the dependency files for a given model.

Vicente Penades 6 years ago
parent
commit
fba3ab3979

+ 2 - 2
Analyzers.targets

@@ -10,8 +10,8 @@
   </ItemGroup>
 
   <ItemGroup>    
-    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.7" PrivateAssets="all" />
-    <PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.9.7" PrivateAssets="all" />
+    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8" PrivateAssets="all" />
+    <PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.9.8" PrivateAssets="all" />
     <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
   </ItemGroup>
 	

+ 3 - 3
build/SharpGLTF.CodeGen/SharpGLTF.CodeGen.csproj

@@ -7,9 +7,9 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="LibGit2Sharp" Version="0.26.1" />
-    <PackageReference Include="NJsonSchema.CodeGeneration" Version="10.0.27" />
-    <PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="10.0.27" />
+    <PackageReference Include="LibGit2Sharp" Version="0.26.2" />
+    <PackageReference Include="NJsonSchema.CodeGeneration" Version="10.1.2" />
+    <PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="10.1.2" />
   </ItemGroup>
 
 </Project>

+ 19 - 0
src/SharpGLTF.Core/IO/ReadContext.cs

@@ -102,6 +102,25 @@ namespace SharpGLTF.IO
             return new MemoryStream(content.Array, content.Offset, content.Count);
         }
 
+        public String ReadJson(Stream stream)
+        {
+            Guard.NotNull(stream, nameof(stream));
+
+            bool binaryFile = glb._Identify(stream);
+
+            if (binaryFile)
+            {
+                var chunks = glb.ReadBinaryFile(stream);
+
+                return Encoding.UTF8.GetString(chunks[glb.CHUNKJSON]);
+            }
+
+            using (var streamReader = new StreamReader(stream))
+            {
+                return streamReader.ReadToEnd();
+            }
+        }
+
         /// <summary>
         /// Reads a <see cref="SCHEMA2"/> instance from a <see cref="Stream"/> containing a GLB or a GLTF file.
         /// </summary>

+ 48 - 0
src/SharpGLTF.Core/Schema2/gltf.Serialization.Read.cs

@@ -135,6 +135,54 @@ namespace SharpGLTF.Schema2
             return context.ReadBinarySchema2(stream);
         }
 
+        /// <summary>
+        /// Gets the list of satellite / dependency files for a given glTF file.
+        /// This includes binary blobs and texture images.
+        /// </summary>
+        /// <param name="filePath">A valid file path.</param>
+        /// <returns>A list of relative file paths, as found in the file.</returns>
+        /// <remarks>
+        /// This method is designed to be as fast as possible, and it avoids performing much
+        /// of the validation and parsing of a glTf file, it just blindly looks for URI fields.
+        /// </remarks>
+        public static string[] GetSatellitePaths(string filePath)
+        {
+            Guard.FilePathMustExist(filePath, nameof(filePath));
+
+            var context = IO.ReadContext.CreateFromFile(filePath);
+
+            string json = null;
+
+            using (var s = File.OpenRead(filePath))
+            {
+                json = context.ReadJson(s);
+            }
+
+            return ParseSatellitePaths(json);
+        }
+
+        private static string[] ParseSatellitePaths(string json)
+        {
+            var rss = Newtonsoft.Json.Linq.JObject.Parse(json);
+
+            var buffers = rss["buffers"]?.Select(item => (String)item["uri"]);
+            var images = rss["images"]?.Select(item => (String)item["uri"]);
+
+            IEnumerable<string> uris = buffers;
+
+            if (images != null)
+            {
+                uris = uris == null ? images : uris.Concat(images);
+            }
+
+            uris = uris
+                .Where(uri => !string.IsNullOrWhiteSpace(uri))
+                .Where(uri => !uri.StartsWith("data:", StringComparison.Ordinal))
+                .Distinct();
+
+            return uris.ToArray();
+        }
+
         #endregion
 
         #region externals dependencies resolver

+ 6 - 1
src/build-preview.cmd

@@ -29,4 +29,9 @@ set VERSIONSUFFIX=Preview-%_YYYY%%_MM%%_DD%-%_HOUR%%_MINUTE%
 echo Building %VERSIONSUFFIX%
 
 dotnet build -c:Release --version-suffix %VERSIONSUFFIX% SharpGLTF.Core\SharpGLTF.Core.csproj
-dotnet build -c:Release --version-suffix %VERSIONSUFFIX% SharpGLTF.Toolkit\SharpGLTF.Toolkit.csproj
+dotnet build -c:Release --version-suffix %VERSIONSUFFIX% SharpGLTF.Toolkit\SharpGLTF.Toolkit.csproj
+
+rem dotnet nuget push "SharpGLTF.Core/bin/Release/SharpGLTF.Core.1.0.0-%VERSIONSUFFIX%.nupkg" --source "github"
+rem dotnet nuget push "SharpGLTF.Toolkit/bin/Release/SharpGLTF.Toolkit.1.0.0-%VERSIONSUFFIX%.nupkg" --source "github"
+
+pause

+ 1 - 1
tests/SharpGLTF.DownloadTestFiles/SharpGLTF.DownloadTestFiles.csproj

@@ -7,7 +7,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="LibGit2Sharp" Version="0.26.1" />    
+    <PackageReference Include="LibGit2Sharp" Version="0.26.2" />    
   </ItemGroup>
 
 </Project>

+ 23 - 0
tests/SharpGLTF.Tests/Schema2/LoadAndSave/LoadSampleTests.cs

@@ -344,5 +344,28 @@ namespace SharpGLTF.Schema2.LoadAndSave
 
 
         }
+
+
+
+        [Test]
+        public void FindDependencyFiles()
+        {
+            TestContext.CurrentContext.AttachShowDirLink();
+            TestContext.CurrentContext.AttachGltfValidatorLinks();
+
+            foreach (var f in TestFiles.GetBabylonJSValidModelsPaths())
+            {
+                TestContext.WriteLine(f);
+
+                var dependencies = ModelRoot.GetSatellitePaths(f);
+
+                foreach(var d in dependencies)
+                {
+                    TestContext.WriteLine($"    {d}");
+                }
+
+                TestContext.WriteLine();
+            }
+        }
     }
 }