48 lines
1 KiB
C#
48 lines
1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace org.niclasundharald.engine.graphics
|
|
{
|
|
public class ModelManager
|
|
{
|
|
public static readonly ModelManager instance = new ModelManager();
|
|
|
|
Dictionary<string, Model3D> knownModels;
|
|
List<string> searchPaths;
|
|
|
|
protected ModelManager()
|
|
{
|
|
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);
|
|
}
|
|
|
|
|
|
public Model3D loadModel(String mName,float scale){
|
|
string fullName = FileHelper.findFile(String.Format("{0}.obj",mName),searchPaths.ToArray());
|
|
if (fullName != null){
|
|
Console.WriteLine("Model found: {0}",fullName);
|
|
return Model3D.loadObjFile(fullName,scale);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Model3D findModel(String mName){
|
|
if (!knownModels.ContainsKey(mName)){
|
|
return loadModel(mName,1);
|
|
} else {
|
|
return knownModels[mName];
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|