Merge pull request #5217 from larsbrubaker/main

When loading from zip it is important that we cache the assets
This commit is contained in:
Lars Brubaker 2022-02-15 11:43:40 -08:00 committed by GitHub
commit abd5ef3159
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View file

@ -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);

View file

@ -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;
/// <summary>
/// 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);
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

@ -1 +1 @@
Subproject commit f8a6ce095e4a653cb714b1816e00949722497b3e
Subproject commit d3202dd3aa31d18b9ca937daac5634d72fb2f7c7