Garry's Mod Wiki

util.GetModelMeshes

util.GetModelMeshes

  table, table util.GetModelMeshes( string model, number lod = 0, number bodygroupMask = 0 )

Description

Returns a table of visual meshes of given model.

This does not work on brush models (*number models)

See also ENTITY:GetRenderMesh.

Arguments

1 string model
The full path to a model to get the visual meshes of.
2 number lod = 0
3 number bodygroupMask = 0

Returns

1 table
A table of tables with the following format: * string material - The material of the specific mesh * table triangles - A table of Structures/MeshVertexes ready to be fed into IMesh:BuildFromTriangles * table verticies - A table of Structures/MeshVertexes representing all the vertices of the mesh. This table is used internally to generate the "triangles" table.

Each Structures/MeshVertex returned also has an extra table of tables field called "weights" with the following data: * number boneID - The bone this vertex is attached to * number weight - How "strong" this vertex is attached to the bone. A vertex can be attached to multiple bones at once.

2 table
A table of tables containing the model bind pose (where the keys are the bone ID) with the following contents:
* number parent - The ID of the parent bone.
* VMatrix matrix - The bone's bind transform in model (not bone) space.

Example

Simple example usage on a Scripted Entity.

-- The default material to render with in case we for some reason don't have one local myMaterial = Material( "models/wireframe" ) -- models/debug/debugwhite function ENT:CreateMesh() -- Destroy any previous meshes if ( self.Mesh ) then self.Mesh:Destroy() end -- Get a list of all meshes of a model local visualMeshes = util.GetModelMeshes( "models/combine_helicopter/helicopter_bomb01.mdl" ) -- Check if the model even exists if ( !visualMeshes ) then return end -- Select the first mesh local visualMesh = visualMeshes[ 1 ] -- Set the material to draw the mesh with from the model data myMaterial = Material( visualMesh.material ) -- You can apply any changes to visualMesh.trianges table here, distorting the mesh -- or any other changes you can come up with -- Create and build the mesh self.Mesh = Mesh() self.Mesh:BuildFromTriangles( visualMesh.triangles ) end -- A special hook to override the normal mesh for rendering function ENT:GetRenderMesh() -- If the mesh doesn't exist, create it! if ( !self.Mesh ) then return self:CreateMesh() end return { Mesh = self.Mesh, Material = myMaterial } end function ENT:Draw() -- Draw the entity's model normally, this calls GetRenderMesh at some point self:DrawModel() end

Special Pages


Wikis

?

Render Time: 73ms

DB GetPage 30
Generate Html 15
SaveChanges (1) 20
Render Body 0
Render Sidebar 6