2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <dali/internal/event/modeling/entity-impl.h>
21 #include <dali/public-api/geometry/mesh.h>
22 #include <dali/internal/event/modeling/model-data-impl.h>
23 #include <dali/internal/event/modeling/mesh-impl.h>
31 namespace // unnamed namespace
33 static const float kBoundsDefault = 1e10f;
34 } // unnamed namespace
42 mLowerBounds( kBoundsDefault, kBoundsDefault, kBoundsDefault),
43 mUpperBounds(-kBoundsDefault, -kBoundsDefault, -kBoundsDefault),
44 mType(Dali::Entity::OBJECT)
48 EntityPtr Entity::New(const std::string name)
50 EntityPtr entity(new Entity());
51 entity->SetName(name);
62 Entity* Entity::Find(const std::string& name) const
64 Entity* entity = NULL;
68 entity = const_cast<Entity*>(this);
70 else if (mChildren.size() != 0)
72 for (EntityConstIter it = mChildren.begin(); it != mChildren.end() && !entity; ++it)
74 const Entity& child = GetImplementation(*it);
75 entity = child.Find(name);
87 void Entity::SetName(const char* name)
92 void Entity::SetName(const std::string& name)
97 const std::string& Entity::GetName() const
102 const Vector3& Entity::GetLowerBounds() const
107 void Entity::SetLowerBounds(const Vector3& bounds)
109 mLowerBounds = bounds;
112 const Vector3& Entity::GetUpperBounds() const
117 void Entity::SetUpperBounds(const Vector3& bounds)
119 mUpperBounds = bounds;
123 void Entity::SetType(const Dali::Entity::EntityType type)
128 Dali::Entity::EntityType Entity::GetType() const
133 void Entity::SetTransformMatrix(Matrix& matrix)
135 mTransformMatrix = matrix;
138 const Matrix& Entity::GetTransformMatrix() const
140 return mTransformMatrix;
143 bool Entity::HasChildren() const
145 return 0 != mChildren.size();
148 int Entity::NumberOfChildren() const
150 return mChildren.size();
153 const EntityContainer& Entity::GetChildren() const
158 void Entity::Add(Entity& child)
160 if(this != child.mParent)
162 child.SetParent(this);
163 mChildren.push_back(Dali::Entity(&child));
167 void Entity::SetChildCapacity(unsigned int capacity)
169 mChildren.reserve(capacity);
172 void Entity::SetParent(Entity* parent)
176 DALI_ASSERT_ALWAYS( this != parent && "Cannot parent an entity to itself" );
177 DALI_ASSERT_ALWAYS(mParent == NULL && "Entity already has a parent" );
182 Entity* Entity::GetParent() const
187 bool Entity::HasMeshes() const
189 return 0 != mMeshes.size();
192 void Entity::SetMeshCapacity(unsigned int capacity)
194 mMeshes.reserve(capacity);
197 int Entity::NumberOfMeshes() const
199 return mMeshes.size();
202 void Entity::AddMeshIndex(unsigned int meshIdx)
204 mMeshes.push_back(meshIdx);
207 unsigned int Entity::GetMeshByIndex(unsigned int meshIndex) const
209 DALI_ASSERT_DEBUG( meshIndex < mMeshes.size());
210 return mMeshes[meshIndex];
213 const EntityMeshIndices& Entity::GetMeshes() const
218 void Entity::AddToBounds(Entity& child)
220 mLowerBounds.x = std::min(mLowerBounds.x, child.GetLowerBounds().x);
221 mLowerBounds.y = std::min(mLowerBounds.y, child.GetLowerBounds().y);
222 mLowerBounds.z = std::min(mLowerBounds.z, child.GetLowerBounds().z);
223 mUpperBounds.x = std::max(mUpperBounds.x, child.GetUpperBounds().x);
224 mUpperBounds.y = std::max(mUpperBounds.y, child.GetUpperBounds().y);
225 mUpperBounds.z = std::max(mUpperBounds.z, child.GetUpperBounds().z);
228 void Entity::AddToBounds( const Vector3& lowerBounds, const Vector3& upperBounds )
230 mLowerBounds.x = std::min(mLowerBounds.x, lowerBounds.x);
231 mLowerBounds.y = std::min(mLowerBounds.y, lowerBounds.y);
232 mLowerBounds.z = std::min(mLowerBounds.z, lowerBounds.z);
233 mUpperBounds.x = std::max(mUpperBounds.x, upperBounds.x);
234 mUpperBounds.y = std::max(mUpperBounds.y, upperBounds.y);
235 mUpperBounds.z = std::max(mUpperBounds.z, upperBounds.z);
238 } // namespace Internal