mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2025-01-26 02:01:32 +01:00
Fix parent and texture-variable baking
This commit is contained in:
parent
7389cb1a16
commit
f98376fe27
@ -1 +1 @@
|
|||||||
Subproject commit 0776e69c88ed24e2d2f0141e616d0512a5482ac9
|
Subproject commit be1c4b4939d88d8a8da166219c1968ec290e40ac
|
@ -327,9 +327,6 @@ public synchronized ResourcePack getResourcePack() throws ConfigurationException
|
|||||||
resourcePack.loadResources(defaultResourceFile);
|
resourcePack.loadResources(defaultResourceFile);
|
||||||
|
|
||||||
resourcePack.bake();
|
resourcePack.bake();
|
||||||
|
|
||||||
StateDumper.global().dump(Path.of("dump.json"));
|
|
||||||
|
|
||||||
} catch (IOException | RuntimeException e) {
|
} catch (IOException | RuntimeException e) {
|
||||||
throw new ConfigurationException("Failed to parse resources!\n" +
|
throw new ConfigurationException("Failed to parse resources!\n" +
|
||||||
"Is one of your resource-packs corrupted?", e);
|
"Is one of your resource-packs corrupted?", e);
|
||||||
|
@ -117,8 +117,8 @@ public HttpResponse handle(HttpRequest request) {
|
|||||||
// provide meta-data
|
// provide meta-data
|
||||||
Matcher metaMatcher = META_PATTERN.matcher(path);
|
Matcher metaMatcher = META_PATTERN.matcher(path);
|
||||||
if (metaMatcher.matches()) {
|
if (metaMatcher.matches()) {
|
||||||
String mapId = tileMatcher.group(1);
|
String mapId = metaMatcher.group(1);
|
||||||
String metaFilePath = tileMatcher.group(2);
|
String metaFilePath = metaMatcher.group(2);
|
||||||
|
|
||||||
Storage storage = mapStorageProvider.apply(mapId);
|
Storage storage = mapStorageProvider.apply(mapId);
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
@ -191,7 +191,6 @@ private static long stringToTimestamp(String timeString) throws IllegalArgumentE
|
|||||||
|
|
||||||
int month = Calendar.JANUARY;
|
int month = Calendar.JANUARY;
|
||||||
switch (timeString.substring(8, 11)){
|
switch (timeString.substring(8, 11)){
|
||||||
case "Jan" : month = Calendar.JANUARY; break;
|
|
||||||
case "Feb" : month = Calendar.FEBRUARY; break;
|
case "Feb" : month = Calendar.FEBRUARY; break;
|
||||||
case "Mar" : month = Calendar.MARCH; break;
|
case "Mar" : month = Calendar.MARCH; break;
|
||||||
case "Apr" : month = Calendar.APRIL; break;
|
case "Apr" : month = Calendar.APRIL; break;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
import de.bluecolored.bluemap.core.resources.adapter.ResourcesGson;
|
import de.bluecolored.bluemap.core.resources.adapter.ResourcesGson;
|
||||||
import de.bluecolored.bluemap.core.resources.resourcepack.ResourcePack;
|
import de.bluecolored.bluemap.core.resources.resourcepack.ResourcePack;
|
||||||
import de.bluecolored.bluemap.core.resources.resourcepack.texture.Texture;
|
import de.bluecolored.bluemap.core.resources.resourcepack.texture.Texture;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -22,7 +23,8 @@ public TextureGallery() {
|
|||||||
this.nextId = 0;
|
this.nextId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int get(ResourcePath<Texture> textureResourcePath) {
|
public int get(@Nullable ResourcePath<Texture> textureResourcePath) {
|
||||||
|
if (textureResourcePath == null) textureResourcePath = ResourcePack.MISSING_TEXTURE;
|
||||||
Integer ordinal = ordinalMap.get(textureResourcePath);
|
Integer ordinal = ordinalMap.get(textureResourcePath);
|
||||||
return ordinal != null ? ordinal : 0;
|
return ordinal != null ? ordinal : 0;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,9 @@ public class ResourcePack {
|
|||||||
|
|
||||||
private final Map<String, ResourcePath<BlockState>> blockStatePaths;
|
private final Map<String, ResourcePath<BlockState>> blockStatePaths;
|
||||||
private final Map<ResourcePath<BlockState>, BlockState> blockStates;
|
private final Map<ResourcePath<BlockState>, BlockState> blockStates;
|
||||||
|
private final Map<String, ResourcePath<BlockModel>> blockModelPaths;
|
||||||
private final Map<ResourcePath<BlockModel>, BlockModel> blockModels;
|
private final Map<ResourcePath<BlockModel>, BlockModel> blockModels;
|
||||||
|
private final Map<String, ResourcePath<Texture>> texturePaths;
|
||||||
private final Map<ResourcePath<Texture>, Texture> textures;
|
private final Map<ResourcePath<Texture>, Texture> textures;
|
||||||
private final Map<ResourcePath<BufferedImage>, BufferedImage> colormaps;
|
private final Map<ResourcePath<BufferedImage>, BufferedImage> colormaps;
|
||||||
|
|
||||||
@ -54,7 +56,9 @@ public class ResourcePack {
|
|||||||
public ResourcePack() {
|
public ResourcePack() {
|
||||||
this.blockStatePaths = new HashMap<>();
|
this.blockStatePaths = new HashMap<>();
|
||||||
this.blockStates = new HashMap<>();
|
this.blockStates = new HashMap<>();
|
||||||
|
this.blockModelPaths = new HashMap<>();
|
||||||
this.blockModels = new HashMap<>();
|
this.blockModels = new HashMap<>();
|
||||||
|
this.texturePaths = new HashMap<>();
|
||||||
this.textures = new HashMap<>();
|
this.textures = new HashMap<>();
|
||||||
this.colormaps = new HashMap<>();
|
this.colormaps = new HashMap<>();
|
||||||
|
|
||||||
@ -68,6 +72,11 @@ public ResourcePack() {
|
|||||||
.build(this::loadBlockProperties);
|
.build(this::loadBlockProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public ResourcePath<BlockState> getBlockStatePath(String formatted) {
|
||||||
|
return blockStatePaths.get(formatted);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BlockState getBlockState(de.bluecolored.bluemap.core.world.BlockState blockState) {
|
public BlockState getBlockState(de.bluecolored.bluemap.core.world.BlockState blockState) {
|
||||||
ResourcePath<BlockState> path = blockStatePaths.get(blockState.getFormatted());
|
ResourcePath<BlockState> path = blockStatePaths.get(blockState.getFormatted());
|
||||||
@ -84,6 +93,11 @@ public Map<ResourcePath<BlockState>, BlockState> getBlockStates() {
|
|||||||
return blockStates;
|
return blockStates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public ResourcePath<BlockModel> getBlockModelPath(String formatted) {
|
||||||
|
return blockModelPaths.get(formatted);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BlockModel getBlockModel(ResourcePath<BlockModel> path) {
|
public BlockModel getBlockModel(ResourcePath<BlockModel> path) {
|
||||||
BlockModel blockModel = blockModels.get(path);
|
BlockModel blockModel = blockModels.get(path);
|
||||||
@ -94,6 +108,11 @@ public Map<ResourcePath<BlockModel>, BlockModel> getBlockModels() {
|
|||||||
return blockModels;
|
return blockModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public ResourcePath<Texture> getTexturePath(String formatted) {
|
||||||
|
return texturePaths.get(formatted);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Texture getTexture(ResourcePath<Texture> path) {
|
public Texture getTexture(ResourcePath<Texture> path) {
|
||||||
Texture texture = textures.get(path);
|
Texture texture = textures.get(path);
|
||||||
@ -279,12 +298,23 @@ public synchronized void loadResources(Path root) throws IOException {
|
|||||||
public synchronized void bake() throws IOException {
|
public synchronized void bake() throws IOException {
|
||||||
Logger.global.logInfo("Baking resources...");
|
Logger.global.logInfo("Baking resources...");
|
||||||
|
|
||||||
for (ResourcePath<BlockState> path : blockStates.keySet()) {
|
// fill path maps
|
||||||
blockStatePaths.put(path.getFormatted(), path);
|
blockStates.keySet().forEach(path -> blockStatePaths.put(path.getFormatted(), path));
|
||||||
|
blockModels.keySet().forEach(path -> blockModelPaths.put(path.getFormatted(), path));
|
||||||
|
textures.keySet().forEach(path -> texturePaths.put(path.getFormatted(), path));
|
||||||
|
|
||||||
|
// optimize references
|
||||||
|
for (BlockModel model : blockModels.values()) {
|
||||||
|
model.optimize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// apply model parents
|
||||||
for (BlockModel model : blockModels.values()) {
|
for (BlockModel model : blockModels.values()) {
|
||||||
model.applyParent(this);
|
model.applyParent(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate model properties
|
||||||
|
for (BlockModel model : blockModels.values()) {
|
||||||
model.calculateProperties(this);
|
model.calculateProperties(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,7 @@
|
|||||||
import de.bluecolored.bluemap.core.util.Direction;
|
import de.bluecolored.bluemap.core.util.Direction;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"})
|
@SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"})
|
||||||
@DebugDump
|
@DebugDump
|
||||||
@ -56,6 +54,18 @@ public boolean isOccluding() {
|
|||||||
return occluding;
|
return occluding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void optimize(ResourcePack resourcePack) {
|
||||||
|
for (var variable : this.textures.values()) {
|
||||||
|
variable.optimize(resourcePack);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.elements != null) {
|
||||||
|
for (var element : elements) {
|
||||||
|
element.optimize(resourcePack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void applyParent(ResourcePack resourcePack) {
|
public synchronized void applyParent(ResourcePack resourcePack) {
|
||||||
if (this.parent == null) return;
|
if (this.parent == null) return;
|
||||||
|
|
||||||
@ -72,8 +82,17 @@ public synchronized void applyParent(ResourcePack resourcePack) {
|
|||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
parent.applyParent(resourcePack);
|
parent.applyParent(resourcePack);
|
||||||
|
|
||||||
parent.textures.forEach(this.textures::putIfAbsent);
|
parent.textures.forEach(this::applyTextureVariable);
|
||||||
if (this.elements == null) this.elements = parent.elements;
|
if (this.elements == null && parent.elements != null) {
|
||||||
|
this.elements = new ArrayList<>();
|
||||||
|
parent.elements.forEach(element -> this.elements.add(element.copy()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void applyTextureVariable(String key, TextureVariable value) {
|
||||||
|
if (!this.textures.containsKey(key)) {
|
||||||
|
this.textures.put(key, value.copy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import de.bluecolored.bluemap.core.debug.DebugDump;
|
import de.bluecolored.bluemap.core.debug.DebugDump;
|
||||||
import de.bluecolored.bluemap.core.resources.AbstractTypeAdapterFactory;
|
import de.bluecolored.bluemap.core.resources.AbstractTypeAdapterFactory;
|
||||||
|
import de.bluecolored.bluemap.core.resources.resourcepack.ResourcePack;
|
||||||
import de.bluecolored.bluemap.core.util.Direction;
|
import de.bluecolored.bluemap.core.util.Direction;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -25,7 +26,17 @@ public class Element {
|
|||||||
private boolean shade = true;
|
private boolean shade = true;
|
||||||
private EnumMap<Direction, Face> faces = new EnumMap<>(Direction.class);
|
private EnumMap<Direction, Face> faces = new EnumMap<>(Direction.class);
|
||||||
|
|
||||||
private Element(){}
|
@SuppressWarnings("unused")
|
||||||
|
private Element() {}
|
||||||
|
|
||||||
|
private Element(Element copyFrom) {
|
||||||
|
this.from = copyFrom.from;
|
||||||
|
this.to = copyFrom.to;
|
||||||
|
this.rotation = copyFrom.rotation;
|
||||||
|
this.shade = copyFrom.shade;
|
||||||
|
|
||||||
|
copyFrom.faces.forEach((direction, face) -> this.faces.put(direction, face.copy()));
|
||||||
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
faces.forEach((direction, face) -> face.init(direction, this::calculateDefaultUV));
|
faces.forEach((direction, face) -> face.init(direction, this::calculateDefaultUV));
|
||||||
@ -84,6 +95,10 @@ public EnumMap<Direction, Face> getFaces() {
|
|||||||
return faces;
|
return faces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Element copy() {
|
||||||
|
return new Element(this);
|
||||||
|
}
|
||||||
|
|
||||||
boolean isFullCube() {
|
boolean isFullCube() {
|
||||||
if (!(FULL_BLOCK_MIN.equals(from) && FULL_BLOCK_MAX.equals(to))) return false;
|
if (!(FULL_BLOCK_MIN.equals(from) && FULL_BLOCK_MAX.equals(to))) return false;
|
||||||
for (Direction dir : Direction.values()) {
|
for (Direction dir : Direction.values()) {
|
||||||
@ -92,6 +107,12 @@ boolean isFullCube() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void optimize(ResourcePack resourcePack) {
|
||||||
|
for (var face : faces.values()) {
|
||||||
|
face.optimize(resourcePack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class Adapter extends AbstractTypeAdapterFactory<Element> {
|
static class Adapter extends AbstractTypeAdapterFactory<Element> {
|
||||||
|
|
||||||
public Adapter() {
|
public Adapter() {
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
import com.flowpowered.math.vector.Vector4f;
|
import com.flowpowered.math.vector.Vector4f;
|
||||||
import de.bluecolored.bluemap.core.debug.DebugDump;
|
import de.bluecolored.bluemap.core.debug.DebugDump;
|
||||||
import de.bluecolored.bluemap.core.resources.ResourcePath;
|
import de.bluecolored.bluemap.core.resources.resourcepack.ResourcePack;
|
||||||
import de.bluecolored.bluemap.core.resources.resourcepack.texture.Texture;
|
|
||||||
import de.bluecolored.bluemap.core.util.Direction;
|
import de.bluecolored.bluemap.core.util.Direction;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -12,7 +11,7 @@
|
|||||||
@DebugDump
|
@DebugDump
|
||||||
public class Face {
|
public class Face {
|
||||||
|
|
||||||
private static final TextureVariable DEFAULT_TEXTURE = new TextureVariable((ResourcePath<Texture>) null);
|
private static final TextureVariable DEFAULT_TEXTURE = new TextureVariable(ResourcePack.MISSING_TEXTURE);
|
||||||
|
|
||||||
private Vector4f uv;
|
private Vector4f uv;
|
||||||
private TextureVariable texture = DEFAULT_TEXTURE;
|
private TextureVariable texture = DEFAULT_TEXTURE;
|
||||||
@ -20,7 +19,16 @@ public class Face {
|
|||||||
private int rotation = 0;
|
private int rotation = 0;
|
||||||
private int tintindex = -1;
|
private int tintindex = -1;
|
||||||
|
|
||||||
private Face(){}
|
@SuppressWarnings("unused")
|
||||||
|
private Face() {}
|
||||||
|
|
||||||
|
private Face(Face copyFrom) {
|
||||||
|
this.uv = copyFrom.uv;
|
||||||
|
this.texture = copyFrom.texture.copy();
|
||||||
|
this.cullface = copyFrom.cullface;
|
||||||
|
this.rotation = copyFrom.rotation;
|
||||||
|
this.tintindex = copyFrom.tintindex;
|
||||||
|
}
|
||||||
|
|
||||||
void init(Direction direction, Function<Direction, Vector4f> defaultUvCalculator) {
|
void init(Direction direction, Function<Direction, Vector4f> defaultUvCalculator) {
|
||||||
if (cullface == null) cullface = direction;
|
if (cullface == null) cullface = direction;
|
||||||
@ -47,4 +55,11 @@ public int getTintindex() {
|
|||||||
return tintindex;
|
return tintindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Face copy() {
|
||||||
|
return new Face(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void optimize(ResourcePack resourcePack) {
|
||||||
|
this.texture.optimize(resourcePack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,12 @@
|
|||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
import de.bluecolored.bluemap.core.debug.DebugDump;
|
import de.bluecolored.bluemap.core.debug.DebugDump;
|
||||||
import de.bluecolored.bluemap.core.resources.ResourcePath;
|
import de.bluecolored.bluemap.core.resources.ResourcePath;
|
||||||
|
import de.bluecolored.bluemap.core.resources.resourcepack.ResourcePack;
|
||||||
import de.bluecolored.bluemap.core.resources.resourcepack.texture.Texture;
|
import de.bluecolored.bluemap.core.resources.resourcepack.texture.Texture;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@DebugDump
|
@DebugDump
|
||||||
@ -21,8 +23,15 @@ public class TextureVariable {
|
|||||||
|
|
||||||
private transient volatile boolean isReference, isResolving;
|
private transient volatile boolean isReference, isResolving;
|
||||||
|
|
||||||
|
private TextureVariable(TextureVariable copyFrom) {
|
||||||
|
this.referenceName = copyFrom.referenceName;
|
||||||
|
this.texturePath = copyFrom.texturePath;
|
||||||
|
this.isReference = copyFrom.isReference;
|
||||||
|
this.isResolving = copyFrom.isResolving;
|
||||||
|
}
|
||||||
|
|
||||||
public TextureVariable(String referenceName) {
|
public TextureVariable(String referenceName) {
|
||||||
this.referenceName = referenceName;
|
this.referenceName = Objects.requireNonNull(referenceName);
|
||||||
this.texturePath = null;
|
this.texturePath = null;
|
||||||
this.isReference = true;
|
this.isReference = true;
|
||||||
this.isResolving = false;
|
this.isResolving = false;
|
||||||
@ -30,7 +39,7 @@ public TextureVariable(String referenceName) {
|
|||||||
|
|
||||||
public TextureVariable(ResourcePath<Texture> texturePath) {
|
public TextureVariable(ResourcePath<Texture> texturePath) {
|
||||||
this.referenceName = null;
|
this.referenceName = null;
|
||||||
this.texturePath = texturePath;
|
this.texturePath = Objects.requireNonNull(texturePath);
|
||||||
this.isReference = false;
|
this.isReference = false;
|
||||||
this.isResolving = false;
|
this.isResolving = false;
|
||||||
}
|
}
|
||||||
@ -68,6 +77,7 @@ private ResourcePath<Texture> resolveTexturePath(Function<String, TextureVariabl
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.isReference = false;
|
this.isReference = false;
|
||||||
|
this.isResolving = false;
|
||||||
}
|
}
|
||||||
return this.texturePath;
|
return this.texturePath;
|
||||||
}
|
}
|
||||||
@ -81,6 +91,20 @@ public boolean isReference() {
|
|||||||
return isReference;
|
return isReference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TextureVariable copy() {
|
||||||
|
synchronized (TextureVariable.class) {
|
||||||
|
return new TextureVariable(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void optimize(ResourcePack resourcePack) {
|
||||||
|
synchronized (TextureVariable.class) {
|
||||||
|
if (texturePath != null) {
|
||||||
|
texturePath = resourcePack.getTexturePath(texturePath.getFormatted());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class Adapter extends TypeAdapter<TextureVariable> {
|
static class Adapter extends TypeAdapter<TextureVariable> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,12 +44,13 @@ public String getFormatted() {
|
|||||||
return formatted;
|
return formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("StringEquality")
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
ResourcePath<?> that = (ResourcePath<?>) o;
|
ResourcePath<?> that = (ResourcePath<?>) o;
|
||||||
return getFormatted().equals(that.getFormatted());
|
return getFormatted() == that.getFormatted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user