载入中...
搜索中...
未找到
ControlRigInternal.h
浏览该文件的文档.
1#pragma once
2#include <algorithm>
3#include <cmath>
4#include <set>
7
9template <class T>
10Result<T> error(std::string message) {
12}
13inline bool validTRS(const TransformTRS& t) {
14 const float values[]{t.px, t.py, t.pz, t.qx, t.qy, t.qz, t.qw, t.sx, t.sy, t.sz};
15 for (float v : values)
16 if (!std::isfinite(v)) return false;
17 const float length = t.qx * t.qx + t.qy * t.qy + t.qz * t.qz + t.qw * t.qw;
18 const float scaleTolerance = 1e-5f * std::max({t.sx, t.sy, t.sz});
19 return std::abs(length - 1.f) < 1e-4f && t.sx > 1e-6f && t.sy > 1e-6f && t.sz > 1e-6f &&
20 std::abs(t.sx - t.sy) <= scaleTolerance && std::abs(t.sx - t.sz) <= scaleTolerance;
21}
23 TransformTRS inverse;
24 inverse.qx = -parent.qx;
25 inverse.qy = -parent.qy;
26 inverse.qz = -parent.qz;
27 inverse.qw = parent.qw;
28 TransformTRS delta = world;
29 delta.px -= parent.px;
30 delta.py -= parent.py;
31 delta.pz -= parent.pz;
32 auto local = detail::mulTRS(inverse, delta);
33 local.px /= parent.sx;
34 local.py /= parent.sy;
35 local.pz /= parent.sz;
36 local.sx /= parent.sx;
37 local.sy /= parent.sy;
38 local.sz /= parent.sz;
39 return local;
40}
41inline int controlIndex(const RigDefinition& d, std::string_view id) {
42 for (size_t i = 0; i < d.controls.size(); ++i)
43 if (d.controls[i].id == id) return static_cast<int>(i);
44 return -1;
45}
50 std::vector<int> order;
51 std::vector<bool> visited(d.controls.size(), false);
52 while (order.size() < d.controls.size()) {
53 bool progress = false;
54 for (size_t i = 0; i < d.controls.size(); ++i) {
55 if (visited[i]) continue;
56 const auto& parent = d.controls[i].parent;
57 const int p = controlIndex(d, parent);
58 if (!parent.empty() && p < 0) return error<std::vector<int>>("missing parent: " + parent);
59 if (parent.empty() || visited[static_cast<size_t>(p)]) {
60 visited[i] = true;
61 order.push_back(static_cast<int>(i));
62 progress = true;
63 }
64 }
65 if (!progress) return error<std::vector<int>>("control hierarchy cycle");
66 }
67 return Result<std::vector<int>>::success(std::move(order));
68}
69} // namespace eve::animation::rig_detail
Vec3 relative
Definition AnimSmr.cpp:164
glm::vec4 p[6]
std::string message
float v
float length
const ColourScope * parent
std::string local
std::vector< std::int32_t > order
std::string error
Definition Package.cpp:174
std::set< std::string > values
float d
float t
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
TransformTRS mulTRS(const TransformTRS &parent, const TransformTRS &local)
Mul trs.
int controlIndex(const RigDefinition &d, std::string_view id)
bool validTRS(const TransformTRS &t)
Result< std::vector< int > > controlOrder(const RigDefinition &d)
Resolve authoring hierarchy order. @cost Allocates a control-sized result and scans dependencies; amo...
Owning, versioned rig authoring data; no runtime pointers or indices.
Definition ControlRig.h:62
Local TRS used by skeletal animation (quaternion xyzw).
Definition AnimMath.h:9