Search in sources :

Example 1 with RenderPatch

use of org.dynmap.renderer.RenderPatch in project dynmap by webbukkit.

the class CuboidRenderer method initializeRenderer.

@Override
public boolean initializeRenderer(RenderPatchFactory rpf, String blkname, BitSet blockdatamask, Map<String, String> custparm) {
    if (!super.initializeRenderer(rpf, blkname, blockdatamask, custparm))
        return false;
    ArrayList<RenderPatch> list = new ArrayList<RenderPatch>();
    // Loop through parameters
    for (String key : custparm.keySet()) {
        String v = custparm.get(key);
        if (key.startsWith("cuboid") || key.startsWith("cross")) {
            boolean isCrossed = key.startsWith("cross");
            String[] toks = v.split("/");
            if (toks.length < 2) {
                // Must be at least two
                Log.severe("Invalid cuboid token value: " + v);
                return false;
            }
            String[] mins = toks[0].split(":");
            String[] maxs = toks[1].split(":");
            if ((mins.length < 3) || (maxs.length < 3)) {
                Log.severe("Invalid number of fields: " + v);
                return false;
            }
            double xmin = clamp(Double.parseDouble(mins[0]));
            double ymin = clamp(Double.parseDouble(mins[1]));
            double zmin = clamp(Double.parseDouble(mins[2]));
            double xmax = clamp(Double.parseDouble(maxs[0]));
            double ymax = clamp(Double.parseDouble(maxs[1]));
            double zmax = clamp(Double.parseDouble(maxs[2]));
            int[] patches = (isCrossed) ? crossedPatchDefault : cuboidPatchDefault;
            if (toks.length > 2) {
                patches = new int[isCrossed ? 1 : 6];
                String[] pidx = toks[2].split(":");
                for (int j = 0; j < patches.length; j++) {
                    if (j >= pidx.length) {
                        patches[j] = Integer.parseInt(pidx[pidx.length - 1]);
                    } else {
                        patches[j] = Integer.parseInt(pidx[j]);
                    }
                    if (patches[j] >= textureCount) {
                        textureCount = patches[j] + 1;
                    }
                }
            }
            // Build crossed patches
            if (isCrossed) {
                RenderPatch VertX1Z0ToX0Z1 = rpf.getPatch(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, Math.min(xmin, zmin), Math.max(xmax, zmax), ymin, ymax, SideVisible.FLIP, patches[0]);
                RenderPatch VertX1Z0ToX0Z1_90 = rpf.getRotatedPatch(VertX1Z0ToX0Z1, 0, 90, 0, patches[0]);
                list.add(VertX1Z0ToX0Z1);
                list.add(VertX1Z0ToX0Z1_90);
            } else {
                CustomRenderer.addBox(rpf, list, xmin, xmax, ymin, ymax, zmin, zmax, patches);
            }
        }
    }
    RenderPatch[] model = list.toArray(new RenderPatch[list.size()]);
    // See if we have a rotation list
    String rotlist = custparm.get("rotlist");
    if (rotlist != null) {
        // Get list
        String[] pidx = rotlist.split(":");
        models = new RenderPatch[pidx.length][];
        for (int idx = 0; idx < pidx.length; idx++) {
            int rot = Integer.parseInt(pidx[idx]);
            models[idx] = new RenderPatch[model.length];
            if (rot != 0) {
                for (int i = 0; i < model.length; i++) {
                    models[idx][i] = rpf.getRotatedPatch(model[i], 0, rot, 0, -1);
                }
            } else {
                models[idx] = model;
            }
        }
    } else {
        models = new RenderPatch[1][];
        models[0] = model;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) RenderPatch(org.dynmap.renderer.RenderPatch)

Example 2 with RenderPatch

use of org.dynmap.renderer.RenderPatch in project dynmap by webbukkit.

the class FrameRenderer method getRenderPatchList.

@Override
public RenderPatch[] getRenderPatchList(MapDataContext ctx) {
    int textureIdx = 0;
    if ((map_id != null) && (txtCount == 0)) {
        txtCount = ctx.getPatchFactory().getTextureCountFromMap(map_id);
    }
    /* See if we have texture index */
    if (idx_attrib != null) {
        Object idxv = ctx.getBlockTileEntityField(idx_attrib);
        if (idxv instanceof Number) {
            int val = ((Number) idxv).intValue();
            if (map_id != null) {
                /* If texture map, look up value there */
                textureIdx = ctx.getPatchFactory().getTextureIndexFromMap(map_id, val - txtOffset);
                if ((textureIdx < 0) && (txtDefIndex >= 0))
                    textureIdx = ctx.getPatchFactory().getTextureIndexFromMap(map_id, txtDefIndex);
                if (textureIdx < 0)
                    textureIdx = 0;
            } else {
                for (int i = 0; i < txtIndex.length; i++) {
                    if (val == txtIndex[i]) {
                        textureIdx = i;
                        break;
                    }
                }
            }
        }
    }
    int idx = base_index;
    for (int i = 0; i < x_off.length; i++) {
        if ((idx & (1 << i)) != 0)
            continue;
        DynmapBlockState blk = ctx.getBlockTypeAt(x_off[i], y_off[i], z_off[i]);
        if (linked_ids.get(blk.globalStateIndex)) {
            idx |= (1 << i);
        }
    }
    RenderPatch[][] row = models[idx];
    /* If row not found, add it */
    if (row == null) {
        row = new RenderPatch[txtCount][];
        models[idx] = row;
    }
    /* If model not found, create it */
    RenderPatch[] model = null;
    if (textureIdx < row.length)
        model = row[textureIdx];
    if (model == null) {
        model = buildModel(ctx.getPatchFactory(), idx, textureIdx);
        if (textureIdx >= row.length) {
            row = Arrays.copyOf(row, textureIdx + 1);
            models[idx] = row;
        }
        row[textureIdx] = model;
    }
    return model;
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState) RenderPatch(org.dynmap.renderer.RenderPatch)

Example 3 with RenderPatch

use of org.dynmap.renderer.RenderPatch in project dynmap by webbukkit.

the class BoxStateRenderer method initializeRenderer.

@Override
public boolean initializeRenderer(RenderPatchFactory rpf, String blkname, BitSet blockdatamask, Map<String, String> custparm) {
    if (!super.initializeRenderer(rpf, blkname, blockdatamask, custparm))
        return false;
    double xmin = 0.0, xmax = 1.0;
    double ymin = 0.0, ymax = 1.0;
    double zmin = 0.0, zmax = 1.0;
    /* Check limits */
    String lim = custparm.get("xmin");
    if (lim != null) {
        xmin = Double.valueOf(lim);
        if (xmin < 0.0)
            xmin = 0.0;
    }
    lim = custparm.get("xmax");
    if (lim != null) {
        xmax = Double.valueOf(lim);
        if (xmax > 1.0)
            xmax = 1.0;
    }
    lim = custparm.get("ymin");
    if (lim != null) {
        ymin = Double.valueOf(lim);
        if (ymin < 0.0)
            ymin = 0.0;
    }
    lim = custparm.get("ymax");
    if (lim != null) {
        ymax = Double.valueOf(lim);
        if (ymax > 1.0)
            ymax = 1.0;
    }
    lim = custparm.get("zmin");
    if (lim != null) {
        zmin = Double.valueOf(lim);
        if (zmin < 0.0)
            zmin = 0.0;
    }
    lim = custparm.get("zmax");
    if (lim != null) {
        zmax = Double.valueOf(lim);
        if (zmax > 1.0)
            zmax = 1.0;
    }
    // Look up block
    DynmapBlockState bs = DynmapBlockState.getBaseStateByName(blkname);
    /* Now, build box models */
    models = new RenderPatch[bs.getStateCount()][];
    int[] patchlist = new int[6];
    for (int i = 0; i < models.length; i++) {
        DynmapBlockState cbs = bs.getState(i);
        ArrayList<RenderPatch> list = new ArrayList<RenderPatch>();
        String[] states = cbs.stateList;
        // Produce patch list
        patchlist[0] = Arrays.binarySearch(states, "down=true") >= 0 ? 1 : 0;
        patchlist[1] = Arrays.binarySearch(states, "up=true") >= 0 ? 3 : 2;
        patchlist[2] = Arrays.binarySearch(states, "west=true") >= 0 ? 5 : 4;
        patchlist[3] = Arrays.binarySearch(states, "east=true") >= 0 ? 7 : 6;
        patchlist[4] = Arrays.binarySearch(states, "north=true") >= 0 ? 9 : 8;
        patchlist[5] = Arrays.binarySearch(states, "south=true") >= 0 ? 11 : 10;
        CustomRenderer.addBox(rpf, list, xmin, xmax, ymin, ymax, zmin, zmax, patchlist);
        models[i] = list.toArray(new RenderPatch[patchlist.length]);
    }
    return true;
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState) ArrayList(java.util.ArrayList) RenderPatch(org.dynmap.renderer.RenderPatch)

Example 4 with RenderPatch

use of org.dynmap.renderer.RenderPatch in project dynmap by webbukkit.

the class CTMVertTextureRenderer method getRenderPatchList.

@Override
public RenderPatch[] getRenderPatchList(MapDataContext mapDataCtx) {
    DynmapBlockState bs = mapDataCtx.getBlockType();
    int meta = bs.stateIndex;
    boolean above = false;
    DynmapBlockState id_above = mapDataCtx.getBlockTypeAt(0, 1, 0);
    if (id_above.baseState == blk) {
        /* MIght match */
        int id_meta = id_above.stateIndex;
        if (meta == id_meta) {
            above = true;
        }
    }
    boolean below = false;
    DynmapBlockState id_below = mapDataCtx.getBlockTypeAt(0, -1, 0);
    if (id_below.baseState == blk) {
        /* MIght match */
        int id_meta = id_below.stateIndex;
        if (meta == id_meta) {
            below = true;
        }
    }
    RenderPatch[] mesh;
    if (above) {
        if (below) {
            mesh = this.mesh_both_neighbor;
        } else {
            mesh = this.mesh_above_neighbor;
        }
    } else {
        if (below) {
            mesh = this.mesh_below_neighbor;
        } else {
            mesh = this.mesh_no_neighbor;
        }
    }
    return mesh;
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState) RenderPatch(org.dynmap.renderer.RenderPatch)

Example 5 with RenderPatch

use of org.dynmap.renderer.RenderPatch in project dynmap by webbukkit.

the class RotatedPatchRenderer method initializeRenderer.

@Override
public boolean initializeRenderer(RenderPatchFactory rpf, String blkname, BitSet blockdatamask, Map<String, String> custparm) {
    if (!super.initializeRenderer(rpf, blkname, blockdatamask, custparm))
        return false;
    ArrayList<RenderPatch> patches = new ArrayList<RenderPatch>();
    ArrayList<int[]> rotations = new ArrayList<int[]>();
    /* See if index attribute defined */
    idx_attrib = custparm.get("index");
    /* Now, traverse parameters */
    for (String k : custparm.keySet()) {
        String v = custparm.get(k);
        /* If it is a patch definition */
        if (k.startsWith("patch")) {
            try {
                int id = Integer.parseInt(k.substring(5));
                RenderPatch p = rpf.getNamedPatch(custparm.get(k), id);
                if (p == null) {
                    Log.warning("Invalid patch definition: " + v);
                    return false;
                }
                if (p.getTextureIndex() > maxTextureIndex) {
                    maxTextureIndex = p.getTextureIndex();
                }
                while (patches.size() <= id) {
                    patches.add(null);
                }
                patches.set(id, p);
            } catch (NumberFormatException nfx) {
                Log.warning("Invalid index for parameter: " + k);
                return false;
            }
        } else /* If it is a rotation definition */
        if (k.startsWith("rot")) {
            int id;
            try {
                id = Integer.parseInt(k.substring(3));
            } catch (NumberFormatException nfx) {
                Log.warning("Invalid index for parameter: " + k);
                return false;
            }
            int[] rot = new int[3];
            String[] rotvals = v.split("/");
            try {
                if (rotvals.length >= 3) {
                    rot[0] = Integer.parseInt(rotvals[0]);
                    rot[1] = Integer.parseInt(rotvals[1]);
                    rot[2] = Integer.parseInt(rotvals[2]);
                } else {
                    rot[1] = Integer.parseInt(rotvals[0]);
                }
                while (rotations.size() <= id) {
                    rotations.add(null);
                }
                rotations.set(id, rot);
            } catch (NumberFormatException nfx) {
                Log.warning("Invalid rotation value: " + v);
                return false;
            }
        }
    }
    /* Remove missing patches */
    for (int i = 0; i < patches.size(); i++) {
        if (patches.get(i) == null) {
            patches.remove(i);
            i--;
        }
    }
    /* Save patch list as base model */
    basemodel = patches.toArray(new RenderPatch[patches.size()]);
    /* Now build rotated models for all the defined rotations */
    models = new RenderPatch[rotations.size()][];
    for (int i = 0; i < rotations.size(); i++) {
        int[] rots = rotations.get(i);
        if (rots == null)
            continue;
        /* Skip default values */
        models[i] = new RenderPatch[basemodel.length];
        /* Build list of patches */
        for (int j = 0; j < basemodel.length; j++) {
            models[i][j] = rpf.getRotatedPatch(basemodel[j], rots[0], rots[1], rots[2], basemodel[j].getTextureIndex());
        }
    }
    if (idx_attrib != null) {
        tileEntityAttribs = new String[1];
        tileEntityAttribs[0] = idx_attrib;
    } else {
        tileEntityAttribs = null;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) RenderPatch(org.dynmap.renderer.RenderPatch)

Aggregations

RenderPatch (org.dynmap.renderer.RenderPatch)21 ArrayList (java.util.ArrayList)13 DynmapBlockState (org.dynmap.renderer.DynmapBlockState)6 RenderPatchFactory (org.dynmap.renderer.RenderPatchFactory)5 PatchDefinition (org.dynmap.utils.PatchDefinition)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 LineNumberReader (java.io.LineNumberReader)1 BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 ZipFile (java.util.zip.ZipFile)1 CustomBlockModel (org.dynmap.hdmap.CustomBlockModel)1 SideVisible (org.dynmap.renderer.RenderPatchFactory.SideVisible)1 BlockStateParser (org.dynmap.utils.BlockStateParser)1 BlockStep (org.dynmap.utils.BlockStep)1 DynIntHashMap (org.dynmap.utils.DynIntHashMap)1 ForgeConfigFile (org.dynmap.utils.ForgeConfigFile)1 Vector3D (org.dynmap.utils.Vector3D)1