From e790992fc586e4ac4a3741f04bd9c775937b1aeb Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Tue, 15 Feb 2022 11:20:05 -0800 Subject: [PATCH 1/2] When loading from zip it is important that we cache the assets They need to be available for cloud library and other library opperations --- .../ApplicationView/EditContext.cs | 2 +- .../ContentProviders/MeshContentProvider.cs | 22 +++++++++++++++++-- Submodules/agg-sharp | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/MatterControlLib/ApplicationView/EditContext.cs b/MatterControlLib/ApplicationView/EditContext.cs index a9394fb7d..4c1e4eb32 100644 --- a/MatterControlLib/ApplicationView/EditContext.cs +++ b/MatterControlLib/ApplicationView/EditContext.cs @@ -188,7 +188,7 @@ namespace MatterHackers.MatterControl var fileNames = GetFileNamesFromMcx(fileLocation); foreach (var file in fileNames) { - var fullPath = await Object3DExtensions.ResolveFilePath(file, null, CancellationToken.None); + var fullPath = Object3DExtensions.ResolveFilePath(file, null, CancellationToken.None); if (File.Exists(fullPath)) { hashCode = File.GetLastWriteTime(fullPath).ToString().GetLongHashCode(hashCode); diff --git a/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs b/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs index 97bfef931..83f5401be 100644 --- a/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs +++ b/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs @@ -38,9 +38,11 @@ namespace MatterHackers.MatterControl using MatterHackers.Agg.Platform; using MatterHackers.DataConverters3D; using MatterHackers.ImageProcessing; + using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.DesignTools.Operations; using MatterHackers.MatterControl.Library; - using MatterHackers.RayTracer; + using MatterHackers.PolygonMesh.Processors; + using MatterHackers.RayTracer; /// /// Loads IObject3D objects for mesh based ILibraryItems @@ -90,7 +92,23 @@ namespace MatterHackers.MatterControl if (contentStream != null) { // TODO: Wire up caching - loadedItem = Object3D.Load(contentStream.Stream, Path.GetExtension(streamInterface.FileName), CancellationToken.None, null /*itemCache*/, progressReporter); + var cacheContext = new CacheContext(); + loadedItem = Object3D.Load(contentStream.Stream, Path.GetExtension(streamInterface.FileName), CancellationToken.None, cacheContext, progressReporter); + + foreach(var meshItem in cacheContext.Meshes) + { + var meshPath = meshItem.Key; + if (!string.IsNullOrEmpty(meshPath) + && meshItem.Value != null + && meshItem.Value.Faces.Count > 0) + { + var assetsPath = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, "Assets", meshPath.ToLower()); + if (!File.Exists(assetsPath)) + { + StlProcessing.Save(meshItem.Value, assetsPath, CancellationToken.None); + } + } + } // Set MeshPath for non-mcx content. Avoid on mcx to ensure serialization of children if (loadedItem != null diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index f8a6ce095..d3202dd3a 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit f8a6ce095e4a653cb714b1816e00949722497b3e +Subproject commit d3202dd3aa31d18b9ca937daac5634d72fb2f7c7 From 6365da735fb6eec855b4258e28134ed9e9fca08c Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Tue, 15 Feb 2022 11:26:10 -0800 Subject: [PATCH 2/2] Don't change the casing --- .../Library/ContentProviders/MeshContentProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs b/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs index 83f5401be..a4a5b1b98 100644 --- a/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs +++ b/MatterControlLib/Library/ContentProviders/MeshContentProvider.cs @@ -102,7 +102,7 @@ namespace MatterHackers.MatterControl && meshItem.Value != null && meshItem.Value.Faces.Count > 0) { - var assetsPath = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, "Assets", meshPath.ToLower()); + var assetsPath = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, "Assets", meshPath); if (!File.Exists(assetsPath)) { StlProcessing.Save(meshItem.Value, assetsPath, CancellationToken.None);