5 * Copyright (c) 2020 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.
24 #include <dali/integration-api/debug.h>
27 #include "third-party/pico-json.h"
29 #define GLTF_LOG(...) \
31 Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, __VA_ARGS__); \
34 enum class glTFAttributeType
54 struct glTF_BufferView
65 uint32_t componentType;
67 uint32_t componentSize;
74 std::vector<std::pair<glTFAttributeType, uint32_t>> attributes;
89 struct pbrMetallicRoughness
92 struct baseTextureColor
97 } pbrMetallicRoughness;
104 uint32_t meshId{0xffffffff};
105 uint32_t cameraId{0xffffffff};
106 glTF_Node* parent{nullptr};
107 std::vector<uint32_t> children{};
110 float rotationQuaternion[4] = {0.0f, 0.0f, 0.0f, 1.0f};
111 float translation[3] = {0.0f, 0.0f, 0.0f};
112 float scale[3] = {1.0f, 1.0f, 1.0f};
115 using glTF_Buffer = std::vector<unsigned char>;
120 * This implementation requires 2 files (it doesn't decode Base64 embedded in json)
124 glTF(const std::string& filename);
127 std::vector<const glTF_Mesh*> GetMeshes() const;
129 std::vector<const glTF_Camera*> GetCameras();
131 const std::vector<glTF_Material>& GetMaterials() const;
133 const std::vector<glTF_Texture>& GetTextures() const;
135 const std::vector<glTF_Node>& GetNodes() const
144 * Returns a copy of attribute buffer
147 std::vector<unsigned char> GetMeshAttributeBuffer(const glTF_Mesh& mesh, const std::vector<glTFAttributeType>& attrTypes);
148 uint32_t GetMeshAttributeCount(const glTF_Mesh* mesh) const;
149 const glTF_Mesh* FindMeshByName(const std::string& name) const;
152 * Returns a copy of index buffer
155 std::vector<uint16_t> GetMeshIndexBuffer(const glTF_Mesh* mesh) const;
157 const glTF_Node* FindNodeByName(const std::string& name) const;
160 void LoadFromFile(const std::string& filename);
162 glTF_Buffer LoadFile(const std::string& filename);
166 std::vector<glTF_Mesh> mMeshes;
167 std::vector<glTF_Camera> mCameras;
168 std::vector<glTF_BufferView> mBufferViews;
169 std::vector<glTF_Accessor> mAccessors;
170 std::vector<glTF_Node> mNodes;
171 std::vector<glTF_Material> mMaterials;
172 std::vector<glTF_Texture> mTextures;
174 glTF_Buffer jsonBuffer;
177 picojson::value jsonNode;
180 #endif //DALI_CMAKE_GLTF_SCENE_H