Adding interface for other custom model format importers to implement
This commit is contained in:
parent
09fee09a01
commit
091c4ab6ac
2 changed files with 43 additions and 8 deletions
13
client/net/minecraftforge/client/model/IModelCustom.java
Normal file
13
client/net/minecraftforge/client/model/IModelCustom.java
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package net.minecraftforge.client.model;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public interface IModelCustom {
|
||||||
|
|
||||||
|
public abstract void load(String fileName);
|
||||||
|
|
||||||
|
public abstract void renderAll();
|
||||||
|
|
||||||
|
public abstract void renderPart(String partName);
|
||||||
|
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import java.util.regex.Pattern;
|
||||||
import java.util.zip.DataFormatException;
|
import java.util.zip.DataFormatException;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraftforge.client.model.IModelCustom;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||||
* Based heavily off of the specifications found at http://en.wikipedia.org/wiki/Wavefront_.obj_file
|
* Based heavily off of the specifications found at http://en.wikipedia.org/wiki/Wavefront_.obj_file
|
||||||
*/
|
*/
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class WavefrontObject
|
public class WavefrontObject implements IModelCustom
|
||||||
{
|
{
|
||||||
|
|
||||||
private static Pattern vertexPattern = Pattern.compile("(v( (\\-){0,1}\\d+\\.\\d+){3,4} *\\n)|(v( (\\-){0,1}\\d+\\.\\d+){3,4} *$)");
|
private static Pattern vertexPattern = Pattern.compile("(v( (\\-){0,1}\\d+\\.\\d+){3,4} *\\n)|(v( (\\-){0,1}\\d+\\.\\d+){3,4} *$)");
|
||||||
|
@ -51,7 +52,7 @@ public class WavefrontObject
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
parseObjModel(this.getClass().getResource(fileName));
|
loadObjModel(this.getClass().getResource(fileName));
|
||||||
}
|
}
|
||||||
catch (DataFormatException e)
|
catch (DataFormatException e)
|
||||||
{
|
{
|
||||||
|
@ -59,13 +60,11 @@ public class WavefrontObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WavefrontObject(URL fileURL)
|
public void load(String fileName)
|
||||||
{
|
{
|
||||||
this.fileName = fileURL.getFile();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
parseObjModel(fileURL);
|
loadObjModel(this.getClass().getResource(fileName));
|
||||||
}
|
}
|
||||||
catch (DataFormatException e)
|
catch (DataFormatException e)
|
||||||
{
|
{
|
||||||
|
@ -73,7 +72,19 @@ public class WavefrontObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseObjModel(URL fileURL) throws DataFormatException
|
public void load()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
loadObjModel(this.getClass().getResource(fileName));
|
||||||
|
}
|
||||||
|
catch (DataFormatException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadObjModel(URL fileURL) throws DataFormatException
|
||||||
{
|
{
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
|
@ -213,6 +224,17 @@ public class WavefrontObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void renderPart(String partName)
|
||||||
|
{
|
||||||
|
for (GroupObject groupObject : groupObjects)
|
||||||
|
{
|
||||||
|
if (partName.equalsIgnoreCase(groupObject.name))
|
||||||
|
{
|
||||||
|
groupObject.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void renderAllExcept(String... excludedGroupNames)
|
public void renderAllExcept(String... excludedGroupNames)
|
||||||
{
|
{
|
||||||
for (GroupObject groupObject : groupObjects)
|
for (GroupObject groupObject : groupObjects)
|
||||||
|
|
Loading…
Reference in a new issue