GenerationService
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
GenerationService は、開発者が Roblox の Cube 3D ファウンデーションモデル を使用してテキストプロンプトから 3D オブジェクトを生成できるサービスです。
メッシュ生成は 2 ステップのプロセスです:
- GenerateMeshAsync() は、テキストプロンプトとその他の必要なパラメータを使用して、メッシュ生成プロセスを開始します。将来の結果を取得するために使用できるユニークな識別子 (生成 ID) を返します。
現在、GenerationService は次の使用をサポートしています:
- GenerateMeshAsync() は、サーバースクリプトから呼び出されなければなりません。
- LoadGeneratedMeshAsync() は、クライアントスクリプトから呼び出されなければなりません。
結果として、メッシュ生成リクエストがクライアントから発生すると、クライアントは生成を開始するためにサーバーにシグナルを送信する必要があります。サーバーが生成が完了したことを判断したら、適切なクライアントに LoadGeneratedMeshAsync() を呼び出してメッシュを取得するよう通知する必要があります。生成されたメッシュには、EditableMesh コンテンツがロードされているため、クライアントにのみ複製され、他のクライアントには複製されません。
次のコードは、このデザインパターンを示しています。詳しい例は、このデモエクスペリエンス を参照してください。クリックする ⋯ ボタンと Studio で編集 。
コードサンプル
This setup includes server-side functionality to handle mesh generation requests from clients.
local GenerationService = game:GetService("GenerationService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Create a RemoteEvent for client-server communication
local generationEvent = Instance.new("RemoteEvent")
generationEvent.Name = "GenerationEvent"
generationEvent.Parent = ReplicatedStorage
-- Create a RemoteEvent to send generation results back to clients
local generationResultEvent = Instance.new("RemoteEvent")
generationResultEvent.Name = "GenerationResultEvent"
generationResultEvent.Parent = ReplicatedStorage
-- Handle mesh generation requests from clients
generationEvent.OnServerEvent:Connect(function(player, prompt)
print("Generating mesh for player", player.Name, "with prompt:", prompt)
-- Generate the mesh on the server
local success, generationId, contextId = pcall(function()
return GenerationService:GenerateMeshAsync(
{ ["Prompt"] = prompt },
player,
{},
function(intermediateType, intermediateGenerationId, intermediateContextId)
-- Send intermediate result to the requesting client
generationResultEvent:FireClient(
player,
intermediateGenerationId,
true -- isIntermediate
)
end
)
end)
if success then
-- Send the final generation ID to the client
generationResultEvent:FireClient(player, generationId, false)
print("Successfully generated mesh with ID:", generationId)
else
generationResultEvent:FireClient(player, nil, false)
warn("Failed to generate mesh:", generationId)
end
end)
The following example adds client-side functionality to request mesh generation from the server and display the results. This code assumes that the two RemoteEvent instances created by the server-side example (GenerationEvent and GenerationResultEvent) exist inside ReplicatedStorage.
local GenerationService = game:GetService("GenerationService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Reference to RemoteEvent instances created in server-side script
local generationEvent = ReplicatedStorage:WaitForChild("GenerationEvent")
local generationResultEvent = ReplicatedStorage:WaitForChild("GenerationResultEvent")
local player = Players.LocalPlayer
-- Store generated meshes
local generatedMeshes = {}
-- Function to request mesh generation
local function requestMeshGeneration(prompt)
print("Requesting mesh generation for prompt:", prompt)
generationEvent:FireServer(prompt)
end
-- Handle generation results from the server
generationResultEvent.OnClientEvent:Connect(function(generationId, isIntermediate)
if not generationId then
warn("Generation failed")
return
end
print(isIntermediate and "Loading intermediate result..." or "Loading final result...")
-- Use generation ID generated on the server to retrieve and load the mesh
local mesh = GenerationService:LoadGeneratedMeshAsync(generationId)
if mesh then
-- Clean up previous mesh if it exists
if generatedMeshes[isIntermediate and "intermediate" or "final"] then
generatedMeshes[isIntermediate and "intermediate" or "final"]:Destroy()
end
mesh.Parent = workspace
-- Position the mesh in front of the player
local character = player.Character
if character and character:FindFirstChild("HumanoidRootPart") then
local rootPart = character.HumanoidRootPart
mesh:PivotTo(rootPart.CFrame * CFrame.new(0, 0, -10))
end
-- Store the mesh for cleanup
generatedMeshes[isIntermediate and "intermediate" or "final"] = mesh
print(isIntermediate and "Loaded intermediate result" or "Loaded final result")
else
warn("Failed to load mesh")
end
end)
-- Example usage
requestMeshGeneration("toy robot")
概要
方法
- GenerateMeshAsync(inputs : Dictionary,player : Player,options : Dictionary,intermediateResultCallback : function?):Tuple
テキストプロンプトから新しい 3D メッシュの生成を開始し、結果を追跡して回収するために使用されるユニークなIDを返します。生成が完了した後、LoadGeneratedMeshAsync() を使用して生成されたメッシュをロードして表示します。
提供された を使用して生成されたメッシュを取得し、ロードします。メッシュは 内容で返されます。
プロパティ
方法
GenerateMeshAsync
パラメータ
戻り値
コードサンプル
local generationId, contextId = GenerationService:GenerateMeshAsync({ ["Prompt"] = "toaster" }, player, {})
local generationId, contextId = GenerationService:GenerateMeshAsync(
{ ["Prompt"] = prompt },
player,
{},
function(intermediateType, generationId, contextId)
-- Add your logic here
end
)
local success, generationIdOrError, contextId = pcall(function()
return GenerationService:GenerateMeshAsync(
{ ["Prompt"] = "robot toy" },
player,
{},
function(intermediateType, intermediateId, intermediateContextId)
-- Notify client about intermediate result
generationResultEvent:FireClient(player, intermediateId, true)
end
)
end)
-- Handle a specific error code
if generationIdOrError == "Rate limit exceeded" then
-- Wait for the rate limit to reset
elseif success then
-- Send the final generation ID to the client
generationResultEvent:FireClient(player, generationIdOrError, false)
end