ModelRotation.getMatrix() now returns the correct matrix; fixed the application of custom transformations to vanilla models; fixed application of transformations to B3D models; fixed the culling of rotated vanilla models

This commit is contained in:
RainWarrior 2015-02-14 04:44:09 +03:00
parent 87ef833d32
commit 5616d0c1b0
6 changed files with 59 additions and 15 deletions

View file

@ -69,7 +69,7 @@
{
- this.func_178406_a(p_178415_1_, new Vector3d(0.5D, 0.5D, 0.5D), p_178415_4_.func_177525_a(), new Vector3d(1.0D, 1.0D, 1.0D));
- return p_178415_4_.func_177520_a(p_178415_2_, p_178415_3_);
+ this.func_178406_a(p_178415_1_, new Vector3d(0.5D, 0.5D, 0.5D), new Matrix4d(p_178415_4_.getMatrix()), new Vector3d(1.0D, 1.0D, 1.0D));
+ net.minecraftforge.client.ForgeHooksClient.transform(p_178415_1_, p_178415_4_.getMatrix());
+ return p_178415_4_.rotate(p_178415_2_, p_178415_3_);
}
}

View file

@ -29,9 +29,12 @@
TextureAtlasSprite textureatlassprite = (TextureAtlasSprite)this.field_177599_g.get(new ResourceLocation(p_177578_1_.func_178308_c("particle")));
SimpleBakedModel.Builder builder = (new SimpleBakedModel.Builder(p_177578_1_)).func_177646_a(textureatlassprite);
Iterator iterator = p_177578_1_.func_178298_a().iterator();
@@ -516,11 +522,11 @@
@@ -514,13 +520,13 @@
BlockPartFace blockpartface = (BlockPartFace)blockpart.field_178240_c.get(enumfacing);
TextureAtlasSprite textureatlassprite1 = (TextureAtlasSprite)this.field_177599_g.get(new ResourceLocation(p_177578_1_.func_178308_c(blockpartface.field_178242_d)));
if (blockpartface.field_178244_b == null)
- if (blockpartface.field_178244_b == null)
+ if (blockpartface.field_178244_b == null || !net.minecraftforge.client.model.TRSRTransformation.isInteger(p_177578_2_.getMatrix()))
{
- builder.func_177648_a(this.func_177589_a(blockpart, blockpartface, textureatlassprite1, enumfacing, p_177578_2_, p_177578_3_));
+ builder.func_177648_a(this.makeBakedQuad(blockpart, blockpartface, textureatlassprite1, enumfacing, p_177578_2_, p_177578_3_));

View file

@ -15,7 +15,7 @@
}
+
+ public net.minecraftforge.client.model.TRSRTransformation apply(net.minecraftforge.client.model.IModelPart part) { return new net.minecraftforge.client.model.TRSRTransformation(getMatrix()); }
+ public javax.vecmath.Matrix4f getMatrix() { return new javax.vecmath.Matrix4f(func_177525_a()); }
+ public javax.vecmath.Matrix4f getMatrix() { return net.minecraftforge.client.ForgeHooksClient.getMatrix(this); }
+ public EnumFacing rotate(EnumFacing facing) { return func_177523_a(facing); }
+ public int rotate(EnumFacing facing, int vertexIndex) { return func_177520_a(facing, vertexIndex); }
}

View file

@ -9,6 +9,8 @@ import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector4f;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@ -35,6 +37,7 @@ import net.minecraft.client.resources.I18n;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ModelRotation;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@ -633,4 +636,24 @@ public class ForgeHooksClient
FMLLog.severe("Unimplemented vanilla attribute upload: %s", attrType.getDisplayName());
}
}
public static void transform(Vector3d vec, Matrix4f m)
{
Vector4f tmp = new Vector4f((float)vec.x, (float)vec.y, (float)vec.z, 1f);
m.transform(tmp);
if(Math.abs(tmp.w - 1f) > 1e-5) tmp.scale(1f / tmp.w);
vec.set(tmp.x, tmp.y, tmp.z);
}
public static Matrix4f getMatrix(ModelRotation modelRotation)
{
Matrix4f ret = new Matrix4f(modelRotation.getMatrix4d()), tmp = new Matrix4f();
tmp.setIdentity();
tmp.m03 = tmp.m13 = tmp.m23 = .5f;
ret.mul(tmp, ret);
tmp.invert();
//tmp.m03 = tmp.m13 = tmp.m23 = -.5f;
ret.mul(tmp);
return ret;
}
}

View file

@ -9,6 +9,7 @@ import javax.vecmath.Vector4f;
import net.minecraft.client.renderer.block.model.ItemTransformVec3f;
import net.minecraft.client.resources.model.ModelRotation;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Vec3i;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
@ -57,7 +58,7 @@ public class TRSRTransformation implements IModelState, ITransformation
public TRSRTransformation(ModelRotation rotation)
{
this(new Matrix4f(rotation.getMatrix4d()));
this(rotation.getMatrix());
}
private static final TRSRTransformation identity;
@ -432,9 +433,28 @@ public class TRSRTransformation implements IModelState, ITransformation
public static EnumFacing rotate(Matrix4f matrix, EnumFacing facing)
{
Vector4f vec = new Vector4f(facing.getDirectionVec().getX(), facing.getDirectionVec().getY(), facing.getDirectionVec().getZ(), 1);
Vec3i dir = facing.getDirectionVec();
Vector4f vec = new Vector4f(dir.getX(), dir.getY(), dir.getZ(), 0);
matrix.transform(vec);
return EnumFacing.getFacingFromVector(vec.x / vec.w, vec.y / vec.w, vec.z / vec.w);
return EnumFacing.getFacingFromVector(vec.x, vec.y, vec.z);
}
public static boolean isInteger(Matrix4f matrix)
{
Matrix4f m = new Matrix4f();
m.setIdentity();
m.m30 = m.m31 = m.m32 = 1;
m.m33 = 0;
m.mul(matrix, m);
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
float v = m.getElement(i, j) / m.getElement(3, j);
if(Math.abs(v - Math.round(v)) > 1e-5) return false;
}
}
return true;
}
public int rotate(EnumFacing facing, int vertexIndex)

View file

@ -236,6 +236,11 @@ public class B3DLoader implements ICustomModelLoader
public static TRSRTransformation getNodeMatrix(Animation animation, Node<?> node, int frame)
{
TRSRTransformation ret = TRSRTransformation.identity();
if(node.getParent() != null)
{
TRSRTransformation pm = cache.getUnchecked(Triple.<Animation, Node<?>, Integer>of(animation, node.getParent(), frame));
ret = ret.compose(pm);
}
Key key = null;
if(animation != null) key = animation.getKeys().get(frame, node);
else if(key == null && node.getAnimation() != null && node.getAnimation() != animation) key = node.getAnimation().getKeys().get(frame, node);
@ -441,14 +446,7 @@ public class B3DLoader implements ICustomModelLoader
// gets transformation in global space
public Matrix4f apply(Node<?> node)
{
TRSRTransformation ret = TRSRTransformation.identity(), pm = null;
if(node.getParent() != null) pm = new TRSRTransformation(apply(node.getParent()));
if(pm != null)
{
ret = ret.compose(pm);
}
ret = ret.compose(state.apply(PartWrapper.create(node)));
return ret.getMatrix();
return state.apply(PartWrapper.create(node)).getMatrix();
}
});
for(Face f : faces)