/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CORE__GLTF__DATA_H
#define CORE__GLTF__DATA_H
#include <3d/gltf/gltf.h>
#include <3d/loaders/intf_scene_loader.h>
#include
#include
#include
#include "gltf/gltf2_data_structures.h"
CORE_BEGIN_NAMESPACE()
class IFileManager;
CORE_END_NAMESPACE()
CORE3D_BEGIN_NAMESPACE()
namespace GLTF2 {
struct Assets {
Assets() = default;
Assets(const Assets& aOther) = delete;
virtual ~Assets() = default;
BASE_NS::string filepath;
BASE_NS::string defaultResources;
int32_t defaultResourcesOffset = -1;
size_t size { 0 };
BASE_NS::unique_ptr defaultMaterial;
BASE_NS::unique_ptr defaultSampler;
GLTF2::Scene* defaultScene { nullptr };
BASE_NS::vector> buffers;
BASE_NS::vector> bufferViews;
BASE_NS::vector> accessors;
BASE_NS::vector> meshes;
BASE_NS::vector> cameras;
BASE_NS::vector> images;
BASE_NS::vector> samplers;
BASE_NS::vector> textures;
BASE_NS::vector> materials;
BASE_NS::vector> nodes;
BASE_NS::vector> scenes;
BASE_NS::vector> animations;
BASE_NS::vector> skins;
#if defined(GLTF2_EXTENSION_KHR_LIGHTS) || defined(GLTF2_EXTENSION_KHR_LIGHTS_PBR)
#ifdef GLTF2_EXTENSION_KHR_LIGHTS_PBR
uint32_t pbrLightOffset; // whats this? (seems to be a parse time helper, index to first pbr light)
#endif
BASE_NS::vector> lights;
#endif
#if defined(GLTF2_EXTENSION_HW_XR_EXT)
struct Thumbnail {
BASE_NS::string uri;
BASE_NS::string extension;
BASE_NS::vector data;
};
BASE_NS::vector thumbnails;
#endif
#if defined(GLTF2_EXTENSION_EXT_LIGHTS_IMAGE_BASED)
BASE_NS::vector> imageBasedLights;
#endif
#if defined(GLTF2_EXTENSION_KHR_MESH_QUANTIZATION)
// true then KHR_mesh_quantization extension required. this expands the valid attribute componentTypes.
bool quantization { false };
#endif
};
// Implementation of outside-world GLTF data interface.
class Data : public Assets, public IGLTFData {
public:
explicit Data(CORE_NS::IFileManager& fileManager);
bool LoadBuffers() override;
void ReleaseBuffers() override;
BASE_NS::vector GetExternalFileUris() override;
size_t GetDefaultSceneIndex() const override;
size_t GetSceneCount() const override;
size_t GetThumbnailImageCount() const override;
IGLTFData::ThumbnailImage GetThumbnailImage(size_t thumbnailIndex) override;
CORE_NS::IFile::Ptr memoryFile_;
protected:
CORE_NS::IFileManager& fileManager_;
void Destroy() override;
};
class SceneData : public ISceneData {
public:
static constexpr auto UID = BASE_NS::Uid { "e745a051-2372-4935-8ed1-30dfc0d5f305" };
using Ptr = BASE_NS::refcnt_ptr;
SceneData(BASE_NS::unique_ptr data);
const GLTF2::Data* GetData() const;
size_t GetDefaultSceneIndex() const override;
size_t GetSceneCount() const override;
const IInterface* GetInterface(const BASE_NS::Uid& uid) const override;
IInterface* GetInterface(const BASE_NS::Uid& uid) override;
void Ref() override;
void Unref() override;
protected:
friend Ptr;
uint32_t refcnt_ { 0 };
BASE_NS::unique_ptr data_;
};
} // namespace GLTF2
CORE3D_END_NAMESPACE()
#endif // CORE__GLTF__DATA_H