GenerationService

Hiển Thị Bản Đã Lỗi Thời

*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.

Không Thể Tạo
Dịch Vụ

GenerationService là một dịch vụ cho phép các nhà phát triển tạo các đối tượng 3D từ lời nhắc văn bản bằng cách sử dụng mô hình cơ sở 3D Cube 3D của Roblox.

Quá trình tạo lưới là một quá trình hai bước:

  1. GenerateMeshAsync() bắt đầu quá trình tạo lưới bằng cách sử dụng một lời nhắc văn bản và các tham số bắt buộc khác.Nó trả về một nhận dạng duy nhất (ID thế hệ) có thể được sử dụng để lấy lại kết quả trong tương lai.
  2. LoadGeneratedMeshAsync() tải lưới được tạo vào trải nghiệm. Lưới được trả lại như một MeshPart chứa một EditableMesh .

Hiện tại, GenerationService chỉ hỗ trợ sử dụng sau:

Kết kết quảlà, khi yêu cầu tạo lưới xuất phát từ một khách hàng, khách hàng phải gửi một tín hiệu đến máy chủ để khởi động tạo lưới.Khi máy chủ xác định rằng thế hệ đã hoàn thành, nó nên thông báo khách hàng thích hợp để gọi LoadGeneratedMeshAsync() và lấy lại khối lưới.Lưu ý rằng vì mesh được tạo được tải với nội dung EditableMesh và chỉ trên khách hàng, nó không được sao chép cho bất kỳ khách hàng nào khác.

Mã sau đây minh họa mô hình thiết kế này.Xem trải nghiệm thử này để có ví dụ chi tiết hơn.Nhấp vào nút Chỉnh sửa trong Studio .

Mẫu mã

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")

Tóm Tắt

Phương Pháp

Thuộc Tính

Phương Pháp

GenerateMeshAsync

Sinh Lợi

Bắt đầu việc tạo một khối lượng 3D mới từ một thông báo văn bản và trả về các ID duy nhất được sử dụng để theo dõi và lấy lại kết quả.Bạn có thể nhận kết quả giữa tùy chọn, chẳng hạn như lưới không có văn bản, bằng cách cung cấp một chức năng intermediateResultCallback.Sau khi quá trình tạo hoàn tất, sử dụng LoadGeneratedMeshAsync() để tải và hiển thị lưới được tạo.

Giới hạn tỷ lệ Có giới hạn tốc độ 5 thế hệ mỗi phút cho mỗi trải nghiệm.Nếu bạn vượt quá giới hạn này, các yêu cầu tạo tiếp theo bị chặn cho đến phút tiếp theo.

Mã lỗi | Lỗi | Mô tả | Hành động phát triển nhà phát triển được đề xuất | | ------------------------ | ------------------------------------------------------------------------------------ | | Giới hạn tỷ lệ bị vượt quá | Số lượng tế bào tối đa đã bị vượt quá trong phút.| Chờ đến khi giới hạn tỷ lệ được đặt lại. | | Thất bại kiểm duyệt | Sự tạo lưới đã bị đánh dấu để kiểm duyệt.| Xem xét và chỉnh sửa lời nhắc để đảm bảo nó tuân theo các nguyên tắc kiểm duyệt của Roblox.| | Lỗi máy chủ nội bộ | Một vấn đề bất ngờ xảy ra trên máy chủ.| Hãy thử lại yêu cầu sau này hoặc kiểm tra tình trạng máy chủ đối với các vấn đề.| | Giới hạn nhân vật bị vượt quá | Chiều dài lời nhập cho yêu cầu thế hệ này vượt quá giới hạn.| Giảm số lượng ký tự trong Prompt chuỗi của input từ điển. |

Tham Số

inputs: Dictionary

Một từ điển chứa các lời nhắc về tạo khối lưới.Hiện tại, key duy nhất được hỗ trợ là Prompt (chuỗi) mô tả mesh để tạo ra (string).

Giá Trị Mặc Định: ""
player: Player

Yêu cầu Player yêu cầu tạo.

Giá Trị Mặc Định: ""
options: Dictionary

Các lựa chọn thế hệ bổ sung. Hiện tại, không có lựa chọn nào được hỗ trợ.

Giá Trị Mặc Định: ""
intermediateResultCallback: function

Một chức năng trả lại kích hoạt với kết quả tạo trung gian. Hữu ích để lấy lại phiên bản khối lượng sớm (ví dụ: trước khi áp dụng kết cấu).

Giá Trị Mặc Định: ""

Lợi Nhuận

Một tuple của ID thế hệ và ID ngữ cảnh.

  • ID thế hệ: Một ID duy nhất được trả lại cho mỗi lần triệu hồi của GenerateMeshAsync() .
  • ID ngữ cảnh: Hiện không được sử dụng.

Mẫu mã

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

Sinh Lợi

Lấy và tải một khối lượng được tạo bởi GenerationService:GenerateMeshAsync() bằng cách sử dụng generationId được cung cấp.Mesh được trả lại như một MeshPart với nội dung EditableMesh.Bởi vì lưới có thể chỉnh sửa không được sao lưu, lưới được tải không được sao lưu cho bất kỳ khách hàng nào khác và chỉ có thể được tải một lần mỗi generationId .

Tham Số

generationId: string

ID duy nhất được trả về bởi GenerateMeshAsync(). Xác định mesh để tải.

Giá Trị Mặc Định: ""

Lợi Nhuận

Mesh được tạo ra, trả về như một MeshPart chứa một EditableMesh .

Mẫu mã

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

Sự Kiện