diff --git a/examples/scene3d-model/scene3d-model-example.cpp b/examples/scene3d-model/scene3d-model-example.cpp index b306792..414ae5e 100644 --- a/examples/scene3d-model/scene3d-model-example.cpp +++ b/examples/scene3d-model/scene3d-model-example.cpp @@ -41,54 +41,69 @@ using namespace Dali::Toolkit; namespace { -static constexpr int32_t NUM_OF_GLTF_MODELS = 7; +struct ModelInfo +{ + const char* name; ///< The name of the model. + const Vector2 size; ///< The size of the model + const float yPosition; ///< The position of the model in the Y axis. +}; -const char* gltf_list[7] = +const ModelInfo gltf_list[] = { /** * For the BoxAnimated.glb * Donated by Cesium for glTF testing. * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/BoxAnimated */ - "BoxAnimated.glb", + {"BoxAnimated.glb", Vector2(300.0f, 300.0f), 100.0f}, + /** + * For the quantized Duck.gltf and its Assets + * Created by Sony Computer Entertainment Inc. + * Licensed under the SCEA Shared Source License, Version 1.0 + * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Duck/glTF-Quantized + */ + {"Duck.gltf", Vector2(600.0f, 600.0f), 300.0f}, /** * For the Lantern.gltf and its Assets * Donated by Microsoft for glTF testing * Created by Ryan Martin * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Lantern */ - "Lantern.gltf", + {"Lantern.gltf", Vector2(600.0f, 600.0f), 0.0f}, /** * For the BoomBox.gltf and its Assets * Donated by Microsoft for glTF testing * Created by Ryan Martin * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/BoomBox */ - "BoomBox.gltf", + {"BoomBox.gltf", Vector2(600.0f, 600.0f), 0.0f}, /** * For the DamagedHelmet.glb * Battle Damaged Sci-fi Helmet - PBR by theblueturtle_, published under a * Creative Commons Attribution-NonCommercial license * https://sketchfab.com/models/b81008d513954189a063ff901f7abfe4 */ - "DamagedHelmet.glb", + {"DamagedHelmet.glb", Vector2(600.0f, 600.0f), 0.0f}, /** * For the microphone.gltf and its Assets * Microphone GXL 066 Bafhcteks by Gistold, published under a * Creative Commons Attribution-NonCommercial license * https://sketchfab.com/models/5172dbe9281a45f48cee8c15bdfa1831 */ - "microphone.gltf", + {"microphone.gltf", Vector2(600.0f, 600.0f), 0.0f}, /** * For the beer_model.dli and its Assets * This model includes a bottle of beer and cube box. */ - "beer_model.dli", + {"beer_model.dli", Vector2(600.0f, 600.0f), 0.0f}, /** * For the exercise_model.dli and its Assets * This model includes a sportsman */ - "exercise_model.dli"}; + {"exercise_model.dli", Vector2(600.0f, 600.0f), 0.0f}, +}; + +const int32_t NUM_OF_GLTF_MODELS = sizeof(gltf_list) / sizeof(gltf_list[0]); /** * For the diffuse and specular cube map texture. @@ -266,18 +281,11 @@ public: } std::string gltfUrl = modeldir; - gltfUrl += gltf_list[index]; + gltfUrl += gltf_list[index].name; mModel = Dali::Scene3D::Model::New(gltfUrl); - if(index == 0u) - { - mModel.SetProperty(Dali::Actor::Property::SIZE, Vector2(300, 300)); - mModel.SetProperty(Dali::Actor::Property::POSITION_Y, 100); - } - else - { - mModel.SetProperty(Dali::Actor::Property::SIZE, Vector2(600, 600)); - } + mModel.SetProperty(Dali::Actor::Property::SIZE, gltf_list[index].size); + mModel.SetProperty(Dali::Actor::Property::POSITION_Y, gltf_list[index].yPosition); mModel.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); mModel.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); mModel.SetImageBasedLightSource(uri_diffuse_texture, uri_specular_texture, 0.6f); @@ -292,7 +300,7 @@ public: mReadyToLoad = true; if(mModel.GetAnimationCount() > 0) { - Animation animation = (std::string("exercise_model.dli") == gltf_list[mCurrentGlTF]) ? mModel.GetAnimation("idleToSquatClip_0") : mModel.GetAnimation(0u); + Animation animation = (std::string("exercise_model.dli") == gltf_list[mCurrentGlTF].name) ? mModel.GetAnimation("idleToSquatClip_0") : mModel.GetAnimation(0u); animation.Play(); animation.SetLoopCount(0); } diff --git a/resources/models/Duck.bin b/resources/models/Duck.bin new file mode 100644 index 0000000..e723475 --- /dev/null +++ b/resources/models/Duck.bin diff --git a/resources/models/Duck.gltf b/resources/models/Duck.gltf new file mode 100644 index 0000000..7c5e4c7 --- /dev/null +++ b/resources/models/Duck.gltf @@ -0,0 +1,218 @@ +{ + "buffers":[ + { + "uri":"Duck.bin", + "byteLength":63656 + } + ], + "asset":{ + "version":"2.0", + "generator":"gltfpack 0.13" + }, + "extensionsUsed":[ + "KHR_mesh_quantization", + "KHR_texture_transform" + ], + "extensionsRequired":[ + "KHR_mesh_quantization" + ], + "bufferViews":[ + { + "buffer":0, + "byteOffset":0, + "byteLength":9596, + "byteStride":4, + "target":34962 + }, + { + "buffer":0, + "byteOffset":9596, + "byteLength":19192, + "byteStride":8, + "target":34962 + }, + { + "buffer":0, + "byteOffset":28788, + "byteLength":9596, + "byteStride":4, + "target":34962 + }, + { + "buffer":0, + "byteOffset":38384, + "byteLength":25272, + "target":34963 + } + ], + "accessors":[ + { + "bufferView":0, + "byteOffset":0, + "componentType":5120, + "count":2399, + "type":"VEC3", + "normalized":true + }, + { + "bufferView":1, + "byteOffset":0, + "componentType":5123, + "count":2399, + "type":"VEC3", + "min":[ + 0, + 0, + 0 + ], + "max":[ + 16383, + 15251, + 11411 + ] + }, + { + "bufferView":2, + "byteOffset":0, + "componentType":5123, + "count":2399, + "type":"VEC2" + }, + { + "bufferView":3, + "byteOffset":0, + "componentType":5123, + "count":12636, + "type":"SCALAR" + } + ], + "images":[ + { + "uri":"DuckCM.png" + } + ], + "textures":[ + { + "source":0 + } + ], + "materials":[ + { + "name":"blinn3-fx", + "pbrMetallicRoughness":{ + "baseColorTexture":{ + "index":0, + "texCoord":0, + "extensions":{ + "KHR_texture_transform":{ + "offset":[ + 0.0264090002, + 0.019963026 + ], + "scale":[ + 0.000233684244, + 0.000234450286 + ] + } + } + }, + "metallicFactor":0 + } + } + ], + "meshes":[ + { + "primitives":[ + { + "attributes":{ + "NORMAL":0, + "POSITION":1, + "TEXCOORD_0":2 + }, + "mode":4, + "indices":3, + "material":0 + } + ] + } + ], + "nodes":[ + { + "mesh":0, + "translation":[ + -0.692984998, + 0.0992936939, + -0.613281965 + ], + "scale":[ + 0.900101006161, + 0.900101006161, + 0.900101006161 + ] + }, + { + "matrix":[ + 0.00999999978, + 0, + 0, + 0, + 0, + 0.00999999978, + 0, + 0, + 0, + 0, + 0.00999999978, + 0, + 0, + 0, + 0, + 1 + ], + "children":[ + 2 + ] + }, + { + "matrix":[ + -0.72896868, + 0, + -0.684547067, + 0, + -0.425204903, + 0.783693433, + 0.452797294, + 0, + 0.536475062, + 0.621147811, + -0.57128799, + 0, + 400.113007, + 463.264008, + -431.078033, + 1 + ], + "camera":0 + } + ], + "scenes":[ + { + "nodes":[ + 0, + 1 + ] + } + ], + "cameras":[ + { + "type":"perspective", + "perspective":{ + "yfov":0.660592556, + "znear":1, + "aspectRatio":1.5, + "zfar":10000 + } + } + ], + "scene":0 +} \ No newline at end of file diff --git a/resources/models/DuckCM.png b/resources/models/DuckCM.png new file mode 100644 index 0000000..9fa2dd4 --- /dev/null +++ b/resources/models/DuckCM.png