Generation Service
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
ข้อมูลสรุป
วิธีการ
GenerateMeshAsync(inputs: Dictionary,player: Player,options: Dictionary,intermediateResultCallback: function?):Tuple |
GenerateModelAsync(inputs: GenerateModelInputs,schema: GenerateModelSchema,options: Dictionary?):Tuple |
LoadGeneratedMeshAsync(generationId: string):MeshPart |
SegmentMeshAsync(meshPart: MeshPart,schema: GenerateModelSchema,options: Dictionary?):Tuple |
เอกสารอ้างอิงเกี่ยวกับ API
วิธีการ
Generate Mesh Async
Generate Model Async
Generation Service: Generate Model Async(
พารามิเตอร์
inputs:GenerateModelInputs |
schema:GenerateModelSchema |
ส่งค่ากลับ
ตัวอย่างโค้ด
การสร้างโครงรถยนต์พื้นฐาน
local GenerationService = game:GetService("GenerationService")
local Workspace = game:GetService("Workspace")
-- ตั้งค่าข้อมูลนำเข้าสำหรับเรขาคณิตที่สร้างขึ้น
local inputs = {
TextPrompt = "รถมังกรสีเขียวที่มีล้อ 4 ล้อ"
}
-- ตั้งค่าสคีมาสำหรับโครงรถห้ารุ่นที่กำหนดไว้ล่วงหน้า
local schema = {
PredefinedSchema = "Car5"
}
-- ทำการเรียกเพื่อสร้างโมเดล
local success, model = pcall(function()
return GenerationService:GenerateModelAsync(inputs, schema)
end)
if success then
-- ปรับขนาดโมเดลให้มีขนาดเป้าหมายและวางใกล้ศูนย์กลางของโลก
local targetSize = 16
local modelSize = model:GetExtentsSize()
local scaleFactor = targetSize / math.max(modelSize.X, modelSize.Y, modelSize.Z)
model:ScaleTo(scaleFactor)
model:PivotTo(CFrame.new(15, model:GetExtentsSize().Y / 2, 0))
-- ยึดชิ้นส่วนทั้งหมดเพื่อไม่ให้เมชหลุดออก
for _, descendant in model:GetDescendants() do
if descendant:IsA("BasePart") then
descendant.Anchored = true
end
end
-- ตั้งชื่อโมเดลและทำให้เป็นพ่อแม่ในเวิร์กสเปซ
model.Name = "BasicDragonCarGeneration"
model.Parent = Workspace
endการสร้างด้วยสคีมาที่กำหนดเอง
local GenerationService = game:GetService("GenerationService")
local Workspace = game:GetService("Workspace")
-- อธิบายวัตถุที่จะสร้าง
local inputs = {
TextPrompt = "รถเข็นไม้ที่มีล้อสี่ล้อ",
}
-- กำหนดโครงสร้างหลายส่วนที่กำหนดเองแทนการใช้สคีมาที่กำหนดไว้ล่วงหน้า
-- แต่ละรายการใน `Groups` ตั้งชื่อส่วนที่การสร้างควรผลิต
local schema = {
SchemaDefinition = {
Groups = { "body", "wheel_fl", "wheel_fr", "wheel_rl", "wheel_rr" },
},
}
-- ทำการเรียกเพื่อสร้างโมเดล
local success, model = pcall(function()
return GenerationService:GenerateModelAsync(inputs, schema)
end)
if success then
-- ยึดส่วนทั้งหมดเพื่อไม่ให้เมชหลุดออก
for _, descendant in model:GetDescendants() do
if descendant:IsA("BasePart") then
descendant.Anchored = true
end
end
-- ตั้งชื่อโมเดลและทำให้เป็นพ่อแม่ใน workspace
model.Name = "CustomSchemaGeneration"
model.Parent = Workspace
endการสร้างที่มีเงื่อนไขตามภาพ
local GenerationService = game:GetService("GenerationService")
local Workspace = game:GetService("Workspace")
-- อ้างอิงภาพที่ใช้ในการสร้าง. เปลี่ยน `0` เป็น
-- ID ของสินทรัพย์ภาพที่คุณอัปโหลดเอง.
local imageAssetId = 0
local inputs = {
Image = Content.fromAssetId(imageAssetId),
TextPrompt = "กล่องสมบัติแบบโลว์โพลี",
}
-- ผลิตผลลัพธ์แบบเมชเดียว
local schema = {
PredefinedSchema = "Body1",
}
-- ทำการเรียกเพื่อสร้างโมเดล
local success, model = pcall(function()
return GenerationService:GenerateModelAsync(inputs, schema)
end)
if success then
-- ยึดทุกส่วนเพื่อไม่ให้เมชหลุดออก
for _, descendant in model:GetDescendants() do
if descendant:IsA("BasePart") then
descendant.Anchored = true
end
end
-- ตั้งชื่อโมเดลและทำให้เป็นพ่อแม่ใน workspace
model.Name = "การสร้างตามเงื่อนไขภาพ"
model.Parent = Workspace
endLoad Generated Mesh Async
Segment Mesh Async
Generation Service: Segment Mesh Async(
พารามิเตอร์
schema:GenerateModelSchema |
ส่งค่ากลับ