Keyframe
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
キーフレームは、アニメーションの特定の時点で適用された をジョイントに保持します。Keyframes は、アニメーション再生中にインターポレートされます。
ほとんどの場合、開発者はアニメーションエディタがほとんどのアニメーション機能をカバーしているため、KeyframeSequences を操作する必要はありません。しかし、いくつかの場合、開発者は Script からアニメーションを生成したり、独自のプラグインをビルドしたい場合があります。
構造
キーフレームは KeyframeSequence 内に保持され、Pose オブジェクトを含んでいます。ポーズは、対応する BaseParts に従って名前付けられ、共同の階層で構造化されます。これは、それぞれの Pose が、付属しているパーツに対応する Pose に親属していることを意味します。
注意, as Poses は、対応する BaseParts に従って名前付けられているため、アニメーションは正しく再生するには、それぞれ異なるパーツ名が必要です。
インターポレーション
アニメーション再生中、異なるキーフレームのポーズが交互に表示されます。これにより、すべてのフレームを定義する必要なく、スムーズなアニメーションを作成できます。注: インターポレーションのスタイルは、Pose オブジェクトで決定します。キーフレームオブジェクトは、アニメーションの定義された時点での Poses を単に保持します (Keyframe.Time )。
コードサンプル
This sample includes a function that will generate a 'blank' keyframe containing blank poses for all of the model's connected parts in the correct hierarchical order.
local function generateKeyframe(model)
if not model.PrimaryPart then
warn("No primary part set")
return
end
local rootPart = model.PrimaryPart:GetRootPart()
if not rootPart then
warn("Root part not found")
return
end
local partsAdded = {}
partsAdded[rootPart] = true
local function addPoses(part, parentPose)
-- get all of the joints attached to the part
for _, joint in pairs(part:GetJoints()) do
-- we're only interested in Motor6Ds
if joint:IsA("Motor6D") then
-- find the connected part
local connectedPart = nil
if joint.Part0 == part then
connectedPart = joint.Part1
elseif joint.Part1 == part then
connectedPart = joint.Part0
end
if connectedPart then
-- make sure we haven't already added this part
if not partsAdded[connectedPart] then
partsAdded[connectedPart] = true
-- create a pose
local pose = Instance.new("Pose")
pose.Name = connectedPart.Name
parentPose:AddSubPose(pose)
-- recurse
addPoses(connectedPart, pose)
end
end
end
end
end
local keyframe = Instance.new("Keyframe")
-- populate the keyframe
local rootPose = Instance.new("Pose")
rootPose.Name = rootPart.Name
addPoses(rootPart, rootPose)
keyframe:AddPose(rootPose)
return keyframe
end
local character = script.Parent
local keyframe = generateKeyframe(character)
print(keyframe)
概要
プロパティ
方法
親子関係でキーフレームに追加し、KeyframeMarker を Keyframe に追加します。
返すのは、KeyframeMarkers が追加されたすべての Keyframe を含む配列です。
設定して KeyframeMarker から Keyframe を削除し、Instance.Parent を nil に設定します。
その Pose を Keyframe に設定して、その Instance.Parent を nil に変更します。
プロパティ
Time
このプロパティは、アニメーションで Keyframe 時間位置 (秒) を提供します。これにより、キーフレーム内の Poses が表示される時間が決まります。
アニメーションの長さを決定するために、Keyframe で最も高い時間値を持つ KeyframeSequence が使用されていることに注意してください。
コードサンプル
This sample contains a simple function that will get the length of a KeyframeSequence by finding the Keyframe with the highest Keyframe.Time value.
local function getSequenceLength(keyframeSequence)
local length = 0
for _, keyframe in pairs(keyframeSequence:GetKeyframes()) do
if keyframe.Time > length then
length = keyframe.Time
end
end
return length
end
local keyframeSequence = Instance.new("KeyframeSequence")
getSequenceLength(keyframeSequence)
方法
AddMarker
この機能は、キーフレームに親属させることで KeyframeMarker を追加し、Keyframe にキーフレームを追加します。マーカーの Instance.Parent をキーフレームに設定すると機能的に同じです。
注: この機能は、パラメータとして KeyframeMarker 以外のインスタンスが指定された場合エラーが発生しないようになり、成功して親になります。
キーフレームについてさらに詳しく
Keyframe 名は唯一である必要はありません。たとえば、アニメーションに「パーティクル」と呼ばれる 3つのキーフレームがある場合、AnimationTrack:GetMarkerReachedSignal() によって返された接続イベントは、これらのキーフレームの 1つが達したときに毎回発射します。
Keyframe 名は、アニメーションを作成または編集するときに Roblox アニメーションエディタで設定できます。しかし、それはプレイする前に既存のアニメーションの Script によって設定できません。
参照してください:
パラメータ
親になる KeyframeMarker が Keyframe になっています。
戻り値
コードサンプル
この例では、Keyframe:AddMarker() および Keyframe:RemoveMarker() 機能を示しています。これらは機能的に parenting と同等であり、マーカーを親から取り除いています。
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local marker = Instance.new("KeyframeMarker")
marker.Name = "FootStep"
marker.Value = 100
keyframe:AddMarker(marker) --マーカー.Parent = キーフレーム
task.wait(2)
keyframe:RemoveMarker(marker) --marker.Parent = nil
AddPose
この機能は、キーフレームに親属させることで Pose を追加し、Keyframe にキーフレームを追加します。ポーズの Instance.Parent をキーフレームに設定すると機能的に同じです。
注: この機能は、Pose 以外のインスタンスがポーズパラメータとして指定され、成功して親になるときにエラーは発生しません。
パラメータ
戻り値
コードサンプル
This sample includes a function that will generate a 'blank' keyframe containing blank poses for all of the model's connected parts in the correct hierarchical order.
local function generateKeyframe(model)
if not model.PrimaryPart then
warn("No primary part set")
return
end
local rootPart = model.PrimaryPart:GetRootPart()
if not rootPart then
warn("Root part not found")
return
end
local partsAdded = {}
partsAdded[rootPart] = true
local function addPoses(part, parentPose)
-- get all of the joints attached to the part
for _, joint in pairs(part:GetJoints()) do
-- we're only interested in Motor6Ds
if joint:IsA("Motor6D") then
-- find the connected part
local connectedPart = nil
if joint.Part0 == part then
connectedPart = joint.Part1
elseif joint.Part1 == part then
connectedPart = joint.Part0
end
if connectedPart then
-- make sure we haven't already added this part
if not partsAdded[connectedPart] then
partsAdded[connectedPart] = true
-- create a pose
local pose = Instance.new("Pose")
pose.Name = connectedPart.Name
parentPose:AddSubPose(pose)
-- recurse
addPoses(connectedPart, pose)
end
end
end
end
end
local keyframe = Instance.new("Keyframe")
-- populate the keyframe
local rootPose = Instance.new("Pose")
rootPose.Name = rootPart.Name
addPoses(rootPart, rootPose)
keyframe:AddPose(rootPose)
return keyframe
end
local character = script.Parent
local keyframe = generateKeyframe(character)
print(keyframe)
This sample demonstrates quickly the Keyframe.AddPose, Keyframe.RemovePose and Pose.AddSubPose and Pose.RemoveSubPose functions. Note these are functionally equivalent to parenting and un-parenting the poses.
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local pose = Instance.new("Pose")
pose.EasingStyle = Enum.PoseEasingStyle.Cubic
pose.EasingDirection = Enum.PoseEasingDirection.Out
local pose2 = Instance.new("Pose")
pose2.EasingStyle = Enum.PoseEasingStyle.Cubic
pose2.EasingDirection = Enum.PoseEasingDirection.Out
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
keyframe:RemovePose(pose) -- pose.Parent = nil
task.wait(2)
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
pose:AddSubPose(pose2) -- pose2.Parent = pose
task.wait(2)
pose:RemoveSubPose(pose2) -- pose2.Parent = nil
GetMarkers
この関数は、KeyframeMarkers が追加されたすべての Keyframe を含む配列を返します。注: この機能は、instances タイプのキーフレームマーカーのみを返します。
キーフレームについてさらに詳しく
Keyframe 名は唯一である必要はありません。たとえば、アニメーションに「パーティクル」と呼ばれる 3つのキーフレームがある場合、AnimationTrack:GetMarkerReachedSignal() によって返された接続イベントは、これらのキーフレームの 1つが達したときに毎回発射します。
Keyframe 名は、アニメーションを作成または編集するときに Roblox アニメーションエディタで設定できます。しかし、それはプレイする前に既存のアニメーションの Script によって設定できません。
参照してください:
戻り値
に追加されたすべての を含む配列。
コードサンプル
この例では、Keyframe:AddMarker() および Keyframe:GetMarkers() 機能を示しています。2つのマーカーを追加し、marker1 と marker2 をキーフレームに追加した後、この例では、追加されたマーカーの名前を取得し、印刷します。
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local marker1 = Instance.new("KeyframeMarker")
marker1.Name = "FootStep"
marker1.Value = 100
local marker2 = Instance.new("KeyframeMarker")
marker2.Name = "Wave"
marker2.Value = 100
keyframe:AddMarker(marker1) --マーカー.Parent = キーフレーム
keyframe:AddMarker(marker2) --マーカー.Parent = キーフレーム
local markers = keyframe:GetMarkers()
for _, marker in pairs(markers) do
print(marker.Name)
end
GetPoses
この関数は、Poses が追加されたすべての Keyframe を含む配列を返します。
戻り値
Poses の配列。
コードサンプル
This code sample includes a function to reset the CFrame of the Poses in a Keyframe.
local function resetPoses(parent)
-- both functions are equivalent to GetChildren
local poses = parent:IsA("Keyframe") and parent:GetPoses() or parent:IsA("Pose") and parent:GetSubPoses()
for _, pose in pairs(poses) do
if pose:IsA("Pose") then
pose.CFrame = CFrame.new()
-- recurse
resetPoses(pose)
end
end
end
RemoveMarker
この機能は、KeyframeMarker を設定して Keyframe から Instance.Parent を削除し、nil に変更します。
キーフレームマーカーの Instance.Parent は nil に設定されますが、破壊されません。これは、マーカーが参照されている限り、後で再親にすることができるということです。
注: この機能は、パラメータとして KeyframeMarker 以外のインスタンスが指定された場合、エラーが発生しません。
キーフレームについてさらに詳しく
Keyframe 名は唯一である必要はありません。たとえば、アニメーションに「パーティクル」と呼ばれる 3つのキーフレームがある場合、AnimationTrack:GetMarkerReachedSignal() によって返された接続イベントは、これらのキーフレームの 1つが達したときに毎回発射します。
Keyframe 名は、アニメーションを作成または編集するときに Roblox アニメーションエディタで設定できます。しかし、それはプレイする前に既存のアニメーションの Script によって設定できません。
参照してください:
パラメータ
戻り値
コードサンプル
この例では、Keyframe:AddMarker() および Keyframe:RemoveMarker() 機能を示しています。これらは機能的に parenting と同等であり、マーカーを親から取り除いています。
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local marker = Instance.new("KeyframeMarker")
marker.Name = "FootStep"
marker.Value = 100
keyframe:AddMarker(marker) --マーカー.Parent = キーフレーム
task.wait(2)
keyframe:RemoveMarker(marker) --marker.Parent = nil
RemovePose
この機能は、Pose を破壊せずに、Keyframe から Instance.Parent を削除し、その nil を設定します。つまり、提供されたポーズが参照され、後で再親和することができます。
注: この機能は、Pose 以外のインスタンスがポーズパラメータとして指定された場合、エラーが発生しません。
パラメータ
戻り値
コードサンプル
This sample demonstrates quickly the Keyframe.AddPose, Keyframe.RemovePose and Pose.AddSubPose and Pose.RemoveSubPose functions. Note these are functionally equivalent to parenting and un-parenting the poses.
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local pose = Instance.new("Pose")
pose.EasingStyle = Enum.PoseEasingStyle.Cubic
pose.EasingDirection = Enum.PoseEasingDirection.Out
local pose2 = Instance.new("Pose")
pose2.EasingStyle = Enum.PoseEasingStyle.Cubic
pose2.EasingDirection = Enum.PoseEasingDirection.Out
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
keyframe:RemovePose(pose) -- pose.Parent = nil
task.wait(2)
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
pose:AddSubPose(pose2) -- pose2.Parent = pose
task.wait(2)
pose:RemoveSubPose(pose2) -- pose2.Parent = nil