Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi,

I was wondering if it is possible to set the texture data of an instance of IFlexibleBakedModel. I searched around the forums for a bit and it would seem like this is something that can be done. What I'm attempting to do is take the texture data from a model, convert it to a sepia version (which is a brownish filter, see bit.ly/1ZOLgSt) and change the hue of the sepia texture to a light cyan. Basically, make a block look like a light blue version of that block. Reading some other forums (like this one bit.ly/1ZazR2w, I've managed to change the color, but I cannot figure out what indices of the model's vertex data to change to the appropriate RGB value. My code for what I'm doing is below. The issue is within the 'alterColor' method. And for what it's worth, it seems to change every model into a bright red, texture-less cube. Any information about vertex data or my issue would be much appreciated. Thanks!

ย 

public class FrozenBlockModelBuilder implements ISmartBlockModel
{
public static final ModelResourceLocation modelResourceLocation = new ModelResourceLocation(Reference.MODID + ":frozenBlock");
private IBakedModel currentBlockModel;

public FrozenBlockModelBuilder(IBakedModel defaultModel)
{
	this.currentBlockModel = defaultModel;
}

@Override
public IBakedModel handleBlockState(IBlockState state)
{
	this.currentBlockModel = I9Utils.getBlockModel(FrozenBlockRegistry.getFrozenState(state));
	return this;
}

@Override
public TextureAtlasSprite getTexture()
{
	return this.currentBlockModel.getTexture();
}

@Override
public List getFaceQuads(EnumFacing face)
{
	List<BakedQuad> quads = Lists.<BakedQuad>newArrayList();
	List<BakedQuad> faceQuads = this.currentBlockModel.getFaceQuads(face);

	for(BakedQuad bq : faceQuads)
	{
		quads.add(new BakedQuad(this.alterColor(bq.getVertexData()), 0, face));
	}

	return quads;
}

@Override
public List getGeneralQuads()
{
	List<BakedQuad> quads = Lists.<BakedQuad>newArrayList();
	List<BakedQuad> generalQuads = this.currentBlockModel.getGeneralQuads();

	for(BakedQuad bq : generalQuads)
	{
		quads.add(new BakedQuad(this.alterColor(bq.getVertexData()), 0, bq.getFace()));
	}

	return quads;
}

private int[] alterColor(int[] vd)
{
	int[] vertexData = Arrays.copyOf(vd, vd.length);
	int[] vc = this.sepiaizeWithHue(vertexData[3], vertexData[4], vertexData[5]);
	int[] vc2 = this.sepiaizeWithHue(vertexData[10], vertexData[11], vertexData[12]);
	int[] vc3 = this.sepiaizeWithHue(vertexData[17], vertexData[18], vertexData[19]);
	int[] vc4 = this.sepiaizeWithHue(vertexData[24], vertexData[25], vertexData[26]);

	/* THIS SECTION IS WHAT DOESN'T WORK */
	vertexData[3] = vc[0];
	vertexData[4] = vc[1];
	vertexData[5] = vc[2];
	vertexData[10] = vc2[0];
	vertexData[11] = vc2[1];
	vertexData[12] = vc2[2];
	vertexData[17] = vc3[0];
	vertexData[18] = vc3[1];
	vertexData[19] = vc3[2];
	vertexData[24] = vc4[0];
	vertexData[25] = vc4[1];
	vertexData[26] = vc4[2];
	/* ---------------------------------- */

	return vertexData;
}

private int[] sepiaizeWithHue(int red, int green, int blue)
{
	int tr = (int)((0.393D * red) + (0.769D * green) + (0.189D * blue));
	int tg = (int)((0.349D * red) + (0.686D * green) + (0.168D * blue));
	int tb = (int)((0.272D * red) + (0.534D * green) + (0.131D * blue));
	float[] hsv = Color.RGBtoHSB(Math.min(tr, 255), Math.min(tg, 255), Math.min(tb, 255), null);
	int color = Color.getHSBColor(180, 20, hsv[2]).getRGB();
	int nR = (color >> 16) & 0xFF;
	int nG = (color >>  & 0xFF;
	int nB = (color) & 0xFF;
	return new int[] { nR, nG, nB };
}

@Override
public boolean isAmbientOcclusion()
{
	return this.currentBlockModel.isAmbientOcclusion();
}

@Override
public boolean isGui3d()
{
	return this.currentBlockModel.isGui3d();
}

@Override
public boolean isBuiltInRenderer()
{
	return this.currentBlockModel.isBuiltInRenderer();
}

@Override
public ItemCameraTransforms getItemCameraTransforms()
{
	return this.currentBlockModel.getItemCameraTransforms();
}
}

  • Author

EDIT:

ย 

It would seem like I am too use to shaders in WebGL. I had assumed that each vertex on a side had an associated RGB int array, but apparently that is not the case. I dug deeper into Forge's code and I looks like I was completely wrong. Each vertex does not have an RGB array, but rather, each side has an RGB int shader. I was updating indicies that I thought were colors but were actually uv and vertex points, which explains why the model always rendered as a solid red cube. The correct shader code is below, with vd being the original vertex data array.

ย 

	private int[] alterColor(int[] vd)
{
	int[] vertexData = Arrays.copyOf(vd, vd.length);
	vertexData[3] = this.sepiaizeWithHue(vd[3]);
	vertexData[10] = this.sepiaizeWithHue(vd[10]);
	vertexData[17] = this.sepiaizeWithHue(vd[17]);
	vertexData[24] = this.sepiaizeWithHue(vd[24]);
	return vertexData;
}

ย 

HOWEVER

ย 

This is half-way to what I aim to accomplish. At the moment, the generated color is overlayed on top of the existing color. Does anyone know a way to completely remove the original color of the texture so that only my sepia version remains?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.