• Model vertices
    8 replies, posted
So Is there a way to get model's vertex points? If so, is there a way to check which of those are currently visible?
I would be very interested in hearing a solution to this aswell as there is very little documentation on such topics as this one.
Nobody? :/
I am wondering this, too... There is a function called [lua]IMesh:BuildFromTriangles( table vertexes )[/lua] which seems allowing rendering through vertex. The vertices table is on: [url]http://wiki.garrysmod.com/page/Structures/MeshVertex[/url] However, still no example that how to organize this table... Also, how to access model_view matrix is not sure...
Here's a bit of code that will draw a wireframe around an entity using meshes sent from the server, hope it helps. [lua] local mdraw = {}; mdraw.cache = {}; function mdraw.RequestMesh( ent ) net.Start( "WireframeRequestMesh" ); net.WriteEntity( ent ); net.SendToServer(); end function mdraw.ReceivedMesh( len ) local ent = net.ReadEntity(); local _mesh = net.ReadTable(); mdraw.cache[ ent:GetModel() ] = _mesh; end net.Receive( "WireframeCMesh", mdraw.ReceivedMesh ); function mdraw.Draw() local ent = LocalPlayer():GetEyeTrace().Entity; if ( ent and IsValid( ent ) ) then if ( mdraw.cache[ ent:GetModel() ] ) then cam.Start3D2D( ent:GetPos(), ent:GetAngles(), 1 ) cam.IgnoreZ( true ); local lastPos; for _, data in pairs( mdraw.cache[ ent:GetModel() ] ) do local pos = data.pos; if ( lastPos ) then render.DrawLine( pos, lastPos, Color( 255, 0, 0, 255 ), true ); end lastPos = pos; end cam.IgnoreZ( false ); cam.End3D2D(); else mdraw.RequestMesh( ent ); mdraw.cache[ ent:GetModel() ] = {}; end end end hook.Add( "PostDrawOpaqueRenderables", "MeshDraw", mdraw.Draw ); [/lua] Server : [lua] util.AddNetworkString( "WireframeRequestMesh" ); util.AddNetworkString( "WireframeCMesh" ); net.Receive( "WireframeRequestMesh", function( len, ply ) local ent = net.ReadEntity(); MsgN( "Sending mesh for " .. tostring( ent ) .. " to " .. ply:GetName() ); if ( ent && IsValid( ent ) ) then local phys = ent:GetPhysicsObject(); if ( phys && IsValid( phys ) ) then timer.Simple( 0.1, function() net.Start( "WireframeCMesh" ); net.WriteEntity( ent ); net.WriteTable( phys:GetMesh() ); net.Send( ply ); end); end end end); [/lua] Here's what the code looks like in action : [url]http://youtu.be/MAO5RXKQ5oU[/url]
If I'm not mistaken, get mesh only returns the physics collision model verts as appose to all the vertexes for the model. I've asked around for this a while back, but no one seemed to have a clue how to do this. My answer, though it's hacky, was to decompile the model to a smd and then table the verts.
I saw the face poser of GMod. How is that implemented? I guess that program actually changes the rendering mesh. Also, anyone has a trial on [lua]IMesh:BuildFromTriangles(table vertex)[/lua]? It is server side only, and will it actually change the rendering mesh?
The table structure can be found [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexaddf.html]here[/url] If you need a sample code to understand how to use it ( like I usually do ), I think you can find it on the old wiki. Hope this helps.
Thanks! I do find one on [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index0a87.html[/url] Try it tomorrow and see if it will work!
Sorry, you need to Log In to post a reply to this thread.