Skip to content

Commit

Permalink
Move pivot to true bone pivot
Browse files Browse the repository at this point in the history
  • Loading branch information
iam4722202468 committed Aug 18, 2022
1 parent 508df07 commit 83c73cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ public ModelAnimation(String modelName, String animationName, ModelBone bone, Js
transform.put(0.0, point);
}

System.out.println("[AnimationLoader] Generating cache for " + bone.getName() + "/" + animationName);

if (this.type == AnimationLoader.AnimationType.ROTATION) {
found = calculateAllTransforms(animationTime, transform);
AnimationLoader.addToRotationCache(modelName, bone.getName() + "/" + animationName, found);
Expand Down
16 changes: 4 additions & 12 deletions src/main/java/net/worldseed/multipart/parser/ModelParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ private static void createFiles(@NotNull String modelName, Path modelPath, Path
for (JsonElement bone : bonesJson) {
if (!bone.getAsJsonObject().has("cubes")) continue;
String name = bone.getAsJsonObject().get("name").getAsString();
Point bonePivot = ModelEngine.getPos(bone.getAsJsonObject().get("pivot").getAsJsonArray()).orElse(Vec.ZERO);

List<Cube> cubes = new ArrayList<>();
for (JsonElement cubeJson : bone.getAsJsonObject().get("cubes").getAsJsonArray()) {
Expand All @@ -182,7 +183,7 @@ private static void createFiles(@NotNull String modelName, Path modelPath, Path
}

if (cubes.size() > 0) {
bones.add(new Bone(name, cubes));
bones.add(new Bone(name, cubes, bonePivot));
}
}

Expand Down Expand Up @@ -219,24 +220,15 @@ private static void createFiles(@NotNull String modelName, Path modelPath, Path
double cubeMinY = 100000;
double cubeMinZ = 100000;

double cubeMaxX = -100000;
double cubeMaxY = -100000;
double cubeMaxZ = -100000;

for (Cube cube : bone.cubes) {
Point cubeOrigin = cube.origin;
Point cubeSize = cube.size;

cubeMinX = Math.min(cubeMinX, cubeOrigin.x());
cubeMinY = Math.min(cubeMinY, cubeOrigin.y());
cubeMinZ = Math.min(cubeMinZ, cubeOrigin.z());

cubeMaxX = Math.max(cubeMaxX, cubeOrigin.x() + cubeSize.x());
cubeMaxY = Math.max(cubeMaxY, cubeOrigin.y() + cubeSize.y());
cubeMaxZ = Math.max(cubeMaxZ, cubeOrigin.z() + cubeSize.z());
}

final Point cubeMid = new Vec((cubeMaxX + cubeMinX) / 2 - 8, (cubeMaxY + cubeMinY) / 2 - 8, (cubeMaxZ + cubeMinZ) / 2 - 8);
final Point cubeMid = bone.pivot.mul(-1, 1, 1).sub(8, 8, 8);
final Point cubeDiff = new Vec(cubeMid.x() - cubeMinX + 16, cubeMid.y() - cubeMinY + 16, cubeMid.z() - cubeMinZ + 16);

for (Cube cube : bone.cubes()) {
Expand Down Expand Up @@ -391,7 +383,7 @@ private static JsonElement elementsToJson(List<Element> elements) {
}

record Cube(Point origin, Point size, Point pivot, Point rotation, Map<TextureFace, UV> uv) {}
record Bone(String name, List<Cube> cubes) {}
record Bone(String name, List<Cube> cubes, Point pivot) {}
record ItemId(String name, String bone, Point offset, Point diff, int id) {}

record MappingEntry(Map<String, Integer> map, Point offset, Point diff) {
Expand Down

0 comments on commit 83c73cb

Please sign in to comment.