net.minecraftforge.common.model.TRSRTransformation Java Examples

The following examples show how to use net.minecraftforge.common.model.TRSRTransformation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransformProvider.java    From OpenModsLib with MIT License 6 votes vote down vote up
public Transformation(Orientation orientation) {
	final javax.vecmath.Matrix4f originalMatrix = new javax.vecmath.Matrix4f();
	originalMatrix.set(orientation.getLocalToWorldMatrix());

	asMatrix = TRSRTransformation.toLwjgl(originalMatrix);

	asBuffer = BufferUtils.createFloatBuffer(16);
	asMatrix.store(asBuffer);
	asBuffer.rewind();

	asInverseMatrix = new Matrix4f();
	Matrix4f.invert(asMatrix, asInverseMatrix);

	asInverseBuffer = BufferUtils.createFloatBuffer(16);
	asInverseMatrix.store(asInverseBuffer);
	asInverseBuffer.rewind();
}
 
Example #2
Source File: EvalModelTest.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Test
public void testDoubleApply() {
	EvaluatorFactory factory = new EvaluatorFactory();
	factory.appendStatement("param1 := 1.4");
	factory.appendStatement("clip(param1)");
	factory.appendStatement("clip(param2)");

	final ClipStub clipStub = new ClipStub();
	final IJointClip jointClipMock = clipStub.jointClipMock;

	final TRSRTransformation transform1 = TRSRTransformation.from(EnumFacing.NORTH);
	final TRSRTransformation transform2 = TRSRTransformation.from(EnumFacing.WEST);
	Mockito.when(jointClipMock.apply(1.4f)).thenReturn(transform1);
	Mockito.when(jointClipMock.apply(2.1f)).thenReturn(transform2);

	final TRSRTransformation result = factory.createEvaluator(clips("clip", clipStub)).evaluate(DUMMY_JOINT, ImmutableMap.of("param2", 2.1f));
	Assert.assertEquals(transform1.compose(transform2), result);

	Mockito.verify(jointClipMock).apply(1.4f);
	Mockito.verify(jointClipMock).apply(2.1f);
	Mockito.verifyNoMoreInteractions(jointClipMock);
}
 
Example #3
Source File: BlockGenericPipe.java    From Logistics-Pipes-2 with MIT License 6 votes vote down vote up
@Override
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
      {
          if(part.isPresent())
          {
              // This whole thing is subject to change, but should do for now.
              UnmodifiableIterator<String> parts = Models.getParts(part.get());
              if(parts.hasNext())
              {
                  String name = parts.next();
                  // only interested in the root level
                  if(!parts.hasNext() && hidden.contains(name))
                  {
                      return value;
                  }
              }
          }
          return Optional.absent();
      }
 
Example #4
Source File: EvalModelTest.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Test
public void testArithmeticsVarApply() {
	EvaluatorFactory factory = new EvaluatorFactory();
	factory.appendStatement("clip(2.4 / a + 1/(3 * b))");

	final ClipStub clipStub = new ClipStub();
	final IJointClip jointClipMock = clipStub.jointClipMock;

	final TRSRTransformation transform = TRSRTransformation.from(EnumFacing.NORTH);
	Mockito.when(jointClipMock.apply(Matchers.anyFloat())).thenReturn(transform);

	final TRSRTransformation result = factory.createEvaluator(clips("clip", clipStub))
			.evaluate(DUMMY_JOINT, ImmutableMap.of("a", 5.1f, "b", -0.4f));
	Assert.assertEquals(transform, result);

	Mockito.verify(jointClipMock).apply(2.4f / 5.1f + 1f / (3f * -0.4f));
	Mockito.verifyNoMoreInteractions(jointClipMock);
}
 
Example #5
Source File: EvalModelTest.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Test
public void testConstApply() {
	EvaluatorFactory factory = new EvaluatorFactory();
	factory.appendStatement("clip(2.4 + 1/3)");

	final ClipStub clipStub = new ClipStub();
	final IJointClip jointClipMock = clipStub.jointClipMock;

	final TRSRTransformation transform = TRSRTransformation.from(EnumFacing.NORTH);
	Mockito.when(jointClipMock.apply(Matchers.anyFloat())).thenReturn(transform);

	final TRSRTransformation result = factory.createEvaluator(clips("clip", clipStub)).evaluate(DUMMY_JOINT, NO_ARGS);
	Assert.assertEquals(transform, result);

	Mockito.verify(jointClipMock).apply(2.4f + 1f / 3f);
	Mockito.verifyNoMoreInteractions(jointClipMock);
}
 
Example #6
Source File: EvalModelTest.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Test
public void testVarApply() {
	EvaluatorFactory factory = new EvaluatorFactory();
	factory.appendStatement("param := 1.4");
	factory.appendStatement("clip(param)");

	final ClipStub clipStub = new ClipStub();
	final IJointClip jointClipMock = clipStub.jointClipMock;

	final TRSRTransformation transform = TRSRTransformation.from(EnumFacing.NORTH);
	Mockito.when(jointClipMock.apply(Matchers.anyFloat())).thenReturn(transform);

	final TRSRTransformation result = factory.createEvaluator(clips("clip", clipStub)).evaluate(DUMMY_JOINT, NO_ARGS);
	Assert.assertEquals(transform, result);

	Mockito.verify(jointClipMock).apply(1.4f);
	Mockito.verifyNoMoreInteractions(jointClipMock);
}
 
Example #7
Source File: MultiLayerModel.java    From OpenModsLib with MIT License 6 votes vote down vote up
public MultiLayerBakedModel(Map<BlockRenderLayer, IBakedModel> models, IBakedModel base, IBakedModel missing, ImmutableMap<TransformType, TRSRTransformation> cameraTransforms) {
	super(base, cameraTransforms);
	this.models = ImmutableMap.copyOf(models);
	this.missing = missing;

	final List<BakedQuad> quads = Lists.newArrayList();

	for (BlockRenderLayer layer : BlockRenderLayer.values()) {
		final IBakedModel model = models.get(layer);
		if (model != null) {
			buildQuadsForLayer(quads, model);
		}
	}

	this.quads = ImmutableList.copyOf(quads);
}
 
Example #8
Source File: BakedModelCamouflageBlock.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nullable
public static IBakedModel getRotatedBakedModel(@Nullable IModel model, @Nullable IBakedModel bakedModelDefault, IBlockState state,
        VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
{
    if (model != null)
    {
        if (state.getPropertyKeys().contains(BlockEnderUtilities.FACING))
        {
            return model.bake(TRSRTransformation.from(state.getValue(BlockEnderUtilities.FACING)), format, bakedTextureGetter);
        }
        else if (state.getPropertyKeys().contains(BlockEnderUtilities.FACING_H))
        {
            return model.bake(TRSRTransformation.from(state.getValue(BlockEnderUtilities.FACING_H)), format, bakedTextureGetter);
        }
    }

    return bakedModelDefault;
}
 
Example #9
Source File: BakedModelInserter.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
private List<IBakedModel> getSideModels(IBlockState state)
{
    List<IBakedModel> models = new ArrayList<IBakedModel>();

    for (EnumFacing side : EnumFacing.values())
    {
        BlockInserter.Connection conn = state.getValue(BlockInserter.CONNECTIONS.get(side.getIndex()));

        if (conn == BlockInserter.Connection.VALID)
        {
            models.add(this.sideModelValid.bake(TRSRTransformation.from(side), this.format, this.bakedTextureGetter));
        }
        else if (conn == BlockInserter.Connection.INVALID)
        {
            models.add(this.sideModelInvalid.bake(TRSRTransformation.from(side), this.format, this.bakedTextureGetter));
        }
    }

    return models;
}
 
Example #10
Source File: EvalModelTest.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Test
public void testDirectApply() {
	EvaluatorFactory factory = new EvaluatorFactory();
	factory.appendStatement("clip(param)");

	final ClipStub clipStub = new ClipStub();
	final IJointClip jointClipMock = clipStub.jointClipMock;

	final TRSRTransformation transform = TRSRTransformation.from(EnumFacing.NORTH);
	Mockito.when(jointClipMock.apply(Matchers.anyFloat())).thenReturn(transform);

	final float param = 1.3f;
	final TRSRTransformation result = factory.createEvaluator(clips("clip", clipStub)).evaluate(DUMMY_JOINT, ImmutableMap.of("param", param));
	Assert.assertEquals(transform, result);

	Mockito.verify(jointClipMock).apply(param);
	Mockito.verifyNoMoreInteractions(jointClipMock);
}
 
Example #11
Source File: EvaluatorFactory.java    From OpenModsLib with MIT License 5 votes vote down vote up
private static ITransformExecutor composeTransformExecutors(List<ITransformExecutor> contents) {
	if (contents.isEmpty()) return (initial, joint, args) -> initial;
	if (contents.size() == 1)
		return contents.get(0);

	final List<ITransformExecutor> executors = ImmutableList.copyOf(contents);
	return (initial, joint, args) -> {
		TRSRTransformation result = initial;
		for (ITransformExecutor e : executors)
			result = e.apply(result, joint, args);

		return result;
	};
}
 
Example #12
Source File: OrientationInfoGenerator.java    From OpenModsLib with MIT License 5 votes vote down vote up
private static Multimap<Orientation, ModelRotation> calculateVanillaRotations(Map<Matrix3f, Orientation> fromMatrix) {
	final Multimap<Orientation, ModelRotation> toVanilla = HashMultimap.create();

	for (ModelRotation rot : ModelRotation.values()) {
		final Matrix4f rotMatrix = TRSRTransformation.toVecmath(rot.getMatrix4d());
		final Matrix3f key = roundAndReduceMatrixElements(rotMatrix);
		final Orientation orientation = fromMatrix.get(key);
		Preconditions.checkNotNull(orientation, rot);
		toVanilla.put(orientation, rot);
	}

	return toVanilla;
}
 
Example #13
Source File: EvaluatorFactory.java    From OpenModsLib with MIT License 5 votes vote down vote up
private static ITransformExecutor createForClip(final IClip clip, final NumericExpr param) {
	return (initial, joint, args) -> {
		final float paramValue = param.evaluate(args);
		final TRSRTransformation clipTransform = clip.apply(joint).apply(paramValue);
		return initial.compose(clipTransform);
	};
}
 
Example #14
Source File: ModelEnderTools.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public BakedEnderTool(ModelEnderTools parent, ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, VertexFormat format,
        ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms, Map<String, IBakedModel> cache)
{
    this.quads = quads;
    this.particle = particle;
    this.format = format;
    this.parent = parent;
    this.transforms = transforms;
    this.cache = cache;
}
 
Example #15
Source File: EvaluatorFactory.java    From OpenModsLib with MIT License 5 votes vote down vote up
public ITransformEvaluator createEvaluator(IClipProvider provider) {
	if (statements.isEmpty())
		return (joint, args) -> TRSRTransformation.identity();

	final List<ITransformExecutor> executors = Lists.newArrayList();

	for (IStatement statement : statements)
		executors.add(statement.bind(provider));

	return new EvaluatorImpl(composeTransformExecutors(executors));
}
 
Example #16
Source File: ModelEnderBucket.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public BakedEnderBucket(ModelEnderBucket parent, ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, VertexFormat format,
        ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms, Map<String, IBakedModel> cache)
{
    this.quads = quads;
    this.particle = particle;
    this.format = format;
    this.parent = parent;
    this.transforms = transforms;
    this.cache = cache;
}
 
Example #17
Source File: BakedAnvilModel.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> getTransforms(IPerspectiveAwareModel model) {
	ImmutableMap.Builder<ItemCameraTransforms.TransformType, TRSRTransformation> builder = ImmutableMap.builder();
	for(ItemCameraTransforms.TransformType type : ItemCameraTransforms.TransformType.values()) {
		TRSRTransformation transformation = new TRSRTransformation(model.handlePerspective(type).getRight());
		if(!transformation.equals(TRSRTransformation.identity())) {
			builder.put(type, TRSRTransformation.blockCenterToCorner(transformation));
		}
	}
	return builder.build();
}
 
Example #18
Source File: BakedPitKilnModel.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> getTransforms(IPerspectiveAwareModel model) {
	ImmutableMap.Builder<ItemCameraTransforms.TransformType, TRSRTransformation> builder = ImmutableMap.builder();
	for(ItemCameraTransforms.TransformType type : ItemCameraTransforms.TransformType.values()) {
		TRSRTransformation transformation = new TRSRTransformation(model.handlePerspective(type).getRight());
		if(!transformation.equals(TRSRTransformation.identity())) {
			builder.put(type, TRSRTransformation.blockCenterToCorner(transformation));
		}
	}
	return builder.build();
}
 
Example #19
Source File: BakedSmallVesselModel.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> getTransforms(IPerspectiveAwareModel model) {
	ImmutableMap.Builder<ItemCameraTransforms.TransformType, TRSRTransformation> builder = ImmutableMap.builder();
	for(ItemCameraTransforms.TransformType type : ItemCameraTransforms.TransformType.values()) {
		TRSRTransformation transformation = new TRSRTransformation(model.handlePerspective(type).getRight());
		if(!transformation.equals(TRSRTransformation.identity())) {
			builder.put(type, TRSRTransformation.blockCenterToCorner(transformation));
		}
	}
	return builder.build();
}
 
Example #20
Source File: TRSRBakedModel.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public Transformer(TRSRTransformation transformation, VertexFormat format) {
	super(new UnpackedBakedQuad.Builder(format));
	// position transform
	this.transformation = transformation.getMatrix();
	// normal transform
	this.normalTransformation = new Matrix3f();
	this.transformation.getRotationScale(this.normalTransformation);
	this.normalTransformation.invert();
	this.normalTransformation.transpose();
}
 
Example #21
Source File: TRSRBakedModel.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/** Rotates around the Y axis and adjusts culling appropriately. South is default. */
public TRSRBakedModel(IBakedModel original, EnumFacing facing) {
	this.original = original;
	this.override = new TRSROverride(this);

	this.faceOffset = 4 + EnumFacing.NORTH.getHorizontalIndex() - facing.getHorizontalIndex();

	double r = Math.PI * (360 - facing.getOpposite().getHorizontalIndex() * 90)/180d;
	TRSRTransformation t = new TRSRTransformation(null, null, null, TRSRTransformation.quatFromXYZ(0, (float)r, 0));
	this.transformation = TRSRTransformation.blockCenterToCorner(t);
}
 
Example #22
Source File: WeightedRandomModel.java    From VanillaFix with MIT License 5 votes vote down vote up
public WeightedRandomModel(VariantList variants) throws Exception {
    this.variants = variants.getVariantList();
    locations = new ArrayList<>();
    textures = Sets.newHashSet();
    models = new ArrayList<>();
    ImmutableList.Builder<Pair<IModel, IModelState>> builder = ImmutableList.builder();
    for (Variant variant : this.variants) {
        ResourceLocation location = variant.getModelLocation();
        locations.add(location);

        IModel model = variant.process(ModelLoaderRegistry.getModel(location));

        textures.addAll(model.getTextures());
        models.add(model);

        IModelState modelDefaultState = model.getDefaultState();
        Preconditions.checkNotNull(modelDefaultState, "Model %s returned null as default state", location);
        builder.add(Pair.of(model, new ModelStateComposition(variant.getState(), modelDefaultState)));
    }

    // If all variants are missing, add one with the missing model and default rotation
    if (models.size() == 0) {
        IModel missing = ModelLoaderRegistry.getMissingModel();
        models.add(missing);
        builder.add(Pair.of(missing, TRSRTransformation.identity()));
    }

    defaultState = new MultiModelState(builder.build());
}
 
Example #23
Source File: VanillaModelWrapper.java    From VanillaFix with MIT License 5 votes vote down vote up
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    if (!Attributes.moreSpecific(format, Attributes.DEFAULT_BAKED_FORMAT)) {
        throw new IllegalArgumentException("can't bake vanilla models to the format that doesn't fit into the default one: " + format);
    }
    ModelBlock model = this.model;

    if (model == null) {
        return BuiltinLoader.WRAPPED_MODEL_MISSING.bake(BuiltinLoader.WRAPPED_MODEL_MISSING.getDefaultState(), format, bakedTextureGetter);
    }

    List<TRSRTransformation> newTransforms = Lists.newArrayList();
    for (int i = 0; i < model.getElements().size(); i++) {
        BlockPart part = model.getElements().get(i);
        newTransforms.add(animation.getPartTransform(state, part, i));
    }

    ItemCameraTransforms transforms = model.getAllTransforms();
    Map<ItemCameraTransforms.TransformType, TRSRTransformation> tMap = Maps.newEnumMap(ItemCameraTransforms.TransformType.class);
    tMap.putAll(PerspectiveMapWrapper.getTransforms(transforms));
    tMap.putAll(PerspectiveMapWrapper.getTransforms(state));
    IModelState perState = new SimpleModelState(ImmutableMap.copyOf(tMap));

    if (hasItemModel(model)) {
        return new ItemLayerModel(model).bake(perState, format, bakedTextureGetter);
    }

    if (isCustomRenderer(model)) {
        return new BuiltInModel(transforms, model.createOverrides());
    }

    return bakeNormal(model, perState, state, newTransforms, format, bakedTextureGetter, uvlock);
}
 
Example #24
Source File: GTItemOverrideTestTube.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world,
		EntityLivingBase entity) {
	FluidStack fluidStack = FluidUtil.getFluidContained(stack);
	if (fluidStack == null)
		return originalModel;
	IBakedModel baked = CACHE.get(fluidStack.getFluid().getName());
	if (baked == null) {
		GTBakedTestTube bakedCell = (GTBakedTestTube) originalModel;
		GTModelTestTube model = new GTModelTestTube(fluidStack.getFluid());
		CACHE.put(fluidStack.getFluid().getName(), (baked = model.bake(TRSRTransformation.identity(), bakedCell.format, GTModelUtils.getTextureGetter())));
	}
	return baked;
}
 
Example #25
Source File: EvalModelTest.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Test
public void testSeparateClipsApply() {
	EvaluatorFactory factory = new EvaluatorFactory();
	factory.appendStatement("param := 2.5");
	factory.appendStatement("clip1(param)");
	factory.appendStatement("clip2(param)");

	final ClipStub clipStub1 = new ClipStub();
	final IJointClip jointClipMock1 = clipStub1.jointClipMock;

	final ClipStub clipStub2 = new ClipStub();
	final IJointClip jointClipMock2 = clipStub2.jointClipMock;

	final TRSRTransformation transform1 = TRSRTransformation.from(EnumFacing.EAST);
	final TRSRTransformation transform2 = TRSRTransformation.from(EnumFacing.UP);
	Mockito.when(jointClipMock1.apply(Matchers.anyFloat())).thenReturn(transform1);
	Mockito.when(jointClipMock2.apply(Matchers.anyFloat())).thenReturn(transform2);

	final TRSRTransformation result = factory.createEvaluator(clips("clip1", clipStub1).put("clip2", clipStub2)).evaluate(DUMMY_JOINT, NO_ARGS);
	Assert.assertEquals(transform1.compose(transform2), result);

	Mockito.verify(jointClipMock1).apply(2.5f);
	Mockito.verifyNoMoreInteractions(jointClipMock1);

	Mockito.verify(jointClipMock2).apply(2.5f);
	Mockito.verifyNoMoreInteractions(jointClipMock2);
}
 
Example #26
Source File: EvalModelTest.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public TRSRTransformation getInvBindPose() {
	throw new AssertionError("unsupported operation");
}
 
Example #27
Source File: PerspectiveAwareModel.java    From OpenModsLib with MIT License 4 votes vote down vote up
public PerspectiveAwareBakedModel(Map<TransformType, IBakedModel> models, IBakedModel base, ImmutableMap<TransformType, TRSRTransformation> cameraTransforms) {
	super(base, cameraTransforms);
	this.models = ImmutableMap.copyOf(models);
}
 
Example #28
Source File: TexturedItemModel.java    From OpenModsLib with MIT License 4 votes vote down vote up
public BakedModel(IBakedModel base, ImmutableMap<TransformType, TRSRTransformation> cameraTransforms, ItemOverrideList itemOverrideList) {
	super(base, cameraTransforms);
	this.overrideList = itemOverrideList;
}
 
Example #29
Source File: BakedModelAdapter.java    From OpenModsLib with MIT License 4 votes vote down vote up
public BakedModelAdapter(IBakedModel base, ImmutableMap<TransformType, TRSRTransformation> cameraTransforms) {
	this.base = base;
	this.cameraTransforms = cameraTransforms;
}
 
Example #30
Source File: EvaluatorFactory.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public TRSRTransformation evaluate(IJoint joint, Map<String, Float> args) {
	final Map<String, Float> mutableArgs = Maps.newHashMap(args);
	return executor.apply(TRSRTransformation.identity(), joint, mutableArgs);
}