2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-scene3d/public-api/loader/scene-definition.h>
22 #include <dali/devel-api/common/map-wrapper.h>
23 #include <dali/public-api/animation/constraints.h>
26 #include <dali-scene3d/internal/graphics/builtin-shader-extern-gen.h>
27 #include <dali-scene3d/internal/model-components/model-node-impl.h>
28 #include <dali-scene3d/public-api/loader/blend-shape-details.h>
29 #include <dali-scene3d/public-api/loader/skinning-details.h>
30 #include <dali-scene3d/public-api/loader/utils.h>
32 // #define DEBUG_SCENE_DEFINITION
33 // #define DEBUG_JOINTS
35 #if defined(DEBUG_SCENE_DEFINITION) || defined(DEBUG_JOINTS)
36 #define DEBUG_ONLY(x) x
41 #define LOGD(x) DEBUG_ONLY(printf x; printf("\n"); fflush(stdout))
43 namespace Dali::Scene3D::Loader
47 const std::map<Property::Type, Constraint (*)(Actor&, Property::Index)>& GetConstraintFactory()
49 static const std::map<Property::Type, Constraint (*)(Actor&, Property::Index)> sConstraintFactory = {
50 {Property::Type::BOOLEAN,
51 [](Actor& a, Property::Index i)
53 return Constraint::New<bool>(a, i, [](bool& current, const PropertyInputContainer& inputs)
54 { current = inputs[0]->GetBoolean(); });
56 {Property::Type::INTEGER,
57 [](Actor& a, Property::Index i)
59 return Constraint::New<int>(a, i, [](int& current, const PropertyInputContainer& inputs)
60 { current = inputs[0]->GetInteger(); });
62 {Property::Type::FLOAT,
63 [](Actor& a, Property::Index i)
65 return Constraint::New<float>(a, i, EqualToConstraint());
67 {Property::Type::VECTOR2,
68 [](Actor& a, Property::Index i)
70 return Constraint::New<Vector2>(a, i, EqualToConstraint());
72 {Property::Type::VECTOR3,
73 [](Actor& a, Property::Index i)
75 return Constraint::New<Vector3>(a, i, EqualToConstraint());
77 {Property::Type::VECTOR4,
78 [](Actor& a, Property::Index i)
80 return Constraint::New<Vector4>(a, i, EqualToConstraint());
82 {Property::Type::MATRIX,
83 [](Actor& a, Property::Index i)
85 return Constraint::New<Matrix>(a, i, EqualToConstraint());
87 {Property::Type::MATRIX3,
88 [](Actor& a, Property::Index i)
90 return Constraint::New<Matrix3>(a, i, EqualToConstraint());
92 {Property::Type::ROTATION,
93 [](Actor& a, Property::Index i)
95 return Constraint::New<Quaternion>(a, i, EqualToConstraint());
98 return sConstraintFactory;
101 struct ResourceReflector : IResourceReflector
103 Index* iMesh = nullptr;
104 Index* iShader = nullptr;
106 void Reflect(ResourceType::Value type, Index& id)
110 case ResourceType::Shader:
111 DALI_ASSERT_ALWAYS(!iShader && "Shader index already assigned!");
115 case ResourceType::Mesh:
116 DALI_ASSERT_ALWAYS(!iMesh && "Mesh index already assigned!");
120 default: // Other resource types are not relevant to the problem at hand.
128 Shader sJointDebugShader;
131 void EnsureJointDebugShaderCreated()
135 sJointDebugShader = Shader::New(SHADER_SCENE3D_JOINT_DEBUG_VERT, SHADER_SCENE3D_JOINT_DEBUG_FRAG);
140 void AddJointDebugVisual(Actor aJoint)
142 Property::Map attribs;
143 attribs["aPosition"] = Property::Type::VECTOR3;
144 attribs["aColor"] = Property::Type::FLOAT;
146 PropertyBuffer vbo = PropertyBuffer::New(attribs);
153 {Vector3::ZERO, .999f + .999f * 256.f + .999f * 256.f * 256.f},
154 {Vector3::XAXIS, .999f},
155 {Vector3::YAXIS, .999f * 256.f},
156 {Vector3::ZAXIS, .999f * 256.f * 256.f},
159 vbo.SetData(&vertices, std::extent<decltype(vertices)>::value);
161 uint16_t indices[] = {0, 1, 0, 2, 0, 3};
163 Geometry geo = Geometry::New();
164 geo.AddVertexBuffer(vbo);
165 geo.SetIndexBuffer(indices, std::extent<decltype(indices)>::value);
166 geo.SetType(Geometry::LINES);
168 Renderer r = Renderer::New(geo, sJointDebugShader);
169 aJoint.AddRenderer(r);
171 aJoint.SetVisible(true);
173 #endif // DEBUG_JOINTS
175 class ActorCreatorVisitor : public NodeDefinition::IVisitor
178 ActorCreatorVisitor(NodeDefinition::CreateParams& params)
179 : mCreationContext(params)
183 void Start(NodeDefinition& n)
185 mCreationContext.mXforms.modelStack.Push(n.GetLocalSpace());
187 ModelNode a = n.CreateModelNode(mCreationContext);
188 if(!mActorStack.empty())
190 mActorStack.back().Add(a);
196 mActorStack.push_back(a);
199 void Finish(NodeDefinition& n)
201 mActorStack.pop_back();
202 mCreationContext.mXforms.modelStack.Pop();
205 ModelNode GetRoot() const
211 NodeDefinition::CreateParams& mCreationContext;
212 std::vector<ModelNode> mActorStack;
216 template<typename RequestType>
217 void SortAndDeduplicateRequests(std::vector<RequestType>& requests)
219 // Sort requests by shaders and primitives.
220 std::sort(requests.begin(), requests.end());
222 // Remove duplicates.
223 auto iter = requests.begin();
224 auto iterEnd = requests.end();
226 Shader shader = iter->mShader;
227 ModelPrimitive modelPrimitive = iter->mPrimitive;
231 // Multiple identical shader and primitive instances are removed.
232 while(iter != iterEnd && iter->mShader == shader && iter->mPrimitive == modelPrimitive)
235 iter->mShader = Shader();
243 shader = iter->mShader;
244 modelPrimitive = iter->mPrimitive;
248 requests.erase(std::remove_if(requests.begin(), requests.end(), [](const RequestType& sscr)
249 { return !sscr.mShader; }),
253 void ConfigureBoneMatrix(const Matrix& ibm, ModelNode joint, ModelPrimitive primitive, Index& boneIdx)
255 // Register bone transform on shader.
256 Internal::GetImplementation(joint).SetBoneMatrix(ibm, primitive, boneIdx);
260 template<class Visitor, class SceneDefinition>
261 void VisitInternal(Index iNode, const Customization::Choices& choices, Visitor& v, SceneDefinition& sd)
263 auto& node = *sd.GetNode(iNode);
266 if(node.mCustomization)
268 if(!node.mChildren.empty())
270 auto choice = choices.Get(node.mCustomization->mTag);
271 Index i = std::min(choice != Customization::NONE ? choice : 0, static_cast<Index>(node.mChildren.size() - 1));
272 sd.Visit(node.mChildren[i], choices, v);
277 for(auto i : node.mChildren)
279 sd.Visit(i, choices, v);
288 SceneDefinition::SceneDefinition()
293 EnsureJointDebugShaderCreated();
297 SceneDefinition::SceneDefinition(SceneDefinition&& other)
298 : mNodes(std::move(other.mNodes)),
299 mRootNodeIds(std::move(other.mRootNodeIds))
302 EnsureJointDebugShaderCreated();
306 SceneDefinition::~SceneDefinition()
312 sJointDebugShader = Shader();
317 uint32_t Dali::Scene3D::Loader::SceneDefinition::AddRootNode(Index iNode)
319 if(iNode < mNodes.size())
321 uint32_t result = mRootNodeIds.size();
322 mRootNodeIds.push_back(iNode);
327 ExceptionFlinger(ASSERT_LOCATION) << "Failed to add new root with node " << iNode << " -- index out of bounds.";
332 const std::vector<Index>& SceneDefinition::GetRoots() const
337 void SceneDefinition::RemoveRootNode(Index iRoot)
339 if(iRoot < mRootNodeIds.size())
341 mRootNodeIds.erase(mRootNodeIds.begin() + iRoot);
345 ExceptionFlinger(ASSERT_LOCATION) << "Failed to remove root " << iRoot << " -- index out of bounds.";
349 uint32_t SceneDefinition::GetNodeCount() const
351 return mNodes.size();
354 const NodeDefinition* SceneDefinition::GetNode(Index iNode) const
356 return mNodes[iNode].get();
359 NodeDefinition* SceneDefinition::GetNode(Index iNode)
361 if(iNode != Scene3D::Loader::INVALID_INDEX && iNode < mNodes.size())
363 return mNodes[iNode].get();
368 void SceneDefinition::Visit(Index iNode, const Customization::Choices& choices, NodeDefinition::IVisitor& v)
370 VisitInternal(iNode, choices, v, *this);
373 void SceneDefinition::Visit(Index iNode, const Customization::Choices& choices, NodeDefinition::IConstVisitor& v) const
375 VisitInternal(iNode, choices, v, *this);
378 void SceneDefinition::CountResourceRefs(Index iNode, const Customization::Choices& choices, ResourceRefCounts& refCounts) const
380 struct RefCounter : IResourceReceiver
382 ResourceRefCounts* refCounts;
384 void Register(ResourceType::Value type, Index id)
386 if((!(*refCounts)[type].Empty()) && (id >= 0) && ((*refCounts)[type].Size() > id))
388 ++(*refCounts)[type][id];
393 struct : NodeDefinition::IConstVisitor
397 void Start(const NodeDefinition& n)
399 for(auto& renderable : n.mRenderables)
401 renderable->RegisterResources(counter);
405 void Finish(const NodeDefinition& n)
410 refCounterVisitor.counter.refCounts = &refCounts;
412 Visit(iNode, choices, refCounterVisitor);
415 ModelNode SceneDefinition::CreateNodes(Index iNode, const Customization::Choices& choices, NodeDefinition::CreateParams& params)
417 ActorCreatorVisitor actorCreatorVisitor(params);
419 Visit(iNode, choices, actorCreatorVisitor);
421 return actorCreatorVisitor.GetRoot();
424 void SceneDefinition::GetCustomizationOptions(const Customization::Choices& choices,
425 Customization::Map& outCustomizationOptions,
426 Customization::Choices* outMissingChoices) const
428 struct : NodeDefinition::IConstVisitor
430 const Customization::Choices* choices; // choices that we know about.
431 Customization::Map* options; // tags are registered here. NO OWNERSHIP.
432 Customization::Choices* missingChoices; // tags will be registered with the default 0. NO OWNERSHIP.
434 void Start(const NodeDefinition& n)
438 const std::string& tag = n.mCustomization->mTag;
439 if(missingChoices != nullptr && choices->Get(tag) == Customization::NONE)
441 missingChoices->Set(tag, 0);
444 auto customization = options->Get(tag);
447 customization = options->Set(tag, {});
449 customization->nodes.push_back(n.mName);
450 customization->numOptions = std::max(customization->numOptions,
451 static_cast<uint32_t>(n.mChildren.size()));
455 void Finish(const NodeDefinition& n)
459 } customizationRegistrationVisitor;
460 customizationRegistrationVisitor.choices = &choices;
461 customizationRegistrationVisitor.options = &outCustomizationOptions;
462 customizationRegistrationVisitor.missingChoices = outMissingChoices;
464 for(auto i : mRootNodeIds)
466 Visit(i, choices, customizationRegistrationVisitor);
470 NodeDefinition* SceneDefinition::AddNode(std::unique_ptr<NodeDefinition>&& nodeDef)
472 // add next index (to which we're about to push) as a child to the designated parent, if any.
473 if(nodeDef->mParentIdx != INVALID_INDEX)
475 mNodes[nodeDef->mParentIdx]->mChildren.push_back(mNodes.size());
478 mNodes.push_back(std::move(nodeDef));
480 return mNodes.back().get();
483 bool SceneDefinition::ReparentNode(const std::string& name, const std::string& newParentName, Index siblingOrder)
485 LOGD(("reparenting %s to %s @ %d", name.c_str(), newParentName.c_str(), siblingOrder));
487 std::unique_ptr<NodeDefinition>* nodePtr = nullptr;
488 std::unique_ptr<NodeDefinition>* newParentPtr = nullptr;
489 if(!FindNode(name, &nodePtr) || !FindNode(newParentName, &newParentPtr))
494 auto& node = *nodePtr;
495 auto iNode = std::distance(mNodes.data(), nodePtr);
497 DEBUG_ONLY(auto dumpNode = [](NodeDefinition const& n)
499 std::ostringstream stream;
500 stream << n.mName << " (" << n.mParentIdx << "):";
501 for(auto i : n.mChildren)
505 LOGD(("%s", stream.str().c_str())); };)
507 // Remove node from children of previous parent (if any).
508 if(node->mParentIdx != INVALID_INDEX)
510 LOGD(("old parent:"));
511 DEBUG_ONLY(dumpNode(*mNodes[node->mParentIdx]);)
513 auto& children = mNodes[node->mParentIdx]->mChildren;
514 children.erase(std::remove(children.begin(), children.end(), iNode), children.end());
516 DEBUG_ONLY(dumpNode(*mNodes[node->mParentIdx]);)
519 // Register node to new parent.
520 LOGD(("new parent:"));
521 DEBUG_ONLY(dumpNode(**newParentPtr);)
522 auto& children = (*newParentPtr)->mChildren;
523 if(siblingOrder > children.size())
525 siblingOrder = children.size();
527 children.insert(children.begin() + siblingOrder, 1, iNode);
528 DEBUG_ONLY(dumpNode(**newParentPtr);)
530 // Update parent index.
532 DEBUG_ONLY(dumpNode(*node);)
533 auto iParent = std::distance(mNodes.data(), newParentPtr);
534 node->mParentIdx = iParent;
535 DEBUG_ONLY(dumpNode(*node);)
539 bool SceneDefinition::RemoveNode(const std::string& name)
541 std::unique_ptr<NodeDefinition>* node = nullptr;
542 if(!FindNode(name, &node))
547 // Reset node def pointers recursively.
548 auto& thisNodes = mNodes;
549 unsigned int numReset = 0;
550 std::function<void(std::unique_ptr<NodeDefinition>&)> resetFn =
551 [&thisNodes, &resetFn, &numReset](std::unique_ptr<NodeDefinition>& nd)
553 LOGD(("resetting %d", &nd - thisNodes.data()));
554 for(auto i : nd->mChildren)
556 resetFn(thisNodes[i]);
564 // Gather indices of dead nodes into a vector which we sort on insertion.
565 std::vector<Index> offsets;
566 offsets.reserve(numReset);
567 for(auto& n : mNodes)
571 offsets.push_back(std::distance(mNodes.data(), &n));
575 // Erase dead nodes as they don't have to be processed anymore.
576 mNodes.erase(std::remove(mNodes.begin(), mNodes.end(), decltype(mNodes)::value_type()), mNodes.end());
578 // Offset all indices (parent and child) by the index they'd sort into in offsets.
581 INDEX_FOR_REMOVAL = INVALID_INDEX
583 auto offsetter = [&offsets](Index& i)
585 auto iFind = std::lower_bound(offsets.begin(), offsets.end(), i);
586 if(iFind != offsets.end() && *iFind == i)
588 LOGD(("marking %d for removal.", i));
589 i = INDEX_FOR_REMOVAL;
594 auto distance = std::distance(offsets.begin(), iFind);
597 LOGD(("offsetting %d by %d.", i, distance));
604 for(auto& nd : mNodes)
606 bool parentOffsetResult = offsetter(nd->mParentIdx);
607 DALI_ASSERT_ALWAYS(parentOffsetResult); // since nodes were recursively removed, we should not be finding invalid parents at this point.
609 auto& children = nd->mChildren;
610 for(auto i0 = children.begin(), i1 = children.end(); i0 != i1; ++i0)
615 children.erase(std::remove(children.begin(), children.end(), INDEX_FOR_REMOVAL), children.end());
621 void SceneDefinition::GetNodeModelStack(Index index, MatrixStack& model) const
623 auto& thisNodes = mNodes;
624 std::function<void(int)> buildStack = [&model, &thisNodes, &buildStack](int i)
626 auto node = thisNodes[i].get();
627 if(node->mParentIdx != INVALID_INDEX)
629 buildStack(node->mParentIdx);
631 model.Push(node->GetLocalSpace());
636 NodeDefinition* SceneDefinition::FindNode(const std::string& name, Index* outIndex)
638 auto iBegin = mNodes.begin();
639 auto iEnd = mNodes.end();
640 auto iFind = std::find_if(iBegin, iEnd, [&name](const std::unique_ptr<NodeDefinition>& nd)
641 { return nd->mName == name; });
643 auto result = iFind != iEnd ? iFind->get() : nullptr;
644 if(result && outIndex)
646 *outIndex = std::distance(iBegin, iFind);
651 const NodeDefinition* SceneDefinition::FindNode(const std::string& name, Index* outIndex) const
653 auto iBegin = mNodes.begin();
654 auto iEnd = mNodes.end();
655 auto iFind = std::find_if(iBegin, iEnd, [&name](const std::unique_ptr<NodeDefinition>& nd)
656 { return nd->mName == name; });
658 auto result = iFind != iEnd ? iFind->get() : nullptr;
659 if(result && outIndex)
661 *outIndex = std::distance(iBegin, iFind);
666 Index SceneDefinition::FindNodeIndex(const NodeDefinition& node) const
668 auto iBegin = mNodes.begin();
669 auto iEnd = mNodes.end();
670 auto iFind = std::find_if(iBegin, iEnd, [&node](const std::unique_ptr<NodeDefinition>& n)
671 { return n.get() == &node; });
672 return iFind != iEnd ? std::distance(iBegin, iFind) : INVALID_INDEX;
675 void SceneDefinition::FindNodes(NodePredicate predicate, NodeConsumer consumer, unsigned int limit)
678 for(auto& defp : mNodes)
692 void SceneDefinition::FindNodes(NodePredicate predicate, ConstNodeConsumer consumer, unsigned int limit) const
695 for(auto& defp : mNodes)
709 void SceneDefinition::ApplyConstraints(Actor& root,
710 std::vector<ConstraintRequest>&& constrainables,
711 StringCallback onError) const
713 for(auto& cr : constrainables)
715 auto& nodeDef = mNodes[cr.mConstraint->mSourceIdx];
716 auto sourceName = nodeDef->mName.c_str();
717 Property::Index iTarget = cr.mTarget.GetPropertyIndex(cr.mConstraint->mProperty);
718 if(iTarget != Property::INVALID_INDEX)
720 auto propertyType = cr.mTarget.GetPropertyType(iTarget);
721 auto iFind = GetConstraintFactory().find(propertyType);
722 if(iFind == GetConstraintFactory().end())
724 onError(FormatString("node '%s': Property '%s' has unsupported type '%s'; ignored.",
726 cr.mConstraint->mProperty.c_str(),
727 PropertyTypes::GetName(propertyType)));
731 Constraint constraint = iFind->second(cr.mTarget, iTarget);
733 Actor source = root.FindChildByName(nodeDef->mName);
736 auto targetName = cr.mTarget.GetProperty(Actor::Property::NAME).Get<std::string>();
737 onError(FormatString("node '%s': Failed to locate constraint source %s@%s; ignored.",
739 cr.mConstraint->mProperty.c_str(),
740 targetName.c_str()));
743 else if(source == cr.mTarget)
745 onError(FormatString("node '%s': Cyclic constraint definition for property '%s'; ignored.",
747 cr.mConstraint->mProperty.c_str()));
751 Property::Index iSource = source.GetPropertyIndex(cr.mConstraint->mProperty);
752 constraint.AddSource(Source{source, iSource});
757 auto targetName = cr.mTarget.GetProperty(Actor::Property::NAME).Get<std::string>();
758 onError(FormatString("node '%s': Failed to create constraint for property %s@%s; ignored.",
760 cr.mConstraint->mProperty.c_str(),
761 targetName.c_str()));
766 void SceneDefinition::EnsureUniqueSkinningShaderInstances(ResourceBundle& resources) const
768 std::map<Index, std::map<Index, std::vector<Index*>>> skinningShaderUsers;
769 for(auto& node : mNodes)
771 for(auto& renderable : node->mRenderables)
773 ResourceReflector reflector;
774 renderable->ReflectResources(reflector);
778 const auto& mesh = resources.mMeshes[*reflector.iMesh].first;
781 skinningShaderUsers[*reflector.iShader][mesh.mSkeletonIdx].push_back(reflector.iShader);
787 // For each shader, and each skeleton using the same shader as the first skeleton,
788 // update the shader references (from nodes with skinned meshes) with a new copy of
789 // the shader definition from the node using the first skeleton.
790 for(auto& users : skinningShaderUsers)
792 auto& skeletons = users.second;
793 auto iterSkeleton = skeletons.begin();
794 // skipping the first skeleton.
797 resources.mShaders.reserve(resources.mShaders.size() + std::distance(iterSkeleton, skeletons.end()));
798 const ShaderDefinition& shaderDef = resources.mShaders[users.first].first;
800 while(iterSkeleton != skeletons.end())
802 Index iShader = resources.mShaders.size();
803 resources.mShaders.push_back({shaderDef, Shader()});
805 for(auto& i : iterSkeleton->second)
814 void SceneDefinition::ConfigureSkinningShaders(const ResourceBundle& resources,
816 std::vector<SkinningShaderConfigurationRequest>&& requests) const
823 SortAndDeduplicateRequests(requests);
825 for(auto& request : requests)
827 auto& skeleton = resources.mSkeletons[request.mSkeletonIdx];
828 if(skeleton.mJoints.empty())
830 LOGD(("Skeleton %d has no joints.", request.mSkeletonIdx));
835 for(auto& joint : skeleton.mJoints)
837 auto node = GetNode(joint.mNodeIdx);
838 ModelNode modelNode = ModelNode::DownCast(rootActor.FindChildByName(node->mName));
843 ConfigureBoneMatrix(joint.mInverseBindMatrix, modelNode, request.mPrimitive, boneIdx);
848 bool SceneDefinition::ConfigureBlendshapeShaders(const ResourceBundle& resources,
850 std::vector<BlendshapeShaderConfigurationRequest>&& requests,
851 StringCallback onError) const
858 SortAndDeduplicateRequests(requests);
860 // Configure the rest.
863 for(auto& request : requests)
866 if(FindNode(request.mNodeName, &iNode))
868 const auto& node = GetNode(iNode);
870 const auto& mesh = resources.mMeshes[request.mMeshIdx];
872 if(mesh.first.HasBlendShapes())
874 Actor actor = rootActor.FindChildByName(node->mName);
875 Scene3D::ModelNode node = Scene3D::ModelNode::DownCast(actor);
880 BlendShapes::BlendShapeData data;
881 data.components = 0x0;
882 for(auto&& blendShape : mesh.first.mBlendShapes)
884 data.names.push_back(blendShape.name);
885 data.weights.push_back(blendShape.weight);
886 data.components |= (blendShape.deltas.IsDefined() * BlendShapes::Component::POSITIONS) |
887 (blendShape.normals.IsDefined() * BlendShapes::Component::NORMALS) | (blendShape.tangents.IsDefined() * BlendShapes::Component::TANGENTS);
889 for(auto&& factor : mesh.second.blendShapeUnnormalizeFactor)
891 data.unnormalizeFactors.push_back(factor);
893 data.version = mesh.first.mBlendShapeVersion;
894 data.bufferOffset = mesh.second.blendShapeBufferOffset;
896 Internal::GetImplementation(node).SetBlendShapeData(data, request.mPrimitive);
904 void SceneDefinition::EnsureUniqueBlendShapeShaderInstances(ResourceBundle& resources) const
906 std::map<Index, std::map<std::string, std::vector<Index*>>> blendShapeShaderUsers;
907 for(auto& node : mNodes)
909 for(auto& renderable : node->mRenderables)
911 ResourceReflector reflector;
912 renderable->ReflectResources(reflector);
916 const auto& mesh = resources.mMeshes[*reflector.iMesh].first;
917 if(mesh.HasBlendShapes())
919 blendShapeShaderUsers[*reflector.iShader][node->mName].push_back(reflector.iShader);
925 for(auto& users : blendShapeShaderUsers)
927 resources.mShaders.reserve(resources.mShaders.size() + users.second.size() - 1u);
928 const ShaderDefinition& shaderDef = resources.mShaders[users.first].first;
930 auto nodesIt = users.second.begin();
931 auto nodesEndIt = users.second.end();
932 // skipping the first node.
934 while(nodesIt != nodesEndIt)
936 Index iShader = resources.mShaders.size();
937 resources.mShaders.push_back({shaderDef, Shader()});
939 auto& nodes = *nodesIt;
940 for(auto& shader : nodes.second)
949 SceneDefinition& SceneDefinition::operator=(SceneDefinition&& other)
951 SceneDefinition temp(std::move(other));
952 std::swap(mNodes, temp.mNodes);
953 std::swap(mRootNodeIds, temp.mRootNodeIds);
957 bool SceneDefinition::FindNode(const std::string& name, std::unique_ptr<NodeDefinition>** result)
959 // We're searching from the end assuming a higher probability of operations targeting
960 // recently added nodes. (conf.: root, which is immovable, cannot be removed, and was
961 // the first to be added, is index 0.)
962 auto iFind = std::find_if(mNodes.rbegin(), mNodes.rend(), [&name](const std::unique_ptr<NodeDefinition>& nd)
963 { return nd->mName == name; })
966 const bool success = iFind != mNodes.begin();
967 if(success && result)
976 } // namespace Dali::Scene3D::Loader