Implemented slightly more generic version of UVLock, re-enabled it for json models. Closes #2607.
This commit is contained in:
parent
4b53f0716b
commit
c589a3a299
5 changed files with 135 additions and 15 deletions
|
@ -1,6 +1,6 @@
|
|||
--- ../src-base/minecraft/net/minecraft/client/renderer/block/model/FaceBakery.java
|
||||
+++ ../src-work/minecraft/net/minecraft/client/renderer/block/model/FaceBakery.java
|
||||
@@ -48,14 +48,20 @@
|
||||
@@ -48,14 +48,19 @@
|
||||
|
||||
public BakedQuad func_178414_a(Vector3f p_178414_1_, Vector3f p_178414_2_, BlockPartFace p_178414_3_, TextureAtlasSprite p_178414_4_, EnumFacing p_178414_5_, ModelRotation p_178414_6_, BlockPartRotation p_178414_7_, boolean p_178414_8_, boolean p_178414_9_)
|
||||
{
|
||||
|
@ -14,8 +14,7 @@
|
|||
if (p_178414_8_)
|
||||
{
|
||||
- blockfaceuv = this.func_188010_a(p_178414_3_.field_178243_e, p_178414_5_, p_178414_6_);
|
||||
+ // TODO fix uvlock for custom rotations
|
||||
+ //blockfaceuv = this.applyUVLock(face.blockFaceUV, facing, modelRotationIn);
|
||||
+ blockfaceuv = net.minecraftforge.client.ForgeHooksClient.applyUVLock(p_178414_3_.field_178243_e, p_178414_5_, p_178414_6_);
|
||||
}
|
||||
|
||||
- int[] aint = this.func_188012_a(blockfaceuv, p_178414_4_, p_178414_5_, this.func_178403_a(p_178414_1_, p_178414_2_), p_178414_6_, p_178414_7_, p_178414_9_);
|
||||
|
@ -23,7 +22,7 @@
|
|||
EnumFacing enumfacing = func_178410_a(aint);
|
||||
|
||||
if (p_178414_7_ == null)
|
||||
@@ -63,7 +69,8 @@
|
||||
@@ -63,7 +68,8 @@
|
||||
this.func_178408_a(aint, enumfacing);
|
||||
}
|
||||
|
||||
|
@ -33,7 +32,7 @@
|
|||
}
|
||||
|
||||
private BlockFaceUV func_188010_a(BlockFaceUV p_188010_1_, EnumFacing p_188010_2_, ModelRotation p_188010_3_)
|
||||
@@ -73,11 +80,16 @@
|
||||
@@ -73,11 +79,16 @@
|
||||
|
||||
private int[] func_188012_a(BlockFaceUV p_188012_1_, TextureAtlasSprite p_188012_2_, EnumFacing p_188012_3_, float[] p_188012_4_, ModelRotation p_188012_5_, BlockPartRotation p_188012_6_, boolean p_188012_7_)
|
||||
{
|
||||
|
@ -51,7 +50,7 @@
|
|||
}
|
||||
|
||||
return aint;
|
||||
@@ -123,12 +135,17 @@
|
||||
@@ -123,12 +134,17 @@
|
||||
|
||||
private void func_188015_a(int[] p_188015_1_, int p_188015_2_, EnumFacing p_188015_3_, BlockFaceUV p_188015_4_, float[] p_188015_5_, TextureAtlasSprite p_188015_6_, ModelRotation p_188015_7_, BlockPartRotation p_188015_8_, boolean p_188015_9_)
|
||||
{
|
||||
|
@ -71,7 +70,7 @@
|
|||
this.func_178404_a(p_188015_1_, j, p_188015_2_, vector3f, i, p_188015_6_, p_188015_4_);
|
||||
}
|
||||
|
||||
@@ -189,14 +206,19 @@
|
||||
@@ -189,14 +205,19 @@
|
||||
|
||||
public int func_188011_a(Vector3f p_188011_1_, EnumFacing p_188011_2_, int p_188011_3_, ModelRotation p_188011_4_)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
--- ../src-base/minecraft/net/minecraft/client/renderer/block/model/Variant.java
|
||||
+++ ../src-work/minecraft/net/minecraft/client/renderer/block/model/Variant.java
|
||||
@@ -12,7 +12,7 @@
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
-public class Variant
|
||||
+public class Variant implements net.minecraftforge.client.model.ISmartVariant
|
||||
{
|
||||
private final ResourceLocation field_188050_a;
|
||||
private final ModelRotation field_188051_b;
|
||||
@@ -32,11 +32,17 @@
|
||||
return this.field_188050_a;
|
||||
}
|
||||
|
@ -18,3 +27,13 @@
|
|||
public boolean func_188049_c()
|
||||
{
|
||||
return this.field_188052_c;
|
||||
@@ -138,4 +144,9 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
+
|
||||
+ public net.minecraftforge.client.model.IModel process(net.minecraftforge.client.model.IModel base)
|
||||
+ {
|
||||
+ return net.minecraftforge.client.model.ModelProcessingHelper.uvlock(base, func_188049_c());
|
||||
+ }
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.FloatBuffer;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.vecmath.Matrix3f;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
import javax.vecmath.Vector4f;
|
||||
|
@ -28,9 +29,9 @@ import net.minecraft.client.renderer.OpenGlHelper;
|
|||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.BlockFaceUV;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransformVec3f;
|
||||
import net.minecraft.client.renderer.block.model.ModelManager;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.model.ModelRotation;
|
||||
|
@ -52,8 +53,11 @@ import net.minecraft.inventory.EntityEquipmentSlot;
|
|||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.registry.IRegistry;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
@ -75,9 +79,10 @@ import net.minecraftforge.client.model.ModelLoader;
|
|||
import net.minecraftforge.common.ForgeModContainer;
|
||||
import net.minecraftforge.common.ForgeVersion;
|
||||
import net.minecraftforge.common.ForgeVersion.Status;
|
||||
import net.minecraftforge.common.model.IModelPart;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.model.IModelPart;
|
||||
import net.minecraftforge.common.model.ITransformation;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
|
@ -353,7 +358,7 @@ public class ForgeHooksClient
|
|||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Matrix4f getMatrix(ItemTransformVec3f transform)
|
||||
public static Matrix4f getMatrix(net.minecraft.client.renderer.block.model.ItemTransformVec3f transform)
|
||||
{
|
||||
javax.vecmath.Matrix4f m = new javax.vecmath.Matrix4f(), t = new javax.vecmath.Matrix4f();
|
||||
m.setIdentity();
|
||||
|
@ -589,7 +594,7 @@ public class ForgeHooksClient
|
|||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Optional<TRSRTransformation> applyTransform(ItemTransformVec3f transform, Optional<? extends IModelPart> part)
|
||||
public static Optional<TRSRTransformation> applyTransform(net.minecraft.client.renderer.block.model.ItemTransformVec3f transform, Optional<? extends IModelPart> part)
|
||||
{
|
||||
if(part.isPresent()) return Optional.absent();
|
||||
return Optional.of(new TRSRTransformation(transform));
|
||||
|
@ -636,4 +641,42 @@ public class ForgeHooksClient
|
|||
}
|
||||
return !from.getItem().shouldCauseReequipAnimation(from, to, changed);
|
||||
}
|
||||
|
||||
public static BlockFaceUV applyUVLock(BlockFaceUV blockFaceUV, EnumFacing originalSide, ITransformation rotation)
|
||||
{
|
||||
TRSRTransformation global = new TRSRTransformation(rotation.getMatrix());
|
||||
Matrix4f uv = global.getUVLockTransform(originalSide).getMatrix();
|
||||
Vector4f vec = new Vector4f(0, 0, 0, 1);
|
||||
vec.x = blockFaceUV.getVertexU(blockFaceUV.getVertexRotatedRev(0)) / 16;
|
||||
vec.y = blockFaceUV.getVertexV(blockFaceUV.getVertexRotatedRev(0)) / 16;
|
||||
uv.transform(vec);
|
||||
float uMin = 16 * vec.x; // / vec.w;
|
||||
float vMin = 16 * vec.y; // / vec.w;
|
||||
vec.x = blockFaceUV.getVertexU(blockFaceUV.getVertexRotatedRev(2)) / 16;
|
||||
vec.y = blockFaceUV.getVertexV(blockFaceUV.getVertexRotatedRev(2)) / 16;
|
||||
vec.z = 0;
|
||||
vec.w = 1;
|
||||
uv.transform(vec);
|
||||
float uMax = 16 * vec.x; // / vec.w;
|
||||
float vMax = 16 * vec.y; // / vec.w;
|
||||
if(uMin > uMax)
|
||||
{
|
||||
float t = uMin;
|
||||
uMin = uMax;
|
||||
uMax = t;
|
||||
}
|
||||
if(vMin > vMax)
|
||||
{
|
||||
float t = vMin;
|
||||
vMin = vMax;
|
||||
vMax = t;
|
||||
}
|
||||
float a = (float)Math.toRadians(blockFaceUV.rotation);
|
||||
Vector3f rv = new Vector3f(MathHelper.cos(a), MathHelper.sin(a), 0);
|
||||
Matrix3f rot = new Matrix3f();
|
||||
uv.getRotationScale(rot);
|
||||
rot.transform(rv);
|
||||
int angle = MathHelper.normalizeAngle(-(int)Math.round(Math.toDegrees(Math.atan2(rv.y, rv.x)) / 90) * 90, 360);
|
||||
return new BlockFaceUV(new float[]{ uMin, vMin, uMax, vMax }, angle);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -373,7 +373,7 @@ public class ForgeBlockStateV1 extends Marker
|
|||
|
||||
protected SubModel asGenericSubModel()
|
||||
{
|
||||
return new SubModel(state.or(TRSRTransformation.identity()), smooth.or(true), gui3d.or(true), uvLock.or(false), getTextures(), model, getCustomData());
|
||||
return new SubModel(state.or(TRSRTransformation.identity()), uvLock.or(false), smooth.or(true), gui3d.or(true), getTextures(), model, getCustomData());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package net.minecraftforge.common.model;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
import javax.vecmath.AxisAngle4f;
|
||||
import javax.vecmath.Matrix3f;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Quat4f;
|
||||
import javax.vecmath.SingularMatrixException;
|
||||
import javax.vecmath.Tuple3f;
|
||||
import javax.vecmath.Tuple4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
|
@ -19,6 +23,7 @@ import org.apache.commons.lang3.tuple.Triple;
|
|||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/*
|
||||
* Interpolation-friendly affine transformation.
|
||||
|
@ -128,6 +133,14 @@ public final class TRSRTransformation implements IModelState, ITransformation
|
|||
return new TRSRTransformation(m);
|
||||
}
|
||||
|
||||
public TRSRTransformation inverse()
|
||||
{
|
||||
if(this == identity) return this;
|
||||
Matrix4f m = getMatrix();
|
||||
m.invert();
|
||||
return new TRSRTransformation(m);
|
||||
}
|
||||
|
||||
private void genCheck()
|
||||
{
|
||||
if(!full)
|
||||
|
@ -212,7 +225,6 @@ public final class TRSRTransformation implements IModelState, ITransformation
|
|||
return new Vector3f((float)Math.toDegrees(xyz.x), (float)Math.toDegrees(xyz.y), (float)Math.toDegrees(xyz.z));
|
||||
}
|
||||
|
||||
// TODO check if correct
|
||||
public static Vector3f toXYZ(Quat4f q)
|
||||
{
|
||||
float w2 = q.w * q.w;
|
||||
|
@ -731,4 +743,51 @@ public final class TRSRTransformation implements IModelState, ITransformation
|
|||
slerp(this.getRightRot(), that.getRightRot(), progress)
|
||||
);
|
||||
}
|
||||
|
||||
private static final EnumMap<EnumFacing, TRSRTransformation> vanillaUvTransformLocalToGlobal = Maps.newEnumMap(EnumFacing.class);
|
||||
private static final EnumMap<EnumFacing, TRSRTransformation> vanillaUvTransformGlobalToLocal = Maps.newEnumMap(EnumFacing.class);
|
||||
|
||||
static
|
||||
{
|
||||
vanillaUvTransformLocalToGlobal.put(EnumFacing.SOUTH, identity);
|
||||
Quat4f tmp = new Quat4f();
|
||||
tmp.set(new AxisAngle4f(0, 1, 0, (float)Math.toRadians(90)));
|
||||
vanillaUvTransformLocalToGlobal.put(EnumFacing.EAST, new TRSRTransformation(null, new Quat4f(tmp), null, null));
|
||||
tmp.set(new AxisAngle4f(0, 1, 0, (float)Math.toRadians(-90)));
|
||||
vanillaUvTransformLocalToGlobal.put(EnumFacing.WEST, new TRSRTransformation(null, new Quat4f(tmp), null, null));
|
||||
tmp.set(new AxisAngle4f(0, 1, 0, (float)Math.toRadians(180)));
|
||||
vanillaUvTransformLocalToGlobal.put(EnumFacing.NORTH, new TRSRTransformation(null, new Quat4f(tmp), null, null));
|
||||
tmp.set(new AxisAngle4f(1, 0, 0, (float)Math.toRadians(-90)));
|
||||
vanillaUvTransformLocalToGlobal.put(EnumFacing.UP, new TRSRTransformation(null, new Quat4f(tmp), null, null));
|
||||
tmp.set(new AxisAngle4f(1, 0, 0, (float)Math.toRadians(90)));
|
||||
vanillaUvTransformLocalToGlobal.put(EnumFacing.DOWN, new TRSRTransformation(null, new Quat4f(tmp), null, null));
|
||||
|
||||
for(EnumFacing side : EnumFacing.values())
|
||||
{
|
||||
vanillaUvTransformGlobalToLocal.put(side, vanillaUvTransformLocalToGlobal.get(side).inverse());
|
||||
}
|
||||
}
|
||||
|
||||
public static TRSRTransformation getVanillaUvTransformLocalToGlobal(EnumFacing side)
|
||||
{
|
||||
return vanillaUvTransformLocalToGlobal.get(side);
|
||||
}
|
||||
|
||||
public static TRSRTransformation getVanillaUvTransformGlobalToLocal(EnumFacing side)
|
||||
{
|
||||
return vanillaUvTransformGlobalToLocal.get(side);
|
||||
}
|
||||
|
||||
public TRSRTransformation getUVLockTransform(EnumFacing originalSide)
|
||||
{
|
||||
EnumFacing newSide = rotate(originalSide);
|
||||
try
|
||||
{
|
||||
return blockCenterToCorner(vanillaUvTransformGlobalToLocal.get(originalSide).compose(blockCornerToCenter(this.inverse())).compose(vanillaUvTransformLocalToGlobal.get(newSide)));
|
||||
}
|
||||
catch(SingularMatrixException e)
|
||||
{
|
||||
return new TRSRTransformation(null, null, new Vector3f(0, 0, 0), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue