2010-06-03 03:29:43 +02:00
|
|
|
/* Copyright (C) 2010 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2004-11-08 23:02:01 +01:00
|
|
|
#include "precompiled.h"
|
2006-12-20 04:22:24 +01:00
|
|
|
|
|
|
|
#include "MeshManager.h"
|
|
|
|
|
2007-03-01 19:52:53 +01:00
|
|
|
#include "graphics/ColladaManager.h"
|
2006-12-20 04:22:24 +01:00
|
|
|
#include "graphics/ModelDef.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/CLogger.h"
|
2008-02-04 12:40:42 +01:00
|
|
|
#include "ps/FileIo.h" // to get access to its CError
|
2007-03-01 19:52:53 +01:00
|
|
|
#include "ps/Profile.h"
|
2006-12-20 04:22:24 +01:00
|
|
|
|
2007-03-01 19:52:53 +01:00
|
|
|
// TODO: should this cache models while they're not actively in the game?
|
|
|
|
// (Currently they'll probably be deleted when the reference count drops to 0,
|
|
|
|
// even if it's quite possible that they'll get reloaded very soon.)
|
2006-12-20 04:22:24 +01:00
|
|
|
|
2007-03-01 19:52:53 +01:00
|
|
|
CMeshManager::CMeshManager(CColladaManager& colladaManager)
|
|
|
|
: m_ColladaManager(colladaManager)
|
2006-12-20 04:22:24 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CMeshManager::~CMeshManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
CModelDefPtr CMeshManager::GetMesh(const VfsPath& pathname)
|
2006-12-20 04:22:24 +01:00
|
|
|
{
|
2009-11-03 22:46:35 +01:00
|
|
|
const VfsPath name = fs::change_extension(pathname, L"");
|
2006-12-20 04:22:24 +01:00
|
|
|
|
|
|
|
// Find the mesh if it's already been loaded and cached
|
2009-11-03 22:46:35 +01:00
|
|
|
mesh_map::iterator iter = m_MeshMap.find(name.string());
|
2007-03-01 19:52:53 +01:00
|
|
|
if (iter != m_MeshMap.end() && !iter->second.expired())
|
2006-12-20 04:22:24 +01:00
|
|
|
return CModelDefPtr(iter->second);
|
|
|
|
|
2010-06-03 03:29:43 +02:00
|
|
|
PROFILE("load mesh");
|
2006-12-20 04:22:24 +01:00
|
|
|
|
2008-01-07 21:03:19 +01:00
|
|
|
VfsPath pmdFilename = m_ColladaManager.GetLoadableFilename(name, CColladaManager::PMD);
|
2006-12-20 04:22:24 +01:00
|
|
|
|
2007-03-01 19:52:53 +01:00
|
|
|
if (pmdFilename.empty())
|
|
|
|
{
|
2010-06-03 03:29:43 +02:00
|
|
|
LOGERROR(L"Could not load mesh '%ls'", pathname.string().c_str());
|
2007-03-01 19:52:53 +01:00
|
|
|
return CModelDefPtr();
|
|
|
|
}
|
2004-11-11 08:09:32 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2007-03-01 19:52:53 +01:00
|
|
|
CModelDefPtr model (CModelDef::Load(pmdFilename, name));
|
2009-11-03 22:46:35 +01:00
|
|
|
m_MeshMap[name.string()] = model;
|
2007-03-01 19:52:53 +01:00
|
|
|
return model;
|
2004-11-11 08:09:32 +01:00
|
|
|
}
|
2006-04-04 06:14:10 +02:00
|
|
|
catch (PSERROR_File&)
|
2004-11-11 08:09:32 +01:00
|
|
|
{
|
2010-06-03 03:29:43 +02:00
|
|
|
LOGERROR(L"Could not load mesh '%ls'", pathname.string().c_str());
|
2004-12-12 19:40:00 +01:00
|
|
|
return CModelDefPtr();
|
2004-11-11 08:09:32 +01:00
|
|
|
}
|
2004-11-08 23:02:01 +01:00
|
|
|
}
|