Engine Class
GenerationService
Summary
Methods
GenerateMeshAsync(inputs: Dictionary,player: Player,options: Dictionary,intermediateResultCallback: function?):Tuple |
GenerateModelAsync(inputs: Dictionary,schema: Dictionary,options: Dictionary?):Tuple |
LoadGeneratedMeshAsync(generationId: string):MeshPart |
API Reference
Methods
GenerateMeshAsync
GenerateModelAsync
GenerationService:GenerateModelAsync(
Parameters
Returns
Code Samples
Generation of Basic Car Chassis
local GenerationService = game:GetService("GenerationService")
local Workspace = game:GetService("Workspace")
-- Set up inputs for the generated geometry
local inputs = {
TextPrompt = "a green dragon car with 4 wheels"
}
-- Set schema to the predefined five-model car chassis
local schema = {
PredefinedSchema = "Car5"
}
-- Make the call to generate the model
local success, model, metadata = pcall(function()
return GenerationService:GenerateModelAsync(inputs, schema)
end)
if success then
-- Scale model to target size and position near world center
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))
-- Anchor all parts so that the meshes don't fall apart
for _, descendant in model:GetDescendants() do
if descendant:IsA("BasePart") then
descendant.Anchored = true
end
end
-- Name the model and parent it to workspace
model.Name = "BasicDragonCarGeneration"
model.Parent = Workspace
endGeneration With a Custom Schema
local GenerationService = game:GetService("GenerationService")
local Workspace = game:GetService("Workspace")
-- Describe the object to generate
local inputs = {
TextPrompt = "a wooden cart with four wheels",
}
-- Define a custom multi-part structure instead of using a predefined schema.
-- Each entry in `Groups` names a part the generation should produce.
local schema = {
SchemaDefinition = {
Groups = { "body", "wheel_fl", "wheel_fr", "wheel_rl", "wheel_rr" },
},
}
-- Make the call to generate the model
local success, model, metadata = pcall(function()
return GenerationService:GenerateModelAsync(inputs, schema)
end)
if success then
-- Anchor all parts so that the meshes don't fall apart
for _, descendant in model:GetDescendants() do
if descendant:IsA("BasePart") then
descendant.Anchored = true
end
end
-- Name the model and parent it to workspace
model.Name = "CustomSchemaGeneration"
model.Parent = Workspace
endGeneration Conditioned on an Image
local GenerationService = game:GetService("GenerationService")
local Workspace = game:GetService("Workspace")
-- Reference image used to condition the generation. Replace `0` with the asset
-- ID of your own uploaded image.
local imageAssetId = 0
local inputs = {
Image = Content.fromAssetId(imageAssetId),
TextPrompt = "a low-poly treasure chest",
}
-- Produce a single-mesh output
local schema = {
PredefinedSchema = "Body1",
}
-- Make the call to generate the model
local success, model, metadata = pcall(function()
return GenerationService:GenerateModelAsync(inputs, schema)
end)
if success then
-- Anchor all parts so that the meshes don't fall apart
for _, descendant in model:GetDescendants() do
if descendant:IsA("BasePart") then
descendant.Anchored = true
end
end
-- Name the model and parent it to workspace
model.Name = "ImageConditionedGeneration"
model.Parent = Workspace
end