DAVA::Entity* SceneSelectionSystem::GetSelectableEntity(DAVA::Entity* entity)
{
	DAVA::Entity *selectableEntity = NULL;
	
	if(NULL != entity)
	{
		// find most top solid entity
		DAVA::Entity *parent = entity;
		while(NULL != parent)
		{
			if(parent->GetSolid())
			{
				selectableEntity = parent;
			}

			parent = parent->GetParent();
		}

		// still not found?
		if(NULL == selectableEntity)
		{
			// let it current entity to be tread as solid
			selectableEntity = entity;
		}
	}

	return selectableEntity;
}
EntityGroupItem SceneSelectionSystem::GetSelectableEntity(DAVA::Entity* entity)
{
	EntityGroupItem ret;
	DAVA::Entity *solidEntity = entity;
	
	if(NULL != entity)
	{
		// find real solid entity
		solidEntity = entity;
		while(NULL != solidEntity && !solidEntity->GetSolid())
		{
			solidEntity = solidEntity->GetParent();
		}

		// if there is no solid entity, try to find lod parent entity
		if(NULL == solidEntity)
		{
			// find entity that has lod component
			solidEntity = entity;
			while(NULL != solidEntity && NULL == solidEntity->GetComponent(DAVA::Component::LOD_COMPONENT))
			{
				solidEntity = solidEntity->GetParent();
			}
		}

		// still not found?
		if(NULL == solidEntity)
		{
			// let it current entity to be tread as solid
			solidEntity = entity;
		}

		ret.entity = entity;
		ret.solidEntity = solidEntity;
		ret.bbox = CalcAABox(solidEntity);
	}

	return ret;
}