1 #ifndef DALI_TOOLKIT_INTERNAL_GLTF_LOADER_H
\r
2 #define DALI_TOOLKIT_INTERNAL_GLTF_LOADER_H
\r
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
21 // EXTERNAL INCLUDES
\r
22 #include <dali/public-api/actors/layer.h>
\r
23 #include <dali/public-api/animation/animation.h>
\r
24 #include <dali/public-api/common/vector-wrapper.h>
\r
25 #include <dali/public-api/rendering/renderer.h>
\r
26 #include <dali/public-api/rendering/shader.h>
\r
28 // INTERNAL INCLUDES
\r
29 #include <dali-toolkit/devel-api/builder/json-parser.h>
\r
31 using namespace Dali;
\r
47 METALLICROUGHNESS_SHADER,
\r
48 BASECOLOR_METALLICROUGHNESS_SHADER,
\r
50 BASECOLOR_NORMAL_SHADER,
\r
51 METALLICROUGHNESS_NORMAL_SHADER,
\r
52 BASECOLOR_METALLICROUGHNESS_NORMAL_SHADER,
\r
54 BASECOLOR_OCCLUSION_SHADER,
\r
55 METALLICROUGHNESS_OCCLUSION_SHADER,
\r
56 BASECOLOR_METALLICROUGHNESS_OCCLUSION_SHADER,
\r
57 NORMAL_OCCLUSION_SHADER,
\r
58 BASECOLOR_NORMAL_OCCLUSION_SHADER,
\r
59 METALLICROUGHNESS_NORMAL_OCCLUSION_SHADER,
\r
60 BASECOLOR_METALLICROUGHNESS_NORMAL_OCCLUSION_SHADER,
\r
62 BASECOLOR_EMIT_SHADER,
\r
63 METALLICROUGHNESS_EMIT_SHADER,
\r
64 BASECOLOR_METALLICROUGHNESS_EMIT_SHADER,
\r
66 BASECOLOR_NORMAL_EMIT_SHADER,
\r
67 METALLICROUGHNESS_NORMAL_EMIT_SHADER,
\r
68 BASECOLOR_METALLICROUGHNESS_NORMAL_EMIT_SHADER,
\r
69 OCCLUSION_EMIT_SHADER,
\r
70 BASECOLOR_OCCLUSION_EMIT_SHADER,
\r
71 METALLICROUGHNESS_OCCLUSION_EMIT_SHADER,
\r
72 BASECOLOR_METALLICROUGHNESS_OCCLUSION_EMIT_SHADER,
\r
73 NORMAL_OCCLUSION_EMIT_SHADER,
\r
74 BASECOLOR_NORMAL_OCCLUSION_EMIT_SHADER,
\r
75 METALLICROUGHNESS_NORMAL_OCCLUSION_EMIT_SHADER,
\r
76 BASECOLOR_METALLICROUGHNESS_NORMAL_OCCLUSION_EMIT_SHADER,
\r
78 IBL_BASECOLOR_SHADER,
\r
79 IBL_METALLICROUGHNESS_SHADER,
\r
80 IBL_BASECOLOR_METALLICROUGHNESS_SHADER,
\r
82 IBL_BASECOLOR_NORMAL_SHADER,
\r
83 IBL_METALLICROUGHNESS_NORMAL_SHADER,
\r
84 IBL_BASECOLOR_METALLICROUGHNESS_NORMAL_SHADER,
\r
85 IBL_OCCLUSION_SHADER,
\r
86 IBL_BASECOLOR_OCCLUSION_SHADER,
\r
87 IBL_METALLICROUGHNESS_OCCLUSION_SHADER,
\r
88 IBL_BASECOLOR_METALLICROUGHNESS_OCCLUSION_SHADER,
\r
89 IBL_NORMAL_OCCLUSION_SHADER,
\r
90 IBL_BASECOLOR_NORMAL_OCCLUSION_SHADER,
\r
91 IBL_METALLICROUGHNESS_NORMAL_OCCLUSION_SHADER,
\r
92 IBL_BASECOLOR_METALLICROUGHNESS_NORMAL_OCCLUSION_SHADER,
\r
94 IBL_BASECOLOR_EMIT_SHADER,
\r
95 IBL_METALLICROUGHNESS_EMIT_SHADER,
\r
96 IBL_BASECOLOR_METALLICROUGHNESS_EMIT_SHADER,
\r
97 IBL_NORMAL_EMIT_SHADER,
\r
98 IBL_BASECOLOR_NORMAL_EMIT_SHADER,
\r
99 IBL_METALLICROUGHNESS_NORMAL_EMIT_SHADER,
\r
100 IBL_BASECOLOR_METALLICROUGHNESS_NORMAL_EMIT_SHADER,
\r
101 IBL_OCCLUSION_EMIT_SHADER,
\r
102 IBL_BASECOLOR_OCCLUSION_EMIT_SHADER,
\r
103 IBL_METALLICROUGHNESS_OCCLUSION_EMIT_SHADER,
\r
104 IBL_BASECOLOR_METALLICROUGHNESS_OCCLUSION_EMIT_SHADER,
\r
105 IBL_NORMAL_OCCLUSION_EMIT_SHADER,
\r
106 IBL_BASECOLOR_NORMAL_OCCLUSION_EMIT_SHADER,
\r
107 IBL_METALLICROUGHNESS_NORMAL_OCCLUSION_EMIT_SHADER,
\r
108 IBL_BASECOLOR_METALLICROUGHNESS_NORMAL_OCCLUSION_EMIT_SHADER,
\r
109 SHADER_TYPE_MAX = IBL_BASECOLOR_METALLICROUGHNESS_NORMAL_OCCLUSION_EMIT_SHADER
\r
125 int32_t byteLength;
\r
130 struct BufferViewInfo
\r
147 int32_t byteOffset;
\r
148 int32_t byteLength;
\r
149 int32_t byteStride;
\r
166 int32_t samplerIdx;
\r
169 struct PbrTextureInfo
\r
186 struct MaterialInfo
\r
189 : baseColorFactor(1, 1, 1, 1),
\r
190 metallicFactor(1.0),
\r
191 roughnessFactor(1.0),
\r
192 emissiveFactor(0.0, 0.0, 0.0),
\r
193 alphaMode("OPAQUE"),
\r
195 doubleSided(false),
\r
204 Vector4 baseColorFactor;
\r
205 float metallicFactor;
\r
206 float roughnessFactor;
\r
207 Vector3 emissiveFactor;
\r
208 std::string alphaMode;
\r
212 PbrTextureInfo baseColorTexture;
\r
213 PbrTextureInfo metallicRoughnessTexture;
\r
214 PbrTextureInfo normalTexture;
\r
215 PbrTextureInfo occlusionTexture;
\r
216 PbrTextureInfo emissiveTexture;
\r
219 //need to add max, min
\r
222 struct AccessorInfo
\r
241 int32_t bufferView;
\r
242 int32_t byteOffset;
\r
243 int32_t componentType;
\r
250 //need to add max, min
\r
270 std::vector<int32_t> TEXCOORD;
\r
271 std::vector<int32_t> COLOR;
\r
289 int32_t indicesIdx;
\r
290 int32_t materialsIdx;
\r
296 Attribute attribute;
\r
297 //need to add max, min
\r
300 struct AnimationChannelInfo
\r
302 AnimationChannelInfo()
\r
309 ~AnimationChannelInfo()
\r
314 int32_t targetNode;
\r
318 struct AnimationSamplerInfo
\r
320 AnimationSamplerInfo()
\r
327 ~AnimationSamplerInfo()
\r
333 std::string interpolation;
\r
336 struct AnimationInfo
\r
348 std::vector<AnimationChannelInfo> channelArray;
\r
349 std::vector<AnimationSamplerInfo> samplerArray;
\r
352 struct OrthographicInfo
\r
362 ~OrthographicInfo()
\r
372 struct PerspectiveInfo
\r
375 : aspectRatio(0.0f),
\r
406 OrthographicInfo orthographic;
\r
407 PerspectiveInfo perspective;
\r
412 * Loader is a class to parse glTf, to load data from file, and to generate Scene.
\r
413 * This glTF loader supports glTF 2.0 features.
\r
415 * @remarks glTF loader didn't support such features.
\r
416 * - Sparse accessor
\r
418 * - Skeletal Animation
\r
419 * These features will be supported soon.
\r
426 * @brief Create an uninitialized Loader.
\r
431 * @brief Destructor
\r
436 * @brief Load Scene3dView from scene format file(e.g., glTF).
\r
437 * @param[in] filePath Path of scene format file.
\r
438 * @param[in] scene3dView Scene3dView data loaded from file.
\r
439 * @return true if scene is successfully loaded
\r
441 bool LoadScene(const std::string& filePath, Internal::Scene3dView& scene3dView);
\r
444 bool ParseGltf(const std::string& filePath);
\r
447 bool CreateScene(Internal::Scene3dView& scene3dView);
\r
449 void LoadCamera(Scene3dView& scene3dView);
\r
450 bool LoadOrthoGraphic(const TreeNode& camera, CameraInfo& cameraInfo);
\r
451 bool LoadPerspective(const TreeNode& camera, CameraInfo& cameraInfo);
\r
453 bool LoadSceneNodes(Scene3dView& scene3dView);
\r
454 Actor AddNode(Scene3dView& scene3dView, uint32_t index);
\r
455 void SetActorCache(Actor& actor, uint32_t index);
\r
456 bool SetTextureAndSampler(TextureSet& textureSet, int32_t textureIdx, std::string& toShader, std::string shader, int32_t& addIdx);
\r
458 bool LoadAnimation(Scene3dView& scene3dView);
\r
459 bool LoadAnimationChannels(const TreeNode& animation, AnimationInfo& animationInfo);
\r
460 bool LoadAnimationSamplers(const TreeNode& animation, AnimationInfo& animationInfo);
\r
463 Dali::Toolkit::JsonParser mParser;
\r
464 const TreeNode* mNodes;
\r
465 const TreeNode* mRoot;
\r
469 std::vector<Actor> mActorCache;
\r
470 Shader mShaderCache[ShaderType::SHADER_TYPE_MAX + 1];
\r
472 std::vector<BufferInfo> mBufferArray;
\r
473 std::vector<BufferViewInfo> mBufferViewArray;
\r
474 std::vector<AccessorInfo> mAccessorArray;
\r
476 std::vector<MeshInfo> mMeshArray;
\r
477 std::vector<MaterialInfo> mMaterialArray;
\r
478 std::vector<TextureInfo> mTextureArray;
\r
480 std::vector<Texture> mSourceArray;
\r
481 std::vector<Sampler> mSamplerArray;
\r
486 } //namespace Internal
\r
488 } //namespace Toolkit
\r
492 #endif // DALI_TOOLKIT_INTERNAL_GLTF_LOADER_H
\r