GenerationService
无法创建
服务

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处。


摘要

方法
GenerateMeshAsync(inputs: Dictionary,player: Player,options: Dictionary,intermediateResultCallback: function?):Tuple
已弃用
GenerateModelAsync(inputs: GenerateModelInputs,schema: GenerateModelSchema,options: Dictionary?):Tuple
SegmentMeshAsync(meshPart: MeshPart,schema: GenerateModelSchema,options: Dictionary?):Tuple
继承成员

API 参考
方法
GenerateMeshAsync
已弃用

GenerateModelAsync
暂停
功能: DynamicGeneration
GenerationService:GenerateModelAsync(
inputs:GenerateModelInputs, schema:GenerateModelSchema, options:Dictionary?
参数
inputs:GenerateModelInputs
schema:GenerateModelSchema
options:Dictionary?
返回
代码示例
基本汽车底盘的生成
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
end

LoadGeneratedMeshAsync
暂停
功能: DynamicGeneration
GenerationService:LoadGeneratedMeshAsync(generationId:string):MeshPart
参数
generationId:string
返回

SegmentMeshAsync
暂停
功能: DynamicGeneration
GenerationService:SegmentMeshAsync(
meshPart:MeshPart, schema:GenerateModelSchema, options:Dictionary?
参数
meshPart:MeshPart
schema:GenerateModelSchema
options:Dictionary?
返回

©2026 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。