Skip to content

Commit cc8e68c

Browse files
committed
initial bone-based animation logic
1 parent ab493a8 commit cc8e68c

File tree

2 files changed

+44
-48
lines changed

2 files changed

+44
-48
lines changed

DenizenModelsConverter/PackMaker.cs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,34 +80,27 @@ public static void BuildPack(string rawModelPath, BBModel model, string item, st
8080
foreach (BBModel.Outliner outline in model.Outlines)
8181
{
8282
string modelText = MinecraftModelMaker.CreateModelFor(model, outline);
83-
if (modelText is null)
84-
{
85-
Debug("Skip this model outline entry - no content");
86-
JObject skippedEntry = new();
87-
skippedEntry.Add("name", outline.Name);
88-
skippedEntry.Add("empty", true);
89-
skippedEntry.Add("parent", outline.Parent == null ? "none" : outline.Parent.ToString());
90-
modelSet.Add(outline.UUID.ToString(), skippedEntry);
91-
continue;
92-
}
93-
string modelName = $"{modelPath}/{outline.Name}";
94-
bool reused = existingCmd.TryGetValue(modelName, out int id);
95-
if (!reused)
83+
JObject modelEntry = new();
84+
if (modelText is not null)
9685
{
97-
Debug($"Adding new custom_model_data for {modelName} as {min}");
98-
id = min++;
99-
JObject overrideEntry = new();
100-
overrideEntry.Add("model", $"{modelPath}/{outline.Name}");
101-
JObject predicate = new();
102-
predicate.Add("custom_model_data", id);
103-
overrideEntry.Add("predicate", predicate);
104-
overrides.Add(overrideEntry);
86+
string modelName = $"{modelPath}/{outline.Name}";
87+
bool reused = existingCmd.TryGetValue(modelName, out int id);
88+
if (!reused)
89+
{
90+
Debug($"Adding new custom_model_data for {modelName} as {min}");
91+
id = min++;
92+
JObject overrideEntry = new();
93+
overrideEntry.Add("model", $"{modelPath}/{outline.Name}");
94+
JObject predicate = new();
95+
predicate.Add("custom_model_data", id);
96+
overrideEntry.Add("predicate", predicate);
97+
overrides.Add(overrideEntry);
98+
}
99+
Debug($"Creating model for {modelName} as {item}[custom_model_data={id}]");
100+
File.WriteAllText($"{fullModelPath}/{outline.Name}.json", modelText);
101+
modelEntry.Add("item", $"{item}[custom_model_data={id}]");
105102
}
106-
Debug($"Creating model for {modelName} as {item}[custom_model_data={id}]");
107-
File.WriteAllText($"{fullModelPath}/{outline.Name}.json", modelText);
108-
JObject modelEntry = new();
109103
modelEntry.Add("name", outline.Name);
110-
modelEntry.Add("item", $"{item}[custom_model_data={id}]");
111104
modelEntry.Add("origin", outline.Origin.ToDenizenString());
112105
modelEntry.Add("rotation", outline.Rotation.ToDenizenString());
113106
modelEntry.Add("parent", outline.Parent == null ? "none" : outline.Parent.ToString());

scripts/dmodels.dsc

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dmodels_load_model:
1616
- define yamlid dmodels_<[model_name]>
1717
- define filename data/models/<[model_name]>.dmodel.yml
1818
- if !<server.has_file[<[filename]>]>:
19-
- debug error "Invalid model <[model_name]>, file does not exist: <[filename]>, cannot load"
19+
- debug error "[DModels] Invalid model <[model_name]>, file does not exist: <[filename]>, cannot load"
2020
- stop
2121
- ~yaml id:<[yamlid]> load:<[filename]>
2222
- define order <yaml[<[yamlid]>].read[order]>
@@ -28,7 +28,7 @@ dmodels_load_model:
2828
- foreach <[animations]> key:name as:anim:
2929
- foreach <[order]> as:id:
3030
- if <[anim.animators].contains[<[id]>]>:
31-
- define raw_animators.<[id]> <[anim.animators.<[id]>]>
31+
- define raw_animators.<[id]>.frames <[anim.animators.<[id]>.frames].sort_by_value[get[time]]>
3232
- else:
3333
- define raw_animators.<[id]> <map[frames=<list>]>
3434
- define anim.animators <[raw_animators]>
@@ -48,7 +48,7 @@ dmodels_spawn_model:
4848
- spawn dmodel_part_stand <[location]> save:root
4949
- flag <entry[root].spawned_entity> dmodel_model_id:<[model_name]>
5050
- foreach <server.flag[dmodels_data.model_<[model_name]>]> key:id as:part:
51-
- if <[part.empty]||false>:
51+
- if !<[part.item].exists>:
5252
- foreach next
5353
- define rots <[part.rotation].split[,].parse[to_radians]>
5454
# Idk wtf is with the scale here. It's somewhere in the range of 25 to 26. 25.45 seems closest in one of my tests,
@@ -110,6 +110,8 @@ dmodels_move_to_frame:
110110
- flag server dmodels_anim_active.<[root_entity].uuid>:!
111111
- define parentage <map>
112112
- foreach <[animation_data.animators]> key:part_id as:animator:
113+
- define framedata.position 0,0,0
114+
- define framedata.rotation 0,0,0
113115
- foreach position|rotation as:channel:
114116
- define relevant_frames <[animator.frames].filter[get[channel].equals[<[channel]>]]>
115117
- define before_frame <[relevant_frames].filter[get[time].is_less_than_or_equal_to[<[timespot]>]].last||null>
@@ -130,10 +132,10 @@ dmodels_move_to_frame:
130132
- case catmullrom:
131133
- define before_extra <[relevant_frames].filter[get[time].is_less_than[<[before_frame.time]>]].last||null>
132134
- if <[before_extra]> == null:
133-
- define before_extra <[before_frame]>
135+
- define before_extra <[animation_data.loop].equals[loop].if_true[<[relevant_frames].last>].if_false[<[before_frame]>]>
134136
- define after_extra <[relevant_frames].filter[get[time].is_more_than[<[after_frame.time]>]].first||null>
135137
- if <[after_extra]> == null:
136-
- define after_extra <[after_frame]>
138+
- define after_extra <[animation_data.loop].equals[loop].if_true[<[relevant_frames].first>].if_false[<[after_frame]>]>
137139
- define p0 <[before_extra.data].as_location>
138140
- define p1 <[before_frame.data].as_location>
139141
- define p2 <[after_frame.data].as_location>
@@ -143,24 +145,25 @@ dmodels_move_to_frame:
143145
- define data <[after_frame.data].as_location.sub[<[before_frame.data]>].mul[<[time_percent]>].add[<[before_frame.data]>].xyz>
144146
- case step:
145147
- define data <[before_frame.data]>
146-
- define parent_data 0,0,0
147-
- define parent_id <[model_data.<[part_id]>.parent]>
148-
- while <[parent_id]> != none:
149-
- define new_data <[parentage.<[parent_id]>.<[channel]>]||null>
150-
- if <[new_data]> != null:
151-
- define parent_data <[new_data]>
152-
- while stop
153-
- define parent_id <[model_data.<[parent_id]>.parent]>
154-
- define data <[data].as_location.add[<[parent_data]>]>
155-
- define parentage.<[part_id]>.<[channel]>:<[data]>
156-
- debug log "<[data]> and <[parent_data]> for <[part_id]> and <[model_data.<[part_id]>.parent]||0> in <[channel]>"
157-
- foreach <[root_entity].flag[dmodel_anim_part.<[part_id]>]||<list>> as:ent:
158-
- choose <[channel]>:
159-
- case position:
160-
- teleport <[ent]> <[root_entity].location.add[<[ent].flag[dmodel_def_offset].add[<[data].div[25.6]>]>]>
161-
- case rotation:
162-
- define radian_rot <[data].xyz.split[,].parse[to_radians].separated_by[,]>
163-
- adjust <[ent]> armor_pose:[head=<[ent].flag[dmodel_def_pose].as_location.add[<[radian_rot]>].xyz>]
148+
- define framedata.<[channel]> <[data]>
149+
- define this_part <[model_data.<[part_id]>]>
150+
- define parent_id <[this_part.parent]>
151+
- define parent_pos <location[<[parentage.<[parent_id]>.position]||0,0,0>]>
152+
- define parent_rot <location[<[parentage.<[parent_id]>.rotation]||0,0,0>]>
153+
- define parent_offset <location[<[parentage.<[parent_id]>.offset]||0,0,0>]>
154+
#- define parent_part <[model_data.<[parent_id]>]||<map>>
155+
- define rel_offset <location[<[this_part.origin]>].sub[<[parent_offset]>]>
156+
- define rot_offset <[rel_offset].rotate_around_x[<[parent_rot].x.to_radians>].rotate_around_y[<[parent_rot].y.to_radians>].rotate_around_z[<[parent_rot].z.to_radians>]>
157+
- define pos_shift <[rot_offset].sub[<[rel_offset]>]>
158+
- define new_pos <[framedata.position].as_location.add[<[pos_shift]>].add[<[parent_pos]>]>
159+
- define new_rot <[framedata.rotation].as_location.add[<[parent_rot]>]>
160+
- define parentage.<[part_id]>.position:<[new_pos]>
161+
- define parentage.<[part_id]>.rotation:<[new_rot]>
162+
- define parentage.<[part_id]>.offset:<[rot_offset]>
163+
- foreach <[root_entity].flag[dmodel_anim_part.<[part_id]>]||<list>> as:ent:
164+
- teleport <[ent]> <[root_entity].location.add[<[ent].flag[dmodel_def_offset].add[<[new_pos].div[25.6]>]>]>
165+
- define radian_rot <[new_rot].xyz.split[,].parse[to_radians].separated_by[,]>
166+
- adjust <[ent]> armor_pose:[head=<[ent].flag[dmodel_def_pose].as_location.add[<[radian_rot]>].xyz>]
164167

165168
dmodels_catmullrom_get_t:
166169
type: procedure

0 commit comments

Comments
 (0)