class
Eagle::Mesh
- Eagle::Mesh
- Reference
- Object
Overview
3D geometry: vertices with positions, normals, texture coordinates and colors, plus triangle indices.
Use the built-in primitives (.cube, .sphere, .plane, .cylinder, .capsule, .torus and
more), load an OBJ file, or build your own vertex by vertex. Show a mesh with a
MeshInstance3D.
floor = Mesh.plane(20, 20, uv_scale: 10)
rock = Mesh.sphere(1, segments: 8, rings: 6).flat_shaded # low-poly look
ship = Mesh.load("res://models/ship.obj")
tri = Mesh.new("triangle")
a = tri.add_vertex(v3(0, 1, 0), c: Color::RED)
b = tri.add_vertex(v3(-1, 0, 0), c: Color::GREEN)
c = tri.add_vertex(v3(1, 0, 0), c: Color::BLUE)
tri.add_triangle(a, b, c)
tri.compute_normals
Meshes upload to the GPU on first draw, and again after you change them.
Defined in:
eagle/graphics3d/mesh.crConstructors
-
.axes(length : Number = 1) : Mesh
Red, green and blue lines along X, Y and Z, for orientation while debugging.
-
.box(w : Number, h : Number, d : Number, color : Color = Color::WHITE) : Mesh
A box of w by h by d.
-
.capsule(radius : Number = 0.5, height : Number = 1, segments : Int32 = 16, color : Color = Color::WHITE) : Mesh
A capsule: a cylinder with rounded ends, the usual character shape.
-
.cone(radius : Number = 0.5, height : Number = 1, segments : Int32 = 24, color : Color = Color::WHITE) : Mesh
A cone pointing up.
-
.cube(size : Number = 1, color : Color = Color::WHITE) : Mesh
A cube with sides of size.
-
.cylinder(radius : Number = 0.5, height : Number = 1, segments : Int32 = 24, color : Color = Color::WHITE, top_radius : Number | Nil = nil) : Mesh
A capped cylinder.
-
.decode(text : String, hint : String = "") : Mesh
Parses OBJ text into a mesh.
-
.grid(size : Number = 10, divisions : Int32 = 10, color : Color = Color.gray(0.4)) : Mesh
A line grid on the ground, drawn as lines.
-
.load(path : String) : Mesh
Loads an OBJ file through the asset cache.
-
.new(name : String = "mesh")
Creates an empty mesh.
-
.plane(w : Number = 1, d : Number = 1, subdivisions : Int32 = 1, color : Color = Color::WHITE, uv_scale : Number = 1) : Mesh
A flat rectangle on the ground (the XZ plane), facing up.
-
.quad(w : Number = 1, h : Number = 1, color : Color = Color::WHITE) : Mesh
--- primitives ---------------------------------------------------------- A flat rectangle in the XY plane, facing +Z.
-
.sphere(radius : Number = 0.5, segments : Int32 = 24, rings : Int32 = 16, color : Color = Color::WHITE) : Mesh
A UV sphere.
-
.torus(radius : Number = 1, tube : Number = 0.3, segments : Int32 = 32, rings : Int32 = 16, color : Color = Color::WHITE) : Mesh
A torus (donut).
Instance Method Summary
-
#add_quad(a : UInt32, b : UInt32, c : UInt32, d : UInt32) : Nil
Adds a quad as two triangles.
-
#add_triangle(a : UInt32, b : UInt32, c : UInt32) : Nil
Adds a triangle from three vertex indices, counter-clockwise when seen from the front.
-
#add_vertex(p : Vec3, n : Vec3 = Vec3::UP, uv : Vec2 = Vec2::ZERO, c : Color = Color::WHITE) : UInt32
Adds a vertex and returns its index.
-
#append(other : Mesh, mat : Mat4 | Nil = nil) : self
Appends another mesh's geometry, optionally transformed, to merge static props into one draw call.
-
#bounds : AABB
The bounding box of every vertex.
-
#clear : Nil
Removes all geometry.
-
#color!(c : Color) : self
Sets every vertex color.
-
#colors : Array(Eagle::Color)
Vertex colors, multiplied with the material.
-
#compute_normals : self
Recomputes smooth normals from the triangles.
-
#dispose : Nil
Frees the GPU buffers.
-
#draw : Nil
Draws the mesh with whatever shader is bound.
-
#flat_shaded : Mesh
A copy with separate vertices per face, so each triangle is lit flat.
-
#indices : Array(UInt32)
Triangle indices, three per triangle.
-
#name : String
A label for debugging.
-
#normals : Array(Eagle::Vec3)
Vertex normals, used for lighting.
-
#positions : Array(Eagle::Vec3)
Vertex positions.
-
#primitive : GPU::Primitive
How indices are drawn: triangles, or lines for grids and wireframes.
-
#primitive=(primitive : GPU::Primitive)
How indices are drawn: triangles, or lines for grids and wireframes.
-
#transform!(mat : Mat4) : self
Transforms every vertex in place.
-
#triangle_count : Int32
Number of triangles.
-
#upload : Nil
Sends the geometry to the GPU.
-
#uvs : Array(Eagle::Vec2)
Texture coordinates.
-
#vertex_count : Int32
Number of vertices.
Constructor Detail
Red, green and blue lines along X, Y and Z, for orientation while debugging.
A box of w by h by d.
A capsule: a cylinder with rounded ends, the usual character shape.
A cone pointing up.
A capped cylinder. Set top_radius for a tapered shape.
A line grid on the ground, drawn as lines. Use an unlit material.
A flat rectangle on the ground (the XZ plane), facing up. uv_scale repeats the texture.
--- primitives ---------------------------------------------------------- A flat rectangle in the XY plane, facing +Z.
A UV sphere. More segments and rings make it smoother.
A torus (donut).
Instance Method Detail
Adds a triangle from three vertex indices, counter-clockwise when seen from the front.
Adds a vertex and returns its index.
Appends another mesh's geometry, optionally transformed, to merge static props into one draw call.
Draws the mesh with whatever shader is bound. Normally MeshInstance3D and the renderer do this.
A copy with separate vertices per face, so each triangle is lit flat. Gives a faceted, low-poly look.
How indices are drawn: triangles, or lines for grids and wireframes.
How indices are drawn: triangles, or lines for grids and wireframes.