GenerationService

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

作成できません
サービス

GenerationService は、開発者が Roblox の Cube 3D ファウンデーションモデル を使用してテキストプロンプトから 3D オブジェクトを生成できるサービスです。

メッシュ生成は 2 ステップのプロセスです:

  1. GenerateMeshAsync() は、テキストプロンプトとその他の必要なパラメータを使用して、メッシュ生成プロセスを開始します。将来の結果を取得するために使用できるユニークな識別子 (生成 ID) を返します。
  2. LoadGeneratedMeshAsync() 生成されたメッシュをエクスペリエンスにロードします。メッシュは MeshPart 内に含まれる EditableMesh として返されます。

現在、GenerationService は次の使用をサポートしています:

  • GenerateMeshAsync() は、サーバースクリプトから呼び出されなければなりません。
  • LoadGeneratedMeshAsync() は、クライアントスクリプトから呼び出されなければなりません。

結果として、メッシュ生成リクエストがクライアントから発生すると、クライアントは生成を開始するためにサーバーにシグナルを送信する必要があります。サーバーが生成が完了したことを判断したら、適切なクライアントに LoadGeneratedMeshAsync() を呼び出してメッシュを取得するよう通知する必要があります。生成されたメッシュには、EditableMesh コンテンツがロードされているため、クライアントにのみ複製され、他のクライアントには複製されません。

次のコードは、このデザインパターンを示しています。詳しい例は、このデモエクスペリエンス を参照してください。クリックする ボタンと Studio で編集

コードサンプル

Adds server-side functionality to handle mesh generation requests from clients.

Server-side mesh generation

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GenerationService = game:GetService("GenerationService")
-- Create a RemoteEvent for client-server communication
local meshGenerationEvent = Instance.new("RemoteEvent")
meshGenerationEvent.Name = "MeshGenerationEvent"
meshGenerationEvent.Parent = ReplicatedStorage
-- Event to send generation results back to clients
local generationResultEvent = Instance.new("RemoteEvent")
generationResultEvent.Name = "GenerationResultEvent"
generationResultEvent.Parent = ReplicatedStorage
-- Handle mesh generation requests from clients
meshGenerationEvent.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
-- Notify the client of failure
generationResultEvent:FireClient(player, nil, false)
warn("Failed to generate mesh:", generationId)
end
end)

Adds client-side functionality to request mesh generation from the server and display the results.

Client-side mesh generation

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GenerationService = game:GetService("GenerationService")
local Players = game:GetService("Players")
-- Connect to the RemoteEvents
local meshGenerationEvent = ReplicatedStorage:WaitForChild("MeshGenerationEvent")
local generationResultEvent = ReplicatedStorage:WaitForChild("GenerationResultEvent")
-- Local player
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)
meshGenerationEvent:FireServer(prompt)
end
-- Handle generation results from the server
generationResultEvent.OnClientEvent:Connect(function(generationId, isIntermediate)
if not generationId then
print("Generation failed")
return
end
print(isIntermediate and "Loading intermediate result..." or "Loading final result...")
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
print("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

イールド

テキストプロンプトから新しい 3D メッシュの生成を開始し、結果を追跡して回収するために使用されるユニークなIDを返します。オプションで、intermediateResultCallback 関数を提供して、テクスチャなしのメッシュなどの中間結果を受け取ることができます。生成が完了した後、LoadGeneratedMeshAsync() を使用して生成されたメッシュをロードして表示します。

レート制限 経験ごとに 5 世代毎分のレート制限があります。この制限を超えると、次の分まで生成リクエストがブロックされます。

エラーコード | エラー | 説明 | 推奨開発者アクション | | ------------------------ | ------------------------------------------------------------------------------------ | | レート制限超え | メッシュ生成の最大数が分に超えられました。| レート制限がリセットされるまで待ちます。 | | モデレーション失敗 | メッシュ生成がモデレーションにマークされました。 | レビューして変更して、Roblox のモデレーションガイドラインに従うようにプロンプトを確認します。| | 内部サーバーエラー | サーバーで予期せぬ問題が発生しました。 | 後でリクエストを再試行するか、問題のサーバーステータスをチェックします。 | | 文字数制限を超えました | この世代リクエストの入力プロンプト長が制限を超えました。| Prompt 辞書の input 文字列の数を減少させる。 |

パラメータ

inputs: Dictionary

メッシュ生成プロンプトを含む辞書。現在、サポートされている唯一のキーは、生成するメッシュを説明する Prompt (文字列) です。

既定値: ""
player: Player

生成をリクエストする Player リクエスト。

既定値: ""
options: Dictionary

追加の生成オプション。現在、オプションはサポートされていません。

既定値: ""
intermediateResultCallback: function

中間生成結果でトリガーされたコールバック関数。テクスチャが適用される前(例えば、テクスチャが適用される前)に早期のメッシュバージョンを取得するのに便利です。

既定値: ""

戻り値

生成 ID とコンテキスト ID のタプル。

  • 生成 ID: GenerateMeshAsync() の各呼び出しに返されるユニークな ID。
  • コンテキスト ID: 現在使用されていません。

コードサンプル

Simple example showing how to use GenerateMeshAsync() to generate a mesh from a prompt.

Basic usage

local generationId, contextId = GenerationService:GenerateMeshAsync({["Prompt"] = "toaster"}, player, {})

Example showing how to use GenerateMeshAsync() with a callback for intermediate results.

Intermediate results callback

local generationId, contextId = GenerationService:GenerateMeshAsync({["Prompt"] = prompt}, player, {}, function(intermediateType, generationId, contextId)
-- Add your logic here
end)

Example showing how to handle errors when generating meshes with GenerateMeshAsync().

Server-side generation with error handling

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

LoadGeneratedMeshAsync

イールド

提供された generationId を使用して、GenerationService:GenerateMeshAsync() によって生成されたメッシュを取得してロードします。メッシュは MeshPart コンテンツで返され、EditableMesh として返されます。編集可能なメッシュがレプリケートされないため、ロードされたメッシュは他のクライアントにレプリケートされず、generationId ごとに 1回のみロードできます。

パラメータ

generationId: string

GenerateMeshAsync() によって返されたユニークID。ロードするメッシュを識別しま読み込む。

既定値: ""

戻り値

生成されたメッシュ、MeshPart に含まれる EditableMesh を返す。

コードサンプル

Example showing how to load a generated mesh using LoadGeneratedMeshAsync().

LoadGeneratedMeshAsync - Load generated mesh

-- Take your generation ID generated on the server and load your generation
local mesh = GenerationService:LoadGeneratedMeshAsync(generationId)
mesh.Parent = workspace

イベント