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 Link Removed) 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 Link Removed, 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 >> 8) & 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();
}
}
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 Link Removed) 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 Link Removed, 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!