49absl::StatusOr<rig::Rig>
ParseRig(std::string_view text) {
51 const absl::Status parsed =
ParseText(text, file);
56 std::set<std::string> joints;
57 for (
const rig::Joint& joint : file.joints()) {
58 if (joint.name().empty()) {
59 return absl::InvalidArgumentError(
"a joint has no name");
61 if (joint.parent().empty() ? !joints.empty()
62 : !joints.contains(joint.parent())) {
63 return absl::InvalidArgumentError(absl::StrCat(
64 "the ", joint.name(),
" hangs from a joint that isn't before it"));
66 std::vector<std::string> names = {joint.name()};
67 if (joint.mirrored()) {
68 names.push_back(ToTheRight(joint.name()));
70 for (
const std::string& name : names) {
71 if (!joints.insert(name).second) {
72 return absl::InvalidArgumentError(
73 absl::StrCat(
"there are two joints called ", name));
77 for (
const rig::Build& build : file.builds()) {
78 for (
const rig::Shift& shift : build.shifts()) {
79 if (!joints.contains(shift.joint())) {
80 return absl::InvalidArgumentError(absl::StrCat(
81 "a build moves a joint ", shift.joint(),
" the rig doesn't have"));
85 absl::Status checked = CheckGait(file.walk(),
"walk");
87 checked = CheckGait(file.run(),
"run");
90 checked = CheckMove(file.idle(),
"idle");
93 checked = CheckMove(file.death(),
"death");
101std::vector<rig::Joint>
Skeleton(
const rig::Rig& rig,
int build) {
102 std::vector<rig::Joint> joints;
103 for (
const rig::Joint& joint : rig.joints()) {
104 joints.push_back(joint);
105 if (!joint.mirrored()) {
108 rig::Joint right = joint;
109 right.set_name(ToTheRight(joint.name()));
110 right.set_parent(ToTheRight(joint.parent()));
111 right.mutable_at()->set_x(-joint.at().x());
112 joints.push_back(right);
114 if (build < 0 || build >= rig.builds_size()) {
117 for (
const rig::Shift& shift : rig.builds(build).shifts()) {
120 const std::string twin = ToTheRight(shift.joint());
121 for (
const bool right : {
false,
true}) {
122 if (right && twin == shift.joint()) {
125 std::set<std::string> moved = {right ? twin : shift.joint()};
126 for (rig::Joint& joint : joints) {
127 if (!moved.contains(joint.name()) && !moved.contains(joint.parent())) {
130 moved.insert(joint.name());
131 figures::Offset& at = *joint.mutable_at();
132 at.set_x(at.x() + (right ? -shift.by().x() : shift.by().x()));
133 at.set_y(at.y() + shift.by().y());
134 at.set_z(at.z() + shift.by().z());