new materials

This commit is contained in:
zimzaza4
2024-10-13 18:15:37 +08:00
parent 73caf2ec76
commit 42d92dd809
6 changed files with 77 additions and 48 deletions

View File

@@ -13,10 +13,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.HashMap; import java.util.*;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class GeneratorMain { public class GeneratorMain {
public static final Map<String, Entity> entityMap = new HashMap<>(); public static final Map<String, Entity> entityMap = new HashMap<>();
@@ -42,11 +39,12 @@ public class GeneratorMain {
String modelId = folder.getName().toLowerCase(); String modelId = folder.getName().toLowerCase();
Entity entity = new Entity(modelId); Entity entity = new Entity(modelId);
TextureConfig textureConfig = new TextureConfig(); ModelConfig modelConfig = new ModelConfig();
File textureConfigFile = new File(folder, "texture_config.json"); boolean shouldOverrideConfig = false;
File textureConfigFile = new File(folder, "config.json");
if (textureConfigFile.exists()) { if (textureConfigFile.exists()) {
try { try {
textureConfig = GSON.fromJson(Files.readString(textureConfigFile.toPath()), TextureConfig.class); modelConfig = GSON.fromJson(Files.readString(textureConfigFile.toPath()), ModelConfig.class);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -60,14 +58,15 @@ public class GeneratorMain {
String textureName = e.getName().replace(".png", ""); String textureName = e.getName().replace(".png", "");
Set<String> bindingBones = new HashSet<>(); Set<String> bindingBones = new HashSet<>();
bindingBones.add("*"); bindingBones.add("*");
if (textureConfig.getBingingBones().containsKey(textureName)) { if (modelConfig.getBingingBones().containsKey(textureName)) {
bindingBones = textureConfig.getBingingBones().get(textureName); bindingBones = modelConfig.getBingingBones().get(textureName);
} }
Map<String, Texture> map = textureMap.computeIfAbsent(modelId, s -> new HashMap<>()); Map<String, Texture> map = textureMap.computeIfAbsent(modelId, s -> new HashMap<>());
map.put(textureName, new Texture(modelId, currentPath, bindingBones, e.toPath())); map.put(textureName, new Texture(modelId, currentPath, bindingBones, e.toPath()));
entity.setTextureMap(map); entity.setTextureMap(map);
if (textureConfig.getBingingBones().isEmpty()) { if (modelConfig.getBingingBones().isEmpty()) {
textureConfig.getBingingBones().put(textureName, Set.of("*")); modelConfig.getBingingBones().put(textureName, Set.of("*"));
shouldOverrideConfig = true;
} }
} }
@@ -99,26 +98,30 @@ public class GeneratorMain {
} }
} }
if (canAdd) { if (canAdd) {
File config = new File(folder, "config.properties"); // old config
File oldConfig = new File(folder, "config.properties");
Properties old = new Properties();
try { try {
if (config.exists()) { if (oldConfig.exists()) {
entity.getConfig().load(new FileReader(config)); old.load(new FileReader(oldConfig));
} else { modelConfig.setMaterial(old.getProperty("material", "entity_alphatest_change_color"));
entity.getConfig().setProperty("head-rotation", "true"); modelConfig.setEnableBlendTransition(Boolean.parseBoolean(old.getProperty("blend-transition", "true")));
entity.getConfig().setProperty("material", "entity_alphatest_change_color"); modelConfig.setEnableHeadRotation(Boolean.parseBoolean(old.getProperty("head-rotation", "true")));
entity.getConfig().setProperty("blend-transition", "true"); shouldOverrideConfig = true;
entity.getConfig().store(new FileWriter(config), ""); oldConfig.delete();
} }
} catch (IOException ex) {
ex.printStackTrace();
}
try {
Files.writeString(textureConfigFile.toPath(), GSON.toJson(textureConfig));
} catch (IOException ex) {
ex.printStackTrace();
}
entity.setTextureConfig(textureConfig); } catch (IOException ex) {
ex.printStackTrace();
}
if (shouldOverrideConfig) {
try {
Files.writeString(textureConfigFile.toPath(), GSON.toJson(modelConfig));
} catch (IOException ex) {
ex.printStackTrace();
}
}
entity.setModelConfig(modelConfig);
entity.setPath(currentPath); entity.setPath(currentPath);
entityMap.put(modelId, entity); entityMap.put(modelId, entity);
} }
@@ -237,7 +240,6 @@ public class GeneratorMain {
for (Map.Entry<String, Entity> entry : entityMap.entrySet()) { for (Map.Entry<String, Entity> entry : entityMap.entrySet()) {
Entity entity = entry.getValue(); Entity entity = entry.getValue();
entity.getConfig().setProperty("render_controller", "controller.render." + entry.getKey());
entity.modify(); entity.modify();
Path entityPath = entityFolder.toPath().resolve(entity.getPath() + entry.getKey() + ".entity.json"); Path entityPath = entityFolder.toPath().resolve(entity.getPath() + entry.getKey() + ".entity.json");

View File

@@ -57,7 +57,7 @@ public class AnimationController {
animationControllers.add("controller.animation." + animation.modelId + "." + id, controller); animationControllers.add("controller.animation." + animation.modelId + "." + id, controller);
i++; i++;
if (entity != null) { if (entity != null) {
boolean blend = Boolean.parseBoolean(entity.getConfig().getProperty("blend-transition", "true")); boolean blend = entity.getModelConfig().isEnableBlendTransition();
if (!blend) { if (!blend) {
for (Map.Entry<String, JsonElement> states : controller.get("states").getAsJsonObject().entrySet()) { for (Map.Entry<String, JsonElement> states : controller.get("states").getAsJsonObject().entrySet()) {
states.getValue().getAsJsonObject().remove("blend_transition"); states.getValue().getAsJsonObject().remove("blend_transition");

View File

@@ -8,7 +8,6 @@ import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import me.zimzaza4.geyserutils.geyser.GeyserUtils; import me.zimzaza4.geyserutils.geyser.GeyserUtils;
import re.imc.geysermodelenginepackgenerator.GeneratorMain;
import java.util.*; import java.util.*;
@@ -25,7 +24,7 @@ public class Entity {
"identifier": "modelengine:%entity_id%", "identifier": "modelengine:%entity_id%",
"materials": { "materials": {
"default": "%material%", "default": "%material%",
"anim": "entity_alphatest_anim_change_color" "anim": "entity_alphatest_anim_change_color_one_sided"
}, },
"textures": { "textures": {
}, },
@@ -56,10 +55,9 @@ public class Entity {
RenderController renderController; RenderController renderController;
String path; String path;
Map<String, Texture> textureMap = new HashMap<>(); Map<String, Texture> textureMap = new HashMap<>();
TextureConfig textureConfig; ModelConfig modelConfig;
Properties config = new Properties();
@@ -72,8 +70,8 @@ public class Entity {
json = new JsonParser().parse(TEMPLATE.replace("%entity_id%", modelId) json = new JsonParser().parse(TEMPLATE.replace("%entity_id%", modelId)
.replace("%geometry%", "geometry.modelengine_" + modelId) .replace("%geometry%", "geometry.modelengine_" + modelId)
.replace("%texture%", "textures/entity/" + path + modelId) .replace("%texture%", "textures/entity/" + path + modelId)
.replace("%look_at_target%", Boolean.parseBoolean(config.getProperty("head-rotation", "true".toLowerCase())) ? "animation." + modelId + ".look_at_target" : "animation.none") .replace("%look_at_target%", modelConfig.isEnableHeadRotation() ? "animation." + modelId + ".look_at_target" : "animation.none")
.replace("%material%", config.getProperty("material", "entity_alphatest_change_color"))).getAsJsonObject(); .replace("%material%", modelConfig.getMaterial())).getAsJsonObject();
JsonObject description = json.get("minecraft:client_entity").getAsJsonObject().get("description").getAsJsonObject(); JsonObject description = json.get("minecraft:client_entity").getAsJsonObject().get("description").getAsJsonObject();
JsonObject jsonAnimations = description.get("animations").getAsJsonObject(); JsonObject jsonAnimations = description.get("animations").getAsJsonObject();

View File

@@ -9,6 +9,28 @@ public class Material {
"+defines":[ "+defines":[
"USE_UV_ANIM" "USE_UV_ANIM"
] ]
},
"entity_change_color_one_sided:entity": {
"+defines": [
"USE_OVERLAY",
"USE_COLOR_MASK"
]
},
"entity_alphatest_change_color_one_sided:entity_change_color_one_sided": {
"+defines": [ "ALPHA_TEST" ],
"+samplerStates": [
{
"samplerIndex": 1,
"textureWrap": "Repeat"
}
],
"msaaSupport": "Both"
},
"entity_alphatest_anim_change_color_one_sided:entity_alphatest_change_color_one_sided":{
"+defines":[
"USE_UV_ANIM"
]
} }
} }
} }

View File

@@ -14,8 +14,14 @@ import java.util.Set;
@NoArgsConstructor @NoArgsConstructor
@Getter @Getter
@Setter @Setter
public class TextureConfig { public class ModelConfig {
@SerializedName("head_rotation")
boolean enableHeadRotation = true;
@SerializedName("material")
String material = "entity_alphatest_change_color_one_sided";
@SerializedName("blend_transition")
boolean enableBlendTransition = true;
@SerializedName("binding_bones") @SerializedName("binding_bones")
Map<String, Set<String>> bingingBones = new HashMap<>(); Map<String, Set<String>> bingingBones = new HashMap<>();
@SerializedName("anim_textures") @SerializedName("anim_textures")
@@ -26,7 +32,6 @@ public class TextureConfig {
@Getter @Getter
@Setter @Setter
public static class AnimTextureOptions { public static class AnimTextureOptions {
boolean animUv;
float fps; float fps;
int frames; int frames;
} }

View File

@@ -2,17 +2,12 @@ package re.imc.geysermodelenginepackgenerator.generator;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.internal.bind.TypeAdapters;
import re.imc.geysermodelenginepackgenerator.GeneratorMain;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.*; import java.util.*;
public class RenderController { public class RenderController {
public static final Set<String> NEED_REMOVE_WHEN_SORT = Set.of("pbody_", "plarm_", "prarm_", "plleg_", "prleg_", "phead_", "p_", "uv_"); public static final Set<String> NEED_REMOVE_WHEN_SORT = Set.of("pbody_", "plarm_", "prarm_", "plleg_", "prleg_", "phead_", "p_");
String modelId; String modelId;
Map<String, Bone> bones; Map<String, Bone> bones;
Entity entity; Entity entity;
@@ -35,8 +30,8 @@ public class RenderController {
for (String key : entity.textureMap.keySet()) { for (String key : entity.textureMap.keySet()) {
Texture texture = entity.textureMap.get(key); Texture texture = entity.textureMap.get(key);
Set<String> uvBonesId = entity.getTextureConfig().bingingBones.get(key); Set<String> uvBonesId = entity.getModelConfig().bingingBones.get(key);
TextureConfig.AnimTextureOptions anim = entity.getTextureConfig().getAnimTextures().get(key); ModelConfig.AnimTextureOptions anim = entity.getModelConfig().getAnimTextures().get(key);
JsonObject controller = new JsonObject(); JsonObject controller = new JsonObject();
@@ -106,17 +101,24 @@ public class RenderController {
for (String boneName : sorted) { for (String boneName : sorted) {
boneName = originalId.get(boneName); boneName = originalId.get(boneName);
JsonObject visibilityItem = new JsonObject(); JsonObject visibilityItem = new JsonObject();
int n = (int) Math.pow(2, (i % 24));
Bone bone = bones.get(boneName); Bone bone = bones.get(boneName);
if (!processedBones.contains(bone) && (uvAllBones.contains(boneName) || uvBonesId.contains("*"))) { if (!processedBones.contains(bone) && (uvAllBones.contains(boneName) || uvBonesId.contains("*"))) {
int index = i;
if (boneName.startsWith("uv_")) {
index = sorted.indexOf(bone.parent);
}
int n = (int) Math.pow(2, (index % 24));
visibilityItem.addProperty(boneName, "math.mod(math.floor(query.property('modelengine:bone" + i / 24 + "') / " + n + "), 2) == 1"); visibilityItem.addProperty(boneName, "math.mod(math.floor(query.property('modelengine:bone" + i / 24 + "') / " + n + "), 2) == 1");
partVisibility.add(visibilityItem); partVisibility.add(visibilityItem);
if (!uvBonesId.contains("*")) { if (!uvBonesId.contains("*")) {
processedBones.add(bone); processedBones.add(bone);
} }
} }
i++; if (!boneName.startsWith("uv_")) {
i++;
}
} }
controller.add("part_visibility", partVisibility); controller.add("part_visibility", partVisibility);
//} //}