mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-28 07:55:53 +00:00
Added OBJ loader for the ModelLoaderRegistry system.
This commit is contained in:
1 parent
d5a658b5ea
commit
d1b220f6a3
33 files changed
+6023
-9
No files matched your search
@@ -27,7 +27,7 @@ public class MapModelState implements IModelState
|
||||
this.map = ImmutableMap.<IModelPart, IModelState>copyOf(map);
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
|
||||
public TRSRTransformation apply(IModelPart part)
|
||||
{
|
||||
if(!map.containsKey(part)) return def.apply(part);
|
||||
|
||||
@@ -209,7 +209,7 @@ public class ModelLoader extends ModelBakery
|
||||
{
|
||||
return new ResourceLocation(model.getResourceDomain(), model.getResourcePath() + ".json");
|
||||
}
|
||||
|
||||
|
||||
private void loadAnyModel(ResourceLocation location) throws IOException
|
||||
{
|
||||
if(loadingModels.contains(location))
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.ModelLoader.VanillaLoader;
|
||||
import net.minecraftforge.client.model.b3d.B3DLoader;
|
||||
import net.minecraftforge.client.model.obj.OBJLoader;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
@@ -29,6 +30,7 @@ public class ModelLoaderRegistry
|
||||
static
|
||||
{
|
||||
registerLoader(B3DLoader.instance);
|
||||
registerLoader(OBJLoader.instance);
|
||||
registerLoader(ModelFluid.FluidLoader.instance);
|
||||
registerLoader(ItemLayerModel.Loader.instance);
|
||||
}
|
||||
|
||||
@@ -68,6 +68,25 @@ public class TRSRTransformation implements IModelState, ITransformation
|
||||
{
|
||||
this(rotation.getMatrix());
|
||||
}
|
||||
|
||||
public TRSRTransformation(EnumFacing facing)
|
||||
{
|
||||
this(getMatrix(facing));
|
||||
}
|
||||
|
||||
public static Matrix4f getMatrix(EnumFacing facing)
|
||||
{
|
||||
switch(facing)
|
||||
{
|
||||
case DOWN: return ModelRotation.X90_Y0.getMatrix();
|
||||
case UP: return ModelRotation.X270_Y0.getMatrix();
|
||||
case NORTH: return TRSRTransformation.identity.matrix;
|
||||
case SOUTH: return ModelRotation.X0_Y180.getMatrix();
|
||||
case WEST: return ModelRotation.X0_Y270.getMatrix();
|
||||
case EAST: return ModelRotation.X0_Y90.getMatrix();
|
||||
default: return new Matrix4f();
|
||||
}
|
||||
}
|
||||
|
||||
private static final TRSRTransformation identity;
|
||||
|
||||
@@ -516,4 +535,28 @@ public class TRSRTransformation implements IModelState, ITransformation
|
||||
ret.mul(tmp);
|
||||
return new TRSRTransformation(ret);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((matrix == null) ? 0 : matrix.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
TRSRTransformation other = (TRSRTransformation) obj;
|
||||
if (matrix == null)
|
||||
{
|
||||
if (other.matrix != null) return false;
|
||||
}
|
||||
else if (!matrix.equals(other.matrix)) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -629,7 +629,7 @@ public class B3DLoader implements ICustomModelLoader
|
||||
IExtendedBlockState exState = (IExtendedBlockState)state;
|
||||
if(exState.getUnlistedNames().contains(B3DFrameProperty.instance))
|
||||
{
|
||||
B3DState s = (B3DState)exState.getValue(B3DFrameProperty.instance);
|
||||
B3DState s = exState.getValue(B3DFrameProperty.instance);
|
||||
if(s != null)
|
||||
{
|
||||
return getCachedModel(s.getFrame());
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package net.minecraftforge.client.model.obj;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.ICustomModelLoader;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
/*
|
||||
* Loader for OBJ models.
|
||||
* To enable your mod call instance.addDomain(modid).
|
||||
* If you need more control over accepted resources - extend the class, and register a new instance with ModelLoaderRegistry.
|
||||
*/
|
||||
public class OBJLoader implements ICustomModelLoader {
|
||||
public static final OBJLoader instance = new OBJLoader();
|
||||
private IResourceManager manager;
|
||||
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());
|
||||
}
|
||||
|
||||
public void onResourceManagerReload(IResourceManager resourceManager)
|
||||
{
|
||||
this.manager = resourceManager;
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
public boolean accepts(ResourceLocation modelLocation)
|
||||
{
|
||||
return enabledDomains.contains(modelLocation.getResourceDomain()) && modelLocation.getResourcePath().endsWith(".obj");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public IModel loadModel(ResourceLocation modelLocation)
|
||||
{
|
||||
ResourceLocation file = new ResourceLocation(modelLocation.getResourceDomain(), modelLocation.getResourcePath());
|
||||
if (!cache.containsKey(file))
|
||||
{
|
||||
try
|
||||
{
|
||||
IResource resource = null;
|
||||
try
|
||||
{
|
||||
resource = manager.getResource(file);
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
if (modelLocation.getResourcePath().startsWith("models/block/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/item/" + file.getResourcePath().substring("models/block/".length())));
|
||||
else if (modelLocation.getResourcePath().startsWith("models/item/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/block/" + file.getResourcePath().substring("models/item/".length())));
|
||||
else throw e;
|
||||
}
|
||||
OBJModel.Parser parser = new OBJModel.Parser(resource, manager);
|
||||
OBJModel model = parser.parse();
|
||||
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);
|
||||
}
|
||||
}
|
||||
OBJModel model = cache.get(file);
|
||||
if (model == null) return ModelLoaderRegistry.getMissingModel();
|
||||
return model;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -148,4 +148,4 @@ public class ExtendedBlockState extends BlockState
|
||||
return this.normalMap.get(getProperties());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user