Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
/active_project
/test/assets/assets.db
/test/products/
_codeql_detected_source_root
2 changes: 1 addition & 1 deletion runtime/render/adaptor/src/assets/AnimationAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace sky {

archive.LoadValue(channelSize);
channel.rotation.time.resize(channelSize / sizeof(float));
archive.LoadValue(reinterpret_cast<char*>(channel.position.time.data()), channelSize);
archive.LoadValue(reinterpret_cast<char*>(channel.rotation.time.data()), channelSize);

archive.LoadValue(channelSize);
channel.rotation.keys.resize(channelSize / sizeof(Quaternion));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace sky {
template <typename T>
T AnimInterpolateLinear(const T &vk, const T &vk1, float t)
{
return (1 - t) * vk + t * vk1;
return vk * (1 - t) + vk1 * t;
}

Quaternion AnimSphericalLinear(const Quaternion &vk, const Quaternion &vk1, float t);
Expand All @@ -38,22 +38,31 @@ namespace sky {
}
}

const T vk1 = {};
const T vk2 = {};
float t = 0.f;
if (k == 0) {
return data.keys[0];
}

if (k >= data.time.size()) {
return data.keys[data.keys.size() - 1];
}

const T &vk1 = data.keys[k - 1];
const T &vk2 = data.keys[k];
float t = (param.timePoint - data.time[k - 1]) / (data.time[k] - data.time[k - 1]);

switch (param.interpolation) {
case Interpolation::STEP:
return vk1;
break;
case Interpolation::CUBIC_SPLINE: // not supported yet.
case Interpolation::LINEAR:
if constexpr (std::is_same_v<T, Quaternion>) {
return SphericalLinear(vk1, vk2, t);
return AnimSphericalLinear(vk1, vk2, t);
} else {
return AnimInterpolateLinear(vk1, vk2, t);
}
}
SKY_ASSERT(false);
return data.keys[0];
}

} // namespace sky
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ namespace sky {
AnimChannelData<Quaternion> rotation;
};

struct AnimNodeSampleResult : AnimSampleResult {
Vector3 position = {0.f, 0.f, 0.f};
Vector3 scale = {1.f, 1.f, 1.f};
Quaternion rotation = {};
};

class AnimationNodeChannel : public AnimationChannel {
public:
explicit AnimationNodeChannel(const Name &name) : AnimationChannel(name) {}
Expand Down
6 changes: 3 additions & 3 deletions runtime/render/animation/src/croe/AnimationInterpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace sky {
}

return {
k1 * vk.x + k2 * vk1.x,
k1 * vk.w + k2 * vk1.w,
k1 * vk.z + k2 * vk1.z,
k1 * vk.w + k2 * vk1.w
k1 * vk.x + k2 * vk1.x,
k1 * vk.y + k2 * vk1.y,
k1 * vk.z + k2 * vk1.z
};
}

Expand Down
14 changes: 14 additions & 0 deletions runtime/render/animation/src/croe/AnimationNodeChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ namespace sky {

void AnimationNodeChannel::Sample(const SampleParam &param, const AnimSampleResultPtr &ptr)
{
auto *result = static_cast<AnimNodeSampleResult*>(ptr.Get());
SKY_ASSERT(result != nullptr);
if (result == nullptr) {
return;
}

if (!position.time.empty()) {
result->position = AnimSampleChannel(position, param);
}
if (!scale.time.empty()) {
result->scale = AnimSampleChannel(scale, param);
}
if (!rotation.time.empty()) {
result->rotation = AnimSampleChannel(rotation, param);
}
}
} // namespace sky