anim and more config

This commit is contained in:
zimzaza4
2024-10-01 17:20:07 +08:00
parent 8e40bc4246
commit 02017dd8c2
4 changed files with 27 additions and 79 deletions

View File

@@ -21,7 +21,7 @@ public class GeneratorMain {
public static final Map<String, Animation> animationMap = new HashMap<>(); public static final Map<String, Animation> animationMap = new HashMap<>();
public static final Map<String, Geometry> geometryMap = new HashMap<>(); public static final Map<String, Geometry> geometryMap = new HashMap<>();
public static final Map<String, Texture> textureMap = new HashMap<>(); public static final Map<String, Texture> textureMap = new HashMap<>();
public static final Gson GSON = new GsonBuilder() public static final Gson GSON = new GsonBuilder().setPrettyPrinting()
.create(); .create();
@@ -81,8 +81,10 @@ public class GeneratorMain {
if (config.exists()) { if (config.exists()) {
entity.getConfig().load(new FileReader(config)); entity.getConfig().load(new FileReader(config));
} else { } else {
entity.getConfig().setProperty("enable-part-visibility", "false"); entity.getConfig().setProperty("head-rotation", "true");
entity.getConfig().store(new FileWriter(config), "For some reasons, the part visibility render controller may cause client crash"); entity.getConfig().setProperty("material", "entity_alphatest_change_color");
entity.getConfig().setProperty("blend-transition", "true");
entity.getConfig().store(new FileWriter(config), "");
} }
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
@@ -136,6 +138,7 @@ public class GeneratorMain {
File materialFile = new File(materialsFolder, "entity.material"); File materialFile = new File(materialsFolder, "entity.material");
for (Map.Entry<String, Animation> entry : animationMap.entrySet()) { for (Map.Entry<String, Animation> entry : animationMap.entrySet()) {
Entity entity = entityMap.get(entry.getKey());
Geometry geo = geometryMap.get(entry.getKey()); Geometry geo = geometryMap.get(entry.getKey());
if (geo != null) { if (geo != null) {
entry.getValue().addHeadBind(geo); entry.getValue().addHeadBind(geo);
@@ -151,9 +154,10 @@ public class GeneratorMain {
} }
AnimationController controller = new AnimationController(); AnimationController controller = new AnimationController();
controller.load(entry.getValue()); controller.load(entry.getValue(), entity);
try { try {
Files.writeString(path, entry.getValue().getJson().toString(), StandardCharsets.UTF_8); Files.writeString(path, GSON.toJson(entry.getValue().getJson()), StandardCharsets.UTF_8);
Files.writeString(pathController, controller.getJson().toString(), StandardCharsets.UTF_8); Files.writeString(pathController, controller.getJson().toString(), StandardCharsets.UTF_8);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

@@ -54,6 +54,7 @@ public class Animation {
// play once but override must use this to avoid strange anim // play once but override must use this to avoid strange anim
} }
} }
animation.remove("override_previous_animation");
} }
if (animation.has("loop")) { if (animation.has("loop")) {
@@ -81,7 +82,7 @@ public class Animation {
} }
} }
} catch (Throwable t) {} } catch (Throwable t) {}
if (end != null && end.get("lerp_mode").getAsString().equals("catmullrom")) { if (end != null && end.has("lerp_mode") && end.get("lerp_mode").getAsString().equals("catmullrom")) {
end.addProperty("lerp_mode", "linear"); end.addProperty("lerp_mode", "linear");
} }
} }

View File

@@ -1,12 +1,15 @@
package re.imc.geysermodelenginepackgenerator.generator; package re.imc.geysermodelenginepackgenerator.generator;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
public class AnimationController { public class AnimationController {
@@ -28,82 +31,14 @@ public class AnimationController {
} }
} }
}"""; }""";
public static final String TEMPLATE =
"""
{
"format_version": "1.10.0",
"animation_controllers": {
"controller.animation.modelengine": {
"initial_state": "spawn",
"states": {
"spawn": {
"animations": [
"spawn"
],
"transitions": [
{
"idle": "q.variant == 1"
}
],
"blend_transition": 0.2
},
"idle": {
"animations": [
"idle"
],
"transitions": [
{
"spawn": "q.variant == 0"
},
{
"walk": "q.variant == 2"
},
{
"stop": "q.variant == 3"
}
],
"blend_transition": 0.2
},
"walk": {
"animations": [
"walk"
],
"transitions": [
{
"spawn": "q.variant == 0"
},
{
"stop": "q.variant == 3"
},
{
"idle": "q.variant == 1"
}
],
"blend_transition": 0.2
},
"stop": {
"transitions": [
{
"idle": "q.variant == 1"
},
{
"spawn": "q.variant == 0"
},
{
"walk": "q.variant == 2"
}
],
"blend_transition": 0.2
}
}
}
}
}""";
@Getter @Getter
JsonObject json; JsonObject json;
@Setter
@Getter
Entity entity;
public void load(Animation animation) { public void load(Animation animation, Entity entity) {
JsonObject root = new JsonObject(); JsonObject root = new JsonObject();
json = root; json = root;
root.addProperty("format_version", "1.10.0"); root.addProperty("format_version", "1.10.0");
@@ -121,6 +56,14 @@ public class AnimationController {
JsonObject controller = new JsonParser().parse(CONTROLLER_TEMPLATE.replace("%anim%", id).replace("%query%", "math.mod(math.floor(query.property('modelengine:anim" + i / 24 + "') / " + n + "), 2)")).getAsJsonObject(); JsonObject controller = new JsonParser().parse(CONTROLLER_TEMPLATE.replace("%anim%", id).replace("%query%", "math.mod(math.floor(query.property('modelengine:anim" + i / 24 + "') / " + n + "), 2)")).getAsJsonObject();
animationControllers.add("controller.animation." + animation.modelId + "." + id, controller); animationControllers.add("controller.animation." + animation.modelId + "." + id, controller);
i++; i++;
if (entity != null) {
boolean blend = Boolean.parseBoolean(entity.getConfig().getProperty("blend-transition", "true"));
if (!blend) {
for (Map.Entry<String, JsonElement> states : controller.get("states").getAsJsonObject().entrySet()) {
states.getValue().getAsJsonObject().remove("blend_transition");
}
}
}
} }
} }

View File

@@ -81,7 +81,7 @@ 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%", "animation." + modelId + ".look_at_target") .replace("%look_at_target%", Boolean.parseBoolean(config.getProperty("head-rotation", "true".toLowerCase())) ? "animation." + modelId + ".look_at_target" : "animation.none")
.replace("%material%", config.getProperty("material", "entity_alphatest_change_color")) .replace("%material%", config.getProperty("material", "entity_alphatest_change_color"))
.replace("%render_controller%", config.getProperty("render_controller", "controller.render.default"))).getAsJsonObject(); .replace("%render_controller%", config.getProperty("render_controller", "controller.render.default"))).getAsJsonObject();