2 * Copyright (c) 2014 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/internal/event/modeling/entity-impl.h>
22 #include <dali/public-api/geometry/mesh.h>
23 #include <dali/internal/event/modeling/model-data-impl.h>
24 #include <dali/internal/event/modeling/mesh-impl.h>
32 namespace // unnamed namespace
34 static const float kBoundsDefault = 1e10f;
35 } // unnamed namespace
43 mLowerBounds( kBoundsDefault, kBoundsDefault, kBoundsDefault),
44 mUpperBounds(-kBoundsDefault, -kBoundsDefault, -kBoundsDefault),
45 mType(Dali::Entity::OBJECT)
49 EntityPtr Entity::New(const std::string name)
51 EntityPtr entity(new Entity());
52 entity->SetName(name);
63 Entity* Entity::Find(const std::string& name) const
65 Entity* entity = NULL;
69 entity = const_cast<Entity*>(this);
71 else if (mChildren.size() != 0)
73 for (EntityConstIter it = mChildren.begin(); it != mChildren.end() && !entity; ++it)
75 const Entity& child = GetImplementation(*it);
76 entity = child.Find(name);
88 void Entity::SetName(const char* name)
93 void Entity::SetName(const std::string& name)
98 const std::string& Entity::GetName() const
103 const Vector3& Entity::GetLowerBounds() const
108 void Entity::SetLowerBounds(const Vector3& bounds)
110 mLowerBounds = bounds;
113 const Vector3& Entity::GetUpperBounds() const
118 void Entity::SetUpperBounds(const Vector3& bounds)
120 mUpperBounds = bounds;
124 void Entity::SetType(const Dali::Entity::EntityType type)
129 Dali::Entity::EntityType Entity::GetType() const
134 void Entity::SetTransformMatrix(Matrix& matrix)
136 mTransformMatrix = matrix;
139 const Matrix& Entity::GetTransformMatrix() const
141 return mTransformMatrix;
144 bool Entity::HasChildren() const
146 return 0 != mChildren.size();
149 int Entity::NumberOfChildren() const
151 return mChildren.size();
154 const EntityContainer& Entity::GetChildren() const
159 void Entity::Add(Entity& child)
161 if(this != child.mParent)
163 child.SetParent(this);
164 mChildren.push_back(Dali::Entity(&child));
168 void Entity::SetChildCapacity(unsigned int capacity)
170 mChildren.reserve(capacity);
173 void Entity::SetParent(Entity* parent)
177 DALI_ASSERT_ALWAYS( this != parent && "Cannot parent an entity to itself" );
178 DALI_ASSERT_ALWAYS(mParent == NULL && "Entity already has a parent" );
183 Entity* Entity::GetParent() const
188 bool Entity::HasMeshes() const
190 return 0 != mMeshes.size();
193 void Entity::SetMeshCapacity(unsigned int capacity)
195 mMeshes.reserve(capacity);
198 int Entity::NumberOfMeshes() const
200 return mMeshes.size();
203 void Entity::AddMeshIndex(unsigned int meshIdx)
205 mMeshes.push_back(meshIdx);
208 unsigned int Entity::GetMeshByIndex(unsigned int meshIndex) const
210 DALI_ASSERT_DEBUG( meshIndex < mMeshes.size());
211 return mMeshes[meshIndex];
214 const EntityMeshIndices& Entity::GetMeshes() const
219 void Entity::AddToBounds(Entity& child)
221 mLowerBounds.x = std::min(mLowerBounds.x, child.GetLowerBounds().x);
222 mLowerBounds.y = std::min(mLowerBounds.y, child.GetLowerBounds().y);
223 mLowerBounds.z = std::min(mLowerBounds.z, child.GetLowerBounds().z);
224 mUpperBounds.x = std::max(mUpperBounds.x, child.GetUpperBounds().x);
225 mUpperBounds.y = std::max(mUpperBounds.y, child.GetUpperBounds().y);
226 mUpperBounds.z = std::max(mUpperBounds.z, child.GetUpperBounds().z);
229 void Entity::AddToBounds( const Vector3& lowerBounds, const Vector3& upperBounds )
231 mLowerBounds.x = std::min(mLowerBounds.x, lowerBounds.x);
232 mLowerBounds.y = std::min(mLowerBounds.y, lowerBounds.y);
233 mLowerBounds.z = std::min(mLowerBounds.z, lowerBounds.z);
234 mUpperBounds.x = std::max(mUpperBounds.x, upperBounds.x);
235 mUpperBounds.y = std::max(mUpperBounds.y, upperBounds.y);
236 mUpperBounds.z = std::max(mUpperBounds.z, upperBounds.z);
239 } // namespace Internal