Search in sources :

Example 6 with TextureAnimation

use of com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureAnimation in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class ModelRenderer method render.

public RenderResult render(int width, int height, int internalWidth, int internalHeight, ResourceManager manager, boolean post1_8, String modelKey, ModelDisplayPosition displayPosition, Map<ModelOverrideType, Float> predicate, Map<String, TextureResource> providedTextures, TintIndexData tintIndexData, boolean enchanted, boolean usePlayerModelPosition) {
    String cacheKey = cacheKey(width, height, manager.getUuid(), modelKey, displayPosition, predicate, cacheKeyProvidedTextures(providedTextures), enchanted);
    Cache<?> cachedRender = Cache.getCache(cacheKey);
    if (cachedRender != null) {
        RenderResult cachedResult = (RenderResult) cachedRender.getObject();
        if (cachedResult.isSuccessful()) {
            return cachedResult;
        }
    }
    String rejectedReason = null;
    BlockModel blockModel = manager.getModelManager().resolveBlockModel(modelKey, post1_8, predicate);
    if (blockModel == null) {
        return new RenderResult(MODEL_NOT_FOUND, null);
    }
    BufferedImage image = new BufferedImage(internalWidth, internalHeight, BufferedImage.TYPE_INT_ARGB);
    if (blockModel.getRawParent() == null || !blockModel.getRawParent().contains("/")) {
        renderBlockModel(generateStandardRenderModel(blockModel, manager, providedTextures, tintIndexData, enchanted, false), image, blockModel.getDisplay(displayPosition), blockModel.getGUILight(), usePlayerModelPosition);
    } else if (blockModel.getRawParent().equals(ModelManager.ITEM_BASE)) {
        Graphics2D g = image.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
        for (int i = 0; blockModel.getTextures().containsKey(ModelManager.ITEM_BASE_LAYER + i); i++) {
            String resourceLocation = blockModel.getTextures().get(ModelManager.ITEM_BASE_LAYER + i);
            if (!resourceLocation.contains(":")) {
                resourceLocation = ResourceRegistry.DEFAULT_NAMESPACE + ":" + resourceLocation;
            }
            TextureResource resource = providedTextures.get(resourceLocation);
            if (resource == null) {
                resource = manager.getTextureManager().getTexture(resourceLocation);
            }
            BufferedImage texture = resource.getTexture();
            if (resource.hasTextureMeta()) {
                TextureMeta meta = resource.getTextureMeta();
                if (meta.hasProperties()) {
                    TextureProperties properties = meta.getProperties();
                    if (properties.isBlur()) {
                        texture = ImageUtils.applyGaussianBlur(texture);
                    }
                }
                if (meta.hasAnimation()) {
                    TextureAnimation animation = meta.getAnimation();
                    if (animation.hasWidth() && animation.hasHeight()) {
                        texture = ImageUtils.copyAndGetSubImage(texture, 0, 0, animation.getWidth(), animation.getHeight());
                    } else {
                        texture = ImageUtils.copyAndGetSubImage(texture, 0, 0, texture.getWidth(), texture.getWidth());
                    }
                }
            }
            if (resourceLocation.equals(ResourceRegistry.MAP_MARKINGS_LOCATION)) {
                ImageUtils.xor(image, ImageUtils.resizeImageAbs(texture, image.getWidth(), image.getHeight()), 200);
            } else {
                g.drawImage(texture, 0, 0, image.getWidth(), image.getHeight(), null);
            }
        }
        g.dispose();
        image = tintIndexData.applyTint(image, 0);
        if (enchanted) {
            image = enchantmentGlintProvider.apply(image);
        }
    } else {
        rejectedReason = blockModel.getRawParent();
    }
    RenderResult result;
    if (rejectedReason == null) {
        result = new RenderResult(ImageUtils.resizeImageQuality(image, width, height), blockModel);
    } else {
        result = new RenderResult(rejectedReason == null ? "null" : rejectedReason, blockModel);
    }
    Cache.putCache(cacheKey, result, cacheTimeoutSupplier.getAsLong());
    return result;
}
Also used : TextureResource(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureResource) TextureProperties(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureProperties) TextureMeta(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureMeta) TextureAnimation(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureAnimation) BlockModel(com.loohp.interactivechatdiscordsrvaddon.resources.models.BlockModel) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

TextureAnimation (com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureAnimation)6 TextureMeta (com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureMeta)6 TextureProperties (com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureProperties)6 TextureResource (com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureResource)6 BufferedImage (java.awt.image.BufferedImage)6 Graphics2D (java.awt.Graphics2D)5 BlockModel (com.loohp.interactivechatdiscordsrvaddon.resources.models.BlockModel)3 Model (com.loohp.blockmodelrenderer.render.Model)2 GeneratedTextureResource (com.loohp.interactivechatdiscordsrvaddon.resources.textures.GeneratedTextureResource)2 Hexahedron (com.loohp.blockmodelrenderer.render.Hexahedron)1 Point3D (com.loohp.blockmodelrenderer.render.Point3D)1 Coordinates3D (com.loohp.interactivechatdiscordsrvaddon.resources.models.Coordinates3D)1 ModelDisplay (com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelDisplay)1 ModelElement (com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelElement)1 ModelElementRotation (com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelElement.ModelElementRotation)1 ModelFace (com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelFace)1 ModelFaceSide (com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelFace.ModelFaceSide)1 TextureUV (com.loohp.interactivechatdiscordsrvaddon.resources.models.TextureUV)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1