Finish converting the code from javax.vecmath to the vanilla vector classes. Forge is now vecmath-free!

This commit is contained in:
David Quintana 2019-12-17 19:14:52 +01:00
parent 1558362583
commit 738abbb360
28 changed files with 307 additions and 494 deletions

View File

@ -417,7 +417,6 @@ project(':forge') {
installer 'org.jline:jline:3.12.+'
installer 'org.apache.maven:maven-artifact:3.6.0'
installer 'net.jodah:typetools:0.6.1'
installer 'java3d:vecmath:1.5.2'
installer 'org.apache.logging.log4j:log4j-api:2.11.2'
installer 'org.apache.logging.log4j:log4j-core:2.11.2'
installer 'net.minecrell:terminalconsoleappender:1.2.+'

View File

@ -1,10 +1,11 @@
--- a/net/minecraft/client/renderer/Matrix3f.java
+++ b/net/minecraft/client/renderer/Matrix3f.java
@@ -406,4 +406,10 @@
@@ -406,4 +406,11 @@
public Matrix3f func_226121_d_() {
return new Matrix3f(this);
}
+
+ // Forge start
+ public void multiplyBackward(Matrix3f other) {
+ Matrix3f copy = other.func_226121_d_();
+ copy.func_226118_b_(this);

View File

@ -1,12 +1,30 @@
--- a/net/minecraft/client/renderer/Matrix4f.java
+++ b/net/minecraft/client/renderer/Matrix4f.java
@@ -373,4 +373,88 @@
@@ -373,4 +373,78 @@
matrix4f.field_226586_l_ = p_226599_2_;
return matrix4f;
}
+
+ // Forge start
+ public Matrix4f(float[] values) { set(values); }
+ public Matrix4f(float[] values) {
+ field_226575_a_ = values[0];
+ field_226576_b_ = values[1];
+ field_226577_c_ = values[2];
+ field_226578_d_ = values[3];
+ field_226579_e_ = values[4];
+ field_226580_f_ = values[5];
+ field_226581_g_ = values[6];
+ field_226582_h_ = values[7];
+ field_226583_i_ = values[8];
+ field_226584_j_ = values[9];
+ field_226585_k_ = values[10];
+ field_226586_l_ = values[11];
+ field_226587_m_ = values[12];
+ field_226588_n_ = values[13];
+ field_226589_o_ = values[14];
+ field_226590_p_ = values[15];
+ }
+
+ public void set(Matrix4f mat) {
+ this.field_226575_a_ = mat.field_226575_a_;
+ this.field_226576_b_ = mat.field_226576_b_;
@ -45,47 +63,19 @@
+ field_226590_p_ += other.field_226590_p_;
+ }
+
+ public void set(float[] others) {
+ field_226575_a_ = others[0];
+ field_226576_b_ = others[1];
+ field_226577_c_ = others[2];
+ field_226578_d_ = others[3];
+ field_226579_e_ = others[4];
+ field_226580_f_ = others[5];
+ field_226581_g_ = others[6];
+ field_226582_h_ = others[7];
+ field_226583_i_ = others[8];
+ field_226584_j_ = others[9];
+ field_226585_k_ = others[10];
+ field_226586_l_ = others[11];
+ field_226587_m_ = others[12];
+ field_226588_n_ = others[13];
+ field_226589_o_ = others[14];
+ field_226590_p_ = others[15];
+ }
+
+ public void write(float[] dest) {
+ dest[0] = field_226575_a_;
+ dest[1] = field_226576_b_;
+ dest[2] = field_226577_c_;
+ dest[3] = field_226578_d_;
+ dest[4] = field_226579_e_;
+ dest[5] = field_226580_f_;
+ dest[6] = field_226581_g_;
+ dest[7] = field_226582_h_;
+ dest[8] = field_226583_i_;
+ dest[9] = field_226584_j_;
+ dest[10] = field_226585_k_;
+ dest[11] = field_226586_l_;
+ dest[12] = field_226587_m_;
+ dest[13] = field_226588_n_;
+ dest[14] = field_226589_o_;
+ dest[15] = field_226590_p_;
+ }
+
+ public void multiplyBackward(Matrix4f other) {
+ Matrix4f copy = other.func_226601_d_();
+ copy.func_226595_a_(this);
+ this.set(copy);
+ }
+
+ public void setTranslation(float x, float y, float z) {
+ this.field_226575_a_ = 1.0F;
+ this.field_226580_f_ = 1.0F;
+ this.field_226585_k_ = 1.0F;
+ this.field_226590_p_ = 1.0F;
+ this.field_226578_d_ = x;
+ this.field_226582_h_ = y;
+ this.field_226586_l_ = z;
+ }
}

View File

@ -1,15 +0,0 @@
--- a/net/minecraft/client/renderer/Quaternion.java
+++ b/net/minecraft/client/renderer/Quaternion.java
@@ -176,4 +176,12 @@
public Quaternion func_227068_g_() {
return new Quaternion(this);
}
+
+ // Forge start
+ public Quaternion(float[] values) {
+ this.field_227061_b_ = values[0];
+ this.field_227062_c_ = values[1];
+ this.field_227063_d_ = values[2];
+ this.field_227064_e_ = values[3];
+ }
}

View File

@ -9,7 +9,7 @@
private final Matrix4f field_227976_a_;
private boolean field_227977_b_;
@Nullable
@@ -133,4 +133,33 @@
@@ -133,4 +133,32 @@
public int hashCode() {
return Objects.hash(this.field_227976_a_);
}
@ -29,17 +29,16 @@
+ return field_227981_f_.func_227068_g_();
+ }
+
+ private javax.vecmath.Matrix3f normalTransform = null;
+ public javax.vecmath.Matrix3f getNormalMatrix() {
+ private Matrix3f normalTransform = null;
+ public Matrix3f getNormalMatrix() {
+ checkNormalTransform();
+ return normalTransform;
+ }
+ private void checkNormalTransform() {
+ if (normalTransform == null) {
+ normalTransform = new javax.vecmath.Matrix3f();
+ net.minecraftforge.common.model.TransformationHelper.toVecmath(field_227976_a_).getRotationScale(normalTransform);
+ normalTransform.invert();
+ normalTransform.transpose();
+ normalTransform = new Matrix3f(field_227976_a_);
+ normalTransform.func_226123_f_();
+ normalTransform.func_226110_a_();
+ }
+ }
}

View File

@ -1,12 +1,15 @@
--- a/net/minecraft/client/renderer/Vector3f.java
+++ b/net/minecraft/client/renderer/Vector3f.java
@@ -198,4 +198,14 @@
@@ -198,4 +198,17 @@
public String toString() {
return "[" + this.field_229184_g_ + ", " + this.field_229185_h_ + ", " + this.field_229186_i_ + "]";
}
+
+ // Forge start
+ public Vector3f(float[] values) {
+ set(values);
+ }
+ public void set(float[] values) {
+ this.field_229184_g_ = values[0];
+ this.field_229185_h_ = values[1];
+ this.field_229186_i_ = values[2];

View File

@ -1,24 +1,19 @@
--- a/net/minecraft/client/renderer/Vector4f.java
+++ b/net/minecraft/client/renderer/Vector4f.java
@@ -129,4 +129,21 @@
@@ -129,4 +129,16 @@
public String toString() {
return "[" + this.field_229368_a_ + ", " + this.field_229369_b_ + ", " + this.field_229370_c_ + ", " + this.field_229371_d_ + "]";
}
+
+ // Forge start
+ public Vector4f(float[] values) {
+ set(values);
+ }
+ public void set(float[] values) {
+ this.field_229368_a_ = values[0];
+ this.field_229369_b_ = values[1];
+ this.field_229370_c_ = values[2];
+ this.field_229371_d_ = values[3];
+ }
+ public void write(float[] values) {
+ values[0] = this.field_229368_a_;
+ values[1] = this.field_229369_b_;
+ values[2] = this.field_229370_c_;
+ values[3] = this.field_229371_d_;
+ }
+ public void setX(float x) { this.field_229368_a_ = x; }
+ public void setY(float y) { this.field_229369_b_ = y; }
+ public void setZ(float z) { this.field_229370_c_ = z; }
+ public void setW(float z) { this.field_229371_d_ = z; }
}

View File

@ -40,7 +40,6 @@ import static org.lwjgl.opengl.GL20.glVertexAttribPointer;
import java.io.File;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -50,17 +49,13 @@ import java.util.Set;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import javax.vecmath.Matrix3f;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector3f;
import javax.vecmath.Vector4f;
import net.minecraft.client.renderer.*;
import net.minecraftforge.client.model.pipeline.LightUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.async.ThreadNameCachingStrategy;
import org.apache.logging.log4j.core.impl.ReusableLogEventFactory;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL13;
import com.google.common.collect.ImmutableList;
@ -79,14 +74,7 @@ import net.minecraft.client.gui.ClientBossInfo;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.screen.MainMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.Atlases;
import net.minecraft.client.renderer.FogRenderer.FogType;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.TransformationMatrix;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.color.ItemColors;
import net.minecraft.client.renderer.entity.model.BipedModel;
@ -97,7 +85,6 @@ import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.model.ItemTransformVec3f;
import net.minecraft.client.renderer.model.Material;
import net.minecraft.client.renderer.model.ModelManager;
import net.minecraft.client.renderer.model.ModelRotation;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.client.renderer.texture.NativeImage;
import net.minecraft.client.renderer.texture.OverlayTexture;
@ -403,39 +390,10 @@ public class ForgeHooksClient
modelLoader.onPostBakeEvent(modelRegistry);
}
@SuppressWarnings("deprecation")
public static Matrix4f getMatrix(ItemTransformVec3f transform)
{
Matrix4f m = new Matrix4f(), t = new Matrix4f();
m.setIdentity();
m.setTranslation(TransformationHelper.toVecmath(transform.translation));
t.setIdentity();
t.rotY(transform.rotation.getY());
m.mul(t);
t.setIdentity();
t.rotX(transform.rotation.getX());
m.mul(t);
t.setIdentity();
t.rotZ(transform.rotation.getZ());
m.mul(t);
t.setIdentity();
t.m00 = transform.scale.getX();
t.m11 = transform.scale.getY();
t.m22 = transform.scale.getZ();
m.mul(t);
return m;
}
private static final net.minecraft.client.renderer.Matrix4f flipX;
private static final net.minecraft.client.renderer.Matrix3f flipXNormal;
static {
flipX = new net.minecraft.client.renderer.Matrix4f(new float[]{
-1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
});
flipX = Matrix4f.func_226593_a_(-1,1,1);
flipXNormal = new net.minecraft.client.renderer.Matrix3f(flipX);
}
@ -535,26 +493,6 @@ public class ForgeHooksClient
}
}
public static void transform(net.minecraft.client.renderer.Vector3f vec, Matrix4f m)
{
Vector4f tmp = new Vector4f(vec.getX(), vec.getY(), vec.getZ(), 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 = TransformationHelper.toVecmath(modelRotation.func_225615_b_().func_227988_c_()), 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;
}
public static int getColorIndex(VertexFormat fmt)
{
ImmutableList<VertexFormatElement> elements = fmt.func_227894_c_();
@ -787,17 +725,17 @@ public class ForgeHooksClient
public static void fillNormal(int[] faceData, Direction facing)
{
Vector3f v1 = getVertexPos(faceData, 3);
Vector3f t = getVertexPos(faceData, 1);
Vector3f t1 = getVertexPos(faceData, 1);
Vector3f v2 = getVertexPos(faceData, 2);
v1.sub(t);
t.set(getVertexPos(faceData, 0));
v2.sub(t);
v1.cross(v2, v1);
v1.normalize();
Vector3f t2 = getVertexPos(faceData, 0);
v1.sub(t1);
v2.sub(t2);
v2.cross(v1);
v2.func_229194_d_();
int x = ((byte) Math.round(v1.x * 127)) & 0xFF;
int y = ((byte) Math.round(v1.y * 127)) & 0xFF;
int z = ((byte) Math.round(v1.z * 127)) & 0xFF;
int x = ((byte) Math.round(v2.getX() * 127)) & 0xFF;
int y = ((byte) Math.round(v2.getY() * 127)) & 0xFF;
int z = ((byte) Math.round(v2.getZ() * 127)) & 0xFF;
int normal = x | (y << 0x08) | (z << 0x10);
@ -852,24 +790,19 @@ public class ForgeHooksClient
public static BlockFaceUV applyUVLock(BlockFaceUV blockFaceUV, Direction originalSide, TransformationMatrix rotation, ResourceLocation p_228824_9_)
{
TransformationMatrix global = new TransformationMatrix(rotation.func_227988_c_());
Matrix4f uv = TransformationHelper.toVecmath(TransformationHelper.getUVLockTransform(global, originalSide).func_227988_c_());
Vector4f vec = new Vector4f(0, 0, 0, 1);
Matrix4f uv = TransformationHelper.getUVLockTransform(global, originalSide).func_227988_c_();
float u0 = blockFaceUV.getVertexU(blockFaceUV.getVertexRotatedRev(0));
float v0 = blockFaceUV.getVertexV(blockFaceUV.getVertexRotatedRev(0));
vec.x = u0 / 16;
vec.y = v0 / 16;
uv.transform(vec);
float uMin = 16 * vec.x; // / vec.w;
float vMin = 16 * vec.y; // / vec.w;
Vector4f vec = new Vector4f(u0 / 16, v0 / 16, 0, 1);
vec.func_229372_a_(uv);
float uMin = 16 * vec.getX(); // / vec.w;
float vMin = 16 * vec.getY(); // / vec.w;
float u1 = blockFaceUV.getVertexU(blockFaceUV.getVertexRotatedRev(2));
float v1 = blockFaceUV.getVertexV(blockFaceUV.getVertexRotatedRev(2));
vec.x = u1 / 16;
vec.y = v1 / 16;
vec.z = 0;
vec.w = 1;
uv.transform(vec);
float uMax = 16 * vec.x; // / vec.w;
float vMax = 16 * vec.y; // / vec.w;
vec.set(u1 / 16,v1 / 16,0,1);
vec.func_229372_a_(uv);
float uMax = 16 * vec.getX(); // / vec.w;
float vMax = 16 * vec.getY(); // / vec.w;
if (uMin > uMax && u0 < u1 || uMin < uMax && u0 > u1)
{
float t = uMin;
@ -884,10 +817,9 @@ public class ForgeHooksClient
}
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);
Matrix3f rot = new Matrix3f(uv);
rv.func_229188_a_(rot);
int angle = MathHelper.normalizeAngle(-(int)Math.round(Math.toDegrees(Math.atan2(rv.getY(), rv.getX())) / 90) * 90, 360);
return new BlockFaceUV(new float[]{ uMin, vMin, uMax, vMax }, angle);
}

View File

@ -24,7 +24,6 @@ import java.util.Random;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import com.mojang.blaze3d.matrix.MatrixStack;
@ -37,7 +36,6 @@ import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ILightReader;
import net.minecraftforge.client.model.data.IModelData;
import org.apache.commons.lang3.tuple.Pair;
public interface IForgeBakedModel
{

View File

@ -20,12 +20,8 @@
package net.minecraftforge.client.extensions;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.renderer.Matrix4f;
import net.minecraft.client.renderer.TransformationMatrix;
import net.minecraft.client.renderer.Vector3f;
import net.minecraft.client.renderer.Vector4f;
import net.minecraft.client.renderer.*;
import net.minecraft.util.Direction;
import net.minecraftforge.common.model.TransformationHelper;
/*
* Replacement interface for ModelRotation to allow custom transformations of vanilla models.
@ -66,27 +62,20 @@ public interface IForgeTransformationMatrix
default TransformationMatrix inverse()
{
if (isIdentity()) return getTransformaion();
javax.vecmath.Matrix4f m = TransformationHelper.toVecmath(getTransformaion().func_227988_c_());
m.invert();
return new TransformationMatrix(TransformationHelper.toMojang(m));
Matrix4f m = getTransformaion().func_227988_c_().func_226601_d_();
m.func_226600_c_();
return new TransformationMatrix(m);
}
default void transformPosition(Vector4f position)
{
TransformationHelper.transform(getTransformaion().func_227988_c_(), position);
position.func_229372_a_(getTransformaion().func_227988_c_());
}
default void transformNormal(Vector3f normal)
{
javax.vecmath.Vector3f copy = TransformationHelper.toVecmath(normal);
transformNormal(copy);
normal.set(copy.x, copy.y, copy.z);
}
default void transformNormal(javax.vecmath.Vector3f normal)
{
getTransformaion().getNormalMatrix().transform(normal);
normal.normalize();
normal.func_229188_a_(getTransformaion().getNormalMatrix());
normal.func_229194_d_();
}
default Direction rotateTransform(Direction facing)
@ -94,4 +83,38 @@ public interface IForgeTransformationMatrix
return Direction.func_229385_a_(getTransformaion().func_227988_c_(), facing);
}
/**
* convert transformation from assuming center-block system to corner-block system
*/
default TransformationMatrix blockCenterToCorner()
{
TransformationMatrix transform = getTransformaion();
if (transform.isIdentity()) return TransformationMatrix.func_227983_a_();
Matrix4f ret = transform.func_227988_c_();
Matrix4f tmp = Matrix4f.func_226599_b_(.5f, .5f, .5f);
ret.multiplyBackward(tmp);
tmp.func_226591_a_();
tmp.setTranslation(-.5f, -.5f, -.5f);
ret.func_226595_a_(tmp);
return new TransformationMatrix(ret);
}
/**
* convert transformation from assuming corner-block system to center-block system
*/
default TransformationMatrix blockCornerToCenter()
{
TransformationMatrix transform = getTransformaion();
if (transform.isIdentity()) return TransformationMatrix.func_227983_a_();
Matrix4f ret = transform.func_227988_c_();
Matrix4f tmp = Matrix4f.func_226599_b_(-.5f, -.5f, -.5f);
ret.multiplyBackward(tmp);
tmp.func_226591_a_();
tmp.setTranslation(.5f, .5f, .5f);
ret.func_226595_a_(tmp);
return new TransformationMatrix(ret);
}
}

View File

@ -20,7 +20,6 @@
package net.minecraftforge.client.model;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import java.util.List;
import java.util.Random;
@ -36,7 +35,6 @@ import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.model.ItemOverrideList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.Direction;
import org.apache.commons.lang3.tuple.Pair;
public class BakedItemModel implements IBakedModel
{

View File

@ -21,7 +21,6 @@ package net.minecraftforge.client.model;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import java.util.List;
import java.util.Random;
@ -35,9 +34,7 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ILightReader;
import net.minecraft.world.IWorldReader;
import net.minecraftforge.client.model.data.IModelData;
import org.apache.commons.lang3.tuple.Pair;
public abstract class BakedModelWrapper<T extends IBakedModel> implements IBakedModel
{

View File

@ -54,7 +54,8 @@ final class FancyMissingModel implements IUnbakedModel
{
private static final ResourceLocation font = new ResourceLocation("minecraft", "textures/font/ascii.png");
private static final Material font2 = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("minecraft", "font/ascii"));
private static final TransformationMatrix smallTransformation = TransformationHelper.blockCenterToCorner(new TransformationMatrix(null, null, new Vector3f(.25f, .25f, .25f), null));
private static final TransformationMatrix smallTransformation = new TransformationMatrix(null, null, new Vector3f(.25f, .25f, .25f), null)
.blockCenterToCorner();
private static final LoadingCache<VertexFormat, SimpleModelFontRenderer> fontCache = CacheBuilder.newBuilder().maximumSize(3).build(new CacheLoader<VertexFormat, SimpleModelFontRenderer>()
{
@Override

View File

@ -159,10 +159,10 @@ public final class ModelDynBucket implements IModelGeometry<ModelDynBucket>
TextureAtlasSprite particleSprite = particleLocation != null ? spriteGetter.apply(particleLocation) : null;
// if the fluid is lighter than air, will manipulate the initial state to be rotated 180° to turn it upside down
// if the fluid is lighter than air, will manipulate the initial state to be rotated 180deg to turn it upside down
if (flipGas && fluid != Fluids.EMPTY && fluid.getAttributes().isLighterThanAir())
{
sprite = new ModelTransformComposition(state, new SimpleModelTransform(TransformationHelper.blockCenterToCorner(new TransformationMatrix(null, new Quaternion(0, 0, 1, 0), null, null))));
sprite = new ModelTransformComposition(state, new SimpleModelTransform(new TransformationMatrix(null, new Quaternion(0, 0, 1, 0), null, null).blockCenterToCorner()));
state = sprite;
}

View File

@ -157,7 +157,7 @@ public class ModelLoaderRegistry
try
{
TransformationMatrix base = context.deserialize(transformData, TransformationMatrix.class);
return Optional.of(new SimpleModelTransform(ImmutableMap.of(), TransformationHelper.blockCenterToCorner(base)));
return Optional.of(new SimpleModelTransform(ImmutableMap.of(), base.blockCenterToCorner()));
}
catch (JsonParseException e)
{
@ -196,7 +196,7 @@ public class ModelLoaderRegistry
if(!transform.entrySet().isEmpty())
{
base = context.deserialize(transform, TransformationMatrix.class);
base = TransformationHelper.blockCenterToCorner(base);
base = base.blockCenterToCorner();
}
IModelTransform state = new SimpleModelTransform(Maps.immutableEnumMap(transforms), base);
return Optional.of(state);
@ -208,7 +208,7 @@ public class ModelLoaderRegistry
if(transform.has(name))
{
TransformationMatrix t = context.deserialize(transform.remove(name), TransformationMatrix.class);
transforms.put(itemCameraTransform, TransformationHelper.blockCenterToCorner(t));
transforms.put(itemCameraTransform, t.blockCenterToCorner());
}
}

View File

@ -24,7 +24,6 @@ import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.TransformationMatrix;
@ -35,7 +34,6 @@ import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.MinecraftForgeClient;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@ -77,7 +77,7 @@ public class PerspectiveMapWrapper implements IBakedModel
{
if (transforms.hasCustomTransform(type))
{
map.put(type, TransformationHelper.blockCenterToCorner(TransformationHelper.toTransformation(transforms.getTransform(type))));
map.put(type, TransformationHelper.toTransformation(transforms.getTransform(type)).blockCenterToCorner());
}
}
return ImmutableMap.copyOf(map);
@ -96,7 +96,7 @@ public class PerspectiveMapWrapper implements IBakedModel
}
else if (transforms.hasCustomTransform(type))
{
map.put(type, TransformationHelper.blockCenterToCorner(TransformationHelper.toTransformation(transforms.getTransform(type))));
map.put(type, TransformationHelper.toTransformation(transforms.getTransform(type)).blockCenterToCorner());
}
}
return ImmutableMap.copyOf(map);
@ -109,7 +109,7 @@ public class PerspectiveMapWrapper implements IBakedModel
{
// Push to the matrix to make it not empty and indicate that we want to transform things
mat.func_227860_a_();
mat.func_227866_c_().func_227870_a_().func_226595_a_(TransformationHelper.blockCornerToCenter(tr).func_227988_c_());
mat.func_227866_c_().func_227870_a_().func_226595_a_(tr.blockCornerToCenter().func_227988_c_());
}
return model;
}
@ -121,7 +121,7 @@ public class PerspectiveMapWrapper implements IBakedModel
{
// Push to the matrix to make it not empty and indicate that we want to transform things
mat.func_227860_a_();
mat.func_227866_c_().func_227870_a_().func_226595_a_(TransformationHelper.blockCornerToCenter(tr).func_227988_c_());
mat.func_227866_c_().func_227870_a_().func_226595_a_(tr.blockCornerToCenter().func_227988_c_());
}
return model;
}

View File

@ -21,12 +21,12 @@ package net.minecraftforge.client.model;
import com.google.common.collect.Lists;
import net.minecraft.client.renderer.TransformationMatrix;
import net.minecraft.client.renderer.Vector3f;
import net.minecraft.client.renderer.Vector4f;
import net.minecraft.client.renderer.model.BakedQuad;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import javax.vecmath.Vector3f;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

View File

@ -32,12 +32,8 @@ import java.util.Optional;
import java.util.TreeMap;
import javax.annotation.Nullable;
import javax.vecmath.AxisAngle4f;
import net.minecraft.client.renderer.Matrix4f;
import net.minecraft.client.renderer.Quaternion;
import net.minecraft.client.renderer.TransformationMatrix;
import net.minecraft.client.renderer.Vector3f;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.model.IModelTransform;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -334,7 +330,8 @@ public class ModelBlockAnimation
Vector3f translation = new Vector3f(0, 0, 0);
Vector3f scale = new Vector3f(1, 1, 1);
Vector3f origin = new Vector3f(0, 0, 0);
AxisAngle4f rotation = new AxisAngle4f(0, 0, 0, 0);
Vector3f rotation_axis = new Vector3f(0, 0, 0);
float rotation_angle = 0;
for(MBVariableClip var : variables)
{
int length = loop ? var.samples.length : (var.samples.length - 1);
@ -375,16 +372,16 @@ public class ModelBlockAnimation
translation.setZ(value);
break;
case XROT:
rotation.x = value;
rotation_axis.setX(value);
break;
case YROT:
rotation.y = value;
rotation_axis.setY(value);
break;
case ZROT:
rotation.z = value;
rotation_axis.setZ(value);
break;
case ANGLE:
rotation.angle = (float)Math.toRadians(value);
rotation_angle = (float)Math.toRadians(value);
break;
case SCALE:
scale.set(value, value, value);
@ -409,12 +406,12 @@ public class ModelBlockAnimation
break;
}
}
Quaternion rot = new Quaternion(new Vector3f(rotation.x, rotation.y, rotation.z), rotation.angle, false);
Quaternion rot = new Quaternion(rotation_axis, rotation_angle, false);
TransformationMatrix base = new TransformationMatrix(translation, rot, scale, null);
Vector3f negOrigin = origin.func_229195_e_();
negOrigin.func_229192_b_(-1,-1,-1);
base = new TransformationMatrix(origin, null, null, null).compose(base).compose(new TransformationMatrix(negOrigin, null, null, null));
return TransformationHelper.blockCenterToCorner(base);
return base.blockCenterToCorner();
}
}
}

View File

@ -68,20 +68,20 @@ public enum B3DClip implements IClip
TransformationMatrix ret = TransformationMatrix.func_227983_a_();
if(node.getAnimation() == null)
{
return ret.compose(B3DLoader.fromVecmath(node.getPos(), node.getRot(), node.getScale(), null));
return ret.compose(new TransformationMatrix(node.getPos(), node.getRot(), node.getScale(), null));
}
int start = Math.max(1, (int)Math.round(Math.floor(time)));
int end = Math.min(start + 1, (int)Math.round(Math.ceil(time)));
float progress = time - (float)Math.floor(time);
Key keyStart = node.getAnimation().getKeys().get(start, node);
Key keyEnd = node.getAnimation().getKeys().get(end, node);
TransformationMatrix startTr = keyStart == null ? null : B3DLoader.fromVecmath(keyStart.getPos(), keyStart.getRot(),keyStart.getScale(), null);
TransformationMatrix endTr = keyEnd == null ? null : B3DLoader.fromVecmath(keyEnd.getPos(), keyEnd.getRot(),keyEnd.getScale(), null);
TransformationMatrix startTr = keyStart == null ? null : new TransformationMatrix(keyStart.getPos(), keyStart.getRot(),keyStart.getScale(), null);
TransformationMatrix endTr = keyEnd == null ? null : new TransformationMatrix(keyEnd.getPos(), keyEnd.getRot(),keyEnd.getScale(), null);
if(keyStart == null)
{
if(keyEnd == null)
{
ret = ret.compose(B3DLoader.fromVecmath(node.getPos(), node.getRot(), node.getScale(), null));
ret = ret.compose(new TransformationMatrix(node.getPos(), node.getRot(), node.getScale(), null));
}
// TODO animated TRSRTransformation for speed?
else

View File

@ -36,11 +36,11 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector3f;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.renderer.Matrix4f;
import net.minecraft.client.renderer.TransformationMatrix;
import net.minecraft.client.renderer.Vector3f;
import net.minecraft.client.renderer.model.*;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.client.renderer.texture.MissingTextureSprite;
@ -156,12 +156,6 @@ public enum B3DLoader implements ISelectiveResourceReloadListener
return new ModelWrapper(modelLocation, model, ImmutableSet.of(model.getRoot().getName()), true, true, 1);
}
@Deprecated // TODO: Does a lot of unnecessary work converting things, should use the TransformationMatrix constructor directly with mojang vector classes instead.
public static TransformationMatrix fromVecmath(javax.vecmath.Vector3f pos, javax.vecmath.Quat4f rot, javax.vecmath.Vector3f scale, javax.vecmath.Quat4f rot2)
{
return new TransformationMatrix(TransformationHelper.toMojang(pos), TransformationHelper.toMojang(rot), TransformationHelper.toMojang(scale), TransformationHelper.toMojang(rot2));
}
public static final class B3DState implements IModelTransform
{
@Nullable
@ -310,10 +304,10 @@ public enum B3DLoader implements ISelectiveResourceReloadListener
TransformationMatrix pm = cache.getUnchecked(Triple.of(animation, node.getParent(), frame));
ret = ret.compose(pm);
// joint offset in the parent coords
ret = ret.compose(fromVecmath(parent.getPos(), parent.getRot(), parent.getScale(), null));
ret = ret.compose(new TransformationMatrix(parent.getPos(), parent.getRot(), parent.getScale(), null));
}
// current node local pose
ret = ret.compose(fromVecmath(key.getPos(), key.getRot(), key.getScale(), null));
ret = ret.compose(new TransformationMatrix(key.getPos(), key.getRot(), key.getScale(), null));
// this part moved inside the model
// inverse bind of the current node
/*Matrix4f rm = new TRSRTransformation(node.getPos(), node.getRot(), node.getScale(), null).getMatrix();
@ -339,9 +333,9 @@ public enum B3DLoader implements ISelectiveResourceReloadListener
TransformationMatrix pm = cache.getUnchecked(Triple.of(animation, node.getParent(), frame));
ret = ret.compose(pm);
// joint offset in the parent coords
ret = ret.compose(fromVecmath(parent.getPos(), parent.getRot(), parent.getScale(), null));
ret = ret.compose(new TransformationMatrix(parent.getPos(), parent.getRot(), parent.getScale(), null));
}
ret = ret.compose(fromVecmath(node.getPos(), node.getRot(), node.getScale(), null));
ret = ret.compose(new TransformationMatrix(node.getPos(), node.getRot(), node.getScale(), null));
// TODO cache
TransformationMatrix invBind = new NodeJoint(node).getInvBindPose();
ret = ret.compose(invBind);
@ -362,9 +356,9 @@ public enum B3DLoader implements ISelectiveResourceReloadListener
@Override
public TransformationMatrix getInvBindPose()
{
Matrix4f m = TransformationHelper.toVecmath(fromVecmath(node.getPos(), node.getRot(), node.getScale(), null).func_227988_c_());
m.invert();
TransformationMatrix pose = new TransformationMatrix(TransformationHelper.toMojang(m));
Matrix4f m = new TransformationMatrix(node.getPos(), node.getRot(), node.getScale(), null).func_227988_c_();
m.func_226600_c_();
TransformationMatrix pose = new TransformationMatrix(m);
if(node.getParent() != null)
{
@ -714,14 +708,14 @@ public enum B3DLoader implements ISelectiveResourceReloadListener
@Override
public Matrix4f apply(Node<?> node)
{
return TransformationHelper.toVecmath(global.compose(localCache.getUnchecked(node)).func_227988_c_());
return global.compose(localCache.getUnchecked(node)).func_227988_c_();
}
});
for(Face f : faces)
{
UnpackedBakedQuad.Builder quadBuilder = new UnpackedBakedQuad.Builder(format);
quadBuilder.setContractUVs(true);
quadBuilder.setQuadOrientation(Direction.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z));
quadBuilder.setQuadOrientation(Direction.getFacingFromVector(f.getNormal().getX(), f.getNormal().getY(), f.getNormal().getZ()));
List<Texture> textures = null;
if(f.getBrush() != null) textures = f.getBrush().getTextures();
TextureAtlasSprite sprite;
@ -747,12 +741,12 @@ public enum B3DLoader implements ISelectiveResourceReloadListener
switch(vertexFormatElements.get(e).getUsage())
{
case POSITION:
builder.put(e, v.getPos().x, v.getPos().y, v.getPos().z, 1);
builder.put(e, v.getPos().getX(), v.getPos().getY(), v.getPos().getZ(), 1);
break;
case COLOR:
if(v.getColor() != null)
{
builder.put(e, v.getColor().x, v.getColor().y, v.getColor().z, v.getColor().w);
builder.put(e, v.getColor().getX(), v.getColor().getY(), v.getColor().getZ(), v.getColor().getW());
}
else
{
@ -764,8 +758,8 @@ public enum B3DLoader implements ISelectiveResourceReloadListener
if(vertexFormatElements.get(e).getIndex() < v.getTexCoords().length)
{
builder.put(e,
sprite.getInterpolatedU(v.getTexCoords()[0].x * 16),
sprite.getInterpolatedV(v.getTexCoords()[0].y * 16),
sprite.getInterpolatedU(v.getTexCoords()[0].getX() * 16),
sprite.getInterpolatedV(v.getTexCoords()[0].getY() * 16),
0,
1
);
@ -778,11 +772,11 @@ public enum B3DLoader implements ISelectiveResourceReloadListener
case NORMAL:
if(v.getNormal() != null)
{
builder.put(e, v.getNormal().x, v.getNormal().y, v.getNormal().z, 0);
builder.put(e, v.getNormal().getX(), v.getNormal().getY(), v.getNormal().getZ(), 0);
}
else
{
builder.put(e, faceNormal.x, faceNormal.y, faceNormal.z, 0);
builder.put(e, faceNormal.getX(), faceNormal.getY(), faceNormal.getZ(), 0);
}
break;
default:

View File

@ -37,13 +37,9 @@ import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import javax.vecmath.Quat4f;
import javax.vecmath.Vector2f;
import javax.vecmath.Vector3f;
import javax.vecmath.Vector4f;
import net.minecraft.client.renderer.TransformationMatrix;
import net.minecraft.client.renderer.*;
import net.minecraft.util.math.Vec2f;
import net.minecraftforge.versions.forge.ForgeVersion;
import net.minecraftforge.common.model.TransformationHelper;
import org.apache.commons.io.IOUtils;
@ -253,8 +249,8 @@ public class B3DModel
String path = readString();
int flags = buf.getInt();
int blend = buf.getInt();
Vector2f pos = new Vector2f(buf.getFloat(), buf.getFloat());
Vector2f scale = new Vector2f(buf.getFloat(), buf.getFloat());
Vec2f pos = new Vec2f(buf.getFloat(), buf.getFloat());
Vec2f scale = new Vec2f(buf.getFloat(), buf.getFloat());
float rot = buf.getFloat();
ret.add(new Texture(path, flags, blend, pos, scale, rot));
}
@ -389,7 +385,7 @@ public class B3DModel
Map<Integer, Key> ret = new HashMap<>();
int flags = buf.getInt();
Vector3f pos = null, scale = null;
Quat4f rot = null;
Quaternion rot = null;
while(buf.hasRemaining())
{
int frame = buf.getInt();
@ -456,7 +452,7 @@ public class B3DModel
String name = readString();
Vector3f pos = new Vector3f(buf.getFloat(), buf.getFloat(), buf.getFloat());
Vector3f scale = new Vector3f(buf.getFloat(), buf.getFloat(), buf.getFloat());
Quat4f rot = readQuat();
Quaternion rot = readQuat();
dump("NODE(" + name + ", " + pos + ", " + scale + ", " + rot + ") {");
while(buf.hasRemaining())
{
@ -494,13 +490,13 @@ public class B3DModel
return node;
}
private Quat4f readQuat()
private Quaternion readQuat()
{
float w = buf.getFloat();
float x = buf.getFloat();
float y = buf.getFloat();
float z = buf.getFloat();
return new Quat4f(x, y, z, w);
return new Quaternion(x, y, z, w);
}
private void skip()
@ -533,15 +529,15 @@ public class B3DModel
public static class Texture
{
public static final Texture White = new Texture("builtin/white", 0, 0, new Vector2f(0, 0), new Vector2f(1, 1), 0);
public static final Texture White = new Texture("builtin/white", 0, 0, new Vec2f(0, 0), new Vec2f(1, 1), 0);
private final String path;
private final int flags;
private final int blend;
private final Vector2f pos;
private final Vector2f scale;
private final Vec2f pos;
private final Vec2f scale;
private final float rot;
public Texture(String path, int flags, int blend, Vector2f pos, Vector2f scale, float rot)
public Texture(String path, int flags, int blend, Vec2f pos, Vec2f scale, float rot)
{
this.path = path;
this.flags = flags;
@ -566,12 +562,12 @@ public class B3DModel
return blend;
}
public Vector2f getPos()
public Vec2f getPos()
{
return pos;
}
public Vector2f getScale()
public Vec2f getScale()
{
return scale;
}
@ -667,7 +663,7 @@ public class B3DModel
Matrix4f t = new Matrix4f();
if(mesh.getWeightMap().get(this).isEmpty())
{
t.setIdentity();
t.func_226591_a_();
}
else
{
@ -675,27 +671,28 @@ public class B3DModel
{
totalWeight += bone.getLeft();
Matrix4f bm = animator.apply(bone.getRight());
bm.mul(bone.getLeft());
bm.func_226592_a_(bone.getLeft());
t.add(bm);
}
if(Math.abs(totalWeight) > 1e-4) t.mul(1f / totalWeight);
else t.setIdentity();
if(Math.abs(totalWeight) > 1e-4) t.func_226592_a_(1f / totalWeight);
else t.func_226591_a_();
}
TransformationMatrix trsr = new TransformationMatrix(TransformationHelper.toMojang(t));
TransformationMatrix trsr = new TransformationMatrix(t);
// pos
Vector4f pos = new Vector4f(this.pos);
pos.w = 1;
trsr.transformPosition(TransformationHelper.toMojang(pos));
Vector3f rPos = new Vector3f(pos.x / pos.w, pos.y / pos.w, pos.z / pos.w);
pos.setW(1);
trsr.transformPosition(pos);
pos.func_229374_e_();
Vector3f rPos = new Vector3f(pos.getX(), pos.getY(), pos.getZ());
// normal
Vector3f rNormal = null;
if(this.normal != null)
{
rNormal = new Vector3f(this.normal);
rNormal = this.normal.func_229195_e_();
trsr.transformNormal(rNormal);
}
@ -787,13 +784,13 @@ public class B3DModel
public static Vector3f getNormal(Vertex v1, Vertex v2, Vertex v3)
{
Vector3f a = new Vector3f(v2.getPos());
Vector3f a = v2.getPos().func_229195_e_();
a.sub(v1.getPos());
Vector3f b = new Vector3f(v3.getPos());
Vector3f b = v3.getPos().func_229195_e_();
b.sub(v1.getPos());
Vector3f c = new Vector3f();
c.cross(a, b);
c.normalize();
Vector3f c = a.func_229195_e_();
c.cross(b);
c.func_229194_d_();
return c;
}
}
@ -805,9 +802,9 @@ public class B3DModel
@Nullable
private final Vector3f scale;
@Nullable
private final Quat4f rot;
private final Quaternion rot;
public Key(@Nullable Vector3f pos, @Nullable Vector3f scale, @Nullable Quat4f rot)
public Key(@Nullable Vector3f pos, @Nullable Vector3f scale, @Nullable Quaternion rot)
{
this.pos = pos;
this.scale = scale;
@ -827,7 +824,7 @@ public class B3DModel
}
@Nullable
public Quat4f getRot()
public Quaternion getRot()
{
return rot;
}
@ -892,7 +889,7 @@ public class B3DModel
private final String name;
private final Vector3f pos;
private final Vector3f scale;
private final Quat4f rot;
private final Quaternion rot;
private final ImmutableMap<String, Node<?>> nodes;
@Nullable
private Animation animation;
@ -900,12 +897,12 @@ public class B3DModel
@Nullable
private Node<? extends IKind<?>> parent;
public static <K extends IKind<K>> Node<K> create(String name, Vector3f pos, Vector3f scale, Quat4f rot, List<Node<?>> nodes, K kind)
public static <K extends IKind<K>> Node<K> create(String name, Vector3f pos, Vector3f scale, Quaternion rot, List<Node<?>> nodes, K kind)
{
return new Node<>(name, pos, scale, rot, nodes, kind);
}
public Node(String name, Vector3f pos, Vector3f scale, Quat4f rot, List<Node<?>> nodes, K kind)
public Node(String name, Vector3f pos, Vector3f scale, Quaternion rot, List<Node<?>> nodes, K kind)
{
this.name = name;
this.pos = pos;
@ -974,7 +971,7 @@ public class B3DModel
return scale;
}
public Quat4f getRot()
public Quaternion getRot()
{
return rot;
}

View File

@ -21,8 +21,8 @@ package net.minecraftforge.client.model.obj;
import com.google.common.collect.Maps;
import joptsimple.internal.Strings;
import net.minecraft.client.renderer.Vector4f;
import javax.vecmath.Vector4f;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;

View File

@ -25,6 +25,8 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import joptsimple.internal.Strings;
import net.minecraft.client.renderer.TransformationMatrix;
import net.minecraft.client.renderer.Vector3f;
import net.minecraft.client.renderer.Vector4f;
import net.minecraft.client.renderer.model.*;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
@ -33,6 +35,7 @@ import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec2f;
import net.minecraftforge.client.model.*;
import net.minecraftforge.client.model.geometry.IModelGeometryPart;
import net.minecraftforge.client.model.geometry.IMultipartModelGeometry;
@ -42,9 +45,6 @@ import net.minecraftforge.common.model.TransformationHelper;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nullable;
import javax.vecmath.Vector2f;
import javax.vecmath.Vector3f;
import javax.vecmath.Vector4f;
import java.io.IOException;
import java.util.*;
import java.util.function.Function;
@ -52,17 +52,17 @@ import java.util.stream.Collectors;
public class OBJModel implements IMultipartModelGeometry<OBJModel>
{
private static Vector2f[] DEFAULT_COORDS = {
new Vector2f(0, 0),
new Vector2f(0, 1),
new Vector2f(1, 1),
new Vector2f(1, 0),
private static Vec2f[] DEFAULT_COORDS = {
new Vec2f(0, 0),
new Vec2f(0, 1),
new Vec2f(1, 1),
new Vec2f(1, 0),
};
private final Map<String, ModelGroup> parts = Maps.newHashMap();
private final List<Vector3f> positions = Lists.newArrayList();
private final List<Vector2f> texCoords = Lists.newArrayList();
private final List<Vec2f> texCoords = Lists.newArrayList();
private final List<Vector3f> normals = Lists.newArrayList();
private final List<Vector4f> colors = Lists.newArrayList();
@ -307,12 +307,12 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
}
}
public static Vector2f parseVector2(String[] line)
public static Vec2f parseVector2(String[] line)
{
switch (line.length) {
case 1: return new Vector2f(0,0);
case 2: return new Vector2f(Float.parseFloat(line[1]), 0);
default: return new Vector2f(Float.parseFloat(line[1]), Float.parseFloat(line[2]));
case 1: return new Vec2f(0,0);
case 2: return new Vec2f(Float.parseFloat(line[1]), 0);
default: return new Vec2f(Float.parseFloat(line[1]), Float.parseFloat(line[2]));
}
}
@ -401,12 +401,12 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
Vector3f a = positions.get(indices[0][0]);
Vector3f ab = positions.get(indices[1][0]);
Vector3f ac = positions.get(indices[2][0]);
Vector3f abs = new Vector3f(ab);
Vector3f abs = ab.func_229195_e_();
abs.sub(a);
Vector3f acs = new Vector3f(ac);
Vector3f acs = ac.func_229195_e_();
acs.sub(a);
abs.cross(abs,acs);
abs.normalize();
abs.cross(acs);
abs.func_229194_d_();
faceNormal = abs;
}
@ -419,8 +419,8 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
builder.setTexture(texture);
builder.setApplyDiffuseLighting(!isFullbright);
int fakeLight = (int)((ambientColor.x + ambientColor.y + ambientColor.z) * 15 / 3.0f);
Vector2f uv2 = new Vector2f(((float) fakeLight * 0x20) / 0xFFFF, ((float) fakeLight * 0x20) / 0xFFFF);
int fakeLight = (int)((ambientColor.getX() + ambientColor.getY() + ambientColor.getZ()) * 15 / 3.0f);
Vec2f uv2 = new Vec2f(((float) fakeLight * 0x20) / 0xFFFF, ((float) fakeLight * 0x20) / 0xFFFF);
boolean hasTransform = !transform.isIdentity();
TransformationMatrix transformation = hasTransform ? transform : null;
@ -429,15 +429,15 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
{
int[] index = indices[Math.min(i,indices.length-1)];
Vector3f pos0 = positions.get(index[0]);
Vector4f position = new Vector4f(pos0.x, pos0.y, pos0.z, 1);
Vector2f texCoord = index.length >= 2 && texCoords.size() > 0 ? texCoords.get(index[1]) : DEFAULT_COORDS[i];
Vector4f position = new Vector4f(pos0.getX(), pos0.getY(), pos0.getZ(), 1);
Vec2f texCoord = index.length >= 2 && texCoords.size() > 0 ? texCoords.get(index[1]) : DEFAULT_COORDS[i];
Vector3f norm0 = !needsNormalRecalculation && index.length >= 3 && normals.size() > 0 ? normals.get(index[2]) : faceNormal;
Vector3f normal = norm0;
Vector4f color = index.length >= 4 && colors.size() > 0 ? colors.get(index[3]) : new Vector4f(1, 1, 1, 1);
if (hasTransform)
{
normal = new Vector3f(norm0);
transformation.transformPosition(TransformationHelper.toMojang(position));
normal = norm0.func_229195_e_();
transformation.transformPosition(position);
transformation.transformNormal(normal);
};
Vector4f tintedColor = new Vector4f(
@ -450,7 +450,7 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
norm[i] = normal;
}
builder.setQuadOrientation(Direction.getFacingFromVector(norm[0].x, norm[0].y,norm[0].z));
builder.setQuadOrientation(Direction.getFacingFromVector(norm[0].getX(), norm[0].getY(),norm[0].getZ()));
Direction cull = null;
if (detectCullableFaces)
@ -508,7 +508,7 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
return Pair.of(builder.build(), cull);
}
private void putVertexData(IVertexConsumer consumer, VertexFormat format, Vector4f position0, Vector2f texCoord0, Vector3f normal0, Vector4f color0, Vector2f uv2, TextureAtlasSprite texture)
private void putVertexData(IVertexConsumer consumer, VertexFormat format, Vector4f position0, Vec2f texCoord0, Vector3f normal0, Vector4f color0, Vec2f uv2, TextureAtlasSprite texture)
{
ImmutableList<VertexFormatElement> elements = format.func_227894_c_();
for(int j=0;j<elements.size();j++)
@ -527,8 +527,8 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
{
case 0:
consumer.put(j,
texture.getInterpolatedU(texCoord0.getX() * 16),
texture.getInterpolatedV((flipV ? (1 - texCoord0.getY()) : texCoord0.getY()) * 16)
texture.getInterpolatedU(texCoord0.x * 16),
texture.getInterpolatedV((flipV ? (1 - texCoord0.y) : texCoord0.y) * 16)
);
break;
case 1:
@ -675,7 +675,7 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
public boolean isFullbright()
{
return mat != null && mat.ambientColor.epsilonEquals(new Vector4f(1,1,1,1), 1/256f);
return mat != null && TransformationHelper.epsilonEquals(mat.ambientColor, new Vector4f(1,1,1,1), 1/256f);
}
}

View File

@ -20,10 +20,9 @@
package net.minecraftforge.client.model.pipeline;
import net.minecraft.client.renderer.TransformationMatrix;
import net.minecraft.client.renderer.Vector3f;
import net.minecraft.client.renderer.Vector4f;
import javax.vecmath.Vector3f;
public class TRSRTransformer extends VertexTransformer
{
private final TransformationMatrix transform;
@ -40,14 +39,19 @@ public class TRSRTransformer extends VertexTransformer
switch (getVertexFormat().func_227894_c_().get(element).getUsage())
{
case POSITION:
Vector4f pos = new Vector4f(data);
Vector4f pos = new Vector4f(data[0], data[1], data[2], data[3]);
transform.transformPosition(pos);
pos.write(data);
data[0] = pos.getX();
data[1] = pos.getY();
data[2] = pos.getZ();
data[3] = pos.getW();
break;
case NORMAL:
Vector3f normal = new Vector3f(data);
transform.transformNormal(normal);
normal.get(data);
data[0] = normal.getX();
data[1] = normal.getY();
data[2] = normal.getZ();
break;
}
super.put(element, data);

View File

@ -19,12 +19,11 @@
package net.minecraftforge.client.model.pipeline;
import javax.vecmath.Vector3f;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.Vector3f;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
@ -153,13 +152,13 @@ public class VertexLighterFlat extends QuadGatheringTransformer
v1.sub(t);
t.set(position[0]);
v2.sub(t);
v1.cross(v2, v1);
v1.normalize();
v2.cross(v1);
v2.func_229194_d_();
for(int v = 0; v < 4; v++)
{
normal[v][0] = v1.x;
normal[v][1] = v1.y;
normal[v][2] = v1.z;
normal[v][0] = v2.getX();
normal[v][1] = v2.getY();
normal[v][2] = v2.getZ();
normal[v][3] = 0;
}
}

View File

@ -23,22 +23,16 @@ import java.lang.reflect.Type;
import java.util.EnumMap;
import java.util.Map;
import javax.annotation.Nullable;
import com.google.gson.*;
import net.minecraft.client.renderer.*;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import net.minecraft.util.math.MathHelper;
import com.google.common.collect.Maps;
import net.minecraft.client.renderer.model.ItemTransformVec3f;
import net.minecraft.client.renderer.model.ModelRotation;
import net.minecraft.util.Direction;
import net.minecraft.util.math.Vec3i;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.ForgeHooksClient;
public final class TransformationHelper
{
@ -51,132 +45,11 @@ public final class TransformationHelper
return new TransformationMatrix(transform.translation, quatFromXYZ(transform.rotation, true), transform.scale, null);
}
public static void transform(Matrix4f matrix, Vector4f vector)
{
javax.vecmath.Vector4f copy = toVecmath(vector);
toVecmath(matrix).transform(copy);
vector.set(copy.x, copy.y, copy.z, copy.w);
}
public static Quaternion quatFromXYZ(Vector3f xyz, boolean degrees)
{
return new Quaternion(xyz.getX(), xyz.getY(), xyz.getZ(), degrees);
}
public static Direction rotate(Matrix4f matrix, Direction facing)
{
Vec3i dir = facing.getDirectionVec();
javax.vecmath.Vector4f vec = new javax.vecmath.Vector4f(dir.getX(), dir.getY(), dir.getZ(), 0);
toVecmath(matrix).transform(vec);
return Direction.getFacingFromVector(vec.x, vec.y, vec.z);
}
/**
* convert transformation from assuming center-block system to corner-block system
*/
public static TransformationMatrix blockCenterToCorner(TransformationMatrix transform)
{
if (transform.isIdentity()) return TransformationMatrix.func_227983_a_();
javax.vecmath.Matrix4f ret = toVecmath(transform.func_227988_c_()), tmp = new javax.vecmath.Matrix4f();
tmp.setIdentity();
tmp.m03 = tmp.m13 = tmp.m23 = .5f;
ret.mul(tmp, ret);
tmp.m03 = tmp.m13 = tmp.m23 = -.5f;
ret.mul(tmp);
return new TransformationMatrix(toMojang(ret));
}
/**
* convert transformation from assuming corner-block system to center-block system
*/
public static TransformationMatrix blockCornerToCenter(TransformationMatrix transform)
{
if (transform.isIdentity()) return TransformationMatrix.func_227983_a_();
javax.vecmath.Matrix4f ret = toVecmath(transform.func_227988_c_()), tmp = new javax.vecmath.Matrix4f();
tmp.setIdentity();
tmp.m03 = tmp.m13 = tmp.m23 = -.5f;
ret.mul(tmp, ret);
tmp.m03 = tmp.m13 = tmp.m23 = .5f;
ret.mul(tmp);
return new TransformationMatrix(toMojang(ret));
}
@OnlyIn(Dist.CLIENT)
public static javax.vecmath.Vector3f toVecmath(Vector3f vec)
{
return new javax.vecmath.Vector3f(vec.getX(), vec.getY(), vec.getZ());
}
@OnlyIn(Dist.CLIENT)
public static javax.vecmath.Vector4f toVecmath(Vector4f vec)
{
return new javax.vecmath.Vector4f(vec.getX(), vec.getY(), vec.getZ(), vec.getW());
}
@OnlyIn(Dist.CLIENT)
public static javax.vecmath.Matrix4f toVecmath(Matrix4f m)
{
float[] all = new float[16];
m.write(all);
return new javax.vecmath.Matrix4f(all);
}
public static javax.vecmath.Quat4f toVecmath(Quaternion q)
{
return new javax.vecmath.Quat4f(q.getX(), q.getY(), q.getZ(), q.getW());
}
public static Quaternion toMojang(javax.vecmath.Quat4f q)
{
return new Quaternion(q.getX(), q.getY(), q.getZ(), q.getW());
}
@OnlyIn(Dist.CLIENT)
public static Vector3f toMojang(javax.vecmath.Vector3f vec)
{
return new Vector3f(vec.x, vec.y, vec.z);
}
@OnlyIn(Dist.CLIENT)
public static Vector4f toMojang(javax.vecmath.Vector4f vec)
{
return new Vector4f(vec.x, vec.y, vec.z, vec.w);
}
@OnlyIn(Dist.CLIENT)
public static Matrix4f toMojang(javax.vecmath.Matrix4f m)
{
Matrix4f r = new Matrix4f();
float[] row = new float[4];
float[] all = new float[16];
for (int x = 0; x < 4; x++)
{
m.getRow(x, row);
for (int y = 0; y < 4; y++)
{
all[y*4+x] = row[y];
}
}
r.set(all);
return r;
}
public static javax.vecmath.Vector3f lerp(javax.vecmath.Tuple3f from, javax.vecmath.Tuple3f to, float progress)
{
javax.vecmath.Vector3f res = new javax.vecmath.Vector3f(from);
res.interpolate(from, to, progress);
return res;
}
public static javax.vecmath.Vector4f lerp(javax.vecmath.Tuple4f from, javax.vecmath.Tuple4f to, float progress)
{
javax.vecmath.Vector4f res = new javax.vecmath.Vector4f(from);
res.interpolate(from, to, progress);
return res;
}
public static Vector3f lerp(Vector3f from, Vector3f to, float progress)
{
Vector3f res = from.func_229195_e_();
@ -184,11 +57,49 @@ public final class TransformationHelper
return res;
}
public static Quaternion slerp(Quaternion from, Quaternion to, float progress)
private static final double THRESHOLD = 0.9995;
private static Quaternion slerp(Quaternion v0, Quaternion v1, float t)
{
javax.vecmath.Quat4f res = new javax.vecmath.Quat4f();
res.interpolate(toVecmath(from), toVecmath(to), progress);
return toMojang(res);
// From https://en.wikipedia.org/w/index.php?title=Slerp&oldid=928959428
// License: CC BY-SA 3.0 https://creativecommons.org/licenses/by-sa/3.0/
// Compute the cosine of the angle between the two vectors.
// If the dot product is negative, slerp won't take
// the shorter path. Note that v1 and -v1 are equivalent when
// the negation is applied to all four components. Fix by
// reversing one quaternion.
float dot = v0.getX() * v1.getX() + v0.getY() * v1.getY() + v0.getZ() * v1.getZ() + v0.getW() * v1.getW();
if (dot < 0.0f) {
v1 = new Quaternion(-v1.getX(), -v1.getY(), -v1.getZ(), -v1.getW());
dot = -dot;
}
// If the inputs are too close for comfort, linearly interpolate
// and normalize the result.
if (dot > THRESHOLD) {
float x = MathHelper.lerp(t, v0.getX(), v1.getX());
float y = MathHelper.lerp(t, v0.getY(), v1.getY());
float z = MathHelper.lerp(t, v0.getZ(), v1.getZ());
float w = MathHelper.lerp(t, v0.getW(), v1.getW());
return new Quaternion(x,y,z,w);
}
// Since dot is in range [0, DOT_THRESHOLD], acos is safe
float angle01 = (float)Math.acos(dot);
float angle0t = angle01*t;
float sin0t = MathHelper.sin(angle0t);
float sin01 = MathHelper.sin(angle01);
float sin1t = MathHelper.sin(angle01 - angle0t);
float s1 = sin0t / sin01;
float s0 = sin1t / sin01;
return new Quaternion(
s0 * v0.getX() + s1 * v1.getX(),
s0 * v0.getY() + s1 * v1.getY(),
s0 * v0.getZ() + s1 * v1.getZ(),
s0 * v0.getW() + s1 * v1.getW()
);
}
public static TransformationMatrix slerp(TransformationMatrix one, TransformationMatrix that, float progress)
@ -207,17 +118,16 @@ public final class TransformationHelper
static
{
vanillaUvTransformLocalToGlobal.put(Direction.SOUTH, TransformationMatrix.func_227983_a_());
javax.vecmath.Quat4f tmp = new javax.vecmath.Quat4f();
tmp.set(new javax.vecmath.AxisAngle4f(0, 1, 0, (float)Math.toRadians(90)));
vanillaUvTransformLocalToGlobal.put(Direction.EAST, new TransformationMatrix(null, toMojang(tmp), null, null));
tmp.set(new javax.vecmath.AxisAngle4f(0, 1, 0, (float)Math.toRadians(-90)));
vanillaUvTransformLocalToGlobal.put(Direction.WEST, new TransformationMatrix(null, toMojang(tmp), null, null));
tmp.set(new javax.vecmath.AxisAngle4f(0, 1, 0, (float)Math.toRadians(180)));
vanillaUvTransformLocalToGlobal.put(Direction.NORTH, new TransformationMatrix(null, toMojang(tmp), null, null));
tmp.set(new javax.vecmath.AxisAngle4f(1, 0, 0, (float)Math.toRadians(-90)));
vanillaUvTransformLocalToGlobal.put(Direction.UP, new TransformationMatrix(null, toMojang(tmp), null, null));
tmp.set(new javax.vecmath.AxisAngle4f(1, 0, 0, (float)Math.toRadians(90)));
vanillaUvTransformLocalToGlobal.put(Direction.DOWN, new TransformationMatrix(null, toMojang(tmp), null, null));
vanillaUvTransformLocalToGlobal.put(Direction.EAST, new TransformationMatrix(null,
new Quaternion(Vector3f.field_229181_d_, 90,true), null, null));
vanillaUvTransformLocalToGlobal.put(Direction.WEST, new TransformationMatrix(null,
new Quaternion(Vector3f.field_229181_d_, -90,true), null, null));
vanillaUvTransformLocalToGlobal.put(Direction.NORTH, new TransformationMatrix(null,
new Quaternion(Vector3f.field_229181_d_, 180,true), null, null));
vanillaUvTransformLocalToGlobal.put(Direction.UP, new TransformationMatrix(null,
new Quaternion(Vector3f.field_229179_b_, -90,true), null, null));
vanillaUvTransformLocalToGlobal.put(Direction.DOWN, new TransformationMatrix(null,
new Quaternion(Vector3f.field_229179_b_, 90,true), null, null));
for(Direction side : Direction.values())
{
@ -225,27 +135,26 @@ public final class TransformationHelper
}
}
public static TransformationMatrix getVanillaUvTransformLocalToGlobal(Direction side)
{
return vanillaUvTransformLocalToGlobal.get(side);
}
public static TransformationMatrix getVanillaUvTransformGlobalToLocal(Direction side)
{
return vanillaUvTransformGlobalToLocal.get(side);
}
public static TransformationMatrix getUVLockTransform(TransformationMatrix matrix, Direction originalSide)
{
Direction newSide = matrix.rotateTransform(originalSide);
try
{
return blockCenterToCorner(vanillaUvTransformGlobalToLocal.get(originalSide).compose(blockCornerToCenter(matrix.inverse())).compose(vanillaUvTransformLocalToGlobal.get(newSide)));
}
catch(javax.vecmath.SingularMatrixException e)
{
return new TransformationMatrix(null, null, new Vector3f(0, 0, 0), null);
}
return vanillaUvTransformGlobalToLocal.get(originalSide)
.compose(matrix.inverse().blockCornerToCenter())
.compose(vanillaUvTransformLocalToGlobal.get(newSide))
.blockCenterToCorner();
}
public static boolean epsilonEquals(Vector4f v1, Vector4f v2, float epsilon)
{
return MathHelper.abs(v1.getX()-v2.getX()) < epsilon &&
MathHelper.abs(v1.getY()-v2.getY()) < epsilon &&
MathHelper.abs(v1.getZ()-v2.getZ()) < epsilon &&
MathHelper.abs(v1.getW()-v2.getW()) < epsilon;
}
public static Quaternion makeQuaternion(float[] values)
{
return new Quaternion(values[0], values[1], values[2], values[3]);
}
public static class Deserializer implements JsonDeserializer<TransformationMatrix>
@ -332,7 +241,7 @@ public final class TransformationHelper
if (!e.isJsonArray()) throw new JsonParseException("Matrix: expected an array, got: " + e);
JsonArray m = e.getAsJsonArray();
if (m.size() != 3) throw new JsonParseException("Matrix: expected an array of length 3, got: " + m.size());
javax.vecmath.Matrix4f ret = new javax.vecmath.Matrix4f();
float[] values = new float[16];
for (int i = 0; i < 3; i++)
{
if (!m.get(i).isJsonArray()) throw new JsonParseException("Matrix row: expected an array, got: " + m.get(i));
@ -342,7 +251,7 @@ public final class TransformationHelper
{
try
{
ret.setElement(i, j, r.get(j).getAsNumber().floatValue());
values[j*4+i] = r.get(j).getAsNumber().floatValue();
}
catch (ClassCastException ex)
{
@ -350,7 +259,7 @@ public final class TransformationHelper
}
}
}
return toMojang(ret);
return new Matrix4f(values);
}
public static float[] parseFloatArray(JsonElement e, int length, String prefix)
@ -422,7 +331,7 @@ public final class TransformationHelper
if (array.size() == 3) //Vanilla rotation
return quatFromXYZ(new Vector3f(parseFloatArray(e, 3, "Rotation")), true);
else // quaternion
return new Quaternion(parseFloatArray(e, 4, "Rotation"));
return makeQuaternion(parseFloatArray(e, 4, "Rotation"));
}
else throw new JsonParseException("Rotation: expected array or object, got: " + e);
}

View File

@ -26,12 +26,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javax.vecmath.AxisAngle4d;
import javax.vecmath.Matrix4f;
import javax.vecmath.Quat4f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector4f;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;