use of com.bergerkiller.bukkit.common.map.util.Model in project BKCommonLib by bergerhealer.
the class MapResourcePack method loadBlockVariant.
private Model loadBlockVariant(BlockModelState.Variant variant, BlockRenderOptions blockRenderOptions) {
Model model = this.loadModel(variant.modelName, blockRenderOptions);
if (model == null) {
return null;
}
model.buildBlock(blockRenderOptions);
variant.update(model);
model.buildQuads();
return model;
}
use of com.bergerkiller.bukkit.common.map.util.Model in project BKCommonLib by bergerhealer.
the class MapResourcePack method loadBlockModel.
/**
* Loads a block model, always fetching it from the resource pack instead of the cache
*
* @param blockRenderOptions of the block
* @return the model, or <i>null</i> if not found
*/
protected final Model loadBlockModel(BlockRenderOptions blockRenderOptions) {
if (blockRenderOptions.getBlockData().isType(Material.AIR)) {
// air. No model.
return new Model();
}
BlockRenderProvider oldProvider = this.currProvider;
try {
// Some blocks are handled by providers
this.currProvider = BlockRenderProvider.get(blockRenderOptions.getBlockData());
if (this.currProvider != null) {
Model model = this.currProvider.createModel(this, blockRenderOptions);
if (model != null) {
return model;
}
}
String blockName = blockRenderOptions.lookupModelName();
// Find the blockstate
BlockModelState state = this.openGsonObject(BlockModelState.class, ResourceType.BLOCKSTATES, blockName);
// Find out the variant that is used
List<BlockModelState.Variant> variants;
if (state != null) {
// Figure out from the blockstate what variant to use
variants = state.findVariants(blockRenderOptions);
} else {
// Default variant based on block name
BlockModelState.Variant variant = new BlockModelState.Variant();
variant.modelName = "block/" + blockName;
variants = Arrays.asList(variant);
}
// If no variants are found, render nothing (AIR)
if (variants.isEmpty()) {
return new Model();
}
// Not multipart, then simply load the one variant
if (variants.size() == 1) {
return this.loadBlockVariant(variants.get(0), blockRenderOptions);
}
// Add all variant elements to the model
Model result = new Model();
boolean succ = true;
for (BlockModelState.Variant variant : variants) {
Model subModel = this.loadBlockVariant(variant, blockRenderOptions);
if (subModel != null) {
result.elements.addAll(subModel.elements);
} else {
succ = false;
}
}
if (!succ && result.elements.isEmpty()) {
return null;
} else {
return result;
}
} finally {
// restore
this.currProvider = oldProvider;
}
}
use of com.bergerkiller.bukkit.common.map.util.Model in project BKCommonLib by bergerhealer.
the class Pseudo3DImagePanel method paintComponent.
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
MapTexture image = MapTexture.createEmpty(MapModelRenderTest.RES_WIDTH, MapModelRenderTest.RES_HEIGHT);
image.draw(background, 0, 0);
image.setBlendMode(MapBlendMode.OVERLAY);
// new Vector3(-1.0, 1.0, -1.0));
image.setLightOptions(0.0f, 1.0f, new Vector3(-1, 1, -1));
System.out.println("{" + p3.x + ", " + p2.x + ", " + p3.y + "}");
// Draws a 3D quad
float scale = 16.0f;
float yaw = (float) (p1.x - 128);
float pitch = (float) (p1.y - 128);
System.out.println("Yaw=" + yaw + " Pitch=" + pitch);
BlockRenderOptions opt = BlockData.fromMaterial(Material.PLAYER_HEAD).getDefaultRenderOptions();
System.out.println(opt);
ItemStack item = ItemUtil.createItem(Material.GOLDEN_PICKAXE, 15, 1);
ItemUtil.getMetaTag(item, true).putValue("Unbreakable", true);
Model model = textures.getBlockModel(opt);
Matrix4x4 transform = new Matrix4x4();
// image.draw(textures.getItemTexture(item, 32, 32), 0, 0);
transform.translate(p0.x, 0.0f, p0.y);
transform.scale(scale);
transform.rotateX(pitch);
transform.rotateY(yaw);
transform.translate(-8, -8, -8);
// image.drawModel(textures.getBlockModel(Material.QUARTZ_BLOCK), transform);
transform.translate(20, 0, 0);
image.drawModel(model, transform);
g.drawImage(image.toJavaImage(), 0, 0, null);
int r = 8;
g.setColor(Color.BLUE);
g.fillOval((int) p0.x - r, (int) p0.y - r, r + r, r + r);
g.fillOval((int) p1.x - r, (int) p1.y - r, r + r, r + r);
g.fillOval((int) p2.x - r, (int) p2.y - r, r + r, r + r);
g.fillOval((int) p3.x - r, (int) p3.y - r, r + r, r + r);
}
use of com.bergerkiller.bukkit.common.map.util.Model in project BKCommonLib by bergerhealer.
the class MapResourcePackTest method testBlockModels.
@Ignore
@Test
public void testBlockModels() {
MapResourcePack resourcePack = MapResourcePack.VANILLA;
// All of these have animations or a complicated model
// We need to define a simplified placeholder model to make it work
// This acts as a TODO list for models to fix
HashSet<String> ignore = new HashSet<String>();
ignore.add("bed");
ignore.add("skull");
ignore.add("barrier");
ignore.add("standing_banner");
ignore.add("wall_banner");
ignore.add("piston_extension");
// this is the black void-looking surface
ignore.add("end_portal");
// I could not find what this was
ignore.add("structure_void");
// Shulker boxes come in many colors. How will we deal?
ignore.add("brown_shulker_box");
ignore.add("white_shulker_box");
ignore.add("red_shulker_box");
ignore.add("magenta_shulker_box");
ignore.add("pink_shulker_box");
ignore.add("yellow_shulker_box");
ignore.add("black_shulker_box");
ignore.add("cyan_shulker_box");
ignore.add("orange_shulker_box");
ignore.add("lime_shulker_box");
ignore.add("light_blue_shulker_box");
ignore.add("green_shulker_box");
ignore.add("purple_shulker_box");
ignore.add("gray_shulker_box");
ignore.add("blue_shulker_box");
ignore.add("silver_shulker_box");
boolean hasLoadErrors = false;
for (BlockData block : BlockData.values()) {
Model model = resourcePack.getBlockModel(block);
String name = block.getBlockName();
if (model.placeholder && !ignore.contains(name)) {
hasLoadErrors = true;
System.err.println("Failed to load model of block " + block.toString());
}
}
if (hasLoadErrors) {
fail("Some block models could not be loaded!");
}
}
use of com.bergerkiller.bukkit.common.map.util.Model in project BKCommonLib by bergerhealer.
the class MapResourcePackTest method testItemModels.
@Ignore
@Test
public void testItemModels() {
MapResourcePack resourcePack = MapResourcePack.VANILLA;
// All of these have animations or a complicated model
// We need to define a simplified placeholder model to make it work
// This acts as a TODO list for models to fix
HashSet<String> ignore = new HashSet<String>();
ignore.add("bed");
ignore.add("chest");
ignore.add("trapped_chest");
ignore.add("ender_chest");
ignore.add("anvil");
ignore.add("skull");
ignore.add("banner");
ignore.add("shield");
// Shulker boxes come in many colors. How will we deal?
ignore.add("brown_shulker_box");
ignore.add("white_shulker_box");
ignore.add("red_shulker_box");
ignore.add("magenta_shulker_box");
ignore.add("pink_shulker_box");
ignore.add("yellow_shulker_box");
ignore.add("black_shulker_box");
ignore.add("cyan_shulker_box");
ignore.add("orange_shulker_box");
ignore.add("lime_shulker_box");
ignore.add("light_blue_shulker_box");
ignore.add("green_shulker_box");
ignore.add("purple_shulker_box");
ignore.add("gray_shulker_box");
ignore.add("blue_shulker_box");
ignore.add("silver_shulker_box");
boolean hasLoadErrors = false;
for (Material type : ItemUtil.getItemTypes()) {
for (ItemStack variant : ItemUtil.getItemVariants(type)) {
Model model = resourcePack.getItemModel(variant);
if (model.placeholder && !ignore.contains(model.name)) {
hasLoadErrors = true;
System.err.println("Failed to load model of item " + variant.getType() + ":" + variant.getDurability() + " " + model.name);
}
}
}
if (hasLoadErrors) {
fail("Some block models could not be loaded!");
}
}
Aggregations