/** *@brief remove an asset from the asset cache. when the asset is removed succesfully a message is send to the attached engine. *@param[in] asset (sulphur.editor.AssetCacheData) asset to remove from the cache *@remark this will not delete the raw asset the packed asset originated from. *@see sulphur.editor.native.networking.NetworkMessages */ public void DeleteAsset(AssetCacheData asset) { string folderpath = asset.origin.Substring(0, asset.origin.LastIndexOf("\\")); native.bool_ success = false; if (data.ContainsKey(folderpath) == false) { return; } foreach (AssetCacheData entry in data[folderpath]) { if (entry.origin == asset.path) { asset = entry; } } switch (asset.type) { case AssetType.kAnimation: success = native.AssetProcessor.DeleteAnimation(asset.id); break; case AssetType.kAudio: success = native.AssetProcessor.DeleteAudio(asset.id); break; case AssetType.kMaterial: success = native.AssetProcessor.DeleteMaterial(asset.id); break; case AssetType.kMesh: success = native.AssetProcessor.DeleteMesh(asset.id); break; case AssetType.kModel: success = native.AssetProcessor.DeleteModel(asset.id); break; case AssetType.kScript: success = native.AssetProcessor.DeleteScript(asset.id); break; case AssetType.kShader: success = native.AssetProcessor.DeleteShader(asset.id); break; case AssetType.kSkeleton: success = native.AssetProcessor.DeleteSkeleton(asset.id); break; case AssetType.kTexture: success = native.AssetProcessor.DeleteTexture(asset.id); break; } if (success == true) { UpdateDatabase(asset.id, Operation.kRemove, asset.type); } }
/** *@brief process a single asset. When an asset has been imported an message is send to the attached engine. *@param[in] path (string) path to a raw asset to import into the current project * @see sulphur.editor.native.networking.NetworkMessages * @remark This does not automatically update the database with the imported asset. But instead will add the imported asset id to the respective cache changelist. * @see UpdateDatabase * @see change_list * @remark If the path to the file points to a path outside the project assets folder the convert will fail. */ public void ProcessAsset(string path) { UInt64 id = 0; native.bool_ success = false; AssetType type = AssetType.kUnknown; if (path.Length < Project.directory_path.Length) { Log.Write(Log.Verbosity.kInfo, "file: \"{0}\" is not in the assets folder. Asset not imported.", path); return; } string relative_path = path.StartsWith(".") == true ? path : path.Remove(0, Project.directory_path.Length); if (File.Exists(Project.directory_path + relative_path) == false) { Log.Write(Log.Verbosity.kInfo, "file: \"{0}\" does not exist. Asset not imported.", path); return; } if (relative_path.StartsWith("\\") == true) { relative_path = relative_path.Remove(0, 1); } string extension = GetExtension(relative_path); extension = extension.ToLower(); if (extension == ".obj" || extension == ".fbx" || extension == ".gltf") { success = native.AssetProcessor.ImportModel(relative_path, true, "", "", ref id); if (success) { type = AssetType.kModel; } } else if (extension == ".someAudioExtension") // @todo: correct the file type { success = native.AssetProcessor.ImportAudio(relative_path, ref id); if (success) { type = AssetType.kAudio; } } else if (extension == ".lua") { success = native.AssetProcessor.ImportScript(relative_path, ref id); if (success) { type = AssetType.kScript; } } else if (extension == ".png" || extension == ".jpeg" || extension == ".bmp" || extension == ".tga" || extension == ".jpg") { success = native.AssetProcessor.ImportTexture(relative_path, ref id); if (success) { type = AssetType.kTexture; } } else if (extension == ".vert" || extension == ".comp" || extension == ".doma" || extension == ".hull" || extension == ".geom" || extension == ".pixe") { success = native.AssetProcessor.ImportShader(relative_path, ref id); if (success) { type = AssetType.kShader; } } if (success == false) { Log.Write(Log.Verbosity.kInfo, "Unable to import asset: {0}", relative_path); } else { UpdateDatabase(id, Operation.kAdd, type); Log.Write(Log.Verbosity.kInfo, "Successfully import asset: {0}", relative_path); } }