Garry's Mod Wiki

Revision Difference

mesh_primitives#562874

<title>Mesh Reference - Primitive Types</title> <warning>This page is work in progress</warning> # Mesh Library References These pages seek to provide helpful insight into the usage of the <page>Mesh</page> library and its functions. The pages in this series are: * **Primitive Types** # Terms and Definitions ## What is a Primitive? Definitionally, a Primitive is the simple shapes that any model (or "Mesh") is built from. Practically, a Primitive is a grouping of one or more vertices that the rendering system interprets together in order to draw a simple shape onto the currently active <page text="Render Target">render_rendertargets</page>. As an example, the most common Primitive types are triangles (3 vertices), and quads (4 vertices). ## Vertex Winding When defining a Primitive, the order of its vertices is very important for ensuring it draws as expected. The rendering system does not perform **any** meaningful validation of the Primitive's information and instead simply draws whatever data it is provided. Because of this, it is important to provide vertices in the order that the rendering system is expecting. There are two ways of ordering verticies (Called "Windings"): **Clockwise** and **Counter-Clockwise** (or Anti-Clockwise, if preferred.) *Fun fact: They're called "Windings" because putting lines between vertices is conceptually similar to ***winding*** a rope or wire around a spool!* <upload src="b2b4c/8dc9548bb80c0ee.png" size="176662" name="VertexWindings.png" /> ## Culling To save on unnecessary draw operations, the rendering system only draws Primitives (or "faces") that are facing generally towards the camera. The way that the rendering system determines which faces to draw and which faces not to draw is based on the vertex winding of the face in question. If a face is wound counter-clockwise relative to the camera, it is assumed to be a "**front**" face (which is drawn), and if it is instead wound clockwise relative to the camera, it is considered a "**back**" face (Which is *not* drawn.) This type of culling is often called "**back face culling**" and it is the major reason why vertex order is important when creating Meshes. In rare cases, it may be necessary to temporarily override the normal winding order by using <page>render.CullMode</page> immediately before and after the rendering operation. # Types of Primitive ## Points This type of Primitive (Also called a "Point List") interprets each of the Mesh's vertices as a standalone point in space. When rendered, each of these points appears as a single pixel. <image src="b2b4c/8dcf911b5bddc93.png" size="11319" name="PrimitivePoints.png" /> <warning> The Point Primitive type is currently broken and will not produce any visual effect when rendered. </warning> ## Lines The Lines Primitive type (Also called a "Line List") interprets the Mesh's vertices in pairs of two where each pair of vertices represents the start and end points for a line. Because each line requires a start and end point, the total number of vertices **must** be evenly divisible by 2. <image src="b2b4c/8dcf9113d3ed5fc.png" size="13925" name="PrimitiveLines.png" /> <image src="b2b4c/8dcf915b28645be.png" size="12356" name="PrimitiveLines.png" /> <warning> The Lines Primitive type is currently broken and will not produce any visual effect when rendered. </warning> ## Triangles ## Triangle Strips ## Line Strips ## Line Loops ## Polygons ## Quads