[dali_2.2.52] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / node-definition.cpp
index d3e8c36..56e63af 100644 (file)
@@ -253,12 +253,18 @@ void ModelRenderable::ReflectResources(IResourceReflector& reflector)
   reflector.Reflect(ResourceType::Material, mMaterialIdx);
 }
 
+// How many shader managers are there?!
 void ModelRenderable::OnCreate(const NodeDefinition& nodeDefinition, NodeDefinition::CreateParams& params, ModelNode& node) const
 {
   DALI_ASSERT_DEBUG(mMeshIdx != INVALID_INDEX);
+  ShaderOption::HashType shaderOptionHash{0u};
   if(mShaderIdx == INVALID_INDEX)
   {
-    Shader          shader          = params.mShaderManager->ProduceShader(params.mResources.mMaterials[mMaterialIdx].first, params.mResources.mMeshes[mMeshIdx].first);
+    ShaderOption option = params.mShaderManager->ProduceShaderOption(params.mResources.mMaterials[mMaterialIdx].first,
+                                                                     params.mResources.mMeshes[mMeshIdx].first);
+    shaderOptionHash    = option.GetOptionHash();
+    Shader shader       = params.mShaderManager->ProduceShader(option);
+
     static Geometry defaultGeometry = Geometry::New();
     Renderer        renderer        = Renderer::New(defaultGeometry, shader);
 
@@ -299,23 +305,24 @@ void ModelRenderable::OnCreate(const NodeDefinition& nodeDefinition, NodeDefinit
 
   {
     mesh.first.mModelPrimitive = ModelPrimitive::New();
-    auto primitive             = mesh.first.mModelPrimitive;
-    GetImplementation(primitive).SetRenderer(renderer);
+    auto& primitive            = GetImplementation(mesh.first.mModelPrimitive);
+    primitive.SetRenderer(renderer);
 
     Index    envIndex       = resources.mMaterials[mMaterialIdx].first.mEnvironmentIdx;
     uint32_t specularMipmap = resources.mEnvironmentMaps[envIndex].second.mSpecularMipmapLevels;
-    GetImplementation(primitive).SetImageBasedLightTexture(resources.mEnvironmentMaps[envIndex].second.mDiffuse,
-                                                           resources.mEnvironmentMaps[envIndex].second.mSpecular,
-                                                           resources.mEnvironmentMaps[envIndex].first.mIblIntensity,
-                                                           specularMipmap);
+    primitive.SetImageBasedLightTexture(resources.mEnvironmentMaps[envIndex].second.mDiffuse,
+                                        resources.mEnvironmentMaps[envIndex].second.mSpecular,
+                                        resources.mEnvironmentMaps[envIndex].first.mIblIntensity,
+                                        specularMipmap);
 
     bool hasPositions = false;
     bool hasNormals   = false;
     bool hasTangents  = false;
     mesh.first.RetrieveBlendShapeComponents(hasPositions, hasNormals, hasTangents);
-    GetImplementation(primitive).SetBlendShapeOptions(hasPositions, hasNormals, hasTangents, mesh.first.mBlendShapeVersion);
-    GetImplementation(primitive).SetBlendShapeGeometry(mesh.second.blendShapeGeometry);
-    GetImplementation(primitive).SetSkinned(mesh.first.IsSkinned());
+    primitive.SetBlendShapeOptions(hasPositions, hasNormals, hasTangents, mesh.first.mBlendShapeVersion);
+    primitive.SetBlendShapeGeometry(mesh.second.blendShapeGeometry);
+    primitive.SetSkinned(mesh.first.IsSkinned(), mesh.first.GetNumberOfJointSets());
+    primitive.SetVertexColor(mesh.first.HasVertexColor());
   }
 
   auto shader = renderer.GetShader();
@@ -357,21 +364,6 @@ void ModelRenderable::OnCreate(const NodeDefinition& nodeDefinition, NodeDefinit
   renderer.RegisterProperty(IBL_INTENSITY_STRING.data(), resources.mEnvironmentMaps[envIndex].first.mIblIntensity);
   renderer.RegisterProperty(IBL_Y_DIRECTION.data(), resources.mEnvironmentMaps[envIndex].first.mYDirection);
 
-  std::string lightCountPropertyName(Scene3D::Internal::Light::GetLightCountUniformName());
-  renderer.RegisterProperty(lightCountPropertyName, 0);
-
-  uint32_t maxLightCount = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
-  for(uint32_t i = 0; i < maxLightCount; ++i)
-  {
-    std::string lightDirectionPropertyName(Scene3D::Internal::Light::GetLightDirectionUniformName());
-    lightDirectionPropertyName += "[" + std::to_string(i) + "]";
-    renderer.RegisterProperty(lightDirectionPropertyName, Vector3::ZAXIS);
-
-    std::string lightColorPropertyName(Scene3D::Internal::Light::GetLightColorUniformName());
-    lightColorPropertyName += "[" + std::to_string(i) + "]";
-    renderer.RegisterProperty(lightColorPropertyName, Vector3(Color::WHITE));
-  }
-
   node.SetProperty(Actor::Property::COLOR, mColor);
 
   // If user uses customshader, the properties of the shader could not be changed by Material.
@@ -398,11 +390,13 @@ void ModelRenderable::OnCreate(const NodeDefinition& nodeDefinition, NodeDefinit
     material.SetProperty(Scene3D::Material::Property::ALPHA_CUTOFF, matDef.GetAlphaCutoff());
     material.SetProperty(Scene3D::Material::Property::DOUBLE_SIDED, matDef.mDoubleSided);
     material.SetProperty(Scene3D::Material::Property::IOR, matDef.mIor);
+
+    // This _should_ keep the same shader as generated at the top of the method.
     GetImplementation(mesh.first.mModelPrimitive).SetMaterial(material, false);
     GetImplementation(material).ResetFlag();
   }
 
-  node.AddModelPrimitive(mesh.first.mModelPrimitive);
+  Internal::GetImplementation(node).AddModelPrimitive(mesh.first.mModelPrimitive, shaderOptionHash);
 }
 
 void ArcRenderable::OnCreate(const NodeDefinition& nodeDefinition, NodeDefinition::CreateParams& params, ModelNode& node) const