First version of updated of ModelLoader, mostly works.

This commit is contained in:
RainWarrior 2016-03-13 12:10:50 +03:00
parent bda688b9b5
commit a799bbad2d
9 changed files with 147 additions and 75 deletions

View File

@ -1,6 +1,13 @@
--- ../src-base/minecraft/net/minecraft/client/renderer/block/model/ModelBakery.java --- ../src-base/minecraft/net/minecraft/client/renderer/block/model/ModelBakery.java
+++ ../src-work/minecraft/net/minecraft/client/renderer/block/model/ModelBakery.java +++ ../src-work/minecraft/net/minecraft/client/renderer/block/model/ModelBakery.java
@@ -132,7 +132,7 @@ @@ -126,13 +126,13 @@
{
try
{
- this.field_177612_i.put(modelresourcelocation, modelblockdefinition.func_188004_c(modelresourcelocation.func_177518_c()));
+ this.func_177569_a(modelblockdefinition, modelresourcelocation);
}
catch (RuntimeException var12)
{ {
if (!modelblockdefinition.func_188002_b()) if (!modelblockdefinition.func_188002_b())
{ {

View File

@ -1,15 +1,14 @@
--- ../src-base/minecraft/net/minecraft/client/renderer/block/model/ModelManager.java --- ../src-base/minecraft/net/minecraft/client/renderer/block/model/ModelManager.java
+++ ../src-work/minecraft/net/minecraft/client/renderer/block/model/ModelManager.java +++ ../src-work/minecraft/net/minecraft/client/renderer/block/model/ModelManager.java
@@ -24,9 +24,11 @@ @@ -24,9 +24,10 @@
public void func_110549_a(IResourceManager p_110549_1_) public void func_110549_a(IResourceManager p_110549_1_)
{ {
- ModelBakery modelbakery = new ModelBakery(p_110549_1_, this.field_174956_b, this.field_174957_c); - ModelBakery modelbakery = new ModelBakery(p_110549_1_, this.field_174956_b, this.field_174957_c);
+ // FIXME: reenable after ModelLoader is fixed + net.minecraftforge.client.model.ModelLoader modelbakery = new net.minecraftforge.client.model.ModelLoader(p_110549_1_, this.field_174956_b, this.field_174957_c);
+ ModelBakery modelbakery = new ModelBakery(p_110549_1_, this.field_174956_b, this.field_174957_c); //new net.minecraftforge.client.model.ModelLoader(resourceManager, this.texMap, this.modelProvider);
this.field_174958_a = modelbakery.func_177570_a(); this.field_174958_a = modelbakery.func_177570_a();
this.field_174955_d = (IBakedModel)this.field_174958_a.func_82594_a(ModelBakery.field_177604_a); this.field_174955_d = (IBakedModel)this.field_174958_a.func_82594_a(ModelBakery.field_177604_a);
+ //net.minecraftforge.client.ForgeHooksClient.onModelBake(this, this.modelRegistry, modelbakery); + net.minecraftforge.client.ForgeHooksClient.onModelBake(this, this.field_174958_a, modelbakery);
this.field_174957_c.func_178124_c(); this.field_174957_c.func_178124_c();
} }

View File

@ -395,13 +395,16 @@ public class ForgeHooksClient
{ {
Pair<? extends IBakedModel, Matrix4f> pair = ((IPerspectiveAwareModel)model).handlePerspective(cameraTransformType); Pair<? extends IBakedModel, Matrix4f> pair = ((IPerspectiveAwareModel)model).handlePerspective(cameraTransformType);
Matrix4f matrix = new Matrix4f(pair.getRight()); if(pair.getRight() != null)
if(leftHandHackery)
{ {
matrix.mul(flipX, matrix); Matrix4f matrix = new Matrix4f(pair.getRight());
matrix.mul(matrix, flipX); if(leftHandHackery)
{
matrix.mul(flipX, matrix);
matrix.mul(matrix, flipX);
}
if(pair.getRight() != null) multiplyCurrentGlMatrix(pair.getRight());
} }
if(pair.getRight() != null) multiplyCurrentGlMatrix(pair.getRight());
return pair.getLeft(); return pair.getLeft();
} }
else else

View File

@ -435,6 +435,15 @@ public class ForgeBlockStateV1 extends Marker
throw new UnsupportedOperationException("Forge BlockStateLoader V1 does not support nested submodels."); throw new UnsupportedOperationException("Forge BlockStateLoader V1 does not support nested submodels.");
} }
private TRSRTransformation get(float tx, float ty, float tz, float ax, float ay, float az, float s)
{
return TRSRTransformation.blockCenterToCorner(new TRSRTransformation(
new Vector3f(tx / 16, ty / 16, tz / 16),
TRSRTransformation.quatFromXYZDegrees(new Vector3f(ax, ay, az)),
new Vector3f(s, s, s),
null));
}
@Override @Override
public ForgeBlockStateV1.Variant deserialize(JsonElement element, Type typeOfT, JsonDeserializationContext context) throws JsonParseException public ForgeBlockStateV1.Variant deserialize(JsonElement element, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{ {
@ -476,47 +485,41 @@ public class ForgeBlockStateV1 extends Marker
{ {
String transform = json.get("transform").getAsString(); 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 // 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")) if (transform.equals("identity"))
{ {
ret.state = Optional.<IModelState>of(TRSRTransformation.identity()); ret.state = Optional.<IModelState>of(TRSRTransformation.identity());
} }
/*else if (transform.equals("forge:default-block")) // block/block
else if (transform.equals("forge:default-block"))
{ {
TRSRTransformation thirdperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation( ImmutableMap.Builder<TransformType, TRSRTransformation> builder = ImmutableMap.builder();
new Vector3f(0, 1.5f / 16, -2.75f / 16), builder.put(TransformType.GUI, get(0, 0, 0, 30, 225, 0, 0.625f));
TRSRTransformation.quatFromYXZDegrees(new Vector3f(10, -45, 170)), builder.put( TransformType.GROUND, get(0, 3, 0, 0, 0, 0, 0.25f));
new Vector3f(0.375f, 0.375f, 0.375f), builder.put(TransformType.FIXED, get(0, 0, 0, 0, 0, 0, 0.5f));
null)); builder.put(TransformType.THIRD_PERSON_RIGHT_HAND, get(0, 2.5f, 0, 75, 45, 0, 0.375f));
ret.state = Optional.<IModelState>of(new SimpleModelState(ImmutableMap.of(TransformType.THIRD_PERSON, 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, 255, 0, 0.4f));
ret.state = Optional.<IModelState>of(new SimpleModelState(builder.build()));
} }
// item/generated
else if (transform.equals("forge:default-item")) else if (transform.equals("forge:default-item"))
{ {
TRSRTransformation thirdperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation( ret.state = Optional.<IModelState>of(new SimpleModelState(ImmutableMap.of(
new Vector3f(0, 1f / 16, -3f / 16), TransformType.GROUND, get(0, 2, 0, 0, 0, 0, 0.5f),
TRSRTransformation.quatFromYXZDegrees(new Vector3f(-90, 0, 0)), TransformType.HEAD, get(0, 13, 7, 0, 180, 0, 1),
new Vector3f(0.55f, 0.55f, 0.55f), TransformType.THIRD_PERSON_RIGHT_HAND, get(0, 3, 1, 0, 0, 0, 0.55f),
null)); TransformType.FIRST_PERSON_RIGHT_HAND, get(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f))));
TRSRTransformation firstperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation(
new Vector3f(0, 4f / 16, 2f / 16),
TRSRTransformation.quatFromYXZDegrees(new Vector3f(0, -135, 25)),
new Vector3f(1.7f, 1.7f, 1.7f),
null));
ret.state = Optional.<IModelState>of(new SimpleModelState(ImmutableMap.of(TransformType.THIRD_PERSON, thirdperson, TransformType.FIRST_PERSON, firstperson)));
} }
// item/handheld
else if (transform.equals("forge:default-tool")) else if (transform.equals("forge:default-tool"))
{ {
TRSRTransformation thirdperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation( ret.state = Optional.<IModelState>of(new SimpleModelState(ImmutableMap.of(
new Vector3f(0, 1.25f / 16, -3.5f / 16), TransformType.THIRD_PERSON_RIGHT_HAND, get(0, 4, 0.5f, 0, -90, 55, 0.85f),
TRSRTransformation.quatFromYXZDegrees(new Vector3f(0, 90, -35)), TransformType.THIRD_PERSON_LEFT_HAND, get(0, 4, 0.5f, 0, 90, -55, 0.85f),
new Vector3f(0.85f, 0.85f, 0.85f), TransformType.FIRST_PERSON_RIGHT_HAND, get(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f),
null)); TransformType.FIRST_PERSON_LEFT_HAND, get(1.13f, 3.2f, 1.13f, 0, 90, -25, 0.68f))));
TRSRTransformation firstperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation( }
new Vector3f(0, 4f / 16, 2f / 16),
TRSRTransformation.quatFromYXZDegrees(new Vector3f(0, -135, 25)),
new Vector3f(1.7f, 1.7f, 1.7f),
null));
ret.state = Optional.<IModelState>of(new SimpleModelState(ImmutableMap.of(TransformType.THIRD_PERSON, thirdperson, TransformType.FIRST_PERSON, firstperson)));
}*/ // FIXME
else else
{ {
throw new JsonParseException("transform: unknown default string: " + transform); throw new JsonParseException("transform: unknown default string: " + transform);

View File

@ -8,7 +8,6 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -110,7 +109,7 @@ public class ModelLoader extends ModelBakery
{ {
isLoading = true; isLoading = true;
loadBlocks(); loadBlocks();
loadItems(); loadVariantItemModels();
try try
{ {
missingModel = getModel(new ResourceLocation(MODEL_MISSING.getResourceDomain(), MODEL_MISSING.getResourcePath())); missingModel = getModel(new ResourceLocation(MODEL_MISSING.getResourceDomain(), MODEL_MISSING.getResourcePath()));
@ -148,7 +147,15 @@ public class ModelLoader extends ModelBakery
return bakedRegistry; return bakedRegistry;
} }
private void loadBlocks() // NOOP, replaced by dependency resolution
@Override
protected void loadVariantModels() {}
// NOOP, replaced by dependency resolution
@Override
protected void loadMultipartVariantModels() {}
/*private void loadBlocks()
{ {
Map<IBlockState, ModelResourceLocation> stateMap = blockModelShapes.getBlockStateMapper().putAllStateModelLocations(); Map<IBlockState, ModelResourceLocation> stateMap = blockModelShapes.getBlockStateMapper().putAllStateModelLocations();
List<ModelResourceLocation> variants = Lists.newArrayList(stateMap.values()); List<ModelResourceLocation> variants = Lists.newArrayList(stateMap.values());
@ -168,9 +175,10 @@ public class ModelLoader extends ModelBakery
blockBar.step(variant.toString()); blockBar.step(variant.toString());
} }
ProgressManager.pop(blockBar); ProgressManager.pop(blockBar);
} }*/
// FIXME: all the new shiny multipart things // FIXME: all the new shiny multipart things
@Deprecated
private void loadVariant(ModelResourceLocation variant) private void loadVariant(ModelResourceLocation variant)
{ {
try try
@ -192,23 +200,20 @@ public class ModelLoader extends ModelBakery
} }
} }
// FIXME: this is probably not the hook point anymore
@Override @Override
protected void registerVariant(ModelBlockDefinition definition, ModelResourceLocation location) protected void registerVariant(ModelBlockDefinition definition, ModelResourceLocation location)
{ {
// for now // TODO loader?
super.registerVariant(definition, location); VariantList variants = null;
/*VariantList variants = null;
try try
{ {
variants = definition.getVariants(location.getVariant()); variants = definition.getVariant(location.getVariant());
} }
catch(MissingVariantException e) catch(MissingVariantException e)
{ {
missingVariants.add(location); missingVariants.add(location);
} }
if (variants != null && !variants.getVariants().isEmpty()) if (variants != null && !variants.getVariantList().isEmpty())
{ {
try try
{ {
@ -218,7 +223,7 @@ public class ModelLoader extends ModelBakery
{ {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}*/ }
} }
private void storeException(ResourceLocation location, Exception exception) private void storeException(ResourceLocation location, Exception exception)
@ -240,7 +245,8 @@ public class ModelLoader extends ModelBakery
return new ModelBlockDefinition(new ArrayList<ModelBlockDefinition>()); return new ModelBlockDefinition(new ArrayList<ModelBlockDefinition>());
} }
private void loadItems() @Override
protected void loadItemModels()
{ {
// register model for the universal bucket, if it exists // register model for the universal bucket, if it exists
if(FluidRegistry.isUniversalBucketEnabled()) if(FluidRegistry.isUniversalBucketEnabled())
@ -454,8 +460,13 @@ public class ModelLoader extends ModelBakery
public Collection<ResourceLocation> getDependencies() public Collection<ResourceLocation> getDependencies()
{ {
if(model.getParentLocation() == null || model.getParentLocation().getResourcePath().startsWith("builtin/")) return Collections.emptyList(); Set<ResourceLocation> set = Sets.newHashSet();
return Collections.singletonList(model.getParentLocation()); set.addAll(model.getOverrideLocations());
if(model.getParentLocation() != null && !model.getParentLocation().getResourcePath().startsWith("builtin/"))
{
set.add(model.getParentLocation());
}
return ImmutableSet.copyOf(set);
} }
public Collection<ResourceLocation> getTextures() public Collection<ResourceLocation> getTextures()

View File

@ -169,8 +169,7 @@ public class MultiModel implements IModel
@Override @Override
public ItemOverrideList getOverrides() public ItemOverrideList getOverrides()
{ {
// TODO Auto-generated method stub return ItemOverrideList.NONE;
return null;
} }
} }

View File

@ -8,7 +8,6 @@ import javax.vecmath.Tuple4f;
import javax.vecmath.Vector3f; import javax.vecmath.Vector3f;
import javax.vecmath.Vector4f; import javax.vecmath.Vector4f;
import net.minecraft.client.renderer.block.model.ItemTransformVec3f;
import net.minecraft.client.renderer.block.model.ModelRotation; import net.minecraft.client.renderer.block.model.ModelRotation;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.Vec3i; import net.minecraft.util.math.Vec3i;
@ -31,7 +30,6 @@ import com.google.common.base.Optional;
* should be comparable to using Matrix4f directly. * should be comparable to using Matrix4f directly.
* Immutable. * Immutable.
*/ */
@SuppressWarnings("deprecation")
public class TRSRTransformation implements IModelState, ITransformation public class TRSRTransformation implements IModelState, ITransformation
{ {
private final Matrix4f matrix; private final Matrix4f matrix;
@ -64,14 +62,16 @@ public class TRSRTransformation implements IModelState, ITransformation
full = true; full = true;
} }
public TRSRTransformation(ItemTransformVec3f transform) @Deprecated
public TRSRTransformation(net.minecraft.client.renderer.block.model.ItemTransformVec3f transform)
{ {
this(getMatrix(transform)); this(getMatrix(transform));
} }
public static Matrix4f getMatrix(ItemTransformVec3f transform) @Deprecated
public static Matrix4f getMatrix(net.minecraft.client.renderer.block.model.ItemTransformVec3f transform)
{ {
TRSRTransformation ret = new TRSRTransformation(toVecmath(transform.translation), quatFromYXZDegrees(toVecmath(transform.rotation)), toVecmath(transform.scale), null); TRSRTransformation ret = new TRSRTransformation(toVecmath(transform.translation), quatFromXYZDegrees(toVecmath(transform.rotation)), toVecmath(transform.scale), null);
return blockCenterToCorner(ret).getMatrix(); return blockCenterToCorner(ret).getMatrix();
} }
@ -135,16 +135,6 @@ public class TRSRTransformation implements IModelState, ITransformation
} }
} }
public static Quat4f quatFromYXZDegrees(Vector3f yxz)
{
return quatFromYXZ((float)Math.toRadians(yxz.y), (float)Math.toRadians(yxz.x), (float)Math.toRadians(yxz.z));
}
public static Quat4f quatFromYXZ(Vector3f yxz)
{
return quatFromYXZ(yxz.y, yxz.x, yxz.z);
}
public static Quat4f quatFromYXZ(float y, float x, float z) public static Quat4f quatFromYXZ(float y, float x, float z)
{ {
Quat4f ret = new Quat4f(0, 0, 0, 1), t = new Quat4f(); Quat4f ret = new Quat4f(0, 0, 0, 1), t = new Quat4f();
@ -157,6 +147,28 @@ public class TRSRTransformation implements IModelState, ITransformation
return ret; return ret;
} }
public static Quat4f quatFromXYZDegrees(Vector3f xyz)
{
return quatFromXYZ((float)Math.toRadians(xyz.x), (float)Math.toRadians(xyz.y), (float)Math.toRadians(xyz.z));
}
public static Quat4f quatFromXYZ(Vector3f xyz)
{
return quatFromXYZ(xyz.x, xyz.y, xyz.z);
}
public static Quat4f quatFromXYZ(float x, float y, float z)
{
Quat4f ret = new Quat4f(0, 0, 0, 1), t = new Quat4f();
t.set((float)Math.sin(x/2), 0, 0, (float)Math.cos(x/2));
ret.mul(t);
t.set(0, (float)Math.sin(y/2), 0, (float)Math.cos(y/2));
ret.mul(t);
t.set(0, 0, (float)Math.sin(z/2), (float)Math.cos(z/2));
ret.mul(t);
return ret;
}
public static Vector3f toYXZDegrees(Quat4f q) public static Vector3f toYXZDegrees(Quat4f q)
{ {
Vector3f yxz = toYXZ(q); Vector3f yxz = toYXZ(q);
@ -187,6 +199,37 @@ public class TRSRTransformation implements IModelState, ITransformation
); );
} }
public static Vector3f toXYZDegrees(Quat4f q)
{
Vector3f xyz = toXYZ(q);
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;
float x2 = q.x * q.x;
float y2 = q.y * q.y;
float z2 = q.z * q.z;
float l = w2 + x2 + y2 + z2;
float sy = 2 * q.w * q.x - 2 * q.y * q.z;
float y = (float)Math.asin(sy / l);
if(Math.abs(sy) > .999f * l)
{
return new Vector3f(
2 * (float)Math.atan2(q.x, q.w),
y,
0
);
}
return new Vector3f(
(float)Math.atan2(2 * q.y * q.z + 2 * q.x * q.w, w2 - x2 - y2 + z2),
y,
(float)Math.atan2(2 * q.x * q.y + 2 * q.w * q.z, w2 + x2 - y2 - z2)
);
}
public static Matrix4f mul(Vector3f translation, Quat4f leftRot, Vector3f scale, Quat4f rightRot) public static Matrix4f mul(Vector3f translation, Quat4f leftRot, Vector3f scale, Quat4f rightRot)
{ {
Matrix4f res = new Matrix4f(), t = new Matrix4f(); Matrix4f res = new Matrix4f(), t = new Matrix4f();
@ -447,9 +490,10 @@ public class TRSRTransformation implements IModelState, ITransformation
/* /*
* Don't use this if you don't need to, conversion is lossy (second rotation component is lost). * Don't use this if you don't need to, conversion is lossy (second rotation component is lost).
*/ */
public ItemTransformVec3f toItemTransform() @Deprecated
public net.minecraft.client.renderer.block.model.ItemTransformVec3f toItemTransform()
{ {
return new ItemTransformVec3f(toLwjgl(toYXZDegrees(getLeftRot())), toLwjgl(getTranslation()), toLwjgl(getScale())); return new net.minecraft.client.renderer.block.model.ItemTransformVec3f(toLwjgl(toXYZDegrees(getLeftRot())), toLwjgl(getTranslation()), toLwjgl(getScale()));
} }
public Matrix4f getMatrix() public Matrix4f getMatrix()

View File

@ -141,6 +141,12 @@ protected net.minecraft.client.renderer.block.model.ModelBakery func_177581_b(Ln
protected net.minecraft.client.renderer.block.model.ModelBakery func_177587_c(Lnet/minecraft/client/renderer/block/model/ModelBlock;)Z # isCustomRenderer protected net.minecraft.client.renderer.block.model.ModelBakery func_177587_c(Lnet/minecraft/client/renderer/block/model/ModelBlock;)Z # isCustomRenderer
protected net.minecraft.client.renderer.block.model.ModelBakery func_177582_d(Lnet/minecraft/client/renderer/block/model/ModelBlock;)Lnet/minecraft/client/renderer/block/model/ModelBlock; # makeItemModel protected net.minecraft.client.renderer.block.model.ModelBakery func_177582_d(Lnet/minecraft/client/renderer/block/model/ModelBlock;)Lnet/minecraft/client/renderer/block/model/ModelBlock; # makeItemModel
protected net.minecraft.client.renderer.block.model.ModelBakery func_177580_d(Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/util/ResourceLocation; # getModelLocation protected net.minecraft.client.renderer.block.model.ModelBakery func_177580_d(Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/util/ResourceLocation; # getModelLocation
protected net.minecraft.client.renderer.block.model.ModelBakery func_188640_b()V # loadBlocks
protected net.minecraft.client.renderer.block.model.ModelBakery func_177577_b()V # loadVariantItemModels
protected net.minecraft.client.renderer.block.model.ModelBakery func_177590_d()V # loadItemModels
protected net.minecraft.client.renderer.block.model.ModelBakery func_177595_c()V # loadVariantModels
protected net.minecraft.client.renderer.block.model.ModelBakery func_188637_e()V # loadMultipartVariantModels
protected net.minecraft.client.renderer.block.model.ModelBakery func_188638_a(Lnet/minecraft/client/renderer/block/model/ModelResourceLocation;Lnet/minecraft/client/renderer/block/model/VariantList;)V # loadVariantList
#public net.minecraft.client.renderer.block.model.WeightedBakedModel field_177565_b # models #public net.minecraft.client.renderer.block.model.WeightedBakedModel field_177565_b # models
# EnumFacing # EnumFacing
public net.minecraft.util.EnumFacing field_82609_l # VALUES public net.minecraft.util.EnumFacing field_82609_l # VALUES

View File

@ -64,7 +64,7 @@ import org.apache.commons.lang3.tuple.Pair;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
//@Mod(modid = ModelAnimationDebug.MODID, version = ModelAnimationDebug.VERSION) @Mod(modid = ModelAnimationDebug.MODID, version = ModelAnimationDebug.VERSION)
public class ModelAnimationDebug public class ModelAnimationDebug
{ {
public static final String MODID = "forgedebugmodelanimation"; public static final String MODID = "forgedebugmodelanimation";