概要
方法
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 = "基本龙形车生成"
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 = "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, 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 = "ImageConditionedGeneration"
model.Parent = Workspace
end