New batch of Model/rendering fixes:

- PerspectiveMapWrapper did not pass IModelData through to the wrapped model.
- CompositeModel did not store the returned textures from getTextureDependencies.
- VertexFormat used COLOR instead of UV to detect UV presence.
- QuadTransformer would crash due to index out of bounds.
- Small cleanup of TransformationHelper
This commit is contained in:
David Quintana 2019-12-24 13:12:38 +01:00
parent ac61018806
commit e8ce61d4cd
8 changed files with 43 additions and 27 deletions

View File

@ -10,5 +10,5 @@
+ public boolean hasPosition() { return field_177355_b.stream().anyMatch(e -> e.func_177374_g()); }
+ public boolean hasNormal() { return field_177355_b.stream().anyMatch(e -> e.func_177375_c() == VertexFormatElement.Usage.NORMAL); }
+ public boolean hasColor() { return field_177355_b.stream().anyMatch(e -> e.func_177375_c() == VertexFormatElement.Usage.COLOR); }
+ public boolean hasUV(int which) { return field_177355_b.stream().anyMatch(e -> e.func_177375_c() == VertexFormatElement.Usage.COLOR && e.func_177369_e() == which); }
+ public boolean hasUV(int which) { return field_177355_b.stream().anyMatch(e -> e.func_177375_c() == VertexFormatElement.Usage.UV && e.func_177369_e() == which); }
}

View File

@ -33,6 +33,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraft.world.World;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.common.model.TransformationHelper;
import javax.annotation.Nullable;
@ -130,7 +131,10 @@ public class PerspectiveMapWrapper implements IBakedModel
@SuppressWarnings("deprecation")
@Override public ItemCameraTransforms getItemCameraTransforms() { return parent.getItemCameraTransforms(); }
@Override public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) { return parent.getQuads(state, side, rand); }
@Override public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData extraData)
{
return parent.getQuads(state, side, rand, extraData);
}
@Override
public ItemOverrideList getOverrides()

View File

@ -48,9 +48,9 @@ public class QuadTransformer
private void processVertices(int[] inData, int[] outData)
{
// TODO: Extract rotation matrix and fix NORMALs if present.
int stride = format.getIntegerSize();
for (int i=0;i<4;i++)
int count = inData.length / stride;
for (int i=0;i<count;i++)
{
int offset = positionOffset + i * stride;
float x = Float.intBitsToFloat(inData[offset ]);
@ -68,7 +68,7 @@ public class QuadTransformer
if (normalOffset >= 0)
{
for (int i=0;i<4;i++)
for (int i=0;i<count;i++)
{
int offset = normalOffset + i * stride;
int normalIn = inData[offset];

View File

@ -27,7 +27,6 @@ import com.mojang.datafixers.util.Pair;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.model.*;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.resources.IResourceManager;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
@ -84,7 +83,7 @@ public class CompositeModel implements IBakedModel
{
quads.addAll(part.getQuads(state, side, rand, EmptyModelData.INSTANCE));
}
return null;
return quads;
}
@Override
@ -228,7 +227,7 @@ public class CompositeModel implements IBakedModel
Set<Material> textures = new HashSet<>();
for(Submodel part : parts.values())
{
part.getTextureDependencies(owner, modelGetter, missingTextureErrors);
textures.addAll(part.getTextureDependencies(owner, modelGetter, missingTextureErrors));
}
return textures;
}

View File

@ -50,6 +50,16 @@ public final class TransformationHelper
return new Quaternion(xyz.getX(), xyz.getY(), xyz.getZ(), degrees);
}
public static Quaternion quatFromXYZ(float[] xyz, boolean degrees)
{
return new Quaternion(xyz[0], xyz[1], xyz[2], degrees);
}
public static Quaternion makeQuaternion(float[] values)
{
return new Quaternion(values[0], values[1], values[2], values[3]);
}
public static Vector3f lerp(Vector3f from, Vector3f to, float progress)
{
Vector3f res = from.func_229195_e_();
@ -120,11 +130,6 @@ public final class TransformationHelper
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>
{
@Override
@ -261,15 +266,15 @@ public final class TransformationHelper
{
if (entry.getKey().equals("x"))
{
ret = new Quaternion(new Vector3f(1, 0, 0), entry.getValue().getAsNumber().floatValue(), true);
ret = Vector3f.field_229179_b_.func_229187_a_(entry.getValue().getAsNumber().floatValue());
}
else if (entry.getKey().equals("y"))
{
ret = new Quaternion(new Vector3f(0, 1, 0), entry.getValue().getAsNumber().floatValue(), true);
ret = Vector3f.field_229181_d_.func_229187_a_(entry.getValue().getAsNumber().floatValue());
}
else if (entry.getKey().equals("z"))
{
ret = new Quaternion(new Vector3f(0, 0, 1), entry.getValue().getAsNumber().floatValue(), true);
ret = Vector3f.field_229183_f_.func_229187_a_(entry.getValue().getAsNumber().floatValue());
}
else throw new JsonParseException("Axis rotation: expected single axis key, got: " + entry.getKey());
}
@ -286,7 +291,7 @@ public final class TransformationHelper
{
if (e.getAsJsonArray().get(0).isJsonObject())
{
Quaternion ret = new Quaternion(0, 0, 0, 1);
Quaternion ret = Quaternion.field_227060_a_.func_227068_g_();
for (JsonElement a : e.getAsJsonArray())
{
ret.multiply(parseAxisRotation(a));
@ -297,7 +302,7 @@ public final class TransformationHelper
{
JsonArray array = e.getAsJsonArray();
if (array.size() == 3) //Vanilla rotation
return quatFromXYZ(new Vector3f(parseFloatArray(e, 3, "Rotation")), true);
return quatFromXYZ(parseFloatArray(e, 3, "Rotation"), true);
else // quaternion
return makeQuaternion(parseFloatArray(e, 4, "Rotation"));
}

View File

@ -1,8 +1,16 @@
{
"parent": "forge:item/default",
"loader": "forge:obj",
"model": "new_model_loader_test:models/item/sugar_glider.obj",
"ambientToFullbright": true,
"loader": "forge:composite",
"parts": {
"part1": {
"loader": "forge:obj",
"model": "new_model_loader_test:models/item/sugar_glider.obj",
"ambientToFullbright": true,
"textures": {
"qr": "new_model_loader_test:item/qr"
}
}
},
"textures": {
"particle": "block/oak_planks"
},
@ -13,7 +21,7 @@
"scale": [ 1, 1, 1 ]
},
"fixed": {
"rotation": [ 0, 180, 0 ],
"rotation": [ 22, 180, 0 ],
"translation": [ 0, 4, 0],
"scale":[ 1, 1, 1 ]
},

View File

@ -6,7 +6,7 @@ Ks 1.0000 1.0000 1.0000
Tf 0.0000 0.0000 0.0000
d 1.0000
Ns 0
map_Kd block/birch_planks
map_Kd #qr
newmtl New material 001
Ka 0.0000 0.0000 0.0000
@ -15,7 +15,7 @@ Ks 1.0000 1.0000 1.0000
Tf 0.0000 0.0000 0.0000
d 1.0000
Ns 0
map_Kd block/birch_planks
map_Kd #qr
newmtl Default
Ka 0.0000 0.0000 0.0000
@ -24,7 +24,7 @@ Ks 1.0000 1.0000 1.0000
Tf 0.0000 0.0000 0.0000
d 1.0000
Ns 0
map_Kd block/birch_planks
map_Kd #qr
newmtl New material 002
Ka 0.0000 0.0000 0.0000
@ -33,7 +33,7 @@ Ks 1.0000 1.0000 1.0000
Tf 0.0000 0.0000 0.0000
d 1.0000
Ns 0
map_Kd block/birch_planks
map_Kd #qr
newmtl New material 003
Ka 0.0000 0.0000 0.0000
@ -42,5 +42,5 @@ Ks 1.0000 1.0000 1.0000
Tf 0.0000 0.0000 0.0000
d 1.0000
Ns 0
map_Kd block/birch_planks
map_Kd #qr

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 B