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)
75 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.

6 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:

4 Likes

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

12 Likes

It is currently not possible on Roblox to create a mesh from code. This is a feature in many other Game Engines and would be great to be in Roblox Studio too.

An example of how a mesh could be formed from code is:

local vertices = {Vector3.new(0,0,0), Vector3.new(1,0,0), Vector3.new(0,1,0), Vector3.new(1,1,0)}

local triangles = {1, 2, 3, 3, 4, 5}

local mesh = Instance.new("MeshPart", workspace, vertices, triangles)

I’m sure this would benefit many developers. I am currently working on a game with custom terrain, this feature would benefit me because it would allow me to make this terrain up with multiple meshes rather than hundreds or thousands of wedges; this would also cut down the polygon count in my game by 8 times, 1 polygon rather than an 8 polygon wedge.

This could also fit hand in hand with another feature request I’ve seen here for level of detail meshes, where you can upload multiple meshes to a mesh part for different level of details rather than automatically generated lower polygon meshes. Along with this request you could make the meshes for different mesh part level of details from code.

10 Likes

Capture

I want to create custom terrain. Currently I need to use 4 differently sized wedges to fill a single square cell in the terrain. Obviously this isnt efficient. If Roblox added a few simple classes, this could be made much more efficient

The Vertex class would act similar to a Vector3Object, it should just hold a Vector3 property (and maybe a Color3 property for vertex paint?).

The Triangle and Quad classes should have Vertex0, Vertex1, Vertex2 (and for Quad, Vertex3) properties where you can set the values to a Vertex instance. Triangles and Quads would need to be parented (not directly, should be compatible with folders) to a MeshPart and they would be rendered as part of that MeshPart

18 Likes

Small update on my custom terrain. Currently 96.4% of the time spent updating terrain (160ms of 166ms) is spent calculating and setting the CFrames and sizes of a bunch of wedges. I could make this terrain system so much more efficient if there was a way to build meshes at runtime

@ engineers working on csg, please stop and do this instead !

8 Likes

Procedural Mesh Generation is the act of creating meshes through code. This is heavily used in cases like terrain features where you can efficiently modify meshes at runtime or creating math-based effects. You can also save on memory and increases performance by cutting out geometry the player can’t see and reducing the overhead of instance counts as each procedural mesh would be a singular instance. The last two points is what can give it an immense benefit over just using parts and especially having to deal with intersection clipping.

I would say NSFW content would be a concern with this, but given we have free reign over parts, I don’t expect anybody to really abuse it more than what you can do with parts.

15 Likes

Please follow the format in How to post a Feature Request

Be as specific as possible, give your post a clear and descriptive title, and focus on problems and use cases, rather than proposed solutions.

As a Roblox developer, it is currently too hard to create terrain, oceans or related things with high part count and moving objects with minimal lag. I heard somewhere that the terrain system is made up of a couple vertices that are joined together why faces, and that’s how they optimised it very well.

Would be really cool to give developers access to this since not all game themes fit the default terrain and other use cases like animated oceans would be nice as well. Other game engines like Unity and Unreal Engine for example give complete customisation over this.

I found a clip on youtube of someone creating an ocean with perlin noise, it’s really laggy and most games would want roblox compatibility. I feel that the current terrain system isn’t really customisable enough.

If Roblox is able to address this issue, it would improve my development experience because it would open up so many use cases and allow people to create their own terrain, cause minimal lag with these problems, and so many other use cases being able to script meshes.

18 Likes