mirror of
https://github.com/GeyserExtensionists/GeyserModelEnginePackGenerator.git
synced 2025-12-28 03:19:16 +00:00
OOOOK
This commit is contained in:
@@ -43,6 +43,14 @@ public class GeneratorMain {
|
|||||||
|
|
||||||
Entity entity = new Entity(modelId);
|
Entity entity = new Entity(modelId);
|
||||||
TextureConfig textureConfig = new TextureConfig();
|
TextureConfig textureConfig = new TextureConfig();
|
||||||
|
File textureConfigFile = new File(folder, "texture_config.json");
|
||||||
|
if (textureConfigFile.exists()) {
|
||||||
|
try {
|
||||||
|
textureConfig = GSON.fromJson(Files.readString(textureConfigFile.toPath()), TextureConfig.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
boolean canAdd = false;
|
boolean canAdd = false;
|
||||||
for (File e : folder.listFiles()) {
|
for (File e : folder.listFiles()) {
|
||||||
if (e.isDirectory()) {
|
if (e.isDirectory()) {
|
||||||
@@ -52,13 +60,16 @@ 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 (textureConfig.getBingingBones().containsKey(textureName)) {
|
||||||
bindingBones = textureConfig.getBingingBones().get(textureName);
|
bindingBones = textureConfig.getBingingBones().get(textureName);
|
||||||
}
|
}
|
||||||
textureMap.computeIfAbsent(modelId, s -> new HashMap<>()).put(textureName, new Texture(modelId, currentPath, bindingBones, e.toPath()));
|
Map<String, Texture> map = textureMap.computeIfAbsent(modelId, s -> new HashMap<>());
|
||||||
if (!textureConfig.getBingingBones().isEmpty()) {
|
map.put(textureName, new Texture(modelId, currentPath, bindingBones, e.toPath()));
|
||||||
|
entity.setTextureMap(map);
|
||||||
|
if (textureConfig.getBingingBones().isEmpty()) {
|
||||||
textureConfig.getBingingBones().put(textureName, Set.of("*"));
|
textureConfig.getBingingBones().put(textureName, Set.of("*"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (e.getName().endsWith(".json")) {
|
if (e.getName().endsWith(".json")) {
|
||||||
try {
|
try {
|
||||||
@@ -101,6 +112,13 @@ public class GeneratorMain {
|
|||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
Files.writeString(textureConfigFile.toPath(), GSON.toJson(textureConfig));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.setTextureConfig(textureConfig);
|
||||||
entity.setPath(currentPath);
|
entity.setPath(currentPath);
|
||||||
entityMap.put(modelId, entity);
|
entityMap.put(modelId, entity);
|
||||||
}
|
}
|
||||||
@@ -200,17 +218,20 @@ public class GeneratorMain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, Map<String, Texture>> entry : textureMap.entrySet()) {
|
for (Map.Entry<String, Map<String, Texture>> textures : textureMap.entrySet()) {
|
||||||
Path path = texturesFolder.toPath().resolve(entry.getValue().getPath() + entry.getKey() + ".png");
|
|
||||||
path.toFile().getParentFile().mkdirs();
|
|
||||||
|
|
||||||
if (path.toFile().exists()) {
|
for (Map.Entry<String, Texture> entry : textures.getValue().entrySet()) {
|
||||||
continue;
|
Path path = texturesFolder.toPath().resolve(entry.getValue().getPath() + textures.getKey() + "/" + entry.getKey() + ".png");
|
||||||
}
|
path.toFile().getParentFile().mkdirs();
|
||||||
try {
|
|
||||||
Files.copy(entry.getValue().getOriginalPath(), path, StandardCopyOption.REPLACE_EXISTING);
|
if (path.toFile().exists()) {
|
||||||
} catch (IOException e) {
|
continue;
|
||||||
e.printStackTrace();
|
}
|
||||||
|
try {
|
||||||
|
Files.copy(entry.getValue().getOriginalPath(), path, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package re.imc.geysermodelenginepackgenerator.generator;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class Bone {
|
||||||
|
String name;
|
||||||
|
String parent;
|
||||||
|
Set<Bone> children = new HashSet<>();
|
||||||
|
Set<Bone> allChildren = new HashSet<>();
|
||||||
|
}
|
||||||
@@ -10,10 +10,7 @@ import lombok.Setter;
|
|||||||
import me.zimzaza4.geyserutils.geyser.GeyserUtils;
|
import me.zimzaza4.geyserutils.geyser.GeyserUtils;
|
||||||
import re.imc.geysermodelenginepackgenerator.GeneratorMain;
|
import re.imc.geysermodelenginepackgenerator.GeneratorMain;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -33,6 +30,7 @@ public class Entity {
|
|||||||
"textures": {
|
"textures": {
|
||||||
},
|
},
|
||||||
"geometry": {
|
"geometry": {
|
||||||
|
"default": "%geometry%"
|
||||||
},
|
},
|
||||||
"animations": {
|
"animations": {
|
||||||
"look_at_target": "%look_at_target%"
|
"look_at_target": "%look_at_target%"
|
||||||
@@ -43,7 +41,6 @@ public class Entity {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"render_controllers": [
|
"render_controllers": [
|
||||||
"%render_controller%"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,7 +55,7 @@ public class Entity {
|
|||||||
Geometry geometry;
|
Geometry geometry;
|
||||||
RenderController renderController;
|
RenderController renderController;
|
||||||
String path;
|
String path;
|
||||||
Map<String, Texture> textureMap;
|
Map<String, Texture> textureMap = new HashMap<>();
|
||||||
TextureConfig textureConfig;
|
TextureConfig textureConfig;
|
||||||
|
|
||||||
|
|
||||||
@@ -76,17 +73,17 @@ public class Entity {
|
|||||||
.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%", 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"))).getAsJsonObject();
|
||||||
.replace("%render_controller%", config.getProperty("render_controller", "controller.render.default"))).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();
|
||||||
JsonObject jsonTextures = description.get("textures").getAsJsonObject();
|
JsonObject jsonTextures = description.get("textures").getAsJsonObject();
|
||||||
JsonObject jsonGeometry = description.get("geometry").getAsJsonObject();
|
JsonArray jsonRenderControllers = description.get("render_controllers").getAsJsonArray();
|
||||||
|
|
||||||
|
|
||||||
for (String name : textureMap.keySet()) {
|
for (String name : textureMap.keySet()) {
|
||||||
jsonTextures.addProperty(name,"textures/entity/" + path + modelId + "/" + name);
|
jsonTextures.addProperty(name,"textures/entity/" + path + modelId + "/" + name);
|
||||||
jsonGeometry.addProperty(name, "geometry.modelengine_" + modelId);
|
jsonRenderControllers.add("controller.render." + modelId + "_" + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonArray animate = description.get("scripts").getAsJsonObject().get("animate").getAsJsonArray();
|
JsonArray animate = description.get("scripts").getAsJsonObject().get("animate").getAsJsonArray();
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.geysermc.geyser.api.extension.ExtensionLogger;
|
||||||
|
import re.imc.geysermodelenginepackgenerator.ExtensionMain;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -17,7 +19,7 @@ public class Geometry {
|
|||||||
|
|
||||||
String modelId;
|
String modelId;
|
||||||
JsonObject json;
|
JsonObject json;
|
||||||
Set<String> bones = new HashSet<>();
|
Map<String, Bone> bones = new HashMap<>();
|
||||||
|
|
||||||
String path;
|
String path;
|
||||||
public void load(String json) {
|
public void load(String json) {
|
||||||
@@ -41,6 +43,7 @@ public class Geometry {
|
|||||||
if (element.isJsonObject()) {
|
if (element.isJsonObject()) {
|
||||||
String name = element.getAsJsonObject().get("name").getAsString().toLowerCase(Locale.ROOT);
|
String name = element.getAsJsonObject().get("name").getAsString().toLowerCase(Locale.ROOT);
|
||||||
|
|
||||||
|
String parent = element.getAsJsonObject().has("parent") ? element.getAsJsonObject().get("parent").getAsString() : null;
|
||||||
element.getAsJsonObject().remove("name");
|
element.getAsJsonObject().remove("name");
|
||||||
|
|
||||||
element.getAsJsonObject().addProperty("name", name);
|
element.getAsJsonObject().addProperty("name", name);
|
||||||
@@ -51,10 +54,27 @@ public class Geometry {
|
|||||||
name.startsWith("b_") ||
|
name.startsWith("b_") ||
|
||||||
name.startsWith("ob_")) {
|
name.startsWith("ob_")) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
} else bones.add(name);
|
} else bones.put(name, new Bone(name, parent, new HashSet<>(), new HashSet<>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Bone bone : bones.values()) {
|
||||||
|
if (bone.parent != null) {
|
||||||
|
Bone parent = bones.get(bone.parent);
|
||||||
|
if (parent != null) {
|
||||||
|
parent.children.add(bone);
|
||||||
|
addAllChildren(parent, bone);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setId("geometry.modelengine_" + modelId);
|
setId("geometry.modelengine_" + modelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addAllChildren(Bone p, Bone c) {
|
||||||
|
p.allChildren.add(c);
|
||||||
|
Bone parent = bones.get(p.parent);
|
||||||
|
if (parent != null) {
|
||||||
|
addAllChildren(parent, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,22 @@ 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 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_");
|
public static final Set<String> NEED_REMOVE_WHEN_SORT = Set.of("pbody_", "plarm_", "prarm_", "plleg_", "prleg_", "phead_", "p_", "uv_");
|
||||||
String modelId;
|
String modelId;
|
||||||
Set<String> bones;
|
Map<String, Bone> bones;
|
||||||
Entity entity;
|
Entity entity;
|
||||||
|
|
||||||
public RenderController(String modelId, Set<String> bones, Entity entity) {
|
public RenderController(String modelId, Map<String, Bone> bones, Entity entity) {
|
||||||
this.modelId = modelId;
|
this.modelId = modelId;
|
||||||
this.bones = bones;
|
this.bones = bones;
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
@@ -27,53 +31,97 @@ public class RenderController {
|
|||||||
JsonObject renderControllers = new JsonObject();
|
JsonObject renderControllers = new JsonObject();
|
||||||
root.add("render_controllers", renderControllers);
|
root.add("render_controllers", renderControllers);
|
||||||
|
|
||||||
JsonObject controller = new JsonObject();
|
Set<Bone> processedBones = new HashSet<>();
|
||||||
renderControllers.add("controller.render." + modelId, controller);
|
for (String key : entity.textureMap.keySet()) {
|
||||||
|
|
||||||
controller.addProperty("geometry", "Geometry.default");
|
Texture texture = entity.textureMap.get(key);
|
||||||
|
Set<String> uvBonesId = entity.getTextureConfig().bingingBones.get(key);
|
||||||
|
TextureConfig.AnimTextureOptions anim = entity.getTextureConfig().getAnimTextures().get(key);
|
||||||
|
|
||||||
JsonArray materials = new JsonArray();
|
JsonObject controller = new JsonObject();
|
||||||
JsonObject materialItem = new JsonObject();
|
|
||||||
materialItem.addProperty("*", "Material.default");
|
|
||||||
materials.add(materialItem);
|
|
||||||
controller.add("materials", materials);
|
|
||||||
|
|
||||||
JsonArray textures = new JsonArray();
|
renderControllers.add("controller.render." + modelId + "_" + key, controller);
|
||||||
textures.add("Texture.default");
|
|
||||||
controller.add("textures", textures);
|
|
||||||
Entity entity = GeneratorMain.entityMap
|
|
||||||
.get(modelId);
|
|
||||||
// boolean enable = Boolean.parseBoolean(entity.getConfig().getProperty("enable-part-visibility", "true"));
|
|
||||||
|
|
||||||
// if (enable) {
|
controller.addProperty("geometry", "Geometry.default");
|
||||||
JsonArray partVisibility = new JsonArray();
|
|
||||||
JsonObject visibilityDefault = new JsonObject();
|
JsonArray materials = new JsonArray();
|
||||||
visibilityDefault.addProperty("*", true);
|
JsonObject materialItem = new JsonObject();
|
||||||
partVisibility.add(visibilityDefault);
|
if (anim != null) {
|
||||||
int i = 0;
|
materialItem.addProperty("*", "Material.anim");
|
||||||
List<String> sorted = new ArrayList<>(bones);
|
JsonObject uvAnim = new JsonObject();
|
||||||
Map<String, String> originalId = new HashMap<>();
|
controller.add("uv_anim", uvAnim);
|
||||||
ListIterator<String> iterator = sorted.listIterator();
|
JsonArray offset = new JsonArray();
|
||||||
while (iterator.hasNext()) {
|
offset.add(0.0);
|
||||||
String s = iterator.next();
|
offset.add("math.mod(math.floor(q.life_time * " + anim.fps + ")," + anim.frames + ") / " + anim.frames);
|
||||||
String o = s;
|
uvAnim.add("offset", offset);
|
||||||
for (String r : NEED_REMOVE_WHEN_SORT) {
|
JsonArray scale = new JsonArray();
|
||||||
s = s.replace(r, "");
|
scale.add(1.0);
|
||||||
|
scale.add("1 / " + anim.frames);
|
||||||
|
uvAnim.add("scale", scale);
|
||||||
|
} else {
|
||||||
|
materialItem.addProperty("*", "Material.default");
|
||||||
}
|
}
|
||||||
iterator.set(s);
|
materials.add(materialItem);
|
||||||
originalId.put(s, o);
|
controller.add("materials", materials);
|
||||||
|
|
||||||
|
JsonArray textures = new JsonArray();
|
||||||
|
textures.add("Texture." + key);
|
||||||
|
controller.add("textures", textures);
|
||||||
|
|
||||||
|
// if (enable) {
|
||||||
|
JsonArray partVisibility = new JsonArray();
|
||||||
|
JsonObject visibilityDefault = new JsonObject();
|
||||||
|
visibilityDefault.addProperty("*", false);
|
||||||
|
partVisibility.add(visibilityDefault);
|
||||||
|
int i = 0;
|
||||||
|
List<String> sorted = new ArrayList<>(bones.keySet());
|
||||||
|
Map<String, String> originalId = new HashMap<>();
|
||||||
|
ListIterator<String> iterator = sorted.listIterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
String s = iterator.next();
|
||||||
|
String o = s;
|
||||||
|
for (String r : NEED_REMOVE_WHEN_SORT) {
|
||||||
|
s = s.replace(r, "");
|
||||||
|
}
|
||||||
|
iterator.set(s);
|
||||||
|
originalId.put(s, o);
|
||||||
|
}
|
||||||
|
Collections.sort(sorted);
|
||||||
|
|
||||||
|
Set<String> uvAllBones = new HashSet<>();
|
||||||
|
for (String uvBone : uvBonesId) {
|
||||||
|
if (uvBone.equals("*")) {
|
||||||
|
uvAllBones.addAll(bones.keySet());
|
||||||
|
}
|
||||||
|
if (!bones.containsKey(uvBone)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Bone child : bones.get(uvBone).allChildren) {
|
||||||
|
uvAllBones.add(child.getName());
|
||||||
|
}
|
||||||
|
uvAllBones.add(uvBone);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (String boneName : sorted) {
|
||||||
|
boneName = originalId.get(boneName);
|
||||||
|
JsonObject visibilityItem = new JsonObject();
|
||||||
|
int n = (int) Math.pow(2, (i % 24));
|
||||||
|
Bone bone = bones.get(boneName);
|
||||||
|
|
||||||
|
if (!processedBones.contains(bone) && (uvAllBones.contains(boneName) || uvBonesId.contains("*"))) {
|
||||||
|
visibilityItem.addProperty(boneName, "math.mod(math.floor(query.property('modelengine:bone" + i / 24 + "') / " + n + "), 2) == 1");
|
||||||
|
partVisibility.add(visibilityItem);
|
||||||
|
if (!uvBonesId.contains("*")) {
|
||||||
|
processedBones.add(bone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
controller.add("part_visibility", partVisibility);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
Collections.sort(sorted);
|
|
||||||
for (String bone : sorted) {
|
|
||||||
bone = originalId.get(bone);
|
|
||||||
JsonObject visibilityItem = new JsonObject();
|
|
||||||
int n = (int) Math.pow(2, (i % 24));
|
|
||||||
visibilityItem.addProperty(bone, "math.mod(math.floor(query.property('modelengine:bone" + i / 24 + "') / " + n + "), 2) == 1");
|
|
||||||
partVisibility.add(visibilityItem);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
controller.add("part_visibility", partVisibility);
|
|
||||||
//}
|
|
||||||
return root.toString();
|
return root.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,4 +16,5 @@ public class Texture {
|
|||||||
String path;
|
String path;
|
||||||
Set<String> bindingBones;
|
Set<String> bindingBones;
|
||||||
Path originalPath;
|
Path originalPath;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user