Mesh.BuildFromTriangles

From GMod Wiki

Jump to: navigation, search
Function
Syntax Mesh.BuildFromTriangles( Table of Mesh Vertexes vertexes )
Description:
Builds the mesh from a table.
Returns: nil
In Object: IMesh
Realm: NewerClient.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Mesh.BuildFromTriangles]Mesh.BuildFromTriangles [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionDraws a mesh box out of 2 triangles next to your entity
Used onNewerClient.png
Code
function ENT:Initialize()
	self.mesh = NewMesh();
	local meshexample = {}
	--top left triangle 
	meshexample[1] = { pos = Vector(-1, -1,-1), normal = Vector(0,-2,2), u=0, v=0  }
	meshexample[2] = { pos = Vector(-1, -1, 1),normal = Vector(0,-2,2), u=0, v=1  }
	meshexample[3] = { pos = Vector( 1,-1 , 1), normal = Vector(0,-2,2), u=1, v=1  }
	--bottom right triangle , we change the normal so you can see the 2 triangles better 
	meshexample[4] = { pos = Vector(-1, -1, -1 ),normal = Vector(0,-2,0), u=0, v=0  }
	meshexample[5] = { pos = Vector( 1,-1,1), normal = Vector(0,-2,0), u=1, v=1  }
	meshexample[6] = { pos = Vector(1,-1,-1), normal = Vector(0,-2,0),  u=1, v=0  }
	-- normal is where the light source is located, think of this as positioning the sun
	-- u is the horizontal texture cord , v is the vertical, they are floats
	-- u = 0 , v = 0 would be the bottom left of the texture , 0,1 is top left
	self.mesh:BuildFromTriangles(meshexample);
end
function ENT:Draw()
	self:DrawModel();
	local scale = 50;
 
	mat = Matrix();
	mat:Translate( self:GetPos() );
	mat:Rotate(Angle(0,0,-45));
	mat:Scale( Vector( 1, 1, 1 ) * scale );
 
 
	render.SetMaterial( Material("models/props_wasteland/wood_fence01a") );
	cam.PushModelMatrix ( mat );
		self.mesh:Draw();
	cam.PopModelMatrix();
end
OutputN/A


Additional Notes

Kdict.pngThis page needs reviewing. An expert needs to verify that all of the information in this page is correct.
See more articles for review here.

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox