use of com.bergerkiller.bukkit.common.map.MapTexture in project BKCommonLib by bergerhealer.
the class Model method build.
public void build(MapResourcePack resourcePack, RenderOptions options) {
// Mostly for debug, but can be useful elsewhere perhaps?
this.name = options.lookupModelName();
// Build all textures, turning paths into absolute paths
boolean hasChanges;
do {
hasChanges = false;
for (Map.Entry<String, String> textureEntry : this.textures.entrySet()) {
if (textureEntry.getValue().startsWith("#")) {
String texture = this.textures.get(textureEntry.getValue().substring(1));
if (texture != null) {
textureEntry.setValue(texture);
hasChanges = true;
}
}
}
} while (hasChanges);
// This basically creates a small cube for every non-transparent pixel in the texture
if (this.builtinType == BuiltinType.GENERATED) {
this.elements.clear();
MapTexture result = null;
for (int i = 0; ; i++) {
String layerKey = "layer" + i;
String layerTexturePath = this.textures.get(layerKey);
if (layerTexturePath == null) {
break;
}
MapTexture texture = resourcePack.getTexture(layerTexturePath);
// Item-specific layer render colors
texture = applyTint(texture, options.get(layerKey + "tint"));
if (result == null) {
result = texture.clone();
} else {
result.draw(texture, 0, 0);
}
}
if (result != null) {
// We really cannot handle models like 600x600 - bad things really happen...
if (result.getWidth() > 16 || result.getHeight() > 16) {
MapTexture newTexture = MapTexture.createEmpty(16, 16);
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
int px = (x * result.getWidth()) / 16;
int py = (y * result.getHeight()) / 16;
newTexture.writePixel(x, y, result.readPixel(px, py));
}
}
result = newTexture;
}
for (int y = 0; y < result.getHeight(); y++) {
for (int x = 0; x < result.getWidth(); x++) {
byte color = result.readPixel(x, y);
if (color == MapColorPalette.COLOR_TRANSPARENT) {
continue;
}
Element element = new Element();
element.from = new Vector3(x, 0, y);
element.to = new Vector3(element.from.x + 1, element.from.y + 1, element.from.z + 1);
for (BlockFace bface : FaceUtil.BLOCK_SIDES) {
// If pixel on this face is not transparent, do not add one there
if (!FaceUtil.isVertical(bface)) {
int x2 = x - bface.getModX();
int y2 = y - bface.getModZ();
if (result.readPixel(x2, y2) == MapColorPalette.COLOR_TRANSPARENT) {
continue;
}
}
Face face = new Face();
MapTexture tex = MapTexture.createEmpty(1, 1);
tex.writePixel(0, 0, color);
face.texture = tex;
element.faces.put(bface, face);
}
this.elements.add(element);
}
}
}
}
// Apply all textures to the model faces
for (Element element : this.elements) {
element.build(resourcePack, this.textures);
}
}
use of com.bergerkiller.bukkit.common.map.MapTexture in project BKCommonLib by bergerhealer.
the class MapCanvasFunctionsTest method testPixelMove.
@Ignore
@Test
public void testPixelMove() {
MapTexture map = MapTexture.createEmpty(200, 200);
map.fillRectangle(0, 0, 50, 50, MapColorPalette.COLOR_RED);
map.fillRectangle(20, 40, 100, 90, MapColorPalette.COLOR_BLUE);
MapDebugWindow.showMap(map);
map.movePixels(-10, -30);
MapDebugWindow.showMapForever(map);
}
use of com.bergerkiller.bukkit.common.map.MapTexture in project BKCommonLib by bergerhealer.
the class MapResourcePackTest method testItemSlotTexture.
@Ignore
@Test
public void testItemSlotTexture() {
Random rand = new Random();
MapTexture map = MapTexture.createEmpty(128, 128);
map.fill(MapColorPalette.getColor(128, 128, 128));
// new MapResourcePack("https://www.dropbox.com/s/s77nz3zaclrdqog/TestPack.zip?dl=1");
MapResourcePack pack = MapResourcePack.SERVER;
pack.load();
ItemStack item = ItemUtil.createItem(Material.DIAMOND_SWORD, 2, 1);
ItemUtil.getMetaTag(item, true).putValue("Unbreakable", true);
for (int x = 0; x < 128 - 16; x += 18) {
for (int y = 0; y < 128 - 16; y += 18) {
testDrawModel(map, pack, x, y, rand.nextInt(70));
}
}
/*
for (int x = 0; x < 128-16; x += 18) {
for (int y = 0; y < 128-16; y += 18) {
testDraw(map, pack, x, y, Material.values()[rand.nextInt(Material.values().length)]);
}
}
*/
MapDebugWindow.showMapForeverAutoScale(map);
}
Aggregations