• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 CORE__GLTF__DATA_H
17 #define CORE__GLTF__DATA_H
18 
19 #include <3d/gltf/gltf.h>
20 #include <base/containers/unique_ptr.h>
21 #include <base/containers/vector.h>
22 #include <core/io/intf_file.h>
23 
24 #include "gltf/gltf2_data_structures.h"
25 
26 CORE_BEGIN_NAMESPACE()
27 class IFileManager;
28 CORE_END_NAMESPACE()
29 
CORE3D_BEGIN_NAMESPACE()30 CORE3D_BEGIN_NAMESPACE()
31 namespace GLTF2 {
32 struct Assets {
33     Assets() = default;
34     Assets(const Assets& aOther) = delete;
35     virtual ~Assets() = default;
36 
37     BASE_NS::string filepath;
38     BASE_NS::string defaultResources;
39     int32_t defaultResourcesOffset = -1;
40 
41     size_t size { 0 };
42 
43     BASE_NS::unique_ptr<GLTF2::Material> defaultMaterial;
44     BASE_NS::unique_ptr<GLTF2::Sampler> defaultSampler;
45     GLTF2::Scene* defaultScene { nullptr };
46 
47     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::Buffer>> buffers;
48     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::BufferView>> bufferViews;
49     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::Accessor>> accessors;
50     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::Mesh>> meshes;
51     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::Camera>> cameras;
52     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::Image>> images;
53     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::Sampler>> samplers;
54     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::Texture>> textures;
55     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::Material>> materials;
56     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::Node>> nodes;
57     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::Scene>> scenes;
58     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::Animation>> animations;
59     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::Skin>> skins;
60 
61 #if defined(GLTF2_EXTENSION_KHR_LIGHTS) || defined(GLTF2_EXTENSION_KHR_LIGHTS_PBR)
62 
63 #ifdef GLTF2_EXTENSION_KHR_LIGHTS_PBR
64     uint32_t pbrLightOffset; // whats this? (seems to be a parse time helper, index to first pbr light)
65 #endif
66 
67     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::KHRLight>> lights;
68 #endif
69 
70 #if defined(GLTF2_EXTENSION_HW_XR_EXT)
71     struct Thumbnail {
72         BASE_NS::string uri;
73         BASE_NS::string extension;
74         BASE_NS::vector<uint8_t> data;
75     };
76     BASE_NS::vector<Thumbnail> thumbnails;
77 #endif
78 
79 #if defined(GLTF2_EXTENSION_EXT_LIGHTS_IMAGE_BASED)
80     BASE_NS::vector<BASE_NS::unique_ptr<GLTF2::ImageBasedLight>> imageBasedLights;
81 #endif
82 
83 #if defined(GLTF2_EXTENSION_KHR_MESH_QUANTIZATION)
84     // true then KHR_mesh_quantization extension required. this expands the valid attribute componentTypes.
85     bool quantization { false };
86 #endif
87 };
88 
89 // Implementation of outside-world GLTF data interface.
90 class Data : public Assets, public IGLTFData {
91 public:
92     explicit Data(CORE_NS::IFileManager& fileManager);
93     bool LoadBuffers() override;
94     void ReleaseBuffers() override;
95 
96     BASE_NS::vector<BASE_NS::string> GetExternalFileUris() override;
97 
98     size_t GetDefaultSceneIndex() const override;
99     size_t GetSceneCount() const override;
100 
101     size_t GetThumbnailImageCount() const override;
102     IGLTFData::ThumbnailImage GetThumbnailImage(size_t thumbnailIndex) override;
103 
104     CORE_NS::IFile::Ptr memoryFile_;
105 
106 protected:
107     CORE_NS::IFileManager& fileManager_;
108     void Destroy() override;
109 };
110 } // namespace GLTF2
111 CORE3D_END_NAMESPACE()
112 
113 #endif // CORE__GLTF__DATA_H
114