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 |
返回