1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef SCENEPLUGIN_INTF_ASSETMANAGER_H
17 #define SCENEPLUGIN_INTF_ASSETMANAGER_H
18
19 #include <scene_plugin/interface/intf_asset_loader.h>
20 #include <scene_plugin/interface/intf_ecs_serializer.h>
21 #include <scene_plugin/interface/intf_entity_collection.h>
22
23 #include <3d/gltf/gltf.h>
24 #include <3d/intf_graphics_context.h>
25 #include <base/containers/unique_ptr.h>
26 #include <base/containers/unordered_map.h>
27
SCENE_BEGIN_NAMESPACE()28 SCENE_BEGIN_NAMESPACE()
29
30 class IAssetManager : public IEcsSerializer::IListener {
31 public:
32 struct Deleter {
33 constexpr Deleter() noexcept = default;
34 void operator()(IAssetManager* ptr) const
35 {
36 ptr->Destroy();
37 }
38 };
39 using Ptr = BASE_NS::unique_ptr<IAssetManager, Deleter>;
40
41 // For now detecting content by extension in the uri.
42 enum ExtensionType { NOT_SUPPORTED, COLLECTION, SCENE, ANIMATION, MATERIAL, GLTF, GLB, PNG, JPG, KTX };
43
44 virtual ExtensionType GetExtensionType(BASE_NS::string_view ext) const = 0;
45
46 /** Create an asset file loader for loading 3D scene assets.
47 * @param ecs ECS instance that will be used for loading and resource creation.
48 * @return asset loader instance.
49 */
50 virtual IAssetLoader::Ptr CreateAssetLoader(
51 IEntityCollection& ec, BASE_NS::string_view src, BASE_NS::string_view contextUri) = 0;
52
53 virtual bool LoadAsset(IEntityCollection& ec, BASE_NS::string_view uri, BASE_NS::string_view contextUri) = 0;
54
55 virtual bool SaveJsonEntityCollection(
56 const IEntityCollection& ec, BASE_NS::string_view uri, BASE_NS::string_view contextUri) const = 0;
57
58 virtual IEntityCollection* LoadAssetToCache(CORE_NS::IEcs& ecs, BASE_NS::string_view cacheUri,
59 BASE_NS::string_view uri, BASE_NS::string_view contextUri, bool active, bool forceReload) = 0;
60
61 virtual bool IsCachedCollection(BASE_NS::string_view uri, BASE_NS::string_view contextUri) const = 0;
62 virtual IEntityCollection* CreateCachedCollection(
63 CORE_NS::IEcs& ecs, BASE_NS::string_view uri, BASE_NS::string_view contextUri) = 0;
64 virtual IEntityCollection* GetCachedCollection(BASE_NS::string_view uri, BASE_NS::string_view contextUri) const = 0;
65 virtual void RemoveFromCache(BASE_NS::string_view uri, BASE_NS::string_view contextUri) = 0;
66 virtual void ClearCache() = 0;
67
68 virtual void RefreshAsset(IEntityCollection& ec, bool active) = 0;
69
70 virtual IEntityCollection* InstantiateCollection(
71 IEntityCollection& ec, BASE_NS::string_view uri, BASE_NS::string_view contextUri) = 0;
72
73 virtual IEcsSerializer& GetEcsSerializer() = 0;
74
75 protected:
76 IAssetManager() = default;
77 virtual ~IAssetManager() = default;
78 virtual void Destroy() = 0;
79 };
80
81 SCENE_END_NAMESPACE()
82
83 #endif // SCENEPLUGIN_INTF_ASSETMANAGER_H
84