Keyframe
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
กรอบสําคัญเก็บ ที่ใช้กับข้อต่อในจุดเวลาที่กำหนดในแอนิเมชั่นKeyframes จะถูกแทรกระหว่างการเล่นแอนิเมชั่น
โปรดทราบว่าในกรณีส่วนใหญ่นักพัฒนาไม่จำเป็นต้องดำเนินการกับ KeyframeSequences เนื่องจากตัวแก้ไขแอนิเมชันครอบคลุมฟังก์ชันแอนิเมชันส่วนใหญ่อย่างไรก็ตามในบางกรณีนักพัฒนาอาจต้องการสร้างแอนิเมชันจาก Script หรือสร้างปลั๊กอินของตนเอง
โครงสร้าง
กรอบรูปถูกเก็บไว้ภายใน KeyframeSequence และมีวัตถุ Poseท่าจะได้รับชื่อตามที่ BaseParts พวกเขาตรงกับและมีโครงสร้างในแง่ของชั้นวาระร่วมซึ่งหมายความว่าแต่ละ Pose เป็นบุตรของ Pose ที่ตรงกับส่วนที่มันแนบมา
โปรดทราบ เนื่องจาก Poses ได้รับการตั้งชื่อตามที่ BaseParts พวกเขาตรงกับ แอนิเมชั่นจะต้องมีชื่อส่วนที่แตกต่างกันเพื่อเล่นอย่างถูกต้อง
การสลับ
ระหว่างการเล่นแอนิเมชั่นโพสต์ในช่วงเวลาที่แตกต่างกันจะถูกแทรกระหว่างกันสิ่งนี้ช่วยให้สามารถสร้างแอนิเมชันที่ราบรื่นได้โดยไม่จำเป็นต้องกำหนดทุกเฟรมโปรดทราบว่าสไตล์ของการ interpolation จะถูกกำหนดในวัตถุ Poseวัตถุ Keyframe เพียงแค่จัดเก็บ 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 โดยการปลูกฝังมันให้กับ 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 โดยการปลูกฝังมันให้กับ keyframeมันเป็นฟังก์ชันเดียวกับการตั้งค่าเครื่องหมาย Instance.Parent ไปยัง Keyframe
โปรดทราบว่าฟังก์ชันนี้จะไม่เกิดข้อผิดพลาดเมื่อให้ตัวแปรที่ไม่ใช่ KeyframeMarker เป็นพารามิเตอร์และจะประสบความสําเร็จในการเป็นพ่อ
เพิ่มเติมเกี่ยวกับกุญแจเฟรม
Keyframe ชื่อไม่จำเป็นต้องเป็นเอกลักษณ์ตัวอย่างเช่นหากแอนิเมชั่นมีชุดกรอบสำคัญสามชุดที่ชื่อว่า "อนุภาค" การเหตุการณ์ที่เชื่อมต่อโดย AnimationTrack:GetMarkerReachedSignal() จะยิงในแต่ละครั้งที่ชุดกรอบสำคัญหนึ่งในนั้นถูกถึง
Keyframe ชื่อสามารถตั้งค่าได้ใน Roblox Animation Editor แอนิเมชันScript ในแอนิเมชั่นที่มีอยู่ก่อนที่จะเล่น
ดูเพิ่ม:
พารามิเตอร์
การเป็นพ่อของ KeyframeMarker กับ Keyframe ที่เป็นพ่อ
ส่งค่ากลับ
ตัวอย่างโค้ด
This example demonstrates the Keyframe:AddMarker() and Keyframe:RemoveMarker() functions. Note these are functionally equivalent to parenting and un-parenting the markers.
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local marker = Instance.new("KeyframeMarker")
marker.Name = "FootStep"
marker.Value = 100
keyframe:AddMarker(marker) --marker.Parent = keyframe
task.wait(2)
keyframe:RemoveMarker(marker) --marker.Parent = nil
AddPose
ฟังก์ชันนี้เพิ่ม Pose ให้กับ Keyframe โดยการปลูกฝังมันให้กับ 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 ของประเภท KeyframeMarker
เพิ่มเติมเกี่ยวกับกุญแจเฟรม
Keyframe ชื่อไม่จำเป็นต้องเป็นเอกลักษณ์ตัวอย่างเช่นหากแอนิเมชั่นมีชุดกรอบสำคัญสามชุดที่ชื่อว่า "อนุภาค" การเหตุการณ์ที่เชื่อมต่อโดย AnimationTrack:GetMarkerReachedSignal() จะยิงในแต่ละครั้งที่ชุดกรอบสำคัญหนึ่งในนั้นถูกถึง
Keyframe ชื่อสามารถตั้งค่าได้ใน Roblox Animation Editor แอนิเมชันScript ในแอนิเมชั่นที่มีอยู่ก่อนที่จะเล่น
ดูเพิ่ม:
ส่งค่ากลับ
คอลเลกชันที่มีทั้งหมด KeyframeMarkers ที่ถูกเพิ่มลงใน Keyframe
ตัวอย่างโค้ด
This example demonstrates the Keyframe:AddMarker() and Keyframe:GetMarkers() functions. After adding two markers, marker1 and marker2 to the keyframe, this example gets and prints the names of the added markers.
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) --marker.Parent = keyframe
keyframe:AddMarker(marker2) --marker.Parent = keyframe
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 ชื่อไม่จำเป็นต้องเป็นเอกลักษณ์ตัวอย่างเช่นหากแอนิเมชั่นมีชุดกรอบสำคัญสามชุดที่ชื่อว่า "อนุภาค" การเหตุการณ์ที่เชื่อมต่อโดย AnimationTrack:GetMarkerReachedSignal() จะยิงในแต่ละครั้งที่ชุดกรอบสำคัญหนึ่งในนั้นถูกถึง
Keyframe ชื่อสามารถตั้งค่าได้ใน Roblox Animation Editor แอนิเมชันScript ในแอนิเมชั่นที่มีอยู่ก่อนที่จะเล่น
ดูเพิ่ม:
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
This example demonstrates the Keyframe:AddMarker() and Keyframe:RemoveMarker() functions. Note these are functionally equivalent to parenting and un-parenting the markers.
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local marker = Instance.new("KeyframeMarker")
marker.Name = "FootStep"
marker.Value = 100
keyframe:AddMarker(marker) --marker.Parent = keyframe
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