Mesh

From Garry's Mod
Jump to: navigation, search
 Mesh( )

Contents

Description

Returns a new mesh object.

Arguments

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

IMesh

The created object.

Examples

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 )


Personal tools
Navigation