Unlike the SurfaceTool or ArrayMesh, ImmediateGeometry is an actual node. Being a node makes it quick to add to a scene and get visual output. It uses an OpenGL 1.x-style API like SurfaceTool, but it’s actually designed to create meshes on the fly.
Generating complex geometry (several thousand vertices) with this node is inefficient, even if it’s done only once. Instead, it is designed to generate simple geometry that changes every frame.
Before starting, you should clear the geometry by calling
clear(). This ensures that
you are not building upon the geometry from the previous frame. If you want to keep geometry between frames, do
To begin generating geometry you must call
begin() takes a
PrimitiveType as an argument.
PrimitiveType is an OpenGL concept that instructs the GPU how to arrange the primitive based on the
vertices given whether it is triangles, lines, points, etc. A complete list can be found under
the Mesh class reference page.
Once you have called
begin() you are ready to start adding vertices. You add vertices one at a time.
First you add vertex specific attributes such as normals or UVs using
Then you call
add_vertex() to add a vertex with those attributes. For example:
Only attributes added before the call to
add_vertex() will be included in that vertex.
Finally, once you have added all your vertices call
end() to signal that you have finished generating the mesh.
The example code below draws a single triangle.