Search in sources :

Example 1 with Model

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;
}
Also used : Model(com.bergerkiller.bukkit.common.map.util.Model) GeneratedModel(com.bergerkiller.bukkit.common.internal.resources.builtin.GeneratedModel)

Example 2 with 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;
    }
}
Also used : BlockRenderProvider(com.bergerkiller.bukkit.common.internal.blocks.BlockRenderProvider) Model(com.bergerkiller.bukkit.common.map.util.Model) GeneratedModel(com.bergerkiller.bukkit.common.internal.resources.builtin.GeneratedModel) BlockModelState(com.bergerkiller.bukkit.common.map.util.BlockModelState)

Example 3 with Model

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);
}
Also used : MapTexture(com.bergerkiller.bukkit.common.map.MapTexture) BlockRenderOptions(com.bergerkiller.bukkit.common.wrappers.BlockRenderOptions) Model(com.bergerkiller.bukkit.common.map.util.Model) Vector3(com.bergerkiller.bukkit.common.math.Vector3) ItemStack(org.bukkit.inventory.ItemStack) Matrix4x4(com.bergerkiller.bukkit.common.math.Matrix4x4)

Example 4 with Model

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!");
    }
}
Also used : MapResourcePack(com.bergerkiller.bukkit.common.map.MapResourcePack) Model(com.bergerkiller.bukkit.common.map.util.Model) BlockData(com.bergerkiller.bukkit.common.wrappers.BlockData) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Model

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!");
    }
}
Also used : MapResourcePack(com.bergerkiller.bukkit.common.map.MapResourcePack) Model(com.bergerkiller.bukkit.common.map.util.Model) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Model (com.bergerkiller.bukkit.common.map.util.Model)11 GeneratedModel (com.bergerkiller.bukkit.common.internal.resources.builtin.GeneratedModel)7 MapResourcePack (com.bergerkiller.bukkit.common.map.MapResourcePack)2 MapTexture (com.bergerkiller.bukkit.common.map.MapTexture)2 Matrix4x4 (com.bergerkiller.bukkit.common.math.Matrix4x4)2 Vector3 (com.bergerkiller.bukkit.common.math.Vector3)2 HashSet (java.util.HashSet)2 BlockFace (org.bukkit.block.BlockFace)2 ItemStack (org.bukkit.inventory.ItemStack)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 BlockRenderProvider (com.bergerkiller.bukkit.common.internal.blocks.BlockRenderProvider)1 BlockModelState (com.bergerkiller.bukkit.common.map.util.BlockModelState)1 Face (com.bergerkiller.bukkit.common.map.util.Model.Element.Face)1 BlockData (com.bergerkiller.bukkit.common.wrappers.BlockData)1 BlockRenderOptions (com.bergerkiller.bukkit.common.wrappers.BlockRenderOptions)1 ItemRenderOptions (com.bergerkiller.bukkit.common.wrappers.ItemRenderOptions)1 Material (org.bukkit.Material)1