/*
- * 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.
// EXTERNAL INCLUDES
#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+#include <dali/devel-api/actors/camera-actor-devel.h>
#include <dali/devel-api/adaptor-framework/file-stream.h>
#include <dali/devel-api/adaptor-framework/image-loading.h>
#include <dali/integration-api/debug.h>
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/controls/scene3d-view/scene3d-view-impl.h>
+
namespace Dali
{
namespace Toolkit
{
namespace
{
+constexpr float MIN_DURATION_SECONDS = 1e-2f;
+
// Utility functions
const TreeNode* Tidx(const TreeNode* node, uint32_t index)
{
template<typename T>
bool ReadBinFile(Vector<T>& 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)
if(accessorIdx >= 0)
{
Dali::Vector<Vector3> bufferData;
- LoadDataFromAccessor(accessorIdx, bufferData, path, accessorArray, bufferViewArray, bufferArray);
+ LoadDataFromAccessor(accessorIdx, bufferData, std::move(path), accessorArray, bufferViewArray, bufferArray);
SetMeshInfoAndCanonize(meshInfo, bufferData);
- VertexBuffer vertexBuffer = CreateVertexBuffer<Vector3>(bufferData, map, type);
+ VertexBuffer vertexBuffer = CreateVertexBuffer<Vector3>(bufferData, std::move(map), type);
meshInfo.geometry.AddVertexBuffer(vertexBuffer);
}
}
if(accessorIdx >= 0)
{
Dali::Vector<T> bufferData;
- LoadDataFromAccessor(accessorIdx, bufferData, path, accessorArray, bufferViewArray, bufferArray);
+ LoadDataFromAccessor(accessorIdx, bufferData, std::move(path), accessorArray, bufferViewArray, bufferArray);
- VertexBuffer vertexBuffer = CreateVertexBuffer<T>(bufferData, map, type);
+ VertexBuffer vertexBuffer = CreateVertexBuffer<T>(bufferData, std::move(map), type);
meshInfo.geometry.AddVertexBuffer(vertexBuffer);
}
}
void SetIndexBuffersData(MeshInfo& meshInfo, std::string path, std::vector<AccessorInfo>& accessorArray, std::vector<BufferViewInfo>& bufferViewArray, std::vector<BufferInfo>& bufferArray, int32_t indexIdx)
{
Dali::Vector<uint16_t> indexBufferData;
- LoadDataFromAccessor(indexIdx, indexBufferData, path, accessorArray, bufferViewArray, bufferArray);
+ LoadDataFromAccessor(indexIdx, indexBufferData, std::move(path), accessorArray, bufferViewArray, bufferArray);
meshInfo.geometry.SetIndexBuffer(&indexBufferData[0], indexBufferData.Size());
}
LoadDataFromAccessor<T>(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)
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")
{
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];
actor.SetProperty(Actor::Property::POSITION, translation);
float hasLightSource = static_cast<float>(!!(scene3dView.GetLightType() & (Toolkit::Scene3dView::LightType::POINT_LIGHT | Toolkit::Scene3dView::LightType::DIRECTIONAL_LIGHT)));
- float isPointLight = static_cast<float>(!!(scene3dView.GetLightType() & Toolkit::Scene3dView::LightType::POINT_LIGHT));
+ float isPointLight = static_cast<float>(!!(scene3dView.GetLightType() & Toolkit::Scene3dView::LightType::POINT_LIGHT));
shader.RegisterProperty("uHasLightSource", hasLightSource);
shader.RegisterProperty("uIsPointLight", isPointLight);
shader.RegisterProperty("uLightVector", scene3dView.GetLightVector());