1 #ifndef DALI_TOOLKIT_INTERNAL_GLTF_LOADER_H
\r
2 #define DALI_TOOLKIT_INTERNAL_GLTF_LOADER_H
\r
5 * Copyright (c) 2018 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/rendering/renderer.h>
\r
24 #include <dali/public-api/rendering/shader.h>
\r
25 #include <dali/public-api/animation/animation.h>
\r
27 // INTERNAL INCLUDES
\r
28 #include <dali-toolkit/devel-api/builder/json-parser.h>
\r
29 #include <dali-toolkit/internal/controls/scene3d-view/scene3d-view-impl.h>
\r
31 using namespace Dali;
\r
49 METALLICROUGHNESS_SHADER,
\r
50 BASECOLOR_METALLICROUGHNESS_SHADER,
\r
52 BASECOLOR_NORMAL_SHADER,
\r
53 METALLICROUGHNESS_NORMAL_SHADER,
\r
54 BASECOLOR_METALLICROUGHNESS_NORMAL_SHADER,
\r
56 BASECOLOR_OCCLUSION_SHADER,
\r
57 METALLICROUGHNESS_OCCLUSION_SHADER,
\r
58 BASECOLOR_METALLICROUGHNESS_OCCLUSION_SHADER,
\r
59 NORMAL_OCCLUSION_SHADER,
\r
60 BASECOLOR_NORMAL_OCCLUSION_SHADER,
\r
61 METALLICROUGHNESS_NORMAL_OCCLUSION_SHADER,
\r
62 BASECOLOR_METALLICROUGHNESS_NORMAL_OCCLUSION_SHADER,
\r
64 BASECOLOR_EMIT_SHADER,
\r
65 METALLICROUGHNESS_EMIT_SHADER,
\r
66 BASECOLOR_METALLICROUGHNESS_EMIT_SHADER,
\r
68 BASECOLOR_NORMAL_EMIT_SHADER,
\r
69 METALLICROUGHNESS_NORMAL_EMIT_SHADER,
\r
70 BASECOLOR_METALLICROUGHNESS_NORMAL_EMIT_SHADER,
\r
71 OCCLUSION_EMIT_SHADER,
\r
72 BASECOLOR_OCCLUSION_EMIT_SHADER,
\r
73 METALLICROUGHNESS_OCCLUSION_EMIT_SHADER,
\r
74 BASECOLOR_METALLICROUGHNESS_OCCLUSION_EMIT_SHADER,
\r
75 NORMAL_OCCLUSION_EMIT_SHADER,
\r
76 BASECOLOR_NORMAL_OCCLUSION_EMIT_SHADER,
\r
77 METALLICROUGHNESS_NORMAL_OCCLUSION_EMIT_SHADER,
\r
78 BASECOLOR_METALLICROUGHNESS_NORMAL_OCCLUSION_EMIT_SHADER,
\r
80 IBL_BASECOLOR_SHADER,
\r
81 IBL_METALLICROUGHNESS_SHADER,
\r
82 IBL_BASECOLOR_METALLICROUGHNESS_SHADER,
\r
84 IBL_BASECOLOR_NORMAL_SHADER,
\r
85 IBL_METALLICROUGHNESS_NORMAL_SHADER,
\r
86 IBL_BASECOLOR_METALLICROUGHNESS_NORMAL_SHADER,
\r
87 IBL_OCCLUSION_SHADER,
\r
88 IBL_BASECOLOR_OCCLUSION_SHADER,
\r
89 IBL_METALLICROUGHNESS_OCCLUSION_SHADER,
\r
90 IBL_BASECOLOR_METALLICROUGHNESS_OCCLUSION_SHADER,
\r
91 IBL_NORMAL_OCCLUSION_SHADER,
\r
92 IBL_BASECOLOR_NORMAL_OCCLUSION_SHADER,
\r
93 IBL_METALLICROUGHNESS_NORMAL_OCCLUSION_SHADER,
\r
94 IBL_BASECOLOR_METALLICROUGHNESS_NORMAL_OCCLUSION_SHADER,
\r
96 IBL_BASECOLOR_EMIT_SHADER,
\r
97 IBL_METALLICROUGHNESS_EMIT_SHADER,
\r
98 IBL_BASECOLOR_METALLICROUGHNESS_EMIT_SHADER,
\r
99 IBL_NORMAL_EMIT_SHADER,
\r
100 IBL_BASECOLOR_NORMAL_EMIT_SHADER,
\r
101 IBL_METALLICROUGHNESS_NORMAL_EMIT_SHADER,
\r
102 IBL_BASECOLOR_METALLICROUGHNESS_NORMAL_EMIT_SHADER,
\r
103 IBL_OCCLUSION_EMIT_SHADER,
\r
104 IBL_BASECOLOR_OCCLUSION_EMIT_SHADER,
\r
105 IBL_METALLICROUGHNESS_OCCLUSION_EMIT_SHADER,
\r
106 IBL_BASECOLOR_METALLICROUGHNESS_OCCLUSION_EMIT_SHADER,
\r
107 IBL_NORMAL_OCCLUSION_EMIT_SHADER,
\r
108 IBL_BASECOLOR_NORMAL_OCCLUSION_EMIT_SHADER,
\r
109 IBL_METALLICROUGHNESS_NORMAL_OCCLUSION_EMIT_SHADER,
\r
110 IBL_BASECOLOR_METALLICROUGHNESS_NORMAL_OCCLUSION_EMIT_SHADER,
\r
111 SHADER_TYPE_MAX = IBL_BASECOLOR_METALLICROUGHNESS_NORMAL_OCCLUSION_EMIT_SHADER
\r
117 : byteLength( -1 ),
\r
127 int32_t byteLength;
\r
132 struct BufferViewInfo
\r
149 int32_t byteOffset;
\r
150 int32_t byteLength;
\r
151 int32_t byteStride;
\r
168 int32_t samplerIdx;
\r
171 struct PbrTextureInfo
\r
188 struct MaterialInfo
\r
191 : baseColorFactor( 1, 1, 1, 1 ),
\r
192 metallicFactor( 1.0 ),
\r
193 roughnessFactor( 1.0 ),
\r
194 emissiveFactor( 0.0, 0.0, 0.0 ),
\r
195 alphaMode( "OPAQUE" ),
\r
196 alphaCutoff( 0.5 ),
\r
197 doubleSided( false ),
\r
206 Vector4 baseColorFactor;
\r
207 float metallicFactor;
\r
208 float roughnessFactor;
\r
209 Vector3 emissiveFactor;
\r
210 std::string alphaMode;
\r
214 PbrTextureInfo baseColorTexture;
\r
215 PbrTextureInfo metallicRoughnessTexture;
\r
216 PbrTextureInfo normalTexture;
\r
217 PbrTextureInfo occlusionTexture;
\r
218 PbrTextureInfo emissiveTexture;
\r
221 //need to add max, min
\r
224 struct AccessorInfo
\r
227 : bufferView( -1 ),
\r
229 componentType( -1 ),
\r
230 normalized( false ),
\r
243 int32_t bufferView;
\r
244 int32_t byteOffset;
\r
245 int32_t componentType;
\r
252 //need to add max, min
\r
272 std::vector<int32_t> TEXCOORD;
\r
273 std::vector<int32_t> COLOR;
\r
279 : indicesIdx( -1 ),
\r
280 materialsIdx( -1 ),
\r
291 int32_t indicesIdx;
\r
292 int32_t materialsIdx;
\r
298 Attribute attribute;
\r
299 //need to add max, min
\r
302 struct AnimationChannelInfo
\r
304 AnimationChannelInfo()
\r
311 ~AnimationChannelInfo()
\r
316 int32_t targetNode;
\r
321 struct AnimationSamplerInfo
\r
323 AnimationSamplerInfo()
\r
326 interpolation( "" )
\r
330 ~AnimationSamplerInfo()
\r
336 std::string interpolation;
\r
339 struct AnimationInfo
\r
351 std::vector<AnimationChannelInfo> channelArray;
\r
352 std::vector<AnimationSamplerInfo> samplerArray;
\r
355 struct OrthographicInfo
\r
365 ~OrthographicInfo()
\r
375 struct PerspectiveInfo
\r
378 : aspectRatio( 0.0f ),
\r
409 OrthographicInfo orthographic;
\r
410 PerspectiveInfo perspective;
\r
415 * Loader is a class to parse glTf, to load data from file, and to generate Scene.
\r
416 * This glTF loader supports glTF 2.0 features.
\r
418 * @remarks glTF loader didn't support such features.
\r
419 * - Sparse accessor
\r
421 * - Skeletal Animation
\r
422 * These features will be supported soon.
\r
430 * @brief Create an uninitialized Loader.
\r
435 * @brief Destructor
\r
440 * @brief Load Scene3dView from scene format file(e.g., glTF).
\r
441 * @param[in] filePath Path of scene format file.
\r
442 * @param[in] scene3dView Scene3dView data loaded from file.
\r
443 * @return true if scene is successfully loaded
\r
445 bool LoadScene( const std::string& filePath, Internal::Scene3dView& scene3dView );
\r
448 bool ParseGltf( const std::string& filePath );
\r
451 bool CreateScene( Internal::Scene3dView& scene3dView );
\r
453 void LoadCamera( Scene3dView& scene3dView );
\r
454 bool LoadOrthoGraphic( const TreeNode& camera, CameraInfo& cameraInfo );
\r
455 bool LoadPerspective( const TreeNode& camera, CameraInfo& cameraInfo );
\r
457 bool LoadSceneNodes( Scene3dView& scene3dView );
\r
458 Actor AddNode( Scene3dView& scene3dView, uint32_t index );
\r
459 void SetActorCache( Actor& actor, uint32_t index );
\r
460 bool SetTextureAndSampler( TextureSet& textureSet, int32_t textureIdx, std::string& toShader, std::string shader, int32_t& addIdx );
\r
462 bool LoadAnimation( Scene3dView& scene3dView );
\r
463 bool LoadAnimationChannels( const TreeNode& animation, AnimationInfo& animationInfo );
\r
464 bool LoadAnimationSamplers( const TreeNode& animation, AnimationInfo& animationInfo );
\r
467 Dali::Toolkit::JsonParser mParser;
\r
468 const TreeNode* mNodes;
\r
469 const TreeNode* mRoot;
\r
473 std::vector<Actor> mActorCache;
\r
474 Shader mShaderCache[ShaderType::SHADER_TYPE_MAX + 1];
\r
476 std::vector<BufferInfo> mBufferArray;
\r
477 std::vector<BufferViewInfo> mBufferViewArray;
\r
478 std::vector<AccessorInfo> mAccessorArray;
\r
480 std::vector<MeshInfo> mMeshArray;
\r
481 std::vector<MaterialInfo> mMaterialArray;
\r
482 std::vector<TextureInfo> mTextureArray;
\r
484 std::vector<Texture> mSourceArray;
\r
485 std::vector<Sampler> mSamplerArray;
\r
490 }//namespace Internal
\r
492 }//namespace Toolkit
\r
496 #endif // DALI_TOOLKIT_INTERNAL_GLTF_LOADER_H
\r