API to create and modify meshes during runtime

As a Roblox developer, it is currently extremely hard (and unreasonably expensive, performance wise) to generate geometry at runtime. Realtime CSG is very often too expensive or not suited to the task at hand, especially when dealing with primitive objects such as shapes or lines.

Being able to create and modify meshes at runtime would create a lot of possibilities that were previously impossible or hacky to do within performance constraints, such as:

  • A game where you can draw in 2d with vector objects
  • A plugin which creates 2d and 3d primitives with any number of points, size, and other customizable factors
  • Triangle terrain without wedges; reducing the polygon count

While all of these are possible with realtime CSG, they would be unreasonable for actual games thanks to the complexity and speed required. Not to mention that realtime CSG is only available on the server, and is wildly unpredictable when it comes to computational errors and such.

If the Roblox engine had this feature, it would open many possibilities to new and innovative technologies developers can create and use in their games.

Suggested implementation (example)
local Vertex = MeshVertex.new(
	Vector3.new(1, 2, 3), -- Position
	Vector2.new(0.25, 0.05), -- UV location
	Color3.new(1, 1, 1) -- Color
)

local Face = MeshFace.new(
	Vertex, Vertex, Vertex,
	Vector3.new(0, 1, 0) -- Surface normal (could potentially be automatic)
)

local Info = MeshInfo.new({
	Face, Face
})

local Mesh = Instance.new("UserMesh", Part)
Mesh.TextureId = "rbxassetid://000000000"
Mesh:ApplyCustomMesh(Info)
23 Likes

Your normals should be defined per-vertex, not per-face. No one wants ugly flat-shaded models! :stuck_out_tongue: Though there could totally be a method to auto-generate them.

I like the idea, I’m not sure how fast they could make this when dealing with complex meshes on-the-fly, but it would still be quite neat to see.

Though I’m sure roblox would have issues with their lack of an ability to moderate the meshes generated by users; Probably in the same vein of why animations cant be changed after they’re uploaded, and are locked to the user/group who created them.

4 Likes

Great feature request! Orange is right with the normals, they should be on vertices! But yea, even if we had super low limit like ~100 vertices per object, there would be a ton of outcomes with this!! Another viable option could be bones and skin (assigning weights to vertices basically) and we’d have more industry standardized results. Exciting stuff :ok_hand:

1 Like

As a Roblox developer, it is currently impossible to create or modify meshes at runtime

This would allow for things like terrain using marching cubes, water with waves, dynamic destruction of existing meshes, capes, clothing, efficiently shattering glass, procedurally generated trees/animals, ropes, and probably a lot more

For terrain and water, yes smooth terrain exists but developers get very little control (ability to adjust tint color is all we have) over how its looks and is interacted with, which ends up being a deal breaker for any game that wants to have a unique art style

Example of Unity’s api for modifying meshes
https://docs.unity3d.com/ScriptReference/Mesh.html

2 Likes