• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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& gltfResourceData, CORE_NS::IEcs& ecs, CORE_NS::Entity rootEntity,
52         GltfSceneImportFlags flags) override;
53     CORE_NS::Entity ImportGltfScene(size_t sceneIndex, const IGLTFData& gltfData,
54         const GLTFResourceData& gltfResourceData, CORE_NS::IEcs& ecs, uint32_t level,
55         GltfSceneImportFlags flags) override;
56 
57     // ISceneLoader
58     Result Load(BASE_NS::string_view uri) override;
59     ISceneImporter::Ptr CreateSceneImporter(CORE_NS::IEcs& ecs) override;
60     ISceneImporter::Ptr CreateSceneImporter(CORE_NS::IEcs& ecs, CORE_NS::IThreadPool& pool) override;
61     BASE_NS::array_view<const BASE_NS::string_view> GetSupportedExtensions() const override;
62 
63     // IInterface
64     const IInterface* GetInterface(const BASE_NS::Uid& uid) const override;
65     IInterface* GetInterface(const BASE_NS::Uid& uid) override;
66     void Ref() override;
67     void Unref() override;
68 
69 private:
70     CORE_NS::IEngine* engine_ { nullptr };
71     RENDER_NS::IRenderContext* renderContext_ { nullptr };
72     CORE_NS::IFileManager& fileManager_;
73 };
GetName(const ISceneLoader *)74 inline constexpr BASE_NS::string_view GetName(const ISceneLoader*)
75 {
76     return "ISceneLoader";
77 }
78 CORE3D_END_NAMESPACE()
79 #endif // CORE_GLTF_GLTF2_H