2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/integration-api/debug.h>
25 #include "pico-json.h"
27 #define GLTF_LOG(...) \
29 Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, __VA_ARGS__); \
32 enum class glTFAttributeType
52 struct glTF_BufferView
63 uint32_t componentType;
65 uint32_t componentSize;
72 std::vector<std::pair<glTFAttributeType, uint32_t>> attributes;
87 struct pbrMetallicRoughness
90 struct baseTextureColor
95 } pbrMetallicRoughness;
102 uint32_t meshId{0xffffffff};
103 uint32_t cameraId{0xffffffff};
104 glTF_Node* parent{nullptr};
105 std::vector<uint32_t> children{};
108 float rotationQuaternion[4] = {0.0f, 0.0f, 0.0f, 1.0f};
109 float translation[3] = {0.0f, 0.0f, 0.0f};
110 float scale[3] = {1.0f, 1.0f, 1.0f};
113 using glTF_Buffer = std::vector<unsigned char>;
118 * This implementation requires 2 files (it doesn't decode Base64 embedded in json)
122 glTF(const std::string& filename);
125 std::vector<const glTF_Mesh*> GetMeshes() const;
127 std::vector<const glTF_Camera*> GetCameras();
129 const std::vector<glTF_Material>& GetMaterials() const;
131 const std::vector<glTF_Texture>& GetTextures() const;
133 const std::vector<glTF_Node>& GetNodes() const
142 * Returns a copy of attribute buffer
145 std::vector<unsigned char> GetMeshAttributeBuffer(const glTF_Mesh& mesh, const std::vector<glTFAttributeType>& attrTypes);
146 uint32_t GetMeshAttributeCount(const glTF_Mesh* mesh) const;
147 const glTF_Mesh* FindMeshByName(const std::string& name) const;
150 * Returns a copy of index buffer
153 std::vector<uint16_t> GetMeshIndexBuffer(const glTF_Mesh* mesh) const;
155 const glTF_Node* FindNodeByName(const std::string& name) const;
158 void LoadFromFile(const std::string& filename);
160 glTF_Buffer LoadFile(const std::string& filename);
164 std::vector<glTF_Mesh> mMeshes;
165 std::vector<glTF_Camera> mCameras;
166 std::vector<glTF_BufferView> mBufferViews;
167 std::vector<glTF_Accessor> mAccessors;
168 std::vector<glTF_Node> mNodes;
169 std::vector<glTF_Material> mMaterials;
170 std::vector<glTF_Texture> mTextures;
172 glTF_Buffer jsonBuffer;
175 picojson::value jsonNode;
178 #endif //DALI_CMAKE_GLTF_SCENE_H