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(...) {Dali::Integration::Log::LogMessage( Dali::Integration::Log::DebugInfo, __VA_ARGS__ );}
29 enum class glTFAttributeType
49 struct glTF_BufferView
60 uint32_t componentType;
62 uint32_t componentSize;
69 std::vector<std::pair<glTFAttributeType, uint32_t>> attributes;
84 struct pbrMetallicRoughness
87 struct baseTextureColor
92 } pbrMetallicRoughness;
99 uint32_t meshId { 0xffffffff };
100 uint32_t cameraId{ 0xffffffff };
101 glTF_Node* parent { nullptr };
102 std::vector<uint32_t> children {};
105 float rotationQuaternion[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
106 float translation[3] = { 0.0f, 0.0f, 0.0f };
107 float scale[3] = { 1.0f, 1.0f, 1.0f };
110 using glTF_Buffer = std::vector<unsigned char>;
115 * This implementation requires 2 files (it doesn't decode Base64 embedded in json)
120 glTF( const std::string& filename );
123 std::vector<const glTF_Mesh*> GetMeshes() const;
125 std::vector<const glTF_Camera*> GetCameras();
127 const std::vector<glTF_Material>& GetMaterials() const;
129 const std::vector<glTF_Texture>& GetTextures() const;
131 const std::vector<glTF_Node>& GetNodes() const
140 * Returns a copy of attribute buffer
143 std::vector<unsigned char> GetMeshAttributeBuffer( const glTF_Mesh& mesh, const std::vector<glTFAttributeType>& attrTypes );
144 uint32_t GetMeshAttributeCount( const glTF_Mesh* mesh ) const;
145 const glTF_Mesh* FindMeshByName( const std::string& name ) const;
148 * Returns a copy of index buffer
151 std::vector<uint16_t> GetMeshIndexBuffer( const glTF_Mesh* mesh ) const;
153 const glTF_Node* FindNodeByName( const std::string& name ) const;
157 void LoadFromFile( const std::string& filename );
159 glTF_Buffer LoadFile( const std::string& filename );
163 std::vector<glTF_Mesh> mMeshes;
164 std::vector<glTF_Camera> mCameras;
165 std::vector<glTF_BufferView> mBufferViews;
166 std::vector<glTF_Accessor> mAccessors;
167 std::vector<glTF_Node> mNodes;
168 std::vector<glTF_Material> mMaterials;
169 std::vector<glTF_Texture> mTextures;
171 glTF_Buffer jsonBuffer;
174 picojson::value jsonNode;
178 #endif //DALI_CMAKE_GLTF_SCENE_H