• draw.RoundedBox on viewmodel
    7 replies, posted
So I got this weapon and I want to draw a RoundedBox on it the best way possible. I was thinking of doing it clientside and serverside(WorldModel) and I wanted to know what best hooks would be good do it, and how exactly can I draw on a weapon viewmodel.
It's simple, you can't really draw on a view model.
[QUOTE=Robotboy655;45297893]It's simple, you can't really draw on a view model.[/QUOTE] I'm not sure you are right here. I mean I want to draw text and roundedboxes on a view model like the Toolgun got this text on top of it.
[QUOTE=KokoNum;45297911]I'm not sure you are right here. I mean I want to draw text and roundedboxes on a view model like the Toolgun got this text on top of it.[/QUOTE] Tool gun models use a special texture that a lua script is modifying using render targets, source code is here: [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/cl_viewscreen.lua[/url]
[QUOTE=Robotboy655;45297927]Tool gun models use a special texture that a lua script is modifying using render targets, source code is here: [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/cl_viewscreen.lua[/url][/QUOTE] Thanks that explains why I had such a hard time doing what I wanted. Thanks anyway.
You can also create a 3D2D camera in ViewModelDrawn, position and rotate it based on a bone or attachment of the viewmodel, and draw your text inside that.
[QUOTE=Kogitsune;45301377]You can also create a 3D2D camera in ViewModelDrawn, position and rotate it based on a bone or attachment of the viewmodel, and draw your text inside that.[/QUOTE] Mind giving me an example? I tried using the muzzle attachment, thing is it moves a lot and I want something stable a draw box that looks like its printed on the gun (like a sticker in cs go)
There isn't much you can do about that - you can either pick a different attachment if the gun has another, or you can try working off a bone on the view model. For example, with this: [img]http://puu.sh/4b2KB.gif[/img] Is translated and rotated from the "Python" bone on the revolver. The important part is that the positioning is going to be different for every model and not all models have the same bones or attachments. The code won't make a lot of sense since it uses helper functions, but it is how I go about doing 3D2D stuff on a view model. [code]pos, ang = GetBonePosition( vm, "Python" ) BoxTranslate( pos, ang, 180, -45, 0, 3, 0, -5 ) Render( self.Projector, .04, pos, ang ) BoxRotate( ang, 180, 180, 0 ) BoxOffset( pos, ang, .7, -1.25, 1 ) newr = 255 * ( 6 - self:Clip1( ) ) / 6 newg = 255 * self:Clip1( ) / 6 self.TextColor.r = math.Approach( self.TextColor.r, newr, FrameTime( ) * 255 ) self.TextColor.g = math.Approach( self.TextColor.g, newg, FrameTime( ) * 255 ) surface.SetFont( "Blackfire_back" ) r, n = surface.GetTextSize( self:Clip1( ) ) cam.Start3D2D( pos, ang, .018 ) render.PushFilterMin( TEXFILTER.ANISOTROPIC ) render.PushFilterMag( TEXFILTER.ANISOTROPIC ) draw.DrawText( self:Clip1( ), "Blackfire_back", -r / 3, 0, self.TextColor, TEXT_ALIGN_CENTER ) draw.DrawText( self:Clip1( ), "Blackfire_front", -r / 3, 0, color_white, TEXT_ALIGN_CENTER ) if self:Clip1( ) < 3 or self:GetReloading( ) then s = "Hold " .. ( input.LookupBinding( "+reload" ) or "[unbound]" ):upper( ) .. " to " .. ( self:GetReloading( ) and "continue " or "" ) .. "reload" .. ( self:GetReloading( ) and "ing " or "" ) draw.DrawText( s, "Blackfire_back2", 0, n + 2, self.TextColor, TEXT_ALIGN_RIGHT ) draw.DrawText( s, "Blackfire_front2", 0, n + 2, color_white, TEXT_ALIGN_RIGHT ) end if self:GetCharge( ) > 0 then --Draw charge bar old = self:GetCharge( ) s = string.rep( "<", math.floor( old ) ) .. "~" draw.DrawText( s, "Blackfire_death2", 0, n * .85, self.TextColor, TEXT_ALIGN_RIGHT ) draw.DrawText( s, "Blackfire_death", 0, n * .85, color_white, TEXT_ALIGN_RIGHT ) surface.SetDrawColor( self.TextColor ) end render.PopFilterMin( ) render.PopFilterMag( ) cam.End3D2D( )[/code] The important parts: vm refers to the viewmodel GetBonePosition returns the angle and position of the named bone on the given entity - you would use Entity:GetBonePosition( boneid ), and boneid would be from Entity:LookupBone( name ) BoxRotate just calls RotateAroundAxis for each part of the angle given BoxOffset adjust the position along the angle ( so ang:Up( ) * z, so on ) The bit about BoxTranslate and Render are not relevant. render.PushFilter* forces a specific level of texture filtering before drawing - this improves the clarity of text if you set it to ANISOTROPIC. You need to pop them after rendering by calling the appropriate PopFilter function. The third argument to cam.Start3D2D is the scale - you get better quality if you draw something really big in a camera with a small scale rather than something small in a large scale - down-scaling will nearly always give you better quality. The rest of it is fairly straightforward text drawing.
Sorry, you need to Log In to post a reply to this thread.