mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-03-11 12:15:35 +00:00
properly add rotmode to animation .json spec, including import/export
This commit is contained in:
parent
67eb2be5a7
commit
d56f30a4fa
@ -51,7 +51,6 @@ public class AnimationLoader {
|
||||
// The offsets are only required when sequences are played for an object, which is why we don't globally offset! The obj rendering handles the non-animated case fine
|
||||
// Effectively, this removes double translation AND ensures that rotations occur around the individual object origin, rather than the weapon origin
|
||||
HashMap<String, double[]> offsets = new HashMap<String, double[]>();
|
||||
HashMap<String, double[]> rotModes = new HashMap<String, double[]>();
|
||||
for(Map.Entry<String, JsonElement> root : json.getAsJsonObject("offset").entrySet()) {
|
||||
JsonArray array = root.getValue().getAsJsonArray();
|
||||
|
||||
@ -61,16 +60,21 @@ public class AnimationLoader {
|
||||
}
|
||||
|
||||
offsets.put(root.getKey(), offset);
|
||||
}
|
||||
|
||||
if(array.size() >= 6) {
|
||||
// Rotation modes, swizzled into our local space. YZX in blender becomes XYZ due to:
|
||||
// * rotation order reversed in blender (XYZ -> ZYX)
|
||||
// * dimensions Y and Z are swapped in blender (ZYX -> YZX)
|
||||
HashMap<String, double[]> rotModes = new HashMap<String, double[]>();
|
||||
if(json.has("rotmode")) {
|
||||
for(Map.Entry<String, JsonElement> root : json.getAsJsonObject("rotmode").entrySet()) {
|
||||
String mode = root.getValue().getAsString();
|
||||
|
||||
double[] rotMode = new double[3];
|
||||
for(int i = 0; i < 3; i++) {
|
||||
rotMode[i] = array.get(i + 3).getAsDouble();
|
||||
}
|
||||
|
||||
rotModes.put(root.getKey(), rotMode);
|
||||
rotMode[0] = getRot(mode.charAt(1));
|
||||
rotMode[1] = getRot(mode.charAt(2));
|
||||
rotMode[2] = getRot(mode.charAt(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -95,6 +99,15 @@ public class AnimationLoader {
|
||||
return animations;
|
||||
}
|
||||
|
||||
private static double getRot(char value) {
|
||||
switch(value) {
|
||||
case 'X': return 0;
|
||||
case 'Y': return 1;
|
||||
case 'Z': return 2;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static BusAnimationSequence loadSequence(JsonObject json, double[] offset, double[] rotMode) {
|
||||
BusAnimationSequence sequence = new BusAnimationSequence();
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -41,7 +41,7 @@ class ExportJSONAnimation(Operator, ExportHelper):
|
||||
print("writing JSON data to file...")
|
||||
f = open(self.filepath, 'w', encoding='utf-8')
|
||||
|
||||
collection = {"anim": {}, "offset": {}, "hierarchy": {}}
|
||||
collection = {"anim": {}, "offset": {}, "hierarchy": {}, "rotmode": {}}
|
||||
dimensions = ["x", "z", "y"] # Swizzled to X, Z, Y
|
||||
mult = [1, -1, 1] # +X, -Z, +Y
|
||||
|
||||
@ -51,6 +51,7 @@ class ExportJSONAnimation(Operator, ExportHelper):
|
||||
|
||||
animations = collection['anim']
|
||||
offsets = collection['offset']
|
||||
modes = collection['rotmode']
|
||||
hierarchy = collection['hierarchy']
|
||||
|
||||
actions = bpy.data.actions
|
||||
@ -112,10 +113,11 @@ class ExportJSONAnimation(Operator, ExportHelper):
|
||||
if object.parent:
|
||||
hierarchy[object.name] = object.parent.name
|
||||
|
||||
if object.location == mathutils.Vector(): # don't export 0,0,0
|
||||
continue
|
||||
if object.location != mathutils.Vector(): # don't export 0,0,0
|
||||
offsets[object.name] = [object.location.x, object.location.z, -object.location.y]
|
||||
|
||||
offsets[object.name] = [object.location.x, object.location.z, -object.location.y]
|
||||
if object.rotation_mode != 'YZX':
|
||||
modes[object.name] = object.rotation_mode
|
||||
|
||||
|
||||
|
||||
@ -229,14 +231,19 @@ class ImportJSONAnimation(Operator, ImportHelper):
|
||||
bpy.ops.object.transform_apply(location=False, rotation=True, scale=False)
|
||||
object.rotation_mode = 'YZX'
|
||||
|
||||
if 'rotmode' in collection:
|
||||
modes = collection['rotmode']
|
||||
for mode in modes:
|
||||
bpy.data.objects[mode].rotation_mode = modes[mode]
|
||||
|
||||
if 'hierarchy' in collection:
|
||||
hierarchy = collection["hierarchy"]
|
||||
hierarchy = collection['hierarchy']
|
||||
for name in hierarchy:
|
||||
parent = hierarchy[name]
|
||||
|
||||
bpy.data.objects[name].parent = bpy.data.objects[parent]
|
||||
|
||||
offsets = collection["offset"]
|
||||
offsets = collection['offset']
|
||||
for name in offsets:
|
||||
offset = offsets[name]
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ class ExportJSONAnimation(Operator, ExportHelper):
|
||||
print("writing JSON data to file...")
|
||||
f = open(self.filepath, 'w', encoding='utf-8')
|
||||
|
||||
collection = {"anim": {}, "offset": {}, "hierarchy": {}}
|
||||
collection = {"anim": {}, "offset": {}, "hierarchy": {}, "rotmode": {}}
|
||||
dimensions = ["x", "z", "y"] # Swizzled to X, Z, Y
|
||||
mult = [1, -1, 1] # +X, -Z, +Y
|
||||
|
||||
@ -51,6 +51,7 @@ class ExportJSONAnimation(Operator, ExportHelper):
|
||||
|
||||
animations = collection['anim']
|
||||
offsets = collection['offset']
|
||||
modes = collection['rotmode']
|
||||
hierarchy = collection['hierarchy']
|
||||
|
||||
actions = bpy.data.actions
|
||||
@ -112,10 +113,11 @@ class ExportJSONAnimation(Operator, ExportHelper):
|
||||
if object.parent:
|
||||
hierarchy[object.name] = object.parent.name
|
||||
|
||||
if object.location == mathutils.Vector(): # don't export 0,0,0
|
||||
continue
|
||||
if object.location != mathutils.Vector(): # don't export 0,0,0
|
||||
offsets[object.name] = [object.location.x, object.location.z, -object.location.y]
|
||||
|
||||
offsets[object.name] = [object.location.x, object.location.z, -object.location.y]
|
||||
if object.rotation_mode != 'YZX':
|
||||
modes[object.name] = object.rotation_mode
|
||||
|
||||
|
||||
|
||||
@ -229,15 +231,20 @@ class ImportJSONAnimation(Operator, ImportHelper):
|
||||
object.select_set(True)
|
||||
bpy.ops.object.transform_apply(location=False, rotation=True, scale=False, properties=False)
|
||||
object.rotation_mode = 'YZX'
|
||||
|
||||
if 'rotmode' in collection:
|
||||
modes = collection['rotmode']
|
||||
for mode in modes:
|
||||
bpy.data.objects[mode].rotation_mode = modes[mode]
|
||||
|
||||
if 'hierarchy' in collection:
|
||||
hierarchy = collection["hierarchy"]
|
||||
hierarchy = collection['hierarchy']
|
||||
for name in hierarchy:
|
||||
parent = hierarchy[name]
|
||||
|
||||
bpy.data.objects[name].parent = bpy.data.objects[parent]
|
||||
|
||||
offsets = collection["offset"]
|
||||
offsets = collection['offset']
|
||||
for name in offsets:
|
||||
offset = offsets[name]
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ class ExportJSONAnimation(Operator, ExportHelper):
|
||||
print("writing JSON data to file...")
|
||||
f = open(self.filepath, 'w', encoding='utf-8')
|
||||
|
||||
collection = {"anim": {}, "offset": {}, "hierarchy": {}}
|
||||
collection = {"anim": {}, "offset": {}, "hierarchy": {}, "rotmode": {}}
|
||||
dimensions = ["x", "z", "y"] # Swizzled to X, Z, Y
|
||||
mult = [1, -1, 1] # +X, -Z, +Y
|
||||
|
||||
@ -51,6 +51,7 @@ class ExportJSONAnimation(Operator, ExportHelper):
|
||||
|
||||
animations = collection['anim']
|
||||
offsets = collection['offset']
|
||||
modes = collection['rotmode']
|
||||
hierarchy = collection['hierarchy']
|
||||
|
||||
actions = bpy.data.actions
|
||||
@ -112,10 +113,11 @@ class ExportJSONAnimation(Operator, ExportHelper):
|
||||
if object.parent:
|
||||
hierarchy[object.name] = object.parent.name
|
||||
|
||||
if object.location == mathutils.Vector(): # don't export 0,0,0
|
||||
continue
|
||||
if object.location != mathutils.Vector(): # don't export 0,0,0
|
||||
offsets[object.name] = [object.location.x, object.location.z, -object.location.y]
|
||||
|
||||
offsets[object.name] = [object.location.x, object.location.z, -object.location.y]
|
||||
if object.rotation_mode != 'YZX':
|
||||
modes[object.name] = object.rotation_mode
|
||||
|
||||
|
||||
|
||||
@ -226,15 +228,20 @@ class ImportJSONAnimation(Operator, ImportHelper):
|
||||
object.select_set(True)
|
||||
bpy.ops.object.transform_apply(location=False, rotation=True, scale=False, properties=False)
|
||||
object.rotation_mode = 'YZX'
|
||||
|
||||
if 'rotmode' in collection:
|
||||
modes = collection['rotmode']
|
||||
for mode in modes:
|
||||
bpy.data.objects[mode].rotation_mode = modes[mode]
|
||||
|
||||
if 'hierarchy' in collection:
|
||||
hierarchy = collection["hierarchy"]
|
||||
hierarchy = collection['hierarchy']
|
||||
for name in hierarchy:
|
||||
parent = hierarchy[name]
|
||||
|
||||
bpy.data.objects[name].parent = bpy.data.objects[parent]
|
||||
|
||||
offsets = collection["offset"]
|
||||
offsets = collection['offset']
|
||||
for name in offsets:
|
||||
offset = offsets[name]
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user