MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / Cook

Method Cook

modules/tools/animation_tool/src/animation_asset.cpp:21–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19namespace skd::asset
20{
21bool SAnimCooker::Cook(SCookContext *ctx)
22{
23 using namespace skr::anim;
24 using namespace ozz::animation::offline;
25 SkrZoneScopedNS("SAnimCooker::Cook", 4);
26
27 //-----load config
28 auto settings = LoadConfig<SAnimCookSettings>(ctx);
29 //-----emit static dependencies
30 if(settings.skeletonAsset.get_serialized() == skr_guid_t{})
31 {
32 SKR_LOG_ERROR(u8"Failed to cook animation asset %s. No skeleton asset specified.", ctx->GetAssetRecord()->path.c_str());
33 return false;
34 }
35 auto idx = ctx->AddStaticDependency(settings.skeletonAsset.get_serialized(), true);
36 if(ctx->GetStaticDependency(idx).get_status() == SKR_LOADING_STATUS_ERROR)
37 return false;
38 SkeletonResource* skeletonResource = (SkeletonResource*)ctx->GetStaticDependency(idx).get_ptr();
39 auto& skeleton = skeletonResource->skeleton;
40 //-----import resource object
41 RawAnimation* rawAnimation = (RawAnimation*)ctx->Import<RawAnimation>();
42 if (!rawAnimation) return false;
43 SKR_DEFER({ctx->Destroy(rawAnimation);});
44 //-----emit dependencies
45 // no static dependencies
46 //-----cook resource
47 if(settings.optimize)
48 {
49 AnimationOptimizer optimizer;
50 AnimationOptimizer::Setting optSettings;
51 optSettings.tolerance = settings.tolerance;
52 optSettings.distance = settings.distance;
53 optimizer.setting = optSettings;
54 for (int i = 0; i < settings.override.size(); ++i)
55 {
56 bool found = false;
57 auto& override = settings.override[i];
58 for (int j = 0; j < skeleton.num_joints(); ++j) {
59 const char* joint_name = skeleton.joint_names()[j];
60 if (ozz::strmatch(joint_name, override.name.c_str())) {
61 found = true;
62
63 SKR_LOG_TRACE(u8"Found joint \"%s\" matching pattern \"%s\" for joint optimization setting override.", joint_name, override.name.c_str());
64
65 const AnimationOptimizer::JointsSetting::value_type entry(j, optSettings);
66 const bool newly =
67 optimizer.joints_setting_override.insert(entry).second;
68 if (!newly) {
69 SKR_LOG_TRACE(u8"Redundant optimization setting for pattern \"%s\".", override.name.c_str());
70 }
71 }
72 }
73
74 optSettings = optimizer.setting;
75
76 if (!found) {
77 SKR_LOG_INFO(u8"No joint matching pattern \"%s\" for joint optimization setting override.", override.name.c_str());
78 }

Callers

nothing calls this directly

Calls 15

strmatchFunction · 0.85
SkeletonRestPoseSoAToAoSFunction · 0.85
make_spanFunction · 0.85
get_serializedMethod · 0.80
AddStaticDependencyMethod · 0.80
num_jointsMethod · 0.80
moveFunction · 0.50
c_strMethod · 0.45
GetAssetRecordMethod · 0.45
get_statusMethod · 0.45
get_ptrMethod · 0.45

Tested by

no test coverage detected