#include <dali/public-api/object/type-registry.h>
// INTERNAL INCLUDES
-#include <dali-scene3d/internal/model-components/model-primitive-impl.h>
+#include <dali-scene3d/internal/controls/model/model-impl.h>
#include <dali-scene3d/internal/light/light-impl.h>
+#include <dali-scene3d/internal/model-components/model-primitive-impl.h>
namespace Dali
{
void ModelNode::Initialize()
{
OnInitialize();
- mLights.resize(Scene3D::Internal::Light::GetMaximumEnabledLightCount());
}
void ModelNode::OnInitialize()
return static_cast<uint32_t>(mModelPrimitiveContainer.size());
}
-void ModelNode::AddModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive)
+void ModelNode::AddModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive, Loader::ShaderOption::HashType hash)
{
for(auto&& primitive : mModelPrimitiveContainer)
{
Actor self = Self();
GetImplementation(modelPrimitive).AddPrimitiveObserver(this);
- if(mDiffuseTexture && mSpecularTexture)
+ if(mShadowMapTexture)
{
- GetImplementation(modelPrimitive).SetImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor, mSpecularMipmapLevels);
+ GetImplementation(modelPrimitive).SetShadowMapTexture(mShadowMapTexture);
}
- uint32_t maxLightCount = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
- for(uint32_t i = 0; i < maxLightCount; ++i)
+ if(mDiffuseTexture && mSpecularTexture)
{
- if(mLights[i])
- {
- GetImplementation(modelPrimitive).AddLight(mLights[i], i);
- }
+ GetImplementation(modelPrimitive).SetImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor, mSpecularMipmapLevels);
}
+ GetImplementation(modelPrimitive).UpdateShader(mShaderManager, hash);
+
Dali::Renderer renderer = GetImplementation(modelPrimitive).GetRenderer();
if(renderer)
{
return;
}
- uint32_t maxLightCount = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
- for(uint32_t i = 0; i < maxLightCount; ++i)
- {
- if(mLights[i])
- {
- GetImplementation(mModelPrimitiveContainer[index]).RemoveLight(i);
- }
- }
+ GetImplementation(mModelPrimitiveContainer[index]).UpdateShader(nullptr, 0u);
Actor self = Self();
GetImplementation(mModelPrimitiveContainer[index]).RemovePrimitiveObserver(this);
return Scene3D::ModelNode::DownCast(childActor);
}
+void ModelNode::RetrieveBlendShapeNames(std::vector<std::string>& blendShapeNames) const
+{
+ blendShapeNames.reserve(blendShapeNames.size() + mBlendShapeIndexMap.size());
+ for(const auto& iter : mBlendShapeIndexMap)
+ {
+ blendShapeNames.push_back(iter.first);
+ }
+}
+
+Loader::BlendShapes::Index ModelNode::GetBlendShapeIndexByName(std::string_view blendShapeName) const
+{
+ auto iter = mBlendShapeIndexMap.find(std::string(blendShapeName));
+ if(iter != mBlendShapeIndexMap.end())
+ {
+ return iter->second;
+ }
+ return Loader::BlendShapes::INVALID_INDEX;
+}
+
+void ModelNode::SetShadowMapTexture(Dali::Texture shadowMapTexture)
+{
+ mShadowMapTexture = shadowMapTexture;
+ for(auto&& primitive : mModelPrimitiveContainer)
+ {
+ GetImplementation(primitive).SetShadowMapTexture(mShadowMapTexture);
+ }
+}
+
void ModelNode::SetImageBasedLightTexture(Dali::Texture diffuseTexture, Dali::Texture specularTexture, float iblScaleFactor, uint32_t specularMipmapLevels)
{
mDiffuseTexture = diffuseTexture;
}
}
-void ModelNode::AddLight(Scene3D::Light light, uint32_t lightIndex)
+void ModelNode::UpdateShader(Scene3D::Loader::ShaderManagerPtr shaderManager)
{
- mLights[lightIndex] = light;
- for(auto&& primitive : mModelPrimitiveContainer)
+ if(mShaderManager != shaderManager)
{
- GetImplementation(primitive).AddLight(light, lightIndex);
+ mShaderManager = shaderManager;
+ for(auto&& primitive : mModelPrimitiveContainer)
+ {
+ GetImplementation(primitive).UpdateShader(mShaderManager, 0u);
+ }
}
}
-void ModelNode::RemoveLight(uint32_t lightIndex)
+void ModelNode::SetBlendShapeData(Scene3D::Loader::BlendShapes::BlendShapeData& data, Scene3D::ModelPrimitive primitive)
{
- for(auto&& primitive : mModelPrimitiveContainer)
+ // Update mBlendShapeIndexMap
+ mBlendShapeIndexMap.clear();
+ const auto blendShapeCount = data.names.size();
+ for(Loader::BlendShapes::Index index = 0u; index < blendShapeCount; ++index)
{
- GetImplementation(primitive).RemoveLight(lightIndex);
+ auto& name = data.names[index];
+ if(!name.empty())
+ {
+ mBlendShapeIndexMap[name] = index;
+ }
}
- mLights[lightIndex].Reset();
-}
-void ModelNode::SetBlendShapeData(Scene3D::Loader::BlendShapes::BlendShapeData& data, Scene3D::ModelPrimitive primitive)
-{
GetImplementation(primitive).SetBlendShapeData(data);
}
Matrix inverseMatrix = boneData.inverseMatrix;
// Constrain bone matrix to joint transform.
- boneData.constraint = Constraint::New<Matrix>(renderer, propBoneXform, [inverseMatrix](Matrix& output, const PropertyInputContainer& inputs)
- { Matrix::Multiply(output, inverseMatrix, inputs[0]->GetMatrix()); });
+ boneData.constraint = Constraint::New<Matrix>(renderer, propBoneXform, [inverseMatrix](Matrix& output, const PropertyInputContainer& inputs) { Matrix::Multiply(output, inverseMatrix, inputs[0]->GetMatrix()); });
Actor joint = Self();
boneData.constraint.AddSource(Source{joint, Actor::Property::WORLD_MATRIX});
}
}
+void ModelNode::SetColliderMesh(ColliderMeshUniquePtr&& colliderMesh)
+{
+ if(!colliderMesh && !mColliderMesh)
+ {
+ return;
+ }
+
+ if(!mParentModel) // find parent model if not set
+ {
+ auto parent = Self().GetParent();
+ while(parent)
+ {
+ auto modelHandle = Scene3D::Model::DownCast(parent);
+ if(modelHandle)
+ {
+ mParentModel = &GetImpl(modelHandle);
+ break;
+ }
+ parent = parent.GetParent();
+ }
+ }
+
+ // Resetting collider mesh if argument is nullptr
+ auto handle = Scene3D::ModelNode::DownCast(Self());
+ if(mParentModel)
+ {
+ if(mColliderMesh || colliderMesh == nullptr)
+ {
+ mParentModel->RemoveColliderMesh(handle);
+ }
+ mParentModel->RegisterColliderMesh(handle, *colliderMesh);
+ }
+
+ mColliderMesh = std::move(colliderMesh);
+}
+
+bool ModelNode::HasColliderMesh() const
+{
+ return mColliderMesh != nullptr;
+}
+
+const Scene3D::Algorithm::ColliderMesh& ModelNode::GetColliderMesh() const
+{
+ return *mColliderMesh;
+}
+
} // namespace Internal
} // namespace Scene3D