概要
方法
GenerateMeshAsync(inputs: Dictionary,player: Player,options: Dictionary,intermediateResultCallback: function?):Tuple |
GenerateModelAsync(inputs: Dictionary,schema: Dictionary,options: Dictionary?):Tuple |
LoadGeneratedMeshAsync(generationId: string):MeshPart |
API 參考
方法
GenerateMeshAsync
GenerateModelAsync
GenerationService:GenerateModelAsync(
參數
返回
範例程式碼
基本汽車底盤的生成
local GenerationService = game:GetService("GenerationService")
local Workspace = game:GetService("Workspace")
-- 設定生成幾何圖形的輸入
local inputs = {
TextPrompt = "一輛有4個輪子的綠色龍車"
}
-- 將模型架構設置為預定義的五模型汽車底盤
local schema = {
PredefinedSchema = "Car5"
}
-- 呼叫生成模型
local success, model, metadata = 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, metadata = 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
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, metadata = 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
end