Search in sources :

Example 1 with BlockStep

use of org.dynmap.utils.BlockStep in project dynmap by webbukkit.

the class ShadowHDLighting method applySmoothLighting.

private void applySmoothLighting(HDPerspectiveState ps, HDShaderState ss, Color incolor, Color[] outcolor, int[] shadowscale) {
    int[] xyz = ps.getSubblockCoord();
    int scale = (int) ps.getScale();
    int mid = scale / 2;
    BlockStep s1, s2;
    int w1, w2;
    /* Figure out which directions to look */
    switch(ps.getLastBlockStep()) {
        case X_MINUS:
        case X_PLUS:
            if (xyz[1] < mid) {
                s1 = BlockStep.Y_MINUS;
                w1 = mid - xyz[1];
            } else {
                s1 = BlockStep.Y_PLUS;
                w1 = xyz[1] - mid;
            }
            if (xyz[2] < mid) {
                s2 = BlockStep.Z_MINUS;
                w2 = mid - xyz[2];
            } else {
                s2 = BlockStep.Z_PLUS;
                w2 = xyz[2] - mid;
            }
            break;
        case Z_MINUS:
        case Z_PLUS:
            if (xyz[0] < mid) {
                s1 = BlockStep.X_MINUS;
                w1 = mid - xyz[0];
            } else {
                s1 = BlockStep.X_PLUS;
                w1 = xyz[0] - mid;
            }
            if (xyz[1] < mid) {
                s2 = BlockStep.Y_MINUS;
                w2 = mid - xyz[1];
            } else {
                s2 = BlockStep.Y_PLUS;
                w2 = xyz[1] - mid;
            }
            break;
        default:
            if (xyz[0] < mid) {
                s1 = BlockStep.X_MINUS;
                w1 = mid - xyz[0];
            } else {
                s1 = BlockStep.X_PLUS;
                w1 = xyz[0] - mid;
            }
            if (xyz[2] < mid) {
                s2 = BlockStep.Z_MINUS;
                w2 = mid - xyz[2];
            } else {
                s2 = BlockStep.Z_PLUS;
                w2 = xyz[2] - mid;
            }
            break;
    }
    /* Now get the 3 needed light levels */
    LightLevels skyemit0 = ps.getCachedLightLevels(0);
    ps.getLightLevels(skyemit0);
    LightLevels skyemit1 = ps.getCachedLightLevels(1);
    ps.getLightLevelsAtStep(s1, skyemit1);
    LightLevels skyemit2 = ps.getCachedLightLevels(2);
    ps.getLightLevelsAtStep(s2, skyemit2);
    /* Get light levels */
    int ll0 = getLightLevel(skyemit0, true);
    int ll1 = getLightLevel(skyemit1, true);
    int weight = 0;
    if (ll1 < ll0)
        weight -= w1;
    else if (ll1 > ll0)
        weight += w1;
    int ll2 = getLightLevel(skyemit2, true);
    if (ll2 < ll0)
        weight -= w2;
    else if (ll2 > ll0)
        weight += w2;
    outcolor[0].setColor(incolor);
    int cscale = 256;
    if (weight == 0) {
        cscale = shadowscale[ll0];
    } else if (weight < 0) {
        /* If negative, interpolate down */
        weight = -weight;
        if (ll0 > 0) {
            cscale = (shadowscale[ll0] * (scale - weight) + shadowscale[ll0 - 1] * weight) / scale;
        } else {
            cscale = shadowscale[ll0];
        }
    } else {
        if (ll0 < 15) {
            cscale = (shadowscale[ll0] * (scale - weight) + shadowscale[ll0 + 1] * weight) / scale;
        } else {
            cscale = shadowscale[ll0];
        }
    }
    if (cscale < 256) {
        Color c = outcolor[0];
        c.setRGBA((c.getRed() * cscale) >> 8, (c.getGreen() * cscale) >> 8, (c.getBlue() * cscale) >> 8, c.getAlpha());
    }
    if (outcolor.length > 1) {
        ll0 = getLightLevel(skyemit0, false);
        ll1 = getLightLevel(skyemit1, false);
        weight = 0;
        if (ll1 < ll0)
            weight -= w1;
        else if (ll1 > ll0)
            weight += w1;
        ll2 = getLightLevel(skyemit2, false);
        if (ll2 < ll0)
            weight -= w2;
        else if (ll2 > ll0)
            weight += w2;
        outcolor[1].setColor(incolor);
        cscale = 256;
        if (weight == 0) {
            cscale = shadowscale[ll0];
        } else if (weight < 0) {
            /* If negative, interpolate down */
            weight = -weight;
            if (ll0 > 0) {
                cscale = (shadowscale[ll0] * (scale - weight) + shadowscale[ll0 - 1] * weight) / scale;
            } else {
                cscale = shadowscale[ll0];
            }
        } else {
            if (ll0 < 15) {
                cscale = (shadowscale[ll0] * (scale - weight) + shadowscale[ll0 + 1] * weight) / scale;
            } else {
                cscale = shadowscale[ll0];
            }
        }
        if (cscale < 256) {
            Color c = outcolor[1];
            c.setRGBA((c.getRed() * cscale) >> 8, (c.getGreen() * cscale) >> 8, (c.getBlue() * cscale) >> 8, c.getAlpha());
        }
    }
}
Also used : LightLevels(org.dynmap.utils.LightLevels) Color(org.dynmap.Color) BlockStep(org.dynmap.utils.BlockStep)

Example 2 with BlockStep

use of org.dynmap.utils.BlockStep in project dynmap by webbukkit.

the class TexturePack method getCurrentBlockMaterials.

public String[] getCurrentBlockMaterials(DynmapBlockState blk, MapIterator mapiter, int[] txtidx, BlockStep[] steps) {
    HDBlockStateTextureMap map = HDBlockStateTextureMap.getByBlockState(blk);
    if (txtidx == null)
        txtidx = deftxtidx;
    // One for each face
    String[] rslt = new String[txtidx.length];
    boolean handlestdrot = (steps != null) && (!map.stdrotate);
    Integer blockcoloring = this.blockColoring.getBlkStateValue(blk);
    int custclrmult = -1;
    // If block has custom coloring
    if (blockcoloring != null) {
        LoadedImage img = imgs[blockcoloring.intValue()];
        if (img.argb != null) {
            custclrmult = mapiter.getSmoothWaterColorMultiplier(img.argb);
        } else {
            blockcoloring = null;
        }
    }
    for (int patchidx = 0; patchidx < txtidx.length; patchidx++) {
        int faceindex = txtidx[patchidx];
        int textid = map.faces[faceindex];
        int mod = textid / COLORMOD_MULT_INTERNAL;
        textid = textid % COLORMOD_MULT_INTERNAL;
        BlockStep step = steps[patchidx];
        /* If clear-inside op, get out early */
        if ((mod == COLORMOD_CLEARINSIDE) || (mod == COLORMOD_MULTTONED_CLEARINSIDE)) {
            BlockStep dir = step.opposite();
            /* Check if previous block is same block type as we are: surface is transparent if it is */
            if (blk.matchingBaseState(mapiter.getBlockTypeAt(dir))) {
                // Skip: no texture
                continue;
            }
            /* If water block, to watercolor tone op */
            if (blk.isWater()) {
                mod = COLORMOD_WATERTONED;
            } else if (mod == COLORMOD_MULTTONED_CLEARINSIDE) {
                mod = COLORMOD_MULTTONED;
            }
        }
        if (ctm != null) {
            textid = ctm.mapTexture(mapiter, blk, step, textid, null);
        }
        if (textid >= 0) {
            // Default texture
            rslt[patchidx] = getMatIDForTileID(textid);
            int mult = 0xFFFFFF;
            BiomeMap bio;
            if (blockcoloring == null) {
                switch(mod) {
                    case COLORMOD_GRASSTONED:
                    case COLORMOD_GRASSTONED270:
                        bio = mapiter.getBiome();
                        if ((bio == BiomeMap.SWAMPLAND) && (imgs[IMG_SWAMPGRASSCOLOR] != null)) {
                            mult = getBiomeTonedColor(imgs[IMG_SWAMPGRASSCOLOR], -1, bio, blk);
                        } else {
                            mult = getBiomeTonedColor(imgs[IMG_GRASSCOLOR], -1, bio, blk);
                        }
                        break;
                    case COLORMOD_FOLIAGETONED:
                    case COLORMOD_FOLIAGETONED270:
                    case COLORMOD_FOLIAGEMULTTONED:
                        mult = getBiomeTonedColor(imgs[IMG_FOLIAGECOLOR], -1, mapiter.getBiome(), blk);
                        break;
                    case COLORMOD_WATERTONED:
                    case COLORMOD_WATERTONED270:
                        mult = getBiomeTonedColor(imgs[IMG_WATERCOLORX], -1, mapiter.getBiome(), blk);
                        break;
                    case COLORMOD_PINETONED:
                        mult = getBiomeTonedColor(imgs[IMG_PINECOLOR], colorMultPine, mapiter.getBiome(), blk);
                        break;
                    case COLORMOD_BIRCHTONED:
                        mult = getBiomeTonedColor(imgs[IMG_BIRCHCOLOR], colorMultBirch, mapiter.getBiome(), blk);
                        break;
                    case COLORMOD_LILYTONED:
                        mult = getBiomeTonedColor(null, colorMultLily, mapiter.getBiome(), blk);
                        break;
                    case COLORMOD_MULTTONED:
                    case COLORMOD_MULTTONED_CLEARINSIDE:
                        if (map.custColorMult == null) {
                            mult = getBiomeTonedColor(null, map.colorMult, mapiter.getBiome(), blk);
                        } else {
                            mult = map.custColorMult.getColorMultiplier(mapiter);
                        }
                        break;
                    default:
                        mult = getBiomeTonedColor(null, -1, mapiter.getBiome(), blk);
                        break;
                }
            } else {
                mult = custclrmult;
            }
            if ((mult & 0xFFFFFF) != 0xFFFFFF) {
                rslt[patchidx] += String.format("__%06X", mult & 0xFFFFFF);
            }
            if (handlestdrot && (!map.stdrotate) && ((step == BlockStep.Y_MINUS) || (step == BlockStep.Y_PLUS))) {
                // Handle rotations
                switch(mod) {
                    case COLORMOD_ROT90:
                        mod = COLORMOD_ROT180;
                        break;
                    case COLORMOD_ROT180:
                        mod = COLORMOD_ROT270;
                        break;
                    case COLORMOD_ROT270:
                    case COLORMOD_GRASSTONED270:
                    case COLORMOD_FOLIAGETONED270:
                    case COLORMOD_WATERTONED270:
                        mod = 0;
                        break;
                    default:
                        mod = COLORMOD_ROT90;
                        break;
                }
            }
            // Handle rotations
            switch(mod) {
                case COLORMOD_ROT90:
                    rslt[patchidx] += "@" + OBJExport.ROT90;
                    break;
                case COLORMOD_ROT180:
                    rslt[patchidx] += "@" + OBJExport.ROT180;
                    break;
                case COLORMOD_ROT270:
                case COLORMOD_GRASSTONED270:
                case COLORMOD_FOLIAGETONED270:
                case COLORMOD_WATERTONED270:
                    rslt[patchidx] += "@" + +OBJExport.ROT270;
                    break;
                case COLORMOD_FLIPHORIZ:
                    rslt[patchidx] += "@" + OBJExport.HFLIP;
                    break;
            }
        }
    }
    return rslt;
}
Also used : BiomeMap(org.dynmap.common.BiomeMap) BlockStep(org.dynmap.utils.BlockStep)

Example 3 with BlockStep

use of org.dynmap.utils.BlockStep in project dynmap by webbukkit.

the class TexturePack method readColor.

/**
 * Read color for given subblock coordinate, with given block id and data and face
 * @param ps - perspective state
 * @param mapiter - map iterator
 * @param rslt - color result (returned with value)
 * @param blk - block state
 * @param lastblocktype - last block ID
 * @param ss - shader state
 */
public final void readColor(final HDPerspectiveState ps, final MapIterator mapiter, final Color rslt, final DynmapBlockState blk, final DynmapBlockState lastblocktype, final TexturePackHDShader.ShaderState ss) {
    HDBlockStateTextureMap map = HDBlockStateTextureMap.getByBlockState(blk);
    BlockStep laststep = ps.getLastBlockStep();
    int patchid = ps.getTextureIndex();
    /* See if patch index */
    int textid;
    int faceindex;
    if (patchid >= 0) {
        faceindex = patchid;
    } else {
        faceindex = laststep.ordinal();
    }
    textid = map.faces[faceindex];
    if (ctm != null) {
        int mod = 0;
        if (textid >= COLORMOD_MULT_INTERNAL) {
            mod = (textid / COLORMOD_MULT_INTERNAL) * COLORMOD_MULT_INTERNAL;
            textid -= mod;
        }
        textid = mod + ctm.mapTexture(mapiter, blk, laststep, textid, ss);
    }
    readColor(ps, mapiter, rslt, blk, lastblocktype, ss, map, laststep, patchid, textid, map.stdrotate);
    if (map.layers != null) {
        /* While transparent and more layers */
        while (rslt.isTransparent() && (map.layers[faceindex] >= 0)) {
            faceindex = map.layers[faceindex];
            textid = map.faces[faceindex];
            readColor(ps, mapiter, rslt, blk, lastblocktype, ss, map, laststep, patchid, textid, map.stdrotate);
        }
    }
}
Also used : BlockStep(org.dynmap.utils.BlockStep)

Example 4 with BlockStep

use of org.dynmap.utils.BlockStep in project dynmap by webbukkit.

the class OBJExport method handleBlock.

/**
 * Handle block at current iterator coord
 * @param id - block ID
 * @param iter - iterator
 * @param edgebits - bit N corresponds to side N being an endge (forge render)
 */
private void handleBlock(DynmapBlockState blk, MapIterator map, boolean[] edgebits) throws IOException {
    BlockStep[] steps = BlockStep.values();
    int[] txtidx = null;
    // See if the block has a patch model
    RenderPatch[] patches = models.getPatchModel(blk);
    /* If no patches, see if custom model */
    if (patches == null) {
        CustomBlockModel cbm = models.getCustomBlockModel(blk);
        if (cbm != null) {
            /* If so, get our meshes */
            patches = cbm.getMeshForBlock(map);
        }
    }
    if (patches != null) {
        steps = new BlockStep[patches.length];
        txtidx = new int[patches.length];
        for (int i = 0; i < txtidx.length; i++) {
            txtidx[i] = ((PatchDefinition) patches[i]).getTextureIndex();
            steps[i] = ((PatchDefinition) patches[i]).step;
        }
    } else {
        // See if volumetric
        short[] smod = models.getScaledModel(blk);
        if (smod != null) {
            patches = getScaledModelAsPatches(smod);
            steps = new BlockStep[patches.length];
            txtidx = new int[patches.length];
            for (int i = 0; i < patches.length; i++) {
                PatchDefinition pd = (PatchDefinition) patches[i];
                steps[i] = pd.step;
                txtidx[i] = pd.getTextureIndex();
            }
        }
    }
    // Set block ID and ID+meta groups
    updateGroup(GROUP_BLOCKID, "blk" + blk.baseState.globalStateIndex);
    updateGroup(GROUP_BLOCKIDMETA, "blk" + blk.globalStateIndex);
    // Get materials for patches
    String[] mats = shader.getCurrentBlockMaterials(blk, map, txtidx, steps);
    if (patches != null) {
        // Patch based model?
        for (int i = 0; i < patches.length; i++) {
            addPatch((PatchDefinition) patches[i], map.getX(), map.getY(), map.getZ(), mats[i]);
        }
    } else {
        boolean opaque = HDBlockStateTextureMap.getTransparency(blk) == BlockTransparency.OPAQUE;
        for (int face = 0; face < 6; face++) {
            // Get block in direction
            DynmapBlockState blk2 = map.getBlockTypeAt(BlockStep.oppositeValues[face]);
            // If we're not solid, or adjacent block is not solid, draw side
            if ((!opaque) || blk2.isAir() || edgebits[face] || (HDBlockStateTextureMap.getTransparency(blk2) != BlockTransparency.OPAQUE)) {
                addPatch(defaultPathces[face], map.getX(), map.getY(), map.getZ(), mats[face]);
            }
        }
    }
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState) BlockStep(org.dynmap.utils.BlockStep) PatchDefinition(org.dynmap.utils.PatchDefinition) CustomBlockModel(org.dynmap.hdmap.CustomBlockModel) RenderPatch(org.dynmap.renderer.RenderPatch)

Aggregations

BlockStep (org.dynmap.utils.BlockStep)4 Color (org.dynmap.Color)1 BiomeMap (org.dynmap.common.BiomeMap)1 CustomBlockModel (org.dynmap.hdmap.CustomBlockModel)1 DynmapBlockState (org.dynmap.renderer.DynmapBlockState)1 RenderPatch (org.dynmap.renderer.RenderPatch)1 LightLevels (org.dynmap.utils.LightLevels)1 PatchDefinition (org.dynmap.utils.PatchDefinition)1