Garry's Mod Wiki

Mesh

  IMesh Mesh( IMaterial mat = nil )

Description

Returns a new static mesh object.

Arguments

1 IMaterial mat = nil
The material the mesh is intended to be rendered with. It's merely a hint that tells that mesh what vertex format it should use.

Returns

1 IMesh
The created object.
This function does not work with "WorldVertexTransition" materials, UnlitGeneric works, however VertexLitGeneric suffers shading issues as well.

Example

Draws a triangle near Vector( 0, 0, 0 ) in the map.

local mat = Material( "editor/wireframe" ) -- The material (a wireframe) local obj = Mesh() -- Create the IMesh object local verts = { -- A table of 3 vertices that form a triangle { pos = Vector( 0, 0, 0 ), u = 0, v = 0 }, -- Vertex 1 { pos = Vector( 10, 0, 0 ), u = 1, v = 0 }, -- Vertex 2 { pos = Vector( 10, 10, 0 ), u = 1, v = 1 }, -- Vertex 3 } obj:BuildFromTriangles( verts ) -- Load the vertices into the IMesh object hook.Add( "PostDrawOpaqueRenderables", "IMeshTest", function() render.SetMaterial( mat ) -- Apply the material obj:Draw() -- Draw the mesh end )