//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * 変換メッシュマネージャ実装
 * @author Junpee
 */

#include "System/stdafx.h"
#include "Translator/Mesh/TranslationMeshManager.h"

namespace LampForMaya{

//------------------------------------------------------------------------------
// コンストラクタ
TranslationMeshManager::TranslationMeshManager() :
	database_(256, 0.75f), array_(256){
}
//------------------------------------------------------------------------------
// デストラクタ
TranslationMeshManager::~TranslationMeshManager(){
	Assert(database_.getCount() == 0);
	Assert(array_.getCount() == 0);
	if(getCount() != 0){ clear(); }
}
//------------------------------------------------------------------------------
// Lampへの変換
bool TranslationMeshManager::convertToLamp(Scene* scene) const{
	for(int i = 0; i < getCount(); i++){
		if(!get(i)->convertToLamp(scene)){ return false; }
	}
	return true;
}
//------------------------------------------------------------------------------
// クリア
int TranslationMeshManager::clear(){
	int result = getCount();
	// 要素の削除
	for(int i = 0; i < result; i++){ delete array_.get(i); }
	array_.clear();
	database_.clear();
	return result;
}
//------------------------------------------------------------------------------
// 剛体メッシュの作成
TranslationRigidMesh* TranslationMeshManager::createRigidMesh(
	const String& meshName){
	// 名前の重複チェック
	TranslationMesh* exist = search(meshName);
	if(exist != NULL){
		MayaErrorOut(String("TranslationMeshManager::createRigidMesh() "
			"名前が重複しています ") + meshName);
		return NULL;
	}
	// メッシュ生成
	TranslationRigidMesh* mesh = new TranslationRigidMesh(meshName);
	database_.put(meshName, mesh);
	array_.add(mesh);
	return mesh;
}
//------------------------------------------------------------------------------
// キャラクタメッシュの作成
TranslationCharacterMesh* TranslationMeshManager::createCharacterMesh(
	const String& meshName){
	// 名前の重複チェック
	TranslationMesh* exist = search(meshName);
	if(exist != NULL){
		MayaErrorOut(String("TranslationMeshManager::createCharacterMesh() "
			"名前が重複しています ") + meshName);
		return NULL;
	}
	// メッシュ生成
	TranslationCharacterMesh* mesh = new TranslationCharacterMesh(meshName);
	database_.put(meshName, mesh);
	array_.add(mesh);
	return mesh;
}
//------------------------------------------------------------------------------
} // End of namespace LampForMaya
//------------------------------------------------------------------------------
