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 #ifndef CORE_GLTF_GLTF2_H
16 #define CORE_GLTF_GLTF2_H
17 
18 #include <3d/gltf/gltf.h>
19 #include <3d/loaders/intf_scene_loader.h>
20 #include <core/namespace.h>
21 #include <render/namespace.h>
22 
23 CORE_BEGIN_NAMESPACE()
24 class IEcs;
25 class IEngine;
26 class IFileManager;
27 CORE_END_NAMESPACE()
28 
29 RENDER_BEGIN_NAMESPACE()
30 class IRenderContext;
31 RENDER_END_NAMESPACE()
32 
33 CORE3D_BEGIN_NAMESPACE()
34 class IGraphicsContext;
35 
36 // implementation of public api..
37 class Gltf2 final : public IGltf2, ISceneLoader {
38 public:
39     explicit Gltf2(IGraphicsContext& graphicsContext);
40     // allows for partial initialization. (used by tests)
41     explicit Gltf2(CORE_NS::IFileManager& fileManager);
42     ~Gltf2() override = default;
43 
44     // IGltf2
45     GLTFLoadResult LoadGLTF(BASE_NS::string_view uri) override;
46     GLTFLoadResult LoadGLTF(BASE_NS::array_view<uint8_t const> data) override;
47     bool SaveGLTF(CORE_NS::IEcs& ecs, BASE_NS::string_view uri) override;
48     IGLTF2Importer::Ptr CreateGLTF2Importer(CORE_NS::IEcs& ecs) override;
49     IGLTF2Importer::Ptr CreateGLTF2Importer(CORE_NS::IEcs& ecs, CORE_NS::IThreadPool& pool) override;
50     CORE_NS::Entity ImportGltfScene(size_t sceneIndex, const IGLTFData& gltfData,
51         const GLTFResourceData& gltfImportData, CORE_NS::IEcs& ecs, CORE_NS::Entity rootEntity,
52         GltfSceneImportFlags flags) override;
53 
54     // ISceneLoader
55     Result Load(BASE_NS::string_view uri) override;
56     ISceneImporter::Ptr CreateSceneImporter(CORE_NS::IEcs& ecs) override;
57     ISceneImporter::Ptr CreateSceneImporter(CORE_NS::IEcs& ecs, CORE_NS::IThreadPool& pool) override;
58     BASE_NS::array_view<const BASE_NS::string_view> GetSupportedExtensions() const override;
59 
60     // IInterface
61     const IInterface* GetInterface(const BASE_NS::Uid& uid) const override;
62     IInterface* GetInterface(const BASE_NS::Uid& uid) override;
63     void Ref() override;
64     void Unref() override;
65 
66 private:
67     CORE_NS::IEngine* engine_ { nullptr };
68     RENDER_NS::IRenderContext* renderContext_ { nullptr };
69     CORE_NS::IFileManager& fileManager_;
70 };
GetName(const ISceneLoader *)71 inline constexpr BASE_NS::string_view GetName(const ISceneLoader*)
72 {
73     return "ISceneLoader";
74 }
75 CORE3D_END_NAMESPACE()
76 #endif // CORE_GLTF_GLTF2_H