budnhead/org.niclasundharald.engine/graphics/ModelManager.cs

48 lines
1.0 KiB
C#
Raw Normal View History

2017-05-01 01:33:33 +02:00
using System;
using System.Collections.Generic;
namespace org.niclasundharald.engine.graphics
{
public class ModelManager
{
2017-05-04 23:57:00 +02:00
public static readonly ModelManager instance = new ModelManager();
2017-05-01 01:33:33 +02:00
Dictionary<string, Model3D> knownModels;
List<string> searchPaths;
2017-05-04 23:57:00 +02:00
protected ModelManager()
2017-05-01 01:33:33 +02:00
{
knownModels = new Dictionary<string, Model3D>();
searchPaths = new List<string>();
searchPaths.Add(".");
}
public void addSearchPath(string sPath){
searchPaths.Add(sPath);
}
public void removeSearchPath(string sPath){
searchPaths.Remove(sPath);
}
2017-05-04 23:57:00 +02:00
public Model3D loadModel(String mName,float scale){
2017-05-01 01:33:33 +02:00
string fullName = FileHelper.findFile(String.Format("{0}.obj",mName),searchPaths.ToArray());
if (fullName != null){
2017-05-04 23:57:00 +02:00
Console.WriteLine("Model found: {0}",fullName);
return Model3D.loadObjFile(fullName,scale);
2017-05-01 01:33:33 +02:00
}
return null;
}
public Model3D findModel(String mName){
if (!knownModels.ContainsKey(mName)){
2017-05-04 23:57:00 +02:00
return loadModel(mName,1);
2017-05-01 01:33:33 +02:00
} else {
return knownModels[mName];
}
}
}
}