mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 04:09:51 +00:00
Implemented slightly more generic version of UVLock, re-enabled it for json models. Closes #2607.
This commit is contained in:
1 parent
4b53f0716b
commit
c589a3a299
5 files changed
+135
-15
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user