Generation Service
概要
方法
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 = "一輛有四個輪子的綠色龍車"
}
-- 設定架構為預定義的五模型車底盤
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
-- 命名模型並將其父級設置為工作區
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
-- 命名模型並將其父級設置為工作區
model.Name = "圖像條件生成"
model.Parent = Workspace
endLoad Generated Mesh Async
Segment Mesh Async
Generation Service: Segment Mesh Async(
參數
schema:GenerateModelSchema |
返回