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) {
52 return Constraint::New<bool>(a, i, [](bool& current, const PropertyInputContainer& inputs) { current = inputs[0]->GetBoolean(); });
54 {Property::Type::INTEGER,
55 [](Actor& a, Property::Index i) {
56 return Constraint::New<int>(a, i, [](int& current, const PropertyInputContainer& inputs) { current = inputs[0]->GetInteger(); });
58 {Property::Type::FLOAT,
59 [](Actor& a, Property::Index i) {
60 return Constraint::New<float>(a, i, EqualToConstraint());
62 {Property::Type::VECTOR2,
63 [](Actor& a, Property::Index i) {
64 return Constraint::New<Vector2>(a, i, EqualToConstraint());
66 {Property::Type::VECTOR3,
67 [](Actor& a, Property::Index i) {
68 return Constraint::New<Vector3>(a, i, EqualToConstraint());
70 {Property::Type::VECTOR4,
71 [](Actor& a, Property::Index i) {
72 return Constraint::New<Vector4>(a, i, EqualToConstraint());
74 {Property::Type::MATRIX,
75 [](Actor& a, Property::Index i) {
76 return Constraint::New<Matrix>(a, i, EqualToConstraint());
78 {Property::Type::MATRIX3,
79 [](Actor& a, Property::Index i) {
80 return Constraint::New<Matrix3>(a, i, EqualToConstraint());
82 {Property::Type::ROTATION,
83 [](Actor& a, Property::Index i) {
84 return Constraint::New<Quaternion>(a, i, EqualToConstraint());
87 return sConstraintFactory;
90 struct ResourceReflector : IResourceReflector
92 Index* iMesh = nullptr;
93 Index* iShader = nullptr;
95 void Reflect(ResourceType::Value type, Index& id)
99 case ResourceType::Shader:
100 DALI_ASSERT_ALWAYS(!iShader && "Shader index already assigned!");
104 case ResourceType::Mesh:
105 DALI_ASSERT_ALWAYS(!iMesh && "Mesh index already assigned!");
109 default: // Other resource types are not relevant to the problem at hand.
117 Shader sJointDebugShader;
120 void EnsureJointDebugShaderCreated()
124 sJointDebugShader = Shader::New(SHADER_SCENE3D_JOINT_DEBUG_VERT, SHADER_SCENE3D_JOINT_DEBUG_FRAG);
129 void AddJointDebugVisual(Actor aJoint)
131 Property::Map attribs;
132 attribs["aPosition"] = Property::Type::VECTOR3;
133 attribs["aColor"] = Property::Type::FLOAT;
135 PropertyBuffer vbo = PropertyBuffer::New(attribs);
142 {Vector3::ZERO, .999f + .999f * 256.f + .999f * 256.f * 256.f},
143 {Vector3::XAXIS, .999f},
144 {Vector3::YAXIS, .999f * 256.f},
145 {Vector3::ZAXIS, .999f * 256.f * 256.f},
148 vbo.SetData(&vertices, std::extent<decltype(vertices)>::value);
150 uint16_t indices[] = {0, 1, 0, 2, 0, 3};
152 Geometry geo = Geometry::New();
153 geo.AddVertexBuffer(vbo);
154 geo.SetIndexBuffer(indices, std::extent<decltype(indices)>::value);
155 geo.SetType(Geometry::LINES);
157 Renderer r = Renderer::New(geo, sJointDebugShader);
158 aJoint.AddRenderer(r);
160 aJoint.SetVisible(true);
162 #endif //DEBUG_JOINTS
164 class ActorCreatorVisitor : public NodeDefinition::IVisitor
167 ActorCreatorVisitor(NodeDefinition::CreateParams& params)
168 : mCreationContext(params)
172 void Start(NodeDefinition& n)
174 mCreationContext.mXforms.modelStack.Push(n.GetLocalSpace());
176 ModelNode a = n.CreateModelNode(mCreationContext);
177 if(!mActorStack.empty())
179 mActorStack.back().Add(a);
185 mActorStack.push_back(a);
188 void Finish(NodeDefinition& n)
190 mActorStack.pop_back();
191 mCreationContext.mXforms.modelStack.Pop();
194 ModelNode GetRoot() const
200 NodeDefinition::CreateParams& mCreationContext;
201 std::vector<ModelNode> mActorStack;
205 template<typename RequestType>
206 void SortAndDeduplicateRequests(std::vector<RequestType>& requests)
208 // Sort requests by shaders and primitives.
209 std::sort(requests.begin(), requests.end());
211 // Remove duplicates.
212 auto iter = requests.begin();
213 auto iterEnd = requests.end();
215 Shader shader = iter->mShader;
216 ModelPrimitive modelPrimitive = iter->mPrimitive;
220 // Multiple identical shader and primitive instances are removed.
221 while(iter != iterEnd && iter->mShader == shader && iter->mPrimitive == modelPrimitive)
224 iter->mShader = Shader();
232 shader = iter->mShader;
233 modelPrimitive = iter->mPrimitive;
237 requests.erase(std::remove_if(requests.begin(), requests.end(), [](const RequestType& sscr) { return !sscr.mShader; }),
241 void ConfigureBoneMatrix(const Matrix& ibm, ModelNode joint, ModelPrimitive primitive, Index& boneIdx)
243 // Register bone transform on shader.
244 Internal::GetImplementation(joint).SetBoneMatrix(ibm, primitive, boneIdx);
248 template<class Visitor, class SceneDefinition>
249 void VisitInternal(Index iNode, const Customization::Choices& choices, Visitor& v, SceneDefinition& sd)
251 auto& node = *sd.GetNode(iNode);
254 if(node.mCustomization)
256 if(!node.mChildren.empty())
258 auto choice = choices.Get(node.mCustomization->mTag);
259 Index i = std::min(choice != Customization::NONE ? choice : 0, static_cast<Index>(node.mChildren.size() - 1));
260 sd.Visit(node.mChildren[i], choices, v);
265 for(auto i : node.mChildren)
267 sd.Visit(i, choices, v);
276 SceneDefinition::SceneDefinition()
281 EnsureJointDebugShaderCreated();
285 SceneDefinition::SceneDefinition(SceneDefinition&& other)
286 : mNodes(std::move(other.mNodes)),
287 mRootNodeIds(std::move(other.mRootNodeIds))
290 EnsureJointDebugShaderCreated();
294 SceneDefinition::~SceneDefinition()
300 sJointDebugShader = Shader();
305 uint32_t Dali::Scene3D::Loader::SceneDefinition::AddRootNode(Index iNode)
307 if(iNode < mNodes.size())
309 uint32_t result = mRootNodeIds.size();
310 mRootNodeIds.push_back(iNode);
315 ExceptionFlinger(ASSERT_LOCATION) << "Failed to add new root with node " << iNode << " -- index out of bounds.";
320 const std::vector<Index>& SceneDefinition::GetRoots() const
325 void SceneDefinition::RemoveRootNode(Index iRoot)
327 if(iRoot < mRootNodeIds.size())
329 mRootNodeIds.erase(mRootNodeIds.begin() + iRoot);
333 ExceptionFlinger(ASSERT_LOCATION) << "Failed to remove root " << iRoot << " -- index out of bounds.";
337 uint32_t SceneDefinition::GetNodeCount() const
339 return mNodes.size();
342 const NodeDefinition* SceneDefinition::GetNode(Index iNode) const
344 return mNodes[iNode].get();
347 NodeDefinition* SceneDefinition::GetNode(Index iNode)
349 if(iNode != Scene3D::Loader::INVALID_INDEX && iNode < mNodes.size())
351 return mNodes[iNode].get();
356 void SceneDefinition::Visit(Index iNode, const Customization::Choices& choices, NodeDefinition::IVisitor& v)
358 VisitInternal(iNode, choices, v, *this);
361 void SceneDefinition::Visit(Index iNode, const Customization::Choices& choices, NodeDefinition::IConstVisitor& v) const
363 VisitInternal(iNode, choices, v, *this);
366 void SceneDefinition::CountResourceRefs(Index iNode, const Customization::Choices& choices, ResourceRefCounts& refCounts) const
368 struct RefCounter : IResourceReceiver
370 ResourceRefCounts* refCounts;
372 void Register(ResourceType::Value type, Index id)
374 ++(*refCounts)[type][id];
378 struct : NodeDefinition::IConstVisitor
382 void Start(const NodeDefinition& n)
384 for(auto& renderable : n.mRenderables)
386 renderable->RegisterResources(counter);
390 void Finish(const NodeDefinition& n)
395 refCounterVisitor.counter.refCounts = &refCounts;
397 Visit(iNode, choices, refCounterVisitor);
400 ModelNode SceneDefinition::CreateNodes(Index iNode, const Customization::Choices& choices, NodeDefinition::CreateParams& params)
402 ActorCreatorVisitor actorCreatorVisitor(params);
404 Visit(iNode, choices, actorCreatorVisitor);
406 return actorCreatorVisitor.GetRoot();
409 void SceneDefinition::GetCustomizationOptions(const Customization::Choices& choices,
410 Customization::Map& outCustomizationOptions,
411 Customization::Choices* outMissingChoices) const
413 struct : NodeDefinition::IConstVisitor
415 const Customization::Choices* choices; // choices that we know about.
416 Customization::Map* options; // tags are registered here. NO OWNERSHIP.
417 Customization::Choices* missingChoices; // tags will be registered with the default 0. NO OWNERSHIP.
419 void Start(const NodeDefinition& n)
423 const std::string& tag = n.mCustomization->mTag;
424 if(missingChoices != nullptr && choices->Get(tag) == Customization::NONE)
426 missingChoices->Set(tag, 0);
429 auto customization = options->Get(tag);
432 customization = options->Set(tag, {});
434 customization->nodes.push_back(n.mName);
435 customization->numOptions = std::max(customization->numOptions,
436 static_cast<uint32_t>(n.mChildren.size()));
440 void Finish(const NodeDefinition& n)
444 } customizationRegistrationVisitor;
445 customizationRegistrationVisitor.choices = &choices;
446 customizationRegistrationVisitor.options = &outCustomizationOptions;
447 customizationRegistrationVisitor.missingChoices = outMissingChoices;
449 for(auto i : mRootNodeIds)
451 Visit(i, choices, customizationRegistrationVisitor);
455 NodeDefinition* SceneDefinition::AddNode(std::unique_ptr<NodeDefinition>&& nodeDef)
457 // add next index (to which we're about to push) as a child to the designated parent, if any.
458 if(nodeDef->mParentIdx != INVALID_INDEX)
460 mNodes[nodeDef->mParentIdx]->mChildren.push_back(mNodes.size());
463 mNodes.push_back(std::move(nodeDef));
465 return mNodes.back().get();
468 bool SceneDefinition::ReparentNode(const std::string& name, const std::string& newParentName, Index siblingOrder)
470 LOGD(("reparenting %s to %s @ %d", name.c_str(), newParentName.c_str(), siblingOrder));
472 std::unique_ptr<NodeDefinition>* nodePtr = nullptr;
473 std::unique_ptr<NodeDefinition>* newParentPtr = nullptr;
474 if(!FindNode(name, &nodePtr) || !FindNode(newParentName, &newParentPtr))
479 auto& node = *nodePtr;
480 auto iNode = std::distance(mNodes.data(), nodePtr);
482 DEBUG_ONLY(auto dumpNode = [](NodeDefinition const& n) {
483 std::ostringstream stream;
484 stream << n.mName << " (" << n.mParentIdx << "):";
485 for(auto i : n.mChildren)
489 LOGD(("%s", stream.str().c_str()));
492 // Remove node from children of previous parent (if any).
493 if(node->mParentIdx != INVALID_INDEX)
495 LOGD(("old parent:"));
496 DEBUG_ONLY(dumpNode(*mNodes[node->mParentIdx]);)
498 auto& children = mNodes[node->mParentIdx]->mChildren;
499 children.erase(std::remove(children.begin(), children.end(), iNode), children.end());
501 DEBUG_ONLY(dumpNode(*mNodes[node->mParentIdx]);)
504 // Register node to new parent.
505 LOGD(("new parent:"));
506 DEBUG_ONLY(dumpNode(**newParentPtr);)
507 auto& children = (*newParentPtr)->mChildren;
508 if(siblingOrder > children.size())
510 siblingOrder = children.size();
512 children.insert(children.begin() + siblingOrder, 1, iNode);
513 DEBUG_ONLY(dumpNode(**newParentPtr);)
515 // Update parent index.
517 DEBUG_ONLY(dumpNode(*node);)
518 auto iParent = std::distance(mNodes.data(), newParentPtr);
519 node->mParentIdx = iParent;
520 DEBUG_ONLY(dumpNode(*node);)
524 bool SceneDefinition::RemoveNode(const std::string& name)
526 std::unique_ptr<NodeDefinition>* node = nullptr;
527 if(!FindNode(name, &node))
532 // Reset node def pointers recursively.
533 auto& thisNodes = mNodes;
534 unsigned int numReset = 0;
535 std::function<void(std::unique_ptr<NodeDefinition>&)> resetFn =
536 [&thisNodes, &resetFn, &numReset](std::unique_ptr<NodeDefinition>& nd) {
537 LOGD(("resetting %d", &nd - thisNodes.data()));
538 for(auto i : nd->mChildren)
540 resetFn(thisNodes[i]);
548 // Gather indices of dead nodes into a vector which we sort on insertion.
549 std::vector<Index> offsets;
550 offsets.reserve(numReset);
551 for(auto& n : mNodes)
555 offsets.push_back(std::distance(mNodes.data(), &n));
559 // Erase dead nodes as they don't have to be processed anymore.
560 mNodes.erase(std::remove(mNodes.begin(), mNodes.end(), decltype(mNodes)::value_type()), mNodes.end());
562 // Offset all indices (parent and child) by the index they'd sort into in offsets.
565 INDEX_FOR_REMOVAL = INVALID_INDEX
567 auto offsetter = [&offsets](Index& i) {
568 auto iFind = std::lower_bound(offsets.begin(), offsets.end(), i);
569 if(iFind != offsets.end() && *iFind == i)
571 LOGD(("marking %d for removal.", i));
572 i = INDEX_FOR_REMOVAL;
577 auto distance = std::distance(offsets.begin(), iFind);
580 LOGD(("offsetting %d by %d.", i, distance));
587 for(auto& nd : mNodes)
589 bool parentOffsetResult = offsetter(nd->mParentIdx);
590 DALI_ASSERT_ALWAYS(parentOffsetResult); // since nodes were recursively removed, we should not be finding invalid parents at this point.
592 auto& children = nd->mChildren;
593 for(auto i0 = children.begin(), i1 = children.end(); i0 != i1; ++i0)
598 children.erase(std::remove(children.begin(), children.end(), INDEX_FOR_REMOVAL), children.end());
604 void SceneDefinition::GetNodeModelStack(Index index, MatrixStack& model) const
606 auto& thisNodes = mNodes;
607 std::function<void(int)> buildStack = [&model, &thisNodes, &buildStack](int i) {
608 auto node = thisNodes[i].get();
609 if(node->mParentIdx != INVALID_INDEX)
611 buildStack(node->mParentIdx);
613 model.Push(node->GetLocalSpace());
618 NodeDefinition* SceneDefinition::FindNode(const std::string& name, Index* outIndex)
620 auto iBegin = mNodes.begin();
621 auto iEnd = mNodes.end();
622 auto iFind = std::find_if(iBegin, iEnd, [&name](const std::unique_ptr<NodeDefinition>& nd) { return nd->mName == name; });
624 auto result = iFind != iEnd ? iFind->get() : nullptr;
625 if(result && outIndex)
627 *outIndex = std::distance(iBegin, iFind);
632 const NodeDefinition* SceneDefinition::FindNode(const std::string& name, Index* outIndex) const
634 auto iBegin = mNodes.begin();
635 auto iEnd = mNodes.end();
636 auto iFind = std::find_if(iBegin, iEnd, [&name](const std::unique_ptr<NodeDefinition>& nd) { return nd->mName == name; });
638 auto result = iFind != iEnd ? iFind->get() : nullptr;
639 if(result && outIndex)
641 *outIndex = std::distance(iBegin, iFind);
646 Index SceneDefinition::FindNodeIndex(const NodeDefinition& node) const
648 auto iBegin = mNodes.begin();
649 auto iEnd = mNodes.end();
650 auto iFind = std::find_if(iBegin, iEnd, [&node](const std::unique_ptr<NodeDefinition>& n) { return n.get() == &node; });
651 return iFind != iEnd ? std::distance(iBegin, iFind) : INVALID_INDEX;
654 void SceneDefinition::FindNodes(NodePredicate predicate, NodeConsumer consumer, unsigned int limit)
657 for(auto& defp : mNodes)
671 void SceneDefinition::FindNodes(NodePredicate predicate, ConstNodeConsumer consumer, unsigned int limit) const
674 for(auto& defp : mNodes)
688 void SceneDefinition::ApplyConstraints(Actor& root,
689 std::vector<ConstraintRequest>&& constrainables,
690 StringCallback onError) const
692 for(auto& cr : constrainables)
694 auto& nodeDef = mNodes[cr.mConstraint->mSourceIdx];
695 auto sourceName = nodeDef->mName.c_str();
696 Property::Index iTarget = cr.mTarget.GetPropertyIndex(cr.mConstraint->mProperty);
697 if(iTarget != Property::INVALID_INDEX)
699 auto propertyType = cr.mTarget.GetPropertyType(iTarget);
700 auto iFind = GetConstraintFactory().find(propertyType);
701 if(iFind == GetConstraintFactory().end())
703 onError(FormatString("node '%s': Property '%s' has unsupported type '%s'; ignored.",
705 cr.mConstraint->mProperty.c_str(),
706 PropertyTypes::GetName(propertyType)));
710 Constraint constraint = iFind->second(cr.mTarget, iTarget);
712 Actor source = root.FindChildByName(nodeDef->mName);
715 auto targetName = cr.mTarget.GetProperty(Actor::Property::NAME).Get<std::string>();
716 onError(FormatString("node '%s': Failed to locate constraint source %s@%s; ignored.",
718 cr.mConstraint->mProperty.c_str(),
719 targetName.c_str()));
722 else if(source == cr.mTarget)
724 onError(FormatString("node '%s': Cyclic constraint definition for property '%s'; ignored.",
726 cr.mConstraint->mProperty.c_str()));
730 Property::Index iSource = source.GetPropertyIndex(cr.mConstraint->mProperty);
731 constraint.AddSource(Source{source, iSource});
736 auto targetName = cr.mTarget.GetProperty(Actor::Property::NAME).Get<std::string>();
737 onError(FormatString("node '%s': Failed to create constraint for property %s@%s; ignored.",
739 cr.mConstraint->mProperty.c_str(),
740 targetName.c_str()));
745 void SceneDefinition::EnsureUniqueSkinningShaderInstances(ResourceBundle& resources) const
747 std::map<Index, std::map<Index, std::vector<Index*>>> skinningShaderUsers;
748 for(auto& node : mNodes)
750 for(auto& renderable : node->mRenderables)
752 ResourceReflector reflector;
753 renderable->ReflectResources(reflector);
757 const auto& mesh = resources.mMeshes[*reflector.iMesh].first;
760 skinningShaderUsers[*reflector.iShader][mesh.mSkeletonIdx].push_back(reflector.iShader);
766 // For each shader, and each skeleton using the same shader as the first skeleton,
767 // update the shader references (from nodes with skinned meshes) with a new copy of
768 // the shader definition from the node using the first skeleton.
769 for(auto& users : skinningShaderUsers)
771 auto& skeletons = users.second;
772 auto iterSkeleton = skeletons.begin();
773 // skipping the first skeleton.
776 resources.mShaders.reserve(resources.mShaders.size() + std::distance(iterSkeleton, skeletons.end()));
777 const ShaderDefinition& shaderDef = resources.mShaders[users.first].first;
779 while(iterSkeleton != skeletons.end())
781 Index iShader = resources.mShaders.size();
782 resources.mShaders.push_back({shaderDef, Shader()});
784 for(auto& i : iterSkeleton->second)
793 void SceneDefinition::ConfigureSkinningShaders(const ResourceBundle& resources,
795 std::vector<SkinningShaderConfigurationRequest>&& requests) const
802 SortAndDeduplicateRequests(requests);
804 for(auto& request : requests)
806 auto& skeleton = resources.mSkeletons[request.mSkeletonIdx];
807 if(skeleton.mJoints.empty())
809 LOGD(("Skeleton %d has no joints.", request.mSkeletonIdx));
814 for(auto& joint : skeleton.mJoints)
816 auto node = GetNode(joint.mNodeIdx);
817 ModelNode modelNode = ModelNode::DownCast(rootActor.FindChildByName(node->mName));
822 ConfigureBoneMatrix(joint.mInverseBindMatrix, modelNode, request.mPrimitive, boneIdx);
827 bool SceneDefinition::ConfigureBlendshapeShaders(const ResourceBundle& resources,
829 std::vector<BlendshapeShaderConfigurationRequest>&& requests,
830 StringCallback onError) const
837 SortAndDeduplicateRequests(requests);
839 // Configure the rest.
842 for(auto& request : requests)
845 if(FindNode(request.mNodeName, &iNode))
847 const auto& node = GetNode(iNode);
849 const auto& mesh = resources.mMeshes[request.mMeshIdx];
851 if(mesh.first.HasBlendShapes())
853 Actor actor = rootActor.FindChildByName(node->mName);
854 Scene3D::ModelNode node = Scene3D::ModelNode::DownCast(actor);
859 BlendShapes::BlendShapeData data;
860 data.components = 0x0;
861 for(auto&& blendShape : mesh.first.mBlendShapes)
863 data.weights.push_back(blendShape.weight);
864 data.components |= (blendShape.deltas.IsDefined() * BlendShapes::Component::POSITIONS) |
865 (blendShape.normals.IsDefined() * BlendShapes::Component::NORMALS) | (blendShape.tangents.IsDefined() * BlendShapes::Component::TANGENTS);
867 for(auto&& factor : mesh.second.blendShapeUnnormalizeFactor)
869 data.unnormalizeFactors.push_back(factor);
871 data.version = mesh.first.mBlendShapeVersion;
872 data.bufferOffset = mesh.second.blendShapeBufferOffset;
874 Internal::GetImplementation(node).SetBlendShapeData(data, request.mPrimitive);
882 void SceneDefinition::EnsureUniqueBlendShapeShaderInstances(ResourceBundle& resources) const
884 std::map<Index, std::map<std::string, std::vector<Index*>>> blendShapeShaderUsers;
885 for(auto& node : mNodes)
887 for(auto& renderable : node->mRenderables)
889 ResourceReflector reflector;
890 renderable->ReflectResources(reflector);
894 const auto& mesh = resources.mMeshes[*reflector.iMesh].first;
895 if(mesh.HasBlendShapes())
897 blendShapeShaderUsers[*reflector.iShader][node->mName].push_back(reflector.iShader);
903 for(auto& users : blendShapeShaderUsers)
905 resources.mShaders.reserve(resources.mShaders.size() + users.second.size() - 1u);
906 const ShaderDefinition& shaderDef = resources.mShaders[users.first].first;
908 auto nodesIt = users.second.begin();
909 auto nodesEndIt = users.second.end();
910 // skipping the first node.
912 while(nodesIt != nodesEndIt)
914 Index iShader = resources.mShaders.size();
915 resources.mShaders.push_back({shaderDef, Shader()});
917 auto& nodes = *nodesIt;
918 for(auto& shader : nodes.second)
927 SceneDefinition& SceneDefinition::operator=(SceneDefinition&& other)
929 SceneDefinition temp(std::move(other));
930 std::swap(mNodes, temp.mNodes);
931 std::swap(mRootNodeIds, temp.mRootNodeIds);
935 bool SceneDefinition::FindNode(const std::string& name, std::unique_ptr<NodeDefinition>** result)
937 // We're searching from the end assuming a higher probability of operations targeting
938 // recently added nodes. (conf.: root, which is immovable, cannot be removed, and was
939 // the first to be added, is index 0.)
940 auto iFind = std::find_if(mNodes.rbegin(), mNodes.rend(), [&name](const std::unique_ptr<NodeDefinition>& nd) { return nd->mName == name; })
943 const bool success = iFind != mNodes.begin();
944 if(success && result)
953 } // namespace Dali::Scene3D::Loader