Skip to content

Commit

Permalink
TMT Update 2
Browse files Browse the repository at this point in the history
Updated the README.md to reflect the TMT changes.
TMT CHANGES:
- Removed TransformGroup, it's only ever used for TransformGroupBone, so
we might as well just use that.
- Added some missing documentation.
- Removed some unnecessary type casting.
- Removed some more unnecessary variable instancing.
  • Loading branch information
EternalBlueFlame committed Jun 10, 2017
1 parent d871ae9 commit 688d996
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 60 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -37,8 +37,9 @@ Date: December, 2016
<ul>
<li> Models must match the Mod's Art-style.</li>
<li> Format is limited to <b>.java</b> models only; you can use tools such as BDCraft Cubik, SMP Toolbox, Technie or even writing it manually.</li>
<li> Model scale is <b>0.75 meters, or, 12 microblocks, wide for the wheel base</b>, In other words they must fit on minecart rails. It is reccomended the body should be 1.25+ meters, or, 20 microblocks, wide.</li>
<li> Technie models are limited to 512x512 base resolution for textures, reguardless of if you actually need that much space.</li>
<li> SMP Toolbox models must not use Shape, we have dropped support of the function for various reasons, instead use ShapeBoxes.</li>
<li> Model scale is <b>0.75 meters, or, 12 microblocks, wide for the wheel base</b>, In other words they must fit on minecart rails. It is reccomended the body should be 1.25+ meters, or, 20+ microblocks, wide.</li>
<li> Technie models are limited to 512x512 base resolution for textures, regardless of if you actually need that much space.</li>
<li> Textures must be in <b>.png</b> format. And are preferred to be at 4 times the resolution of the texture base size defined in the model (this is 4096x4096 in most cases).</li>
<li> Audio must be in <b>.ogg</b> format and no more than 192kb/s.</li>
</ul>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ebf/tim/models/tmt/ModelBase.java
@@ -1,6 +1,8 @@
package ebf.tim.models.tmt;


/**
* Converts ModelBase use to ModelRendererTurbo.
*/
public class ModelBase extends net.minecraft.client.model.ModelBase {

public ModelRendererTurbo base[] = new ModelRendererTurbo[0];
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/ebf/tim/models/tmt/ModelConverter.java
@@ -1,5 +1,8 @@
package ebf.tim.models.tmt;

/**
* Converts flans models to our version of ModelRendererTurbo, which doesn't use the sme animation methods.
*/
public class ModelConverter extends ModelBase {

public ModelRendererTurbo bodyModel[] = new ModelRendererTurbo[0];
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/ebf/tim/models/tmt/ModelPool.java
Expand Up @@ -4,9 +4,12 @@
import java.util.HashMap;
import java.util.Map;

/**
* Stores the list of models loaded from config files such as OBJ.
*/
public class ModelPool {

public static ModelPoolEntry addFile(String file, Map<String, TransformGroup> group, Map<String, TextureGroup> textureGroup){
public static ModelPoolEntry addFile(String file, Map<String, TransformGroupBone> group, Map<String, TextureGroup> textureGroup){
if(modelMap.containsKey(file)){
ModelPoolEntry entry = modelMap.get(file);
entry.applyGroups(group, textureGroup);
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/ebf/tim/models/tmt/ModelPoolEntry.java
Expand Up @@ -10,6 +10,9 @@
import java.util.Iterator;
import java.util.Map;

/**
* Used by the Model Pool to load models from config files such as OBJ.
*/
public class ModelPoolEntry {

/**
Expand Down Expand Up @@ -52,7 +55,7 @@ protected void setTextureGroup(String groupName) {
texture = textures.get(groupName);
}

protected void applyGroups(Map<String, TransformGroup> groupsMap, Map<String, TextureGroup> texturesMap) {
protected void applyGroups(Map<String, TransformGroupBone> groupsMap, Map<String, TextureGroup> texturesMap) {

Iterator<String> groupsItr = groups.keySet().iterator();
Iterator<String> texturesItr = textures.keySet().iterator();
Expand Down Expand Up @@ -93,6 +96,10 @@ public ModelPoolEntry() {
}


/**
* Loads an OBJ model from file and converts it to ModelRendererTurbo
* @param file the path and name of the model file
*/
public void getModelFromObj(File file) {
try {
BufferedReader in = new BufferedReader(new FileReader(file));
Expand All @@ -101,7 +108,7 @@ public void getModelFromObj(File file) {

ArrayList<PositionTransformVertex> verts = new ArrayList<PositionTransformVertex>();
ArrayList<float[]> uvs = new ArrayList<float[]>();
ArrayList<float[]> normals = new ArrayList<float[]>();
ArrayList<int[]> normals = new ArrayList<int[]>();
ArrayList<TexturedPolygon> face = new ArrayList<TexturedPolygon>();

while((s = in.readLine()) != null) {
Expand Down Expand Up @@ -145,31 +152,31 @@ public void getModelFromObj(File file) {
} else if(s.startsWith("vn ")) {
//Normals
s = s.substring(s.indexOf(" ") + 1).trim();
float[] v = new float[3];
int[] v = new int[3];
for(int i = 0; i < 3; i++) {
int ind = s.indexOf(" ");
v[i] = (ind > -1)?Float.parseFloat(s.substring(0, ind)):Float.parseFloat(s);
v[i] = (ind > -1)?Integer.parseInt(s.substring(0, ind)):Integer.parseInt(s);

s = s.substring(s.indexOf(" ") + 1).trim();
}

float flt = v[2];
int flt = v[2];
v[2] = v[1];
v[1] = flt;

normals.add(new float[] {v[0], v[1], v[2]});
normals.add(new int[]{v[0], v[1], v[2]});
} else if(s.startsWith("f ")) {
//faces
s = s.substring(s.indexOf(" ") + 1).trim();
ArrayList<PositionTextureVertex> v = new ArrayList<PositionTextureVertex>();
String s1;
int finalPhase = 0;
float[] normal = new float[] {0F, 0F, 0F};
ArrayList<Vec3d> iNormal = new ArrayList<Vec3d>();
int[] normal = new int[] {0, 0, 0};
ArrayList<int[]> iNormal = new ArrayList<>();
while(finalPhase < 1) {
int vInt;
float[] curUV;
float[] curNormals;
int[] curNormals;
int ind = s.indexOf(" ");
s1 = s;
if(ind > -1) {
Expand All @@ -191,14 +198,14 @@ public void getModelFromObj(File file) {
} else {
vnInt = Integer.parseInt(f[0]) - 1;
}
curNormals = (normals.size() > vnInt)?normals.get(vnInt):new float[]{0, 0, 0};
curNormals = (normals.size() > vnInt)?normals.get(vnInt):new int[]{0, 0, 0};
} else {
vInt = Integer.parseInt(s1) - 1;
curUV = (uvs.size() > vInt)?uvs.get(vInt):new float[]{0, 0};
curNormals = (normals.size() > vInt)?normals.get(vInt):new float[]{0, 0, 0};
curNormals = (normals.size() > vInt)?normals.get(vInt):new int[]{0, 0, 0};
}

iNormal.add(new Vec3d(curNormals[0], curNormals[1], curNormals[2]));
iNormal.add(new int[]{curNormals[0], curNormals[1], curNormals[2]});

normal[0]+= curNormals[0];
normal[1]+= curNormals[1];
Expand Down
32 changes: 21 additions & 11 deletions src/main/java/ebf/tim/models/tmt/ModelRendererTurbo.java
Expand Up @@ -13,33 +13,43 @@

import java.util.*;
/**
* An extension to the CubikModelRenderer class. It basically is a copy to CubikModelRenderer,
* however, it contains various new methods to make your models.
* An extension to the ModelRenderer class that contains various new methods to make your models.
* <br /><br />
* Since the ModelRendererTurbo class gets loaded during startup, the models made
* can be very complex. This is why I can afford to add, for example, Wavefont OBJ
* support or have the addSprite method, methods that add a lot of vertices and
* polygons.
* support or have the addSprite method, methods that add a lot of vertices and polygons.
* @author GaryCXJk
* @license http://fexcraft.net/license?id=tmt
* <br /><br />
* This version of TMT has been modified by Eternal Blue Flame and does not reflect the quality or features of the original version.
* This version of TMT has been heavily modified by Eternal Blue Flame and does not reflect the quality or features of any other version.
* Models made for other versions of TMT may not work with this version, and models made for this version may not work in other versions.
* Shape3D is not supported in this version, use Shape Boxes instead.
* The shape's name is used by the Model Animators for various functionality, there are specific pre-defined names to use for said features
* @see ebf.tim.models.StaticModelAnimator
* @see ebf.tim.models.GroupedModelRender
*/
public class ModelRendererTurbo extends ModelRenderer {


/**converts a radians double to degrees*/
/**converts a radians float to degrees */
public static final float degreesF = (float) (180.0d / Math.PI);


/**
* Creates a new ModelRenderTurbo object with a defined name.
* @param modelbase
* @param s the name of the shape
*/
public ModelRendererTurbo(ModelBase modelbase, String s) {
super(modelbase, s);
transformGroup.put("0", new TransformGroupBone(new Bone(0, 0, 0, 0), 1D));
textureGroup.put("0", new TextureGroup());
currentTextureGroup = textureGroup.get("0");
}

/**
* Creates a new ModelRenderTurbo object with no defined name.
* @param modelbase
*/
public ModelRendererTurbo(ModelBase modelbase)
{
this(modelbase, "");
Expand Down Expand Up @@ -1135,7 +1145,7 @@ public void setGroup(String groupName, Bone bone, double weight) {
* Gets the current transformation group.
* @return the current PositionTransformGroup.
*/
public TransformGroup getGroup()
public TransformGroupBone getGroup()
{
return currentGroup;
}
Expand All @@ -1144,7 +1154,7 @@ public TransformGroup getGroup()
* Gets the transformation group with a given group name.
* @return the current PositionTransformGroup.
*/
public TransformGroup getGroup(String groupName) {
public TransformGroupBone getGroup(String groupName) {
if(!transformGroup.containsKey(groupName)) {
return null;
}
Expand Down Expand Up @@ -1318,9 +1328,9 @@ private void compileLegacyDisplayList(float worldScale) {
private boolean compiled = false;
private int displayList = 0;
private int displayListArray[];
private Map<String, TransformGroup> transformGroup = new HashMap<String, TransformGroup>();
private Map<String, TransformGroupBone> transformGroup = new HashMap<String, TransformGroupBone>();
private Map<String, TextureGroup> textureGroup = new HashMap<String, TextureGroup>();
private TransformGroup currentGroup;
private TransformGroupBone currentGroup;
private TextureGroup currentTextureGroup;
public boolean mirror = false;
public boolean flip = false;
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/ebf/tim/models/tmt/PositionTransformVertex.java
Expand Up @@ -4,6 +4,9 @@

import java.util.ArrayList;

/**
* an extension to PositionTextureVertex that adds support for the neutral vector.
*/
public class PositionTransformVertex extends PositionTextureVertex {
public PositionTransformVertex(double x, double y, double z, float u, float v) {
this(new Vec3d(x, y, z), u, v);
Expand All @@ -29,14 +32,14 @@ public void setTransformation() {
return;
}
double weight = 0D;
for(TransformGroup transform : transformGroups) {
for(TransformGroupBone transform : transformGroups) {
weight += transform.getWeight();
}
vector3D.xCoord = 0;
vector3D.yCoord = 0;
vector3D.zCoord = 0;

for(TransformGroup transform : transformGroups) {
for(TransformGroupBone transform : transformGroups) {
double cWeight = transform.getWeight() / weight;
Vec3d vector = transform.doTransformation(this);

Expand All @@ -46,17 +49,17 @@ public void setTransformation() {
}
}

public void addGroup(TransformGroup group)
public void addGroup(TransformGroupBone group)
{
transformGroups.add(group);
}

public void removeGroup(TransformGroup group)
public void removeGroup(TransformGroupBone group)
{
transformGroups.remove(group);
}

public Vec3d neutralVector;
public ArrayList<TransformGroup> transformGroups = new ArrayList<TransformGroup>();
public ArrayList<TransformGroupBone> transformGroups = new ArrayList<TransformGroupBone>();

}
2 changes: 1 addition & 1 deletion src/main/java/ebf/tim/models/tmt/Tessellator.java
Expand Up @@ -118,7 +118,7 @@ public void addVertexWithUVW(double i, double j, double k, double l, double m, d
public void setNormal(float x, float y, float z){
setNormal((int)x, (int)y, (int)z);
}

public void setNormal(int x, int y, int z){
in = true;
n = ((x * 127)) & 255 | (((y * 127)) & 255) << 8 | (((z * 127)) & 255) << 16;
Expand Down
35 changes: 18 additions & 17 deletions src/main/java/ebf/tim/models/tmt/TexturedPolygon.java
Expand Up @@ -6,25 +6,25 @@

import java.util.ArrayList;

/**
* An extension of TexturedQuad that adds support for more shapes beyond simple quads.
*/
public class TexturedPolygon extends TexturedQuad {
public TexturedPolygon(PositionTextureVertex apositionTexturevertex[]) {
super(apositionTexturevertex);
invertNormal = false;
normals = new int[0];
iNormals = new ArrayList<Vec3d>();
}

public void setInvertNormal(boolean isSet)
{
invertNormal = isSet;
}

public void setNormals(float x, float y, float z)
public void setNormals(int x, int y, int z)
{
normals = new int[] {(int)x, (int)y, (int)z};
normals = new int[] {x, y, z};
}

public void setNormals(ArrayList<Vec3d> vec)
public void setNormals(ArrayList<int[]> vec)
{
iNormals = vec;
}
Expand All @@ -45,12 +45,10 @@ public void draw(Tessellator tessellator, float f) {
} else {
tessellator.setNormal(normals[0], normals[1], normals[2]);
}
} else
if(vertexPositions.length >= 3) {
Vec3d Vec3d = new Vec3d(vertexPositions[1].vector3D.subtract(vertexPositions[0].vector3D));
Vec3d Vec3d1 = new Vec3d(vertexPositions[1].vector3D.subtract(vertexPositions[2].vector3D));
Vec3d Vec3d2 = new Vec3d(Vec3d1.crossProduct(Vec3d).normalize());

} else if(vertexPositions.length > 3) {
Vec3d Vec3d2 = new Vec3d(vertexPositions[1].vector3D.subtract(vertexPositions[2].vector3D)
.crossProduct(vertexPositions[1].vector3D.subtract(vertexPositions[0].vector3D)).normalize());

if(invertNormal) {
tessellator.setNormal((int)-Vec3d2.xCoord, (int)-Vec3d2.yCoord, (int)-Vec3d2.zCoord);
} else {
Expand All @@ -67,9 +65,9 @@ public void draw(Tessellator tessellator, float f) {
}
if(i < iNormals.size()) {
if(invertNormal) {
tessellator.setNormal((int)-iNormals.get(i).xCoord, (int)-iNormals.get(i).yCoord, (int)-iNormals.get(i).zCoord);
tessellator.setNormal(-iNormals.get(i)[0],-iNormals.get(i)[1],-iNormals.get(i)[2]);
} else {
tessellator.setNormal((int)iNormals.get(i).xCoord, (int)iNormals.get(i).yCoord, (int)iNormals.get(i).zCoord);
tessellator.setNormal(iNormals.get(i)[0], iNormals.get(i)[1], iNormals.get(i)[2]);
}
}
tessellator.addVertexWithUV(positionTexturevertex.vector3D.xCoord * f, positionTexturevertex.vector3D.yCoord * f, positionTexturevertex.vector3D.zCoord * f, (float)positionTexturevertex.texturePositionX, (float)positionTexturevertex.texturePositionY);
Expand All @@ -78,7 +76,10 @@ public void draw(Tessellator tessellator, float f) {
tessellator.draw();
}

private boolean invertNormal;
private int[] normals;
private ArrayList<Vec3d> iNormals;
private boolean invertNormal = false;
private int[] normals = new int[0];
public int[] vertices;
public float texturePositionX;
public float texturePositionY;
private ArrayList<int[]> iNormals = new ArrayList<>();
}
8 changes: 0 additions & 8 deletions src/main/java/ebf/tim/models/tmt/TransformGroup.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/ebf/tim/models/tmt/TransformGroupBone.java
Expand Up @@ -8,7 +8,7 @@
* @author GaryCXJk
*
*/
public class TransformGroupBone extends TransformGroup {
public class TransformGroupBone {
public TransformGroupBone(Bone bone, double wght) {
baseVector = bone.getPosition();
baseAngle = bone.getAbsoluteAngle();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ebf/tim/models/tmt/Vec3f.java
@@ -1,7 +1,7 @@
package ebf.tim.models.tmt;

/**
*
* basically the same as Vec3D, but a float. Usually used for storing rotations.
* @author Ferdinand
*/

Expand Down

0 comments on commit 688d996

Please sign in to comment.