5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/integration-api/debug.h>
26 #include "third-party/pico-json.h"
28 #define GLTF_LOG(...) \
30 Dali::Integration::Log::LogMessage(Dali::Integration::Log::INFO, __VA_ARGS__); \
33 enum class glTFAttributeType
53 struct glTF_BufferView
64 uint32_t componentType;
66 uint32_t componentSize;
73 std::vector<std::pair<glTFAttributeType, uint32_t>> attributes;
88 struct pbrMetallicRoughness
91 struct baseTextureColor
96 } pbrMetallicRoughness;
103 uint32_t meshId{0xffffffff};
104 uint32_t cameraId{0xffffffff};
105 glTF_Node* parent{nullptr};
106 std::vector<uint32_t> children{};
109 float rotationQuaternion[4] = {0.0f, 0.0f, 0.0f, 1.0f};
110 float translation[3] = {0.0f, 0.0f, 0.0f};
111 float scale[3] = {1.0f, 1.0f, 1.0f};
114 using glTF_Buffer = std::vector<unsigned char>;
119 * This implementation requires 2 files (it doesn't decode Base64 embedded in json)
123 glTF(const std::string& filename);
126 std::vector<const glTF_Mesh*> GetMeshes() const;
128 std::vector<const glTF_Camera*> GetCameras();
130 const std::vector<glTF_Material>& GetMaterials() const;
132 const std::vector<glTF_Texture>& GetTextures() const;
134 const std::vector<glTF_Node>& GetNodes() const
143 * Returns a copy of attribute buffer
146 std::vector<unsigned char> GetMeshAttributeBuffer(const glTF_Mesh& mesh, const std::vector<glTFAttributeType>& attrTypes);
147 uint32_t GetMeshAttributeCount(const glTF_Mesh* mesh) const;
148 const glTF_Mesh* FindMeshByName(const std::string& name) const;
151 * Returns a copy of index buffer
154 std::vector<uint16_t> GetMeshIndexBuffer(const glTF_Mesh* mesh) const;
156 const glTF_Node* FindNodeByName(const std::string& name) const;
159 void LoadFromFile(const std::string& filename);
161 glTF_Buffer LoadFile(const std::string& filename);
165 std::vector<glTF_Mesh> mMeshes;
166 std::vector<glTF_Camera> mCameras;
167 std::vector<glTF_BufferView> mBufferViews;
168 std::vector<glTF_Accessor> mAccessors;
169 std::vector<glTF_Node> mNodes;
170 std::vector<glTF_Material> mMaterials;
171 std::vector<glTF_Texture> mTextures;
173 glTF_Buffer jsonBuffer;
176 picojson::value jsonNode;
179 #endif //DALI_CMAKE_GLTF_SCENE_H