private static void LoadLinkedMesh(this IObject3D item, CacheContext cacheContext, CancellationToken cancellationToken, Action <double, string> progress)
        {
            // Abort load if cancel requested
            cancellationToken.ThrowIfCancellationRequested();

            // Natural path
            string filePath = item.MeshPath;

            // If relative/asset file name
            if (Path.GetDirectoryName(filePath) == "")
            {
                string sha1PlusExtension = filePath;

                filePath = Path.Combine(Object3D.AssetsPath, sha1PlusExtension);

                // If the asset is not in the local cache folder, acquire it
                if (!File.Exists(filePath))
                {
                    // *************************************************************************
                    // TODO: Fix invalid use of Wait()
                    // *************************************************************************
                    // Prime cache
                    AssetObject3D.AssetManager.AcquireAsset(sha1PlusExtension, cancellationToken, progress).Wait();
                }
            }

            if (string.Equals(Path.GetExtension(filePath), ".mcx", StringComparison.OrdinalIgnoreCase))
            {
                var loadedItem = Object3D.Load(filePath, cancellationToken, cacheContext, progress);
                if (loadedItem != null)
                {
                    item.SetMeshDirect(loadedItem.Mesh);

                    // Copy loaded mcx children to source node
                    // TODO: potentially needed for leaf mcx nodes, review and tests required
                    item.Children = loadedItem.Children;
                }
            }
            else
            {
                Mesh mesh = null;

                try
                {
                    if (!cacheContext.Meshes.TryGetValue(filePath, out mesh))
                    {
                        mesh = Object3D.Load(filePath, cancellationToken).Mesh;
                        cacheContext.Meshes[filePath] = mesh;
                    }
                }
                catch
                {
                    // Fall back to Missing mesh if available
                    mesh = Object3D.FileMissingMesh;
                }

                item.SetMeshDirect(mesh);
            }
        }
Пример #2
0
        private static void LoadLinkedMesh(this IObject3D item, CacheContext cacheContext, CancellationToken cancellationToken, Action <double, string> progress)
        {
            // Abort load if cancel requested
            cancellationToken.ThrowIfCancellationRequested();

            string filePath = item.ResolveFilePath(progress, cancellationToken);

            if (string.Equals(Path.GetExtension(filePath), ".mcx", StringComparison.OrdinalIgnoreCase))
            {
                var loadedItem = Object3D.Load(filePath, cancellationToken, cacheContext, progress);
                if (loadedItem != null)
                {
                    item.SetMeshDirect(loadedItem.Mesh);

                    // Copy loaded mcx children to source node
                    // TODO: potentially needed for leaf mcx nodes, review and tests required
                    item.Children = loadedItem.Children;
                }
            }
            else
            {
                try
                {
                    if (cacheContext.Meshes.TryGetValue(filePath, out Mesh mesh))
                    {
                        item.SetMeshDirect(mesh);
                    }
                    else
                    {
                        var loadedItem = Object3D.Load(filePath, cancellationToken);
                        if (loadedItem?.Children.Count() > 0)
                        {
                            loadedItem.Children.Modify(loadedChildren =>
                            {
                                // copy the children
                                item.Children.Modify(children =>
                                {
                                    children.AddRange(loadedChildren);
                                    loadedChildren.Clear();
                                });
                            });
                        }
                        else
                        {
                            // copy the mesh
                            var loadedMesh = loadedItem?.Mesh;
                            cacheContext.Meshes[filePath] = loadedMesh;
                            item.SetMeshDirect(loadedMesh);
                        }
                    }
                }
                catch
                {
                    // Fall back to Missing mesh if available
                    item.SetMeshDirect(Object3D.FileMissingMesh);
                }
            }
        }
Пример #3
0
        private static void LoadLinkedMesh(this IObject3D item, CacheContext cacheContext, CancellationToken cancellationToken, Action <double, string> progress)
        {
            // Abort load if cancel requested
            cancellationToken.ThrowIfCancellationRequested();

            // *************************************************************************
            // TODO: Fix invalid use of Result
            // *************************************************************************
            string filePath = item.ResolveFilePath(progress, cancellationToken).Result;

            if (string.Equals(Path.GetExtension(filePath), ".mcx", StringComparison.OrdinalIgnoreCase))
            {
                var loadedItem = Object3D.Load(filePath, cancellationToken, cacheContext, progress);
                if (loadedItem != null)
                {
                    item.SetMeshDirect(loadedItem.Mesh);

                    // Copy loaded mcx children to source node
                    // TODO: potentially needed for leaf mcx nodes, review and tests required
                    item.Children = loadedItem.Children;
                }
            }
            else
            {
                Mesh mesh = null;

                try
                {
                    if (!cacheContext.Meshes.TryGetValue(filePath, out mesh))
                    {
                        mesh = Object3D.Load(filePath, cancellationToken).Mesh;
                        cacheContext.Meshes[filePath] = mesh;
                    }
                }
                catch
                {
                    // Fall back to Missing mesh if available
                    mesh = Object3D.FileMissingMesh;
                }

                item.SetMeshDirect(mesh);
            }
        }