X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fscene3d-view%2Fgltf-loader.cpp;h=b1cd70d44cd42b74a4635a37bda4bdeb443c4cc2;hb=HEAD;hp=2c8de12b8ef1a17d28415fd3c67914c0ddc24c63;hpb=87423c1c7c5a6d980b0534f075d022ef7f4dfd4e;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp b/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp index 2c8de12..b1cd70d 100644 --- a/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp +++ b/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,14 @@ // EXTERNAL INCLUDES #include +#include #include #include #include +// INTERNAL INCLUDES +#include + namespace Dali { namespace Toolkit @@ -34,6 +38,8 @@ namespace Gltf { namespace { +constexpr float MIN_DURATION_SECONDS = 1e-2f; + // Utility functions const TreeNode* Tidx(const TreeNode* node, uint32_t index) { @@ -231,7 +237,7 @@ void FitBuffer(Dali::Vector& bufferDestination, Dali::Vector& buffer template bool ReadBinFile(Vector& dataBuffer, std::string url, int32_t offset, int32_t count) { - size_t readCount = 0; + size_t readCount = 0; Dali::FileStream fileStream(url, FileStream::READ | FileStream::BINARY); FILE* fp = fileStream.GetFile(); if(fp) @@ -392,10 +398,10 @@ void SetVertexBufferData(MeshInfo& meshInfo, std::string path, std::vector= 0) { Dali::Vector bufferData; - LoadDataFromAccessor(accessorIdx, bufferData, path, accessorArray, bufferViewArray, bufferArray); + LoadDataFromAccessor(accessorIdx, bufferData, std::move(path), accessorArray, bufferViewArray, bufferArray); SetMeshInfoAndCanonize(meshInfo, bufferData); - VertexBuffer vertexBuffer = CreateVertexBuffer(bufferData, map, type); + VertexBuffer vertexBuffer = CreateVertexBuffer(bufferData, std::move(map), type); meshInfo.geometry.AddVertexBuffer(vertexBuffer); } } @@ -406,9 +412,9 @@ void SetAttributeBufferData(MeshInfo& meshInfo, std::string path, std::vector= 0) { Dali::Vector bufferData; - LoadDataFromAccessor(accessorIdx, bufferData, path, accessorArray, bufferViewArray, bufferArray); + LoadDataFromAccessor(accessorIdx, bufferData, std::move(path), accessorArray, bufferViewArray, bufferArray); - VertexBuffer vertexBuffer = CreateVertexBuffer(bufferData, map, type); + VertexBuffer vertexBuffer = CreateVertexBuffer(bufferData, std::move(map), type); meshInfo.geometry.AddVertexBuffer(vertexBuffer); } } @@ -416,7 +422,7 @@ void SetAttributeBufferData(MeshInfo& meshInfo, std::string path, std::vector& accessorArray, std::vector& bufferViewArray, std::vector& bufferArray, int32_t indexIdx) { Dali::Vector indexBufferData; - LoadDataFromAccessor(indexIdx, indexBufferData, path, accessorArray, bufferViewArray, bufferArray); + LoadDataFromAccessor(indexIdx, indexBufferData, std::move(path), accessorArray, bufferViewArray, bufferArray); meshInfo.geometry.SetIndexBuffer(&indexBufferData[0], indexBufferData.Size()); } @@ -430,7 +436,7 @@ float LoadKeyFrames(const AnimationSamplerInfo& currentSampler, const Property:: LoadDataFromAccessor(currentSampler.output, outputBufferData, path, accessorArray, bufferViewArray, bufferArray); uint32_t keyframeNum = inputBufferData.Size(); - float lengthAnimation = inputBufferData[inputBufferData.Size() - 1]; + float lengthAnimation = std::max((inputBufferData.Size() > 0u ? inputBufferData[inputBufferData.Size() - 1] : MIN_DURATION_SECONDS), MIN_DURATION_SECONDS); for(uint32_t i = 0; i < keyframeNum; i++) { if(propIndex == Dali::Actor::Property::ORIENTATION) @@ -1300,9 +1306,22 @@ void Loader::LoadCamera(Scene3dView& scene3dView) if(cameraInfo.type == "orthographic") { LoadOrthoGraphic((*cameraIter).second, cameraInfo); - float xMag_2 = cameraInfo.orthographic.xmag / 2.0; - float yMag_2 = cameraInfo.orthographic.ymag / 2.0; - cameraActor.SetOrthographicProjection(-xMag_2, xMag_2, yMag_2, -yMag_2, cameraInfo.orthographic.znear, cameraInfo.orthographic.zfar); + float xMag_2 = cameraInfo.orthographic.xmag / 2.0; + float yMag_2 = cameraInfo.orthographic.ymag / 2.0; + const float aspect = xMag_2 / yMag_2; + + cameraActor.SetProjectionMode(Dali::Camera::ORTHOGRAPHIC_PROJECTION); + cameraActor.SetProperty(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE, yMag_2); + + cameraActor.SetNearClippingPlane(cameraInfo.orthographic.znear); + if(cameraInfo.orthographic.zfar > 0.0) + { + cameraActor.SetFarClippingPlane(cameraInfo.orthographic.zfar); + } + if(aspect > 0.0f) // Avoid divide-by-zero logic + { + cameraActor.SetAspectRatio(aspect); + } } else if(cameraInfo.type == "perspective") { @@ -1509,7 +1528,7 @@ Actor Loader::AddNode(Scene3dView& scene3dView, uint32_t index) VERTEX_SHADER += SHADER_GLTF_PHYSICALLY_BASED_SHADER_VERT.data(); FRAGMENT_SHADER = SHADER_GLTF_GLES_VERSION_300_DEF.data(); - bool useIBL = (scene3dView.GetLightType() >= Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT); + bool useIBL = scene3dView.HasImageBasedLighting(); if(isMaterial) { MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx]; @@ -1572,7 +1591,9 @@ Actor Loader::AddNode(Scene3dView& scene3dView, uint32_t index) FRAGMENT_SHADER += SHADER_GLTF_PHYSICALLY_BASED_SHADER_FRAG.data(); if(!mShaderCache[shaderTypeIndex]) { - mShaderCache[shaderTypeIndex] = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); + std::ostringstream oss; + oss << "GLTF_VIEW_" << shaderTypeIndex; + mShaderCache[shaderTypeIndex] = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER, Shader::Hint::NONE, oss.str()); scene3dView.AddShader(mShaderCache[shaderTypeIndex]); } Shader shader = mShaderCache[shaderTypeIndex]; @@ -1592,11 +1613,14 @@ Actor Loader::AddNode(Scene3dView& scene3dView, uint32_t index) actor.RotateBy(orientation); actor.SetProperty(Actor::Property::POSITION, translation); - shader.RegisterProperty("uLightType", (scene3dView.GetLightType() & ~Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT)); + float hasLightSource = static_cast(!!(scene3dView.GetLightType() & (Toolkit::Scene3dView::LightType::POINT_LIGHT | Toolkit::Scene3dView::LightType::DIRECTIONAL_LIGHT))); + float isPointLight = static_cast(!!(scene3dView.GetLightType() & Toolkit::Scene3dView::LightType::POINT_LIGHT)); + shader.RegisterProperty("uHasLightSource", hasLightSource); + shader.RegisterProperty("uIsPointLight", isPointLight); shader.RegisterProperty("uLightVector", scene3dView.GetLightVector()); shader.RegisterProperty("uLightColor", scene3dView.GetLightColor()); - actor.RegisterProperty("uIsColor", meshInfo.attribute.COLOR.size() > 0); + actor.RegisterProperty("uHasVertexColor", meshInfo.attribute.COLOR.size() > 0 ? 1.0f : 0.0f); if(isMaterial) { MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx]; @@ -1605,15 +1629,15 @@ Actor Loader::AddNode(Scene3dView& scene3dView, uint32_t index) if(materialInfo.alphaMode == "OPAQUE") { - actor.RegisterProperty("alphaMode", 0); + actor.RegisterProperty("uAlphaMode", 0.0f); } else if(materialInfo.alphaMode == "MASK") { - actor.RegisterProperty("alphaMode", 1); + actor.RegisterProperty("uAlphaMode", 1.0f); } else { - actor.RegisterProperty("alphaMode", 2); + actor.RegisterProperty("uAlphaMode", 2.0f); } actor.RegisterProperty("alphaCutoff", materialInfo.alphaCutoff);