Start on texture pack shader
This commit is contained in:
parent
0323c98938
commit
edac2e5cd9
4 changed files with 358 additions and 1 deletions
|
|
@ -4,9 +4,14 @@ import java.awt.image.BufferedImage;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.LineNumberReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
|
|
@ -15,6 +20,7 @@ import javax.imageio.ImageIO;
|
|||
import org.dynmap.Color;
|
||||
import org.dynmap.DynmapPlugin;
|
||||
import org.dynmap.Log;
|
||||
import org.dynmap.hdmap.HDPerspectiveState.BlockStep;
|
||||
import org.dynmap.kzedmap.KzedMap;
|
||||
|
||||
/**
|
||||
|
|
@ -56,6 +62,47 @@ public class TexturePack {
|
|||
|
||||
private HashMap<Integer, TexturePack> scaled_textures;
|
||||
|
||||
|
||||
public static class HDTextureMap {
|
||||
private short faces[]; /* index in terrain.png of image for each face (indexed by BlockStep.ordinal()) */
|
||||
private List<Integer> blockids;
|
||||
private int databits;
|
||||
private static HDTextureMap[] texmaps;
|
||||
|
||||
private static void initializeTable() {
|
||||
texmaps = new HDTextureMap[16*256];
|
||||
HDTextureMap blank = new HDTextureMap();
|
||||
for(int i = 0; i < texmaps.length; i++)
|
||||
texmaps[i] = blank;
|
||||
}
|
||||
|
||||
private HDTextureMap() {
|
||||
blockids = Collections.singletonList(Integer.valueOf(0));
|
||||
databits = 0xFFFF;
|
||||
faces = new short[] { -1, -1, -1, -1, -1, -1 };
|
||||
|
||||
for(int i = 0; i < texmaps.length; i++) {
|
||||
texmaps[i] = this;
|
||||
}
|
||||
}
|
||||
|
||||
public HDTextureMap(List<Integer> blockids, int databits, short[] faces) {
|
||||
this.faces = faces;
|
||||
this.blockids = blockids;
|
||||
this.databits = databits;
|
||||
}
|
||||
|
||||
public void addToTable() {
|
||||
/* Add entries to lookup table */
|
||||
for(Integer blkid : blockids) {
|
||||
for(int i = 0; i < 16; i++) {
|
||||
if((databits & (1 << i)) != 0) {
|
||||
texmaps[16*blkid + i] = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/** Get or load texture pack */
|
||||
public static TexturePack getTexturePack(String tpname) {
|
||||
TexturePack tp = packs.get(tpname);
|
||||
|
|
@ -378,6 +425,96 @@ public class TexturePack {
|
|||
BufferedImage img = KzedMap.createBufferedImage(terrain_argb, terrain_width, terrain_height);
|
||||
ImageIO.write(img, "png", f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load texture pack mappings from texture.txt file
|
||||
*/
|
||||
public static void loadTextureMapping(File plugindir) {
|
||||
LineNumberReader rdr = null;
|
||||
int cnt = 0;
|
||||
/* Initialize map with blank map for all entries */
|
||||
HDTextureMap.initializeTable();
|
||||
|
||||
try {
|
||||
String line;
|
||||
rdr = new LineNumberReader(new FileReader(new File(plugindir, "texture.txt")));
|
||||
while((line = rdr.readLine()) != null) {
|
||||
if(line.startsWith("block:")) {
|
||||
ArrayList<Integer> blkids = new ArrayList<Integer>();
|
||||
int databits = 0;
|
||||
short faces[] = new short[] { -1, -1, -1, -1, -1, -1 };
|
||||
line = line.substring(6);
|
||||
String[] args = line.split(",");
|
||||
for(String a : args) {
|
||||
String[] av = a.split("=");
|
||||
if(av.length < 2) continue;
|
||||
if(av[0].equals("id")) {
|
||||
blkids.add(Integer.parseInt(av[1]));
|
||||
}
|
||||
else if(av[0].equals("data")) {
|
||||
if(av[1].equals("*"))
|
||||
databits = 0xFFFF;
|
||||
else
|
||||
databits |= (1 << Integer.parseInt(av[1]));
|
||||
}
|
||||
else if(av[0].equals("top") || av[0].equals("y-")) {
|
||||
faces[BlockStep.Y_MINUS.ordinal()] = Short.parseShort(av[1]);
|
||||
}
|
||||
else if(av[0].equals("bottom") || av[0].equals("y+")) {
|
||||
faces[BlockStep.Y_PLUS.ordinal()] = Short.parseShort(av[1]);
|
||||
}
|
||||
else if(av[0].equals("north") || av[0].equals("x+")) {
|
||||
faces[BlockStep.X_PLUS.ordinal()] = Short.parseShort(av[1]);
|
||||
}
|
||||
else if(av[0].equals("east") || av[0].equals("z-")) {
|
||||
faces[BlockStep.Z_MINUS.ordinal()] = Short.parseShort(av[1]);
|
||||
}
|
||||
else if(av[0].equals("west") || av[0].equals("z+")) {
|
||||
faces[BlockStep.Z_PLUS.ordinal()] = Short.parseShort(av[1]);
|
||||
}
|
||||
else if(av[0].equals("allfaces")) {
|
||||
short id = Short.parseShort(av[1]);
|
||||
for(int i = 0; i < 6; i++) {
|
||||
faces[i] = id;
|
||||
}
|
||||
}
|
||||
else if(av[0].equals("allsides")) {
|
||||
short id = Short.parseShort(av[1]);
|
||||
faces[BlockStep.X_PLUS.ordinal()] = id;
|
||||
faces[BlockStep.X_MINUS.ordinal()] = id;
|
||||
faces[BlockStep.Z_PLUS.ordinal()] = id;
|
||||
faces[BlockStep.Z_MINUS.ordinal()] = id;
|
||||
}
|
||||
}
|
||||
/* If we have everything, build block */
|
||||
if((blkids.size() > 0) && (databits != 0)) {
|
||||
HDTextureMap map = new HDTextureMap(blkids, databits, faces);
|
||||
map.addToTable();
|
||||
cnt++;
|
||||
}
|
||||
else {
|
||||
Log.severe("Texture mapping missing required parameters = line " + rdr.getLineNumber() + " of texture.txt");
|
||||
}
|
||||
}
|
||||
else if(line.startsWith("#") || line.startsWith(";")) {
|
||||
}
|
||||
}
|
||||
Log.info("Loaded " + cnt + " texture mappings");
|
||||
} catch (IOException iox) {
|
||||
Log.severe("Error reading texture.txt - " + iox.toString());
|
||||
} catch (NumberFormatException nfx) {
|
||||
Log.severe("Format error - line " + rdr.getLineNumber() + " of texture.txt");
|
||||
} finally {
|
||||
if(rdr != null) {
|
||||
try {
|
||||
rdr.close();
|
||||
rdr = null;
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TexturePack tp = TexturePack.getTexturePack("test");
|
||||
TexturePack tp2 = tp.resampleTexturePack(4);
|
||||
|
|
|
|||
147
src/main/java/org/dynmap/hdmap/TexturePackHDShader.java
Normal file
147
src/main/java/org/dynmap/hdmap/TexturePackHDShader.java
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
package org.dynmap.hdmap;
|
||||
|
||||
import static org.dynmap.JSONUtils.s;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.dynmap.Color;
|
||||
import org.dynmap.ColorScheme;
|
||||
import org.dynmap.ConfigurationNode;
|
||||
import org.dynmap.Log;
|
||||
import org.dynmap.utils.MapChunkCache;
|
||||
import org.dynmap.utils.MapIterator;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class TexturePackHDShader implements HDShader {
|
||||
private String tpname;
|
||||
private String name;
|
||||
private TexturePack tp;
|
||||
|
||||
public TexturePackHDShader(ConfigurationNode configuration) {
|
||||
tpname = configuration.getString("texturepack", "minecraft");
|
||||
name = configuration.getString("name", tpname);
|
||||
tp = TexturePack.getTexturePack(tpname);
|
||||
if(tp == null) {
|
||||
Log.severe("Error: shader '" + name + "' cannot load texture pack '" + tpname + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBiomeDataNeeded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRawBiomeDataNeeded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHightestBlockYDataNeeded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockTypeDataNeeded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSkyLightLevelNeeded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmittedLightLevelNeeded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
private class OurShaderState implements HDShaderState {
|
||||
private Color color;
|
||||
protected MapIterator mapiter;
|
||||
protected HDMap map;
|
||||
private boolean air;
|
||||
|
||||
private OurShaderState(MapIterator mapiter, HDMap map) {
|
||||
this.mapiter = mapiter;
|
||||
this.map = map;
|
||||
this.color = new Color();
|
||||
}
|
||||
/**
|
||||
* Get our shader
|
||||
*/
|
||||
public HDShader getShader() {
|
||||
return TexturePackHDShader.this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get our map
|
||||
*/
|
||||
public HDMap getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get our lighting
|
||||
*/
|
||||
public HDLighting getLighting() {
|
||||
return map.getLighting();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset renderer state for new ray
|
||||
*/
|
||||
public void reset(HDPerspectiveState ps) {
|
||||
color.setTransparent();
|
||||
air = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process next ray step - called for each block on route
|
||||
* @return true if ray is done, false if ray needs to continue
|
||||
*/
|
||||
public boolean processBlock(HDPerspectiveState ps) {
|
||||
int blocktype = ps.getBlockTypeID();
|
||||
color.setRGBA(0, 0, 0, 255);
|
||||
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Ray ended - used to report that ray has exited map (called if renderer has not reported complete)
|
||||
*/
|
||||
public void rayFinished(HDPerspectiveState ps) {
|
||||
}
|
||||
/**
|
||||
* Get result color - get resulting color for ray
|
||||
* @param c - object to store color value in
|
||||
* @param index - index of color to request (renderer specific - 0=default, 1=day for night/day renderer
|
||||
*/
|
||||
public void getRayColor(Color c, int index) {
|
||||
c.setColor(color);
|
||||
}
|
||||
/**
|
||||
* Clean up state object - called after last ray completed
|
||||
*/
|
||||
public void cleanup() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get renderer state object for use rendering a tile
|
||||
* @param map - map being rendered
|
||||
* @param cache - chunk cache containing data for tile to be rendered
|
||||
* @param mapiter - iterator used when traversing rays in tile
|
||||
* @return state object to use for all rays in tile
|
||||
*/
|
||||
public HDShaderState getStateInstance(HDMap map, MapChunkCache cache, MapIterator mapiter) {
|
||||
return new OurShaderState(mapiter, map);
|
||||
}
|
||||
|
||||
/* Add shader's contributions to JSON for map object */
|
||||
public void addClientConfiguration(JSONObject mapObject) {
|
||||
s(mapObject, "shader", name);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue