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

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

8 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

15 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.

11 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

21 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 !

15 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.

22 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.

22 Likes

As a Roblox developer, it is currently too hard to efficiently create complex shapes without creating unnecessary triangles. For example, if I want to create a curved surface made up of lots of triangles, (which are in turn made up of wedges), and I need 240 triangles to make up a complex path segment, I need 480 wedges. Each wedge is made up of 10 triangles, and that means there will be 4800 triangles, which is 20x more triangles than if I could just define them via a script!

Example:

If Roblox is able to address this issue, it would improve my development experience because I could procedurally create custom meshes and shapes which are performant and good looking, when compared to using base parts.

Alongside this, for each triangle, materials and other maps (normals, depth, colour) could be applied too.
I cannot create these meshes in dedicated applications such as blender, as I need to create them procedurally, which I can’t do beforehand.

I was thinking it could be something like what unity does.

This would open a whole new world of opportunities, and allow Roblox to seriously compete in graphical fidelity against other engines.

19 Likes

I believe this was asked about during last year’s RDC or RDC2020. I remember it being rejected due to the fact that free programs like Blender exist and reinventing the wheel wouldn’t be too logical on Roblox’s side.

3 Likes

Blender is useful for when you already know what shape something is going to be and you can pre-render it into a mesh, but if you’re making something procedural the whole point is you don’t know what shape something is going to be and therefore you can’t make it before hand which is other applications like blender are completely useless in situations like this. Not to mention being forced to use other programs like blender divides up workflow and makes it slower to make stuff.

They wouldn’t be reinventing the wheel, they would just be making the wheel. There’s no invention. It’s been done so many times by so many people, they’re not inventing anything, they’re just creating a new feature that already exists elsewhere.
It’s silly to reject such a good feature that would without a doubt improve the platform several fold.

17 Likes

Bump, we already have mesh deformation, this would couple perfectly and bring the engine up to standard.

7 Likes

If this was implemented then it could give my procedural terrain system a huge performance boost.
image

13 Likes

This has also become necessary for me, I’ve created a pumpkin carving system for Halloween;


Currently this uses an extremely high-resolution skinned mesh with a ton of bones.

Were we to have proper custom mesh support, I would be able to dynamically generate these with the bare minimum of optimization and being able to implement mesh density. I also currently have the limitation that I can’t actually make a hollow pumpkin without absolutely murdering the engine, having a layer behind the carve is a necessary feature. Generally this would’ve been mounds easier and higher quality on any engine; Roblox has no method of allowing me to do this correctly.

9 Likes

bumping this again as I feel like a Mesh Generation API would allow for more immersive and procedural experiences to be created on the platform.

11 Likes

Mesh API and Shader API would be the most useful thing Roblox could add right now

8 Likes

There seems to be a new Instance called DynamicMesh.


So I used it to create a marching cubes terrain system. Source code here


It’s still a little rough around the edges (which is to be expected since this is still, tmk, a WIP feature). In its current form it has visual glitches, no collision mesh, and creating a dynamic mesh requires 2 instances to be created (DynamicMesh and MeshPart - which is not ideal). All in all this feature is very exciting for Roblox and I can’t wait to see how it evolves and improves.

18 Likes

How Would You Get The Dynamic Mesh Feature?

2 Likes

Use the Roblox Studio Mod Manager to set your build channel to “zIntegration”. Then, with the same program, set the FFlag “SimEnableDynamicMesh” to true. Its not officially released yet, so there are several bugs.

6 Likes