Exemplo n.º 1
0
        public bool RenameAsset(CAsset assetToRename, string newName)
        {
            lock (m_registryMutex)
            {
                if (m_assetFileMap.TryGet(assetToRename.Guid, out string assetPath))
                {
                    string oldFullPath = ProjectDefinitions.GetAbsolutePath(assetPath);
                    string newFullPath = Path.GetDirectoryName(oldFullPath) + "/" + newName + assetToRename.GetFileExtension();
                    if (File.Exists(newFullPath))
                    {
                        return(false);
                    }

                    string newRelativePath = ProjectDefinitions.GetRelativePath(newFullPath);
                    assetToRename.Name = newName;
                    assetToRename.Path = newRelativePath;
                    m_assetFileMap[assetToRename.Guid] = newRelativePath;
                    if (File.Exists(oldFullPath))
                    {
                        File.Delete(oldFullPath);
                        SaveAsset(assetToRename);
                    }

                    SaveRegistry();
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public override void CopyFrom(CAsset source)
        {
            base.CopyFrom(source);
            CModelAsset modelSource = (CModelAsset)source;

            MeshChildren = modelSource.MeshChildren;
        }
Exemplo n.º 3
0
 public void GetAssetInDirectoryLoaded(string directory, IList <CAsset> outAssets)
 {
     lock (m_registryMutex)
     {
         object listMutex = new object();
         Parallel.ForEach(m_assetFileMap.ValueToKey, (pathGuidPair) =>
         {
             string directoryName = Path.GetDirectoryName(pathGuidPair.Key);
             directoryName        = directoryName?.Replace('\\', '/');
             if (directoryName == directory)
             {
                 if (m_assetMap.TryGetValue(pathGuidPair.Value, out CAsset asset))
                 {
                     asset.WaitUntilLoaded();
                     lock (listMutex)
                     {
                         outAssets.Add(asset);
                     }
                 }
                 else
                 {
                     CAsset loadedAsset = DeserializeAsset(pathGuidPair.Key);
                     lock (listMutex)
                     {
                         m_assetMap.Add(pathGuidPair.Value, loadedAsset);
                         outAssets.Add(loadedAsset);
                     }
                 }
             }
         });
     }
 }
Exemplo n.º 4
0
        public override void CopyFrom(CAsset source)
        {
            base.CopyFrom(source);
            CMaterialAsset sourceMaterial = (CMaterialAsset)source;

            MaterialParameters = sourceMaterial.MaterialParameters;
            Shader             = sourceMaterial.Shader;
        }
Exemplo n.º 5
0
        public override void CopyFrom(CAsset source)
        {
            base.CopyFrom(source);
            CTextureAsset textureSource = (CTextureAsset)source;

            ImageSurface = textureSource.ImageSurface;
            DDSImagePath = textureSource.DDSImagePath;
        }
Exemplo n.º 6
0
        public override void CopyFrom(CAsset source)
        {
            base.CopyFrom(source);
            CShaderAsset shaderSource = (CShaderAsset)source;

            ShaderName     = shaderSource.ShaderName;
            ShaderBytecode = shaderSource.ShaderBytecode;
        }
Exemplo n.º 7
0
        public override bool Equals(object obj)
        {
            CAsset other = obj as CAsset;

            if (other == null)
            {
                return(false);
            }

            return(other.Guid.Equals(Guid));
        }
Exemplo n.º 8
0
        public override void CopyFrom(CAsset source)
        {
            base.CopyFrom(source);
            CMeshAsset meshSource = (CMeshAsset)source;

            PrimitiveTopology = meshSource.PrimitiveTopology;
            FaceCount         = meshSource.FaceCount;
            VertexData        = meshSource.VertexData;
            IndexData         = meshSource.IndexData;
            MaterialAsset     = meshSource.MaterialAsset;
            AABBMin           = meshSource.AABBMin;
            AABBMax           = meshSource.AABBMax;
        }
Exemplo n.º 9
0
        private CAsset DeserializeAsset(string filePath)
        {
            FileStream fileStream  = new FileStream(ProjectDefinitions.GetAbsolutePath(filePath), FileMode.Open);
            CAsset     loadedAsset = (CAsset)CAssetSerializer.Instance.DeserializeFromStream(fileStream);

            loadedAsset.Path = filePath;

            if (loadedAsset.LoadCustomResources())
            {
                loadedAsset.LoadFinished();
            }

            return(loadedAsset);
        }
Exemplo n.º 10
0
        public bool RemoveAssetFile(CAsset assetToRemove)
        {
            if (assetToRemove == null)
            {
                return(false);
            }

            lock (m_registryMutex)
            {
                assetToRemove.RemoveCustomResources();
                m_assetMap.Remove(assetToRemove.Guid);
                m_assetFileMap.Remove(assetToRemove.Guid);
                SaveRegistry();
                return(true);
            }
        }
Exemplo n.º 11
0
        public void RegisterAsset(CAsset asset, string basePath, bool bOverride)
        {
            lock (m_registryMutex)
            {
                if (!m_assetFileMap.ContainsKey(asset.Guid))
                {
                    basePath = SanitizeAssetPath(basePath);
                    string assetFileName = basePath + asset.Name + asset.GetFileExtension();
                    if (!bOverride)
                    {
                        if (FileUtilities.GetNextAvailableAssetFile(assetFileName, m_assetFileMap.ValueToKey, out string foundFileName))
                        {
                            assetFileName = foundFileName;
                            asset.Name    = Path.GetFileNameWithoutExtension(foundFileName);
                        }
                        else
                        {
                            throw new Exception("Couldn't find a valid asset filename");
                        }
                    }

                    asset.Path = assetFileName;
                    m_assetFileMap.Add(asset.Guid, assetFileName);
                    m_assetMap.Add(asset.Guid, asset);

                    // todo henning defer this until asset is loaded in case it is not loaded yet
                    if (AutoSaveAssets > 0)
                    {
                        Task.Run(() =>
                        {
                            string absoluteFilename = ProjectDefinitions.GetAbsolutePath(assetFileName);
                            FileInfo fileInfo       = new FileInfo(absoluteFilename);
                            fileInfo.Directory?.Create();
                            asset.SaveCustomResources(basePath);
                            FileStream fileStream = new FileStream(absoluteFilename, FileMode.Create);
                            CAssetSerializer.Instance.SerializeToStream(asset, fileStream);
                            SaveRegistry();
                        });
                    }
                    else
                    {
                        m_unsavedAssets.Add(asset);
                    }
                }
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Save modifications made to the given asset, only needed if an asset is modified after registration, does not work for non registered assets use RequestRegisterAsset instead
 /// </summary>
 /// <param name="assetToSave"></param>
 public void SaveAsset(CAsset assetToSave)
 {
     lock (m_registryMutex)
     {
         if (m_assetFileMap.TryGet(assetToSave.Guid, out string assetFilename))
         {
             string   absoluteFilename  = ProjectDefinitions.GetAbsolutePath(assetFilename);
             FileInfo fileInfo          = new FileInfo(absoluteFilename);
             string   relativeDirectory = ProjectDefinitions.GetRelativePath(fileInfo.DirectoryName) + '/';
             assetToSave.SaveCustomResources(relativeDirectory);
             FileStream fileStream = new FileStream(absoluteFilename, FileMode.Create);
             CAssetSerializer.Instance.SerializeToStream(assetToSave, fileStream);
         }
         else
         {
             throw new Exception("Tried to save an asset that is not registered in the registry, make sure to register assets with RequestRegisterAsset");
         }
     }
 }
Exemplo n.º 13
0
        public bool MoveAssetFile(CAsset assetToMove, string targetPath)
        {
            lock (m_registryMutex)
            {
                if (m_assetFileMap.TryGet(assetToMove.Guid, out string currentPath))
                {
                    string assetFileName      = Path.GetFileName(currentPath);
                    string targetRelativePath = SanitizeAssetPath(Path.Combine(targetPath, assetFileName));
                    string absoluteCurrent    = ProjectDefinitions.GetAbsolutePath(currentPath);
                    string absoluteTarget     = ProjectDefinitions.GetAbsolutePath(targetRelativePath);

                    File.Move(absoluteCurrent, absoluteTarget);
                    m_assetFileMap[assetToMove.Guid] = targetRelativePath;
                    assetToMove.Path = targetRelativePath;
                    assetToMove.MoveCustomResources(targetRelativePath);
                    SaveRegistry();
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 14
0
 public virtual void CopyFrom(CAsset source)
 {
     Name = source.Name;
 }