Reduce memory usage of model transforms (#4753)

This commit is contained in:
Ben Staddon 2018-04-01 08:24:37 +01:00 committed by LexManos
parent fb61505d35
commit 0b5a6a3b03
12 changed files with 183 additions and 99 deletions

View file

@ -14,8 +14,8 @@
}
}
+
+ public java.util.Optional<net.minecraftforge.common.model.TRSRTransformation> apply(java.util.Optional<? extends net.minecraftforge.common.model.IModelPart> part) { return net.minecraftforge.client.ForgeHooksClient.applyTransform(getMatrix(), part); }
+ public javax.vecmath.Matrix4f getMatrix() { return net.minecraftforge.client.ForgeHooksClient.getMatrix(this); }
+ public java.util.Optional<net.minecraftforge.common.model.TRSRTransformation> apply(java.util.Optional<? extends net.minecraftforge.common.model.IModelPart> part) { return net.minecraftforge.client.ForgeHooksClient.applyTransform(this, part); }
+ public javax.vecmath.Matrix4f getMatrix() { return net.minecraftforge.common.model.TRSRTransformation.from(this).getMatrix(); }
+ 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

@ -57,6 +57,7 @@ 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;
@ -76,7 +77,6 @@ import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.HorseArmorType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
@ -388,7 +388,7 @@ public class ForgeHooksClient
}
@SuppressWarnings("deprecation")
public static Matrix4f getMatrix(net.minecraft.client.renderer.block.model.ItemTransformVec3f transform)
public static Matrix4f getMatrix(ItemTransformVec3f transform)
{
javax.vecmath.Matrix4f m = new javax.vecmath.Matrix4f(), t = new javax.vecmath.Matrix4f();
m.setIdentity();
@ -627,10 +627,16 @@ public class ForgeHooksClient
}
@SuppressWarnings("deprecation")
public static Optional<TRSRTransformation> applyTransform(net.minecraft.client.renderer.block.model.ItemTransformVec3f transform, Optional<? extends IModelPart> part)
public static Optional<TRSRTransformation> applyTransform(ItemTransformVec3f transform, Optional<? extends IModelPart> part)
{
if(part.isPresent()) return Optional.empty();
return Optional.of(TRSRTransformation.blockCenterToCorner(new TRSRTransformation(transform)));
return Optional.of(TRSRTransformation.blockCenterToCorner(TRSRTransformation.from(transform)));
}
public static Optional<TRSRTransformation> applyTransform(ModelRotation rotation, Optional<? extends IModelPart> part)
{
if(part.isPresent()) return Optional.empty();
return Optional.of(TRSRTransformation.from(rotation));
}
public static Optional<TRSRTransformation> applyTransform(Matrix4f matrix, Optional<? extends IModelPart> part)
@ -746,9 +752,9 @@ public class ForgeHooksClient
@SuppressWarnings("deprecation")
public static Pair<? extends IBakedModel,Matrix4f> handlePerspective(IBakedModel model, ItemCameraTransforms.TransformType type)
{
TRSRTransformation tr = new TRSRTransformation(model.getItemCameraTransforms().getTransform(type));
TRSRTransformation tr = TRSRTransformation.from(model.getItemCameraTransforms().getTransform(type));
Matrix4f mat = null;
if(!tr.equals(TRSRTransformation.identity())) mat = tr.getMatrix();
if (!tr.isIdentity()) mat = tr.getMatrix();
return Pair.of(model, mat);
}

View file

@ -55,7 +55,7 @@ public class BakedItemModel implements IBakedModel
private static boolean hasGuiIdentity(ImmutableMap<TransformType, TRSRTransformation> transforms)
{
TRSRTransformation guiTransform = transforms.get(TransformType.GUI);
return guiTransform == null || guiTransform.equals(TRSRTransformation.identity());
return guiTransform == null || guiTransform.isIdentity();
}
@Override public boolean isAmbientOcclusion() { return true; }

View file

@ -94,8 +94,8 @@ public class BlockStateLoader
boolean gui3d = var.getGui3d().orElse(true);
int weight = var.getWeight().orElse(1);
if (var.getModel() != null && var.getSubmodels().size() == 0 && var.getTextures().size() == 0 && var.getCustomData().size() == 0 && var.getState().orElse(null) instanceof ModelRotation)
mcVars.add(new Variant(var.getModel(), (ModelRotation)var.getState().get(), uvLock, weight));
if (var.getModel() != null && var.getSubmodels().size() == 0 && var.getTextures().size() == 0 && var.getCustomData().size() == 0 && var.getState().orElse(ModelRotation.X0_Y0) instanceof ModelRotation)
mcVars.add(new Variant(var.getModel(), (ModelRotation)var.getState().orElse(ModelRotation.X0_Y0), uvLock, weight));
else
mcVars.add(new ForgeVariant(location, var.getModel(), var.getState().orElse(TRSRTransformation.identity()), uvLock, smooth, gui3d, weight, var.getTextures(), var.getOnlyPartsVariant(), var.getCustomData()));
}

View file

@ -467,6 +467,61 @@ public class ForgeBlockStateV1 extends Marker
return TRSRTransformation.blockCenterToCorner(flipX.compose(TRSRTransformation.blockCornerToCenter(transform)).compose(flipX));
}
// Note: these strings might change to a full-blown resource locations in the future, and move from here to some json somewhere
// TODO: vanilla now includes from parent, deprecate?
private static final ImmutableMap<String, IModelState> transforms;
static
{
ImmutableMap.Builder<String, IModelState> builder = ImmutableMap.builder();
builder.put("identity", TRSRTransformation.identity());
// block/block
{
EnumMap<TransformType, TRSRTransformation> map = new EnumMap<>(TransformType.class);
TRSRTransformation thirdperson = get(0, 2.5f, 0, 75, 45, 0, 0.375f);
map.put(TransformType.GUI, get(0, 0, 0, 30, 225, 0, 0.625f));
map.put(TransformType.GROUND, get(0, 3, 0, 0, 0, 0, 0.25f));
map.put(TransformType.FIXED, get(0, 0, 0, 0, 0, 0, 0.5f));
map.put(TransformType.THIRD_PERSON_RIGHT_HAND, thirdperson);
map.put(TransformType.THIRD_PERSON_LEFT_HAND, leftify(thirdperson));
map.put(TransformType.FIRST_PERSON_RIGHT_HAND, get(0, 0, 0, 0, 45, 0, 0.4f));
map.put(TransformType.FIRST_PERSON_LEFT_HAND, get(0, 0, 0, 0, 225, 0, 0.4f));
builder.put("forge:default-block", new SimpleModelState(ImmutableMap.copyOf(map)));
}
// item/generated
{
EnumMap<TransformType, TRSRTransformation> map = new EnumMap<>(TransformType.class);
TRSRTransformation thirdperson = get(0, 3, 1, 0, 0, 0, 0.55f);
TRSRTransformation firstperson = get(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f);
map.put(TransformType.GROUND, get(0, 2, 0, 0, 0, 0, 0.5f));
map.put(TransformType.HEAD, get(0, 13, 7, 0, 180, 0, 1));
map.put(TransformType.THIRD_PERSON_RIGHT_HAND, thirdperson);
map.put(TransformType.THIRD_PERSON_LEFT_HAND, leftify(thirdperson));
map.put(TransformType.FIRST_PERSON_RIGHT_HAND, firstperson);
map.put(TransformType.FIRST_PERSON_LEFT_HAND, leftify(firstperson));
map.put(TransformType.FIXED, get(0, 0, 0, 0, 180, 0, 1));
builder.put("forge:default-item", new SimpleModelState(ImmutableMap.copyOf(map)));
}
// item/handheld
{
EnumMap<TransformType, TRSRTransformation> map = new EnumMap<>(TransformType.class);
map.put(TransformType.GROUND, get(0, 2, 0, 0, 0, 0, 0.5f));
map.put(TransformType.HEAD, get(0, 13, 7, 0, 180, 0, 1));
map.put(TransformType.THIRD_PERSON_RIGHT_HAND, get(0, 4, 0.5f, 0, -90, 55, 0.85f));
map.put(TransformType.THIRD_PERSON_LEFT_HAND, get(0, 4, 0.5f, 0, 90, -55, 0.85f));
map.put(TransformType.FIRST_PERSON_RIGHT_HAND, get(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f));
map.put(TransformType.FIRST_PERSON_LEFT_HAND, get(1.13f, 3.2f, 1.13f, 0, 90, -25, 0.68f));
map.put(TransformType.FIXED, get(0, 0, 0, 0, 180, 0, 1));
builder.put("forge:default-tool", new SimpleModelState(ImmutableMap.copyOf(map)));
}
transforms = builder.build();
}
@Override
public ForgeBlockStateV1.Variant deserialize(JsonElement element, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
@ -497,7 +552,7 @@ public class ForgeBlockStateV1 extends Marker
{ // Load rotation values.
int x = JsonUtils.getInt(json, "x", 0);
int y = JsonUtils.getInt(json, "y", 0);
ret.state = Optional.of(new TRSRTransformation(ModelRotation.getModelRotation(x, y)));
ret.state = Optional.ofNullable(ModelRotation.getModelRotation(x, y));
if (!ret.state.isPresent())
throw new JsonParseException("Invalid BlockModelRotation x: " + x + " y: " + y);
}
@ -507,51 +562,8 @@ public class ForgeBlockStateV1 extends Marker
if (json.get("transform").isJsonPrimitive() && json.get("transform").getAsJsonPrimitive().isString())
{
String transform = json.get("transform").getAsString();
// Note: these strings might change to a full-blown resource locations in the future, and move from here to some json somewhere
// TODO: vanilla now includes from parent, deprecate?
if (transform.equals("identity"))
{
ret.state = Optional.of(TRSRTransformation.identity());
}
// block/block
else if (transform.equals("forge:default-block"))
{
TRSRTransformation thirdperson = get(0, 2.5f, 0, 75, 45, 0, 0.375f);
ImmutableMap.Builder<TransformType, TRSRTransformation> builder = ImmutableMap.builder();
builder.put(TransformType.GUI, get(0, 0, 0, 30, 225, 0, 0.625f));
builder.put(TransformType.GROUND, get(0, 3, 0, 0, 0, 0, 0.25f));
builder.put(TransformType.FIXED, get(0, 0, 0, 0, 0, 0, 0.5f));
builder.put(TransformType.THIRD_PERSON_RIGHT_HAND, thirdperson);
builder.put(TransformType.THIRD_PERSON_LEFT_HAND, leftify(thirdperson));
builder.put(TransformType.FIRST_PERSON_RIGHT_HAND, get(0, 0, 0, 0, 45, 0, 0.4f));
builder.put(TransformType.FIRST_PERSON_LEFT_HAND, get(0, 0, 0, 0, 225, 0, 0.4f));
ret.state = Optional.of(new SimpleModelState(builder.build()));
}
// item/generated
else if (transform.equals("forge:default-item"))
{
TRSRTransformation thirdperson = get(0, 3, 1, 0, 0, 0, 0.55f);
TRSRTransformation firstperson = get(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f);
ImmutableMap.Builder<TransformType, TRSRTransformation> builder = ImmutableMap.builder();
builder.put(TransformType.GROUND, get(0, 2, 0, 0, 0, 0, 0.5f));
builder.put(TransformType.HEAD, get(0, 13, 7, 0, 180, 0, 1));
builder.put(TransformType.THIRD_PERSON_RIGHT_HAND, thirdperson);
builder.put(TransformType.THIRD_PERSON_LEFT_HAND, leftify(thirdperson));
builder.put(TransformType.FIRST_PERSON_RIGHT_HAND, firstperson);
builder.put(TransformType.FIRST_PERSON_LEFT_HAND, leftify(firstperson));
builder.put(TransformType.FIXED, get(0, 0, 0, 0, 180, 0, 1));
ret.state = Optional.of(new SimpleModelState(builder.build()));
}
// item/handheld
else if (transform.equals("forge:default-tool"))
{
ret.state = Optional.of(new SimpleModelState(ImmutableMap.of(
TransformType.THIRD_PERSON_RIGHT_HAND, get(0, 4, 0.5f, 0, -90, 55, 0.85f),
TransformType.THIRD_PERSON_LEFT_HAND, get(0, 4, 0.5f, 0, 90, -55, 0.85f),
TransformType.FIRST_PERSON_RIGHT_HAND, get(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f),
TransformType.FIRST_PERSON_LEFT_HAND, get(1.13f, 3.2f, 1.13f, 0, 90, -25, 0.68f))));
}
else
ret.state = Optional.ofNullable(transforms.get(transform));
if (!ret.state.isPresent())
{
throw new JsonParseException("transform: unknown default string: " + transform);
}

View file

@ -268,7 +268,7 @@ public final class ItemTextureQuadConverter
switch (format.getElement(e).getUsage())
{
case POSITION:
if (transform == TRSRTransformation.identity())
if (transform.isIdentity())
{
builder.put(e, x, y, z, 1);
}

View file

@ -322,7 +322,7 @@ public final class ModelFluid implements IModel
{
case POSITION:
float[] data = new float[]{ x - side.getDirectionVec().getX() * eps, y, z - side.getDirectionVec().getZ() * eps, 1 };
if(transformation.isPresent() && transformation.get() != TRSRTransformation.identity())
if(transformation.isPresent() && !transformation.get().isIdentity())
{
Vector4f vec = new Vector4f(data);
transformation.get().getMatrix().transform(vec);

View file

@ -461,7 +461,7 @@ public final class ModelLoader extends ModelBakery
}
ItemCameraTransforms transforms = model.getAllTransforms();
Map<TransformType, TRSRTransformation> tMap = Maps.newHashMap();
Map<TransformType, TRSRTransformation> tMap = Maps.newEnumMap(TransformType.class);
tMap.putAll(PerspectiveMapWrapper.getTransforms(transforms));
tMap.putAll(PerspectiveMapWrapper.getTransforms(state));
IModelState perState = new SimpleModelState(ImmutableMap.copyOf(tMap));

View file

@ -20,6 +20,7 @@
package net.minecraftforge.client.model;
import java.util.Collection;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -47,7 +48,6 @@ import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.fml.common.FMLLog;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.Level;
import java.util.function.Function;
import java.util.Optional;
@ -129,14 +129,18 @@ public final class MultiModel implements IModel
// Only changes the base model based on perspective, may recurse for parts in the future.
if(base != null && perspective)
{
ImmutableMap.Builder<TransformType, Pair<Baked, TRSRTransformation>> builder = ImmutableMap.builder();
EnumMap<TransformType, Pair<Baked, TRSRTransformation>> map = new EnumMap<>(TransformType.class);
for(TransformType type : TransformType.values())
{
Pair<? extends IBakedModel, Matrix4f> p = base.handlePerspective(type);
IBakedModel newBase = p.getLeft();
builder.put(type, Pair.of(new Baked(location, false, newBase, parts), new TRSRTransformation(p.getRight())));
Matrix4f matrix = p.getRight();
if (newBase != base || matrix != null)
{
map.put(type, Pair.of(new Baked(location, false, newBase, parts), new TRSRTransformation(matrix)));
}
}
transforms = builder.build();
transforms = ImmutableMap.copyOf(map);
}
else
{
@ -212,8 +216,8 @@ public final class MultiModel implements IModel
@Override
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
{
if(transforms.isEmpty()) return Pair.of(this, null);
Pair<Baked, TRSRTransformation> p = transforms.get(cameraTransformType);
if (p == null) return Pair.of(this, null);
return Pair.of(p.getLeft(), p.getRight().getMatrix());
}

View file

@ -1,5 +1,6 @@
package net.minecraftforge.client.model;
import java.util.EnumMap;
import java.util.Optional;
import com.google.common.collect.ImmutableMap;
import net.minecraft.block.state.IBlockState;
@ -35,41 +36,46 @@ public class PerspectiveMapWrapper implements IBakedModel
public static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> getTransforms(IModelState state)
{
ImmutableMap.Builder<ItemCameraTransforms.TransformType, TRSRTransformation> builder = ImmutableMap.builder();
EnumMap<ItemCameraTransforms.TransformType, TRSRTransformation> map = new EnumMap<>(ItemCameraTransforms.TransformType.class);
for(ItemCameraTransforms.TransformType type : ItemCameraTransforms.TransformType.values())
{
Optional<TRSRTransformation> tr = state.apply(Optional.of(type));
if(tr.isPresent())
{
builder.put(type, tr.get());
map.put(type, tr.get());
}
}
return builder.build();
return ImmutableMap.copyOf(map);
}
@SuppressWarnings("deprecation")
public static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> getTransforms(ItemCameraTransforms transforms)
{
ImmutableMap.Builder<ItemCameraTransforms.TransformType, TRSRTransformation> builder = ImmutableMap.builder();
EnumMap<ItemCameraTransforms.TransformType, TRSRTransformation> map = new EnumMap<>(ItemCameraTransforms.TransformType.class);
for(ItemCameraTransforms.TransformType type : ItemCameraTransforms.TransformType.values())
{
builder.put(type, TRSRTransformation.blockCenterToCorner(new TRSRTransformation(transforms.getTransform(type))));
if (transforms.hasCustomTransform(type))
{
map.put(type, TRSRTransformation.blockCenterToCorner(TRSRTransformation.from(transforms.getTransform(type))));
}
}
return builder.build();
return ImmutableMap.copyOf(map);
}
public static Pair<? extends IBakedModel, Matrix4f> handlePerspective(IBakedModel model, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms, ItemCameraTransforms.TransformType cameraTransformType)
{
TRSRTransformation tr = transforms.get(cameraTransformType);
Matrix4f mat = null;
if(tr != null && !tr.equals(TRSRTransformation.identity())) mat = TRSRTransformation.blockCornerToCenter(tr).getMatrix();
return Pair.of(model, mat);
TRSRTransformation tr = transforms.getOrDefault(cameraTransformType, TRSRTransformation.identity());
if (!tr.isIdentity())
{
return Pair.of(model, TRSRTransformation.blockCornerToCenter(tr).getMatrix());
}
return Pair.of(model, null);
}
public static Pair<? extends IBakedModel, Matrix4f> handlePerspective(IBakedModel model, IModelState state, ItemCameraTransforms.TransformType cameraTransformType)
{
TRSRTransformation tr = state.apply(Optional.of(cameraTransformType)).orElse(TRSRTransformation.identity());
if(tr != TRSRTransformation.identity())
if (!tr.isIdentity())
{
return Pair.of(model, TRSRTransformation.blockCornerToCenter(tr).getMatrix());
}

View file

@ -529,7 +529,7 @@ public class ModelBlockAnimation
{
ModelBlockAnimation.MBJoint joint = new ModelBlockAnimation.MBJoint(info.getName());
Optional<TRSRTransformation> trOp = state.apply(Optional.of(joint));
if(trOp.isPresent() && trOp.get() != TRSRTransformation.identity())
if(trOp.isPresent() && !trOp.get().isIdentity())
{
float w = info.getWeights().get(i)[0];
tmp = trOp.get().getMatrix();

View file

@ -20,6 +20,9 @@
package net.minecraftforge.common.model;
import java.util.EnumMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.vecmath.AxisAngle4f;
@ -32,9 +35,11 @@ import javax.vecmath.Tuple4f;
import javax.vecmath.Vector3f;
import javax.vecmath.Vector4f;
import net.minecraft.client.renderer.block.model.ItemTransformVec3f;
import net.minecraft.client.renderer.block.model.ModelRotation;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.Vec3i;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -42,7 +47,6 @@ import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import com.google.common.base.MoreObjects;
import java.util.Optional;
import com.google.common.collect.Maps;
/*
@ -67,7 +71,7 @@ public final class TRSRTransformation implements IModelState, ITransformation
private Vector3f scale;
private Quat4f rightRot;
public TRSRTransformation(Matrix4f matrix)
public TRSRTransformation(@Nullable Matrix4f matrix)
{
if(matrix == null)
{
@ -89,38 +93,68 @@ public final class TRSRTransformation implements IModelState, ITransformation
full = true;
}
@Deprecated
/** @deprecated use {@link #from(ItemTransformVec3f)} */
@Deprecated // TODO: remove / make private
@SideOnly(Side.CLIENT)
public TRSRTransformation(net.minecraft.client.renderer.block.model.ItemTransformVec3f transform)
public TRSRTransformation(ItemTransformVec3f transform)
{
this(toVecmath(transform.translation), quatFromXYZDegrees(toVecmath(transform.rotation)), toVecmath(transform.scale), null);
}
/** @deprecated use {@link #from(ModelRotation)} */
@Deprecated // TODO: remove
@SideOnly(Side.CLIENT)
public TRSRTransformation(ModelRotation rotation)
{
this(rotation.getMatrix());
}
/** @deprecated use {@link #from(EnumFacing)} */
@Deprecated // TODO: remove
@SideOnly(Side.CLIENT)
public TRSRTransformation(EnumFacing facing)
{
this(getMatrix(facing));
}
@Deprecated
@SideOnly(Side.CLIENT)
public static TRSRTransformation from(ItemTransformVec3f transform)
{
return transform.equals(ItemTransformVec3f.DEFAULT) ? identity : new TRSRTransformation(transform);
}
@SideOnly(Side.CLIENT)
public static TRSRTransformation from(ModelRotation rotation)
{
return Cache.get(rotation);
}
@SideOnly(Side.CLIENT)
public static TRSRTransformation from(EnumFacing facing)
{
return Cache.get(getRotation(facing));
}
@SideOnly(Side.CLIENT)
public static Matrix4f getMatrix(EnumFacing facing)
{
switch(facing)
return getRotation(facing).getMatrix();
}
@SideOnly(Side.CLIENT)
public static ModelRotation getRotation(EnumFacing facing)
{
switch (facing)
{
case DOWN: return ModelRotation.X90_Y0.getMatrix();
case UP: return ModelRotation.X270_Y0.getMatrix();
case NORTH: return TRSRTransformation.identity.matrix;
case SOUTH: return ModelRotation.X0_Y180.getMatrix();
case WEST: return ModelRotation.X0_Y270.getMatrix();
case EAST: return ModelRotation.X0_Y90.getMatrix();
default: return new Matrix4f();
case DOWN: return ModelRotation.X90_Y0;
case UP: return ModelRotation.X270_Y0;
case NORTH: return ModelRotation.X0_Y0;
case SOUTH: return ModelRotation.X0_Y180;
case WEST: return ModelRotation.X0_Y270;
case EAST: return ModelRotation.X0_Y90;
}
throw new IllegalArgumentException(String.valueOf(facing));
}
private static final TRSRTransformation identity;
@ -140,6 +174,8 @@ public final class TRSRTransformation implements IModelState, ITransformation
public TRSRTransformation compose(TRSRTransformation b)
{
if (this.isIdentity()) return b;
if (b.isIdentity()) return this;
Matrix4f m = getMatrix();
m.mul(b.getMatrix());
return new TRSRTransformation(m);
@ -147,7 +183,7 @@ public final class TRSRTransformation implements IModelState, ITransformation
public TRSRTransformation inverse()
{
if(this == identity) return this;
if (this.isIdentity()) return this;
Matrix4f m = getMatrix();
m.invert();
return new TRSRTransformation(m);
@ -523,9 +559,14 @@ public final class TRSRTransformation implements IModelState, ITransformation
*/
@Deprecated
@SideOnly(Side.CLIENT)
public net.minecraft.client.renderer.block.model.ItemTransformVec3f toItemTransform()
public ItemTransformVec3f toItemTransform()
{
return new net.minecraft.client.renderer.block.model.ItemTransformVec3f(toLwjgl(toXYZDegrees(getLeftRot())), toLwjgl(getTranslation()), toLwjgl(getScale()));
return new ItemTransformVec3f(toLwjgl(toXYZDegrees(getLeftRot())), toLwjgl(getTranslation()), toLwjgl(getScale()));
}
public boolean isIdentity()
{
return this.equals(identity);
}
@Override
@ -625,6 +666,8 @@ public final class TRSRTransformation implements IModelState, ITransformation
*/
public static TRSRTransformation blockCenterToCorner(TRSRTransformation transform)
{
if (transform.isIdentity()) return transform;
Matrix4f ret = new Matrix4f(transform.getMatrix()), tmp = new Matrix4f();
tmp.setIdentity();
tmp.m03 = tmp.m13 = tmp.m23 = .5f;
@ -639,6 +682,8 @@ public final class TRSRTransformation implements IModelState, ITransformation
*/
public static TRSRTransformation blockCornerToCenter(TRSRTransformation transform)
{
if (transform.isIdentity()) return transform;
Matrix4f ret = new Matrix4f(transform.getMatrix()), tmp = new Matrix4f();
tmp.setIdentity();
tmp.m03 = tmp.m13 = tmp.m23 = -.5f;
@ -653,7 +698,7 @@ public final class TRSRTransformation implements IModelState, ITransformation
{
final int prime = 31;
int result = 1;
result = prime * result + ((matrix == null) ? 0 : matrix.hashCode());
result = prime * result + Objects.hashCode(matrix);
return result;
}
@ -664,12 +709,7 @@ public final class TRSRTransformation implements IModelState, ITransformation
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
TRSRTransformation other = (TRSRTransformation) obj;
if (matrix == null)
{
if (other.matrix != null) return false;
}
else if (!matrix.equals(other.matrix)) return false;
return true;
return Objects.equals(matrix, other.matrix);
}
@SideOnly(Side.CLIENT)
@ -806,4 +846,20 @@ public final class TRSRTransformation implements IModelState, ITransformation
return new TRSRTransformation(null, null, new Vector3f(0, 0, 0), null);
}
}
@SideOnly(Side.CLIENT)
private static final class Cache
{
private static final Map<ModelRotation, TRSRTransformation> rotations = new EnumMap<>(ModelRotation.class);
static
{
rotations.put(ModelRotation.X0_Y0, identity());
}
static TRSRTransformation get(ModelRotation rotation)
{
return rotations.computeIfAbsent(rotation, r -> new TRSRTransformation(ForgeHooksClient.getMatrix(r)));
}
}
}