Alright, sorry. I was in a hurry to type that last post.
@pspeed I’m not using the same DefaultImageRaster each time, and even if I was I manually clear it to black each time. Here’s the method for generating the textures:
[java]
public Material build() {
if (!isBuilt) {
isBuilt = true;
Texture tempTex = AssetLoading.getAssetManager().loadTexture(“Textures/Weapons/Template.png”).clone();
Image output = tempTex.getImage().clone();
DefaultImageRaster outputPainter = new DefaultImageRaster(output, 0);
int nonBlack = 0;
for (int x = 0; x < 800; x++) {
for (int y = 0; y < 800; y++) {
if (outputPainter.getPixel(x, y).getRed() != 0.0 && outputPainter.getPixel(x, y).getGreen() != 0.0 && outputPainter.getPixel(x, y).getBlue() != 0.0) {
nonBlack++;
}
outputPainter.setPixel(x, y, ColorRGBA.Black);
}
}
System.out.println("— " + name + "\nNon-black pixels: " + nonBlack);
canSetMain = true;
canSetSec = true;
canSetExtra = true;
setMainColor(outputPainter);
setSecondaryColor(outputPainter);
setExtraColor(outputPainter);
Texture2D finalTex = new Texture2D(output.clone());
finalTex.setName(name + “_texture”);
finalMaterial = new Material(AssetLoading.getAssetManager(), “Common/MatDefs/Light/Lighting.j3md”);
finalMaterial.setTexture(“DiffuseMap”, finalTex.clone());
finalMaterial.setName(name);
return finalMaterial;
} else {
return null;
}
}
[/java]
As you can see, I load the template texture, clone it, take it's image, clone it, paint it, then clone it again. Each of the setColor methods looks something like the following:
[java]
private void setMainColor(DefaultImageRaster outputPainter) {
if (canSetMain) {
canSetMain = false;
Texture tex = AssetLoading.getAssetManager().loadTexture("Textures/Weapons/" + weaponType.toString() + "/" + name + "_main.png");
Image main = tex.getImage();
DefaultImageRaster tintingMachineMain = new DefaultImageRaster(main, 0);
for (int x = 1; x < 800; x++) {
for (int y = 1; y < 800; y++) {
try {
ColorRGBA curPixel = tintingMachineMain.getPixel(x, y);
if (curPixel.getRed() == 1 && curPixel.getGreen() == 1 && curPixel.getBlue() == 1) {
outputPainter.setPixel(x, 800 - y, mainColor);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
[/java]
I'm using x, 800-y as the position to flip the image by the way.
@zarch
What should be happening is the colors should be painted to the output image, which is applied to a texture and given to a material for the weapon part.
Here is an image of what really happens:

The lower handle part has the texture of the top slide part. The output is exactly as it should be, showing that the handle’s material was changed to a material with the name “Base2,” texture named “Base2_texture,” and the correct colors.
I don’t do anything special to make this happen, nor is there any rhyme or reason to when it happens. It seems to be entirely random. I output a lot of things while running this and I’m still pretty lost. All of the outputs seem correct except for the number of non-black pixels each time I customize another color.
Here’s the aforementioned buildMaterial() method:
[java]
public void buildMaterial(ColorRGBA main, ColorRGBA sec, ColorRGBA extra) {
Material mat = new WeaponMaterial(getName(), type).setColors(main, sec, extra).build();
//super.setMaterial(mat);
if (getChild(0) != null) {
getChild(0).setMaterial(mat);
}
System.out.println("Attempted to set material for " + getName() + “!!\n”
+ "Mat’s name: " + mat.getName() + (mat.getTextureParam(“DiffuseMap”) != null ? "\nMat’s tex name: " + mat.getTextureParam(“DiffuseMap”).getTextureValue().getName() : “”));
}
[/java]
Hope that makes a little bit more sense.