MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / InitAsAnimation

Method InitAsAnimation

Source/Engine/Content/Assets/AnimationGraph.cpp:75–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73#endif
74
75bool AnimationGraph::InitAsAnimation(SkinnedModel* baseModel, Animation* anim, bool loop, bool rootMotion)
76{
77 if (!IsVirtual())
78 {
79 LOG(Warning, "Only virtual Anim Graph can be modified.");
80 return true;
81 }
82 if (!baseModel || !anim)
83 {
84 Log::ArgumentNullException();
85 return true;
86 }
87 PROFILE_MEM(AnimationsData);
88
89 // Create Graph data
90 MemoryWriteStream writeStream(512);
91 {
92 AnimGraph graph(nullptr);
93 graph.Nodes.Resize(2);
94 auto& rootNode = graph.Nodes[0];
95 rootNode.Type = GRAPH_NODE_MAKE_TYPE(9, 1);
96 rootNode.ID = 1;
97 rootNode.Values.Resize(1);
98 rootNode.Values[0] = (int32)(rootMotion ? RootMotionExtraction::Enable : RootMotionExtraction::Ignore);
99 rootNode.Boxes.Resize(1);
100 rootNode.Boxes[0] = AnimGraphBox(&rootNode, 0, VariantType::Void);
101 auto& animNode = graph.Nodes[1];
102 animNode.Type = GRAPH_NODE_MAKE_TYPE(9, 2);
103 animNode.ID = 2;
104 animNode.Values.Resize(4);
105 animNode.Values[0] = anim->GetID();
106 animNode.Values[1] = 1.0f;
107 animNode.Values[2] = loop;
108 animNode.Values[3] = 0.0f;
109 animNode.Boxes.Resize(8);
110 animNode.Boxes[0] = AnimGraphBox(&animNode, 0, VariantType::Void);
111 animNode.Boxes[0].Connections.Add(&rootNode.Boxes[0]);
112 rootNode.Boxes[0].Connections.Add(&animNode.Boxes[0]);
113 animNode.Boxes[1] = AnimGraphBox(&animNode, 1, VariantType::Void);
114 animNode.Boxes[2] = AnimGraphBox(&animNode, 2, VariantType::Void);
115 animNode.Boxes[3] = AnimGraphBox(&animNode, 3, VariantType::Void);
116 animNode.Boxes[4] = AnimGraphBox(&animNode, 4, VariantType::Void);
117 animNode.Boxes[5] = AnimGraphBox(&animNode, 5, VariantType::Void);
118 animNode.Boxes[6] = AnimGraphBox(&animNode, 6, VariantType::Void);
119 animNode.Boxes[7] = AnimGraphBox(&animNode, 7, VariantType::Void);
120 graph.Parameters.Resize(1);
121 AnimGraphParameter& baseModelParam = graph.Parameters[0];
122 baseModelParam.Identifier = ANIM_GRAPH_PARAM_BASE_MODEL_ID;
123 baseModelParam.Type = VariantType::Asset;
124 baseModelParam.IsPublic = false;
125 baseModelParam.Value = baseModel->GetID();
126 if (graph.Save(&writeStream, USE_EDITOR))
127 return true;
128 }
129
130 // Load Graph data (with initialization)
131 ScopeLock lock(Locker);
132 MemoryReadStream readStream(ToSpan(writeStream));

Callers 1

SetModelMethod · 0.80

Calls 8

IsVirtualFunction · 0.85
GetIDMethod · 0.80
ToSpanFunction · 0.50
ResizeMethod · 0.45
AddMethod · 0.45
SaveMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected