Add **Animation Instance Data node to Anim Graph** for caching value per-model
This commit is contained in:
@@ -973,6 +973,19 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
NodeElementArchetype.Factory.TextBox(30, Surface.Constants.LayoutOffsetY, 140, TextBox.DefaultHeight, 0, false),
|
NodeElementArchetype.Factory.TextBox(30, Surface.Constants.LayoutOffsetY, 140, TextBox.DefaultHeight, 0, false),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
new NodeArchetype
|
||||||
|
{
|
||||||
|
TypeID = 33,
|
||||||
|
Title = "Animation Instance Data",
|
||||||
|
Description = "Caches custom data per-instance and allow sampling it. Can be used to randomize animation play offset to offer randomization for crowds reusing the same graph.",
|
||||||
|
Flags = NodeFlags.AnimGraph,
|
||||||
|
Size = new Float2(240, 20),
|
||||||
|
Elements = new[]
|
||||||
|
{
|
||||||
|
NodeElementArchetype.Factory.Output(0, "Get", typeof(Float4), 0),
|
||||||
|
NodeElementArchetype.Factory.Input(0, "Init", true, typeof(Float4), 1),
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,6 +115,11 @@ void SlotBucketInit(AnimGraphInstanceData::Bucket& bucket)
|
|||||||
bucket.Slot.LoopsLeft = 0;
|
bucket.Slot.LoopsLeft = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InstanceDataBucketInit(AnimGraphInstanceData::Bucket& bucket)
|
||||||
|
{
|
||||||
|
bucket.InstanceData.Init = true;
|
||||||
|
}
|
||||||
|
|
||||||
bool SortMultiBlend1D(const byte& a, const byte& b, AnimGraphNode* n)
|
bool SortMultiBlend1D(const byte& a, const byte& b, AnimGraphNode* n)
|
||||||
{
|
{
|
||||||
// Sort items by X location from the lowest to the highest
|
// Sort items by X location from the lowest to the highest
|
||||||
@@ -432,10 +437,12 @@ bool AnimGraphBase::onNodeLoaded(Node* n)
|
|||||||
}
|
}
|
||||||
// Animation Slot
|
// Animation Slot
|
||||||
case 32:
|
case 32:
|
||||||
{
|
|
||||||
ADD_BUCKET(SlotBucketInit);
|
ADD_BUCKET(SlotBucketInit);
|
||||||
break;
|
break;
|
||||||
}
|
// Animation Instance Data
|
||||||
|
case 33:
|
||||||
|
ADD_BUCKET(InstanceDataBucketInit);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// Custom
|
// Custom
|
||||||
|
|||||||
@@ -315,6 +315,12 @@ public:
|
|||||||
int32 LoopsLeft;
|
int32 LoopsLeft;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct InstanceDataBucket
|
||||||
|
{
|
||||||
|
bool Init;
|
||||||
|
float Data[4];
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The single data storage bucket for the instanced animation graph node. Used to store the node state (playback position, state, transition data).
|
/// The single data storage bucket for the instanced animation graph node. Used to store the node state (playback position, state, transition data).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -327,6 +333,7 @@ public:
|
|||||||
BlendPoseBucket BlendPose;
|
BlendPoseBucket BlendPose;
|
||||||
StateMachineBucket StateMachine;
|
StateMachineBucket StateMachine;
|
||||||
SlotBucket Slot;
|
SlotBucket Slot;
|
||||||
|
InstanceDataBucket InstanceData;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2035,10 +2035,22 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// Animation Instance Data
|
||||||
|
case 33:
|
||||||
|
{
|
||||||
|
auto& bucket = context.Data->State[node->BucketIndex].InstanceData;
|
||||||
|
if (bucket.Init)
|
||||||
|
{
|
||||||
|
bucket.Init = false;
|
||||||
|
*(Float4*)bucket.Data = (Float4)tryGetValue(node->GetBox(1), Value::Zero);
|
||||||
|
}
|
||||||
|
value = *(Float4*)bucket.Data;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
context.ValueCache.Add(boxBase, value);
|
context.ValueCache[boxBase] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimGraphExecutor::ProcessGroupFunction(Box* boxBase, Node* node, Value& value)
|
void AnimGraphExecutor::ProcessGroupFunction(Box* boxBase, Node* node, Value& value)
|
||||||
|
|||||||
Reference in New Issue
Block a user