Merge pull request #2154 from shadekiller666/OBJ_Loader

OBJLoader Update: Fix for normal generation, whitespace handling, and UVs outside 0-1 range
This commit is contained in:
Fry 2015-10-29 13:53:09 +03:00
commit 887f3bf31d
4 changed files with 464 additions and 423 deletions

View file

@ -28,11 +28,10 @@ public class OBJLoader implements ICustomModelLoader {
private final Set<String> enabledDomains = new HashSet<String>();
private final Map<ResourceLocation, OBJModel> cache = new HashMap<ResourceLocation, OBJModel>();
public OBJLoader() {}
public void addDomain(String domain)
{
enabledDomains.add(domain.toLowerCase());
FMLLog.log(Level.INFO, "OBJLoader: Domain %s has been added.", domain.toLowerCase());
}
public void onResourceManagerReload(IResourceManager resourceManager)
@ -46,8 +45,7 @@ public class OBJLoader implements ICustomModelLoader {
return enabledDomains.contains(modelLocation.getResourceDomain()) && modelLocation.getResourcePath().endsWith(".obj");
}
@SuppressWarnings("unchecked")
public IModel loadModel(ResourceLocation modelLocation)
public IModel loadModel(ResourceLocation modelLocation) throws IOException
{
ResourceLocation file = new ResourceLocation(modelLocation.getResourceDomain(), modelLocation.getResourcePath());
if (!cache.containsKey(file))
@ -68,13 +66,20 @@ public class OBJLoader implements ICustomModelLoader {
else throw e;
}
OBJModel.Parser parser = new OBJModel.Parser(resource, manager);
OBJModel model = parser.parse();
cache.put(modelLocation, model);
OBJModel model = null;
try
{
model = parser.parse();
}
finally
{
cache.put(modelLocation, model);
}
}
catch (IOException e)
{
FMLLog.log(Level.ERROR, e, "Exception loading model %s with OBJ loader, skipping", modelLocation);
cache.put(modelLocation, null);
// FMLLog.log(Level.ERROR, e, "Exception loading model '%s' with OBJ loader, skipping", modelLocation);
throw e;
}
}
OBJModel model = cache.get(file);

View file

@ -7,17 +7,23 @@ v 0 1 0
v 1 1 0
v 0 0 0
v 1 0 0
vt 1 0
vt 0 0
vt 1 1
vt 0 1
#vt 1 0
#vt 0 0
#vt 1 1
#vt 0 1
usemtl back
f 1/4 2/3 4/1 3/2
#f 1/4 2/3 4/1 3/2
f 1 2 4 3
usemtl front
f 5/1 6/2 8/4 7/3
#f 5/1 6/2 8/4 7/3
f 5 6 8 7
usemtl side
f 3/4 4/3 6/1 5/2
f 7/1 8/2 2/4 1/3
#f 3/4 4/3 6/1 5/2
f 3 4 6 5
#f 7/1 8/2 2/4 1/3
f 7 8 2 1
usemtl top
f 2/3 8/1 6/2 4/4
f 7/2 1/4 3/3 5/1
#f 2/3 8/1 6/2 4/4
f 2 8 6 4
#f 7/2 1/4 3/3 5/1
f 7 1 3 5

View file

@ -1,8 +1,2 @@
newmtl fancy_fence:Default
illum 4
Kd 1.00 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 1.00 1.00 1.00
Ns 0.00
Kd 1.00 1.00 1.00