Simplify some stuff related to the new OBJ loading
This commit is contained in:
parent
3a3afc4651
commit
bf864e3f88
5 changed files with 79 additions and 128 deletions
|
@ -2,7 +2,6 @@ package com.pahimar.ee3.client.model;
|
||||||
|
|
||||||
import net.minecraft.client.model.ModelBase;
|
import net.minecraft.client.model.ModelBase;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import net.minecraftforge.client.model.obj.Face;
|
|
||||||
import net.minecraftforge.client.model.obj.Group;
|
import net.minecraftforge.client.model.obj.Group;
|
||||||
import net.minecraftforge.client.model.obj.WavefrontObject;
|
import net.minecraftforge.client.model.obj.WavefrontObject;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
@ -50,33 +49,7 @@ public class ModelAludel extends ModelBase {
|
||||||
|
|
||||||
if (modelAludelOBJ.getGroups().size() != 0) {
|
if (modelAludelOBJ.getGroups().size() != 0) {
|
||||||
for (Group group : modelAludelOBJ.getGroups()) {
|
for (Group group : modelAludelOBJ.getGroups()) {
|
||||||
if (group.getFaces().size() != 0) {
|
group.render(tessellator, Reference.MODEL_TEXTURE_OFFSET, scale);
|
||||||
for (Face face : group.getFaces()) {
|
|
||||||
tessellator.startDrawing(face.getDrawingMode());
|
|
||||||
|
|
||||||
float sumU = 0F;
|
|
||||||
float sumV = 0F;
|
|
||||||
|
|
||||||
for (int i = 0; i < face.getTextureCoordinates().length; ++i) {
|
|
||||||
sumU += face.getTextureCoordinates()[i].u;
|
|
||||||
sumV += face.getTextureCoordinates()[i].v;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < face.getVertices().length; ++i) {
|
|
||||||
float offsetU = Reference.MODEL_TEXTURE_OFFSET;
|
|
||||||
float offsetV = Reference.MODEL_TEXTURE_OFFSET;
|
|
||||||
if (face.getTextureCoordinates()[i].u > sumU / face.getTextureCoordinates().length) {
|
|
||||||
offsetU = -offsetU;
|
|
||||||
}
|
|
||||||
if (face.getTextureCoordinates()[i].v > sumV / face.getTextureCoordinates().length) {
|
|
||||||
offsetV = -offsetV;
|
|
||||||
}
|
|
||||||
tessellator.addVertexWithUV(face.getVertices()[i].x * scale, face.getVertices()[i].y * scale, face.getVertices()[i].z * scale, face.getTextureCoordinates()[i].u + offsetU, face.getTextureCoordinates()[i].v + offsetV);
|
|
||||||
}
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.pahimar.ee3.client.model;
|
||||||
|
|
||||||
import net.minecraft.client.model.ModelBase;
|
import net.minecraft.client.model.ModelBase;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import net.minecraftforge.client.model.obj.Face;
|
|
||||||
import net.minecraftforge.client.model.obj.Group;
|
import net.minecraftforge.client.model.obj.Group;
|
||||||
import net.minecraftforge.client.model.obj.WavefrontObject;
|
import net.minecraftforge.client.model.obj.WavefrontObject;
|
||||||
|
|
||||||
|
@ -50,33 +49,7 @@ public class ModelCalcinator extends ModelBase {
|
||||||
if (modelCalcinatorOBJ.getGroups().size() != 0) {
|
if (modelCalcinatorOBJ.getGroups().size() != 0) {
|
||||||
for (Group group : modelCalcinatorOBJ.getGroups()) {
|
for (Group group : modelCalcinatorOBJ.getGroups()) {
|
||||||
if (group.getName().equalsIgnoreCase("calcinator")) {
|
if (group.getName().equalsIgnoreCase("calcinator")) {
|
||||||
if (group.getFaces().size() != 0) {
|
group.render(tessellator, Reference.MODEL_TEXTURE_OFFSET, scale);
|
||||||
for (Face face : group.getFaces()) {
|
|
||||||
tessellator.startDrawing(face.getDrawingMode());
|
|
||||||
|
|
||||||
float sumU = 0F;
|
|
||||||
float sumV = 0F;
|
|
||||||
|
|
||||||
for (int i = 0; i < face.getTextureCoordinates().length; ++i) {
|
|
||||||
sumU += face.getTextureCoordinates()[i].u;
|
|
||||||
sumV += face.getTextureCoordinates()[i].v;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < face.getVertices().length; ++i) {
|
|
||||||
float offsetU = Reference.MODEL_TEXTURE_OFFSET;
|
|
||||||
float offsetV = Reference.MODEL_TEXTURE_OFFSET;
|
|
||||||
if (face.getTextureCoordinates()[i].u > sumU / face.getTextureCoordinates().length) {
|
|
||||||
offsetU = -offsetU;
|
|
||||||
}
|
|
||||||
if (face.getTextureCoordinates()[i].v > sumV / face.getTextureCoordinates().length) {
|
|
||||||
offsetV = -offsetV;
|
|
||||||
}
|
|
||||||
tessellator.addVertexWithUV(face.getVertices()[i].x * scale, face.getVertices()[i].y * scale, face.getVertices()[i].z * scale, face.getTextureCoordinates()[i].u + offsetU, face.getTextureCoordinates()[i].v + offsetV);
|
|
||||||
}
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,68 +1,66 @@
|
||||||
package net.minecraftforge.client.model.obj;
|
package net.minecraftforge.client.model.obj;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraft.util.Vec3;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class Face {
|
public class Face {
|
||||||
|
|
||||||
public int[] vertexIndices;
|
public Vertex[] vertices;
|
||||||
public int[] vertexNormalIndices;
|
public Vertex[] vertexNormals;
|
||||||
public int[] textureCoordinateIndices;
|
public TextureCoordinate[] textureCoordinates;
|
||||||
|
|
||||||
private Vertex[] vertices;
|
public boolean invertNormal = false;
|
||||||
private Vertex[] vertexNormals;
|
public int glDrawingMode;
|
||||||
private TextureCoordinate[] textureCoordinates;
|
|
||||||
|
public Vec3 getFaceNormal() {
|
||||||
private int glDrawingMode;
|
Vec3 v1 = Vec3.createVectorHelper(vertices[1].x - vertices[0].x, vertices[1].y - vertices[0].y, vertices[1].z - vertices[0].z);
|
||||||
|
Vec3 v2 = Vec3.createVectorHelper(vertices[2].x - vertices[0].x, vertices[2].y - vertices[0].y, vertices[2].z - vertices[0].z);
|
||||||
public int[] getVertexIndices() {
|
|
||||||
|
return v1.crossProduct(v2).normalize();
|
||||||
return vertexIndices;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void render(Tessellator tessellator, float scale) {
|
||||||
|
|
||||||
public Vertex[] getVertices() {
|
this.render(tessellator, 0F, scale);
|
||||||
|
|
||||||
return vertices;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void render(Tessellator tessellator, float textureOffset, float scale) {
|
||||||
|
|
||||||
public void setVertexIndices(int[] vertexIndices) {
|
tessellator.startDrawing(glDrawingMode);
|
||||||
|
|
||||||
this.vertexIndices = vertexIndices;
|
tessellator.setNormal((float) getFaceNormal().xCoord, (float) getFaceNormal().yCoord, (float) getFaceNormal().zCoord);
|
||||||
}
|
|
||||||
|
float averageU = 0F;
|
||||||
public void setVertices(Vertex[] vertices) {
|
float averageV = 0F;
|
||||||
|
|
||||||
this.vertices = vertices;
|
for (int i = 0; i < textureCoordinates.length; ++i) {
|
||||||
}
|
averageU += textureCoordinates[i].u;
|
||||||
|
averageV += textureCoordinates[i].v;
|
||||||
public int getDrawingMode() {
|
}
|
||||||
|
|
||||||
return glDrawingMode;
|
averageU = averageU / textureCoordinates.length;
|
||||||
}
|
averageV = averageV / textureCoordinates.length;
|
||||||
|
|
||||||
public void setDrawingMode(int glDrawingMode) {
|
float offsetU, offsetV;
|
||||||
|
|
||||||
this.glDrawingMode = glDrawingMode;
|
for (int i = 0; i < vertices.length; ++i) {
|
||||||
}
|
|
||||||
|
offsetU = textureOffset;
|
||||||
public Vertex[] getVertexNormals() {
|
offsetV = textureOffset;
|
||||||
|
|
||||||
return vertexNormals;
|
if (textureCoordinates[i].u > averageU) {
|
||||||
}
|
offsetU = -offsetU;
|
||||||
|
}
|
||||||
public void setVertexNormals(Vertex[] vertexNormals) {
|
if (textureCoordinates[i].v > averageV) {
|
||||||
|
offsetV = -offsetV;
|
||||||
this.vertexNormals = vertexNormals;
|
}
|
||||||
}
|
|
||||||
|
tessellator.addVertexWithUV(vertices[i].x * scale, vertices[i].y * scale, vertices[i].z * scale, textureCoordinates[i].u + offsetU, textureCoordinates[i].v + offsetV);
|
||||||
public TextureCoordinate[] getTextureCoordinates() {
|
}
|
||||||
|
|
||||||
return textureCoordinates;
|
tessellator.draw();
|
||||||
}
|
|
||||||
|
|
||||||
public void setTextureCoordinates(TextureCoordinate[] textureCoordinates) {
|
|
||||||
|
|
||||||
this.textureCoordinates = textureCoordinates;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.minecraftforge.client.model.obj;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
@ -38,8 +39,8 @@ public class Group {
|
||||||
Vertex currentVertex = null;
|
Vertex currentVertex = null;
|
||||||
for (int i = 0; i < faces.size(); i++) {
|
for (int i = 0; i < faces.size(); i++) {
|
||||||
currentFace = faces.get(i);
|
currentFace = faces.get(i);
|
||||||
for (int j = 0; j < currentFace.getVertices().length; j++) {
|
for (int j = 0; j < currentFace.vertices.length; j++) {
|
||||||
currentVertex = currentFace.getVertices()[j];
|
currentVertex = currentFace.vertices[j];
|
||||||
if (Math.abs(currentVertex.x) > minX) {
|
if (Math.abs(currentVertex.x) > minX) {
|
||||||
minX = Math.abs(currentVertex.x);
|
minX = Math.abs(currentVertex.x);
|
||||||
}
|
}
|
||||||
|
@ -69,4 +70,18 @@ public class Group {
|
||||||
|
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void render(Tessellator tessellator, float scale) {
|
||||||
|
|
||||||
|
for (Face face : faces) {
|
||||||
|
face.render(tessellator, 0F, scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(Tessellator tessellator, float textureOffset, float scale) {
|
||||||
|
|
||||||
|
for (Face face : faces) {
|
||||||
|
face.render(tessellator, textureOffset, scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class FaceParser extends LineParser {
|
||||||
|
|
||||||
private void parseTriangles() {
|
private void parseTriangles() {
|
||||||
|
|
||||||
face.setDrawingMode(GL11.GL_TRIANGLES);
|
face.glDrawingMode = GL11.GL_TRIANGLES;
|
||||||
parseLine(3);
|
parseLine(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ public class FaceParser extends LineParser {
|
||||||
|
|
||||||
private void parseQuad() {
|
private void parseQuad() {
|
||||||
|
|
||||||
face.setDrawingMode(GL11.GL_QUADS);
|
face.glDrawingMode = GL11.GL_QUADS;
|
||||||
parseLine(4);
|
parseLine(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,13 +134,9 @@ public class FaceParser extends LineParser {
|
||||||
group.indices.add(group.indexCount++);
|
group.indices.add(group.indexCount++);
|
||||||
group.indices.add(group.indexCount++); // create index list for current object
|
group.indices.add(group.indexCount++); // create index list for current object
|
||||||
|
|
||||||
face.vertexIndices = vindices;
|
face.vertexNormals = normals;
|
||||||
face.vertexNormalIndices = nindices;
|
face.vertices = vertices;
|
||||||
face.textureCoordinateIndices = tindices;
|
face.textureCoordinates = textures;
|
||||||
face.setVertexNormals(normals);
|
|
||||||
face.setVertexNormals(normals);
|
|
||||||
face.setVertices(vertices);
|
|
||||||
face.setTextureCoordinates(textures);
|
|
||||||
|
|
||||||
wavefrontObject.getCurrentGroup().addFace(face);
|
wavefrontObject.getCurrentGroup().addFace(face);
|
||||||
}
|
}
|
||||||
|
@ -164,13 +160,9 @@ public class FaceParser extends LineParser {
|
||||||
group.indices.add(group.indexCount++);
|
group.indices.add(group.indexCount++);
|
||||||
group.indices.add(group.indexCount++); // create index list for current object
|
group.indices.add(group.indexCount++); // create index list for current object
|
||||||
|
|
||||||
face.vertexIndices = vindices;
|
face.vertexNormals = normals;
|
||||||
face.vertexNormalIndices = nindices;
|
face.vertices = vertices;
|
||||||
face.textureCoordinateIndices = tindices;
|
face.textureCoordinates = textures;
|
||||||
face.setVertexNormals(normals);
|
|
||||||
face.setVertexNormals(normals);
|
|
||||||
face.setVertices(vertices);
|
|
||||||
face.setTextureCoordinates(textures);
|
|
||||||
|
|
||||||
wavefrontObject.getCurrentGroup().addFace(face);
|
wavefrontObject.getCurrentGroup().addFace(face);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue