В общем вот видео
тык
Нужно что бы плоскость отображения (белый квадрат) ложился ровно между двумя точками при клике на объекте, вот код инструмента.
TOOL.Category = "Koshmarov"
TOOL.Name = "Plane Tool"
TOOL.Command = nil
TOOL.ConfigName = ""
if SERVER then return end
local function DrawPlaneBetweenPoints(point1, point2, ent, hitnormal)
local dff = (point2 - point1)
local normal = hitnormal:Angle() -- dff:Angle() --:Forward()
--local distance = normal:Dot(point1)
--normal:RotateAroundAxis( normal:Up(), 90 )
--normal:RotateAroundAxis( normal:Forward(), 90 )
cam.Start3D2D(ent:LocalToWorld(point1), ent:LocalToWorldAngles(normal), 1)
surface.DrawRect( 0, 0, dff:Length(),10 )
cam.End3D2D()
---render.PushCustomClipPlane(normal, distance)
---render.DrawQuad(point1, point1 + Vector(0, 0, 100), point2 + Vector(0, 0, 100), point2)
---render.PopCustomClipPlane()
end
function TOOL:LeftClick( trace )
if not IsValid(trace.Entity) then return end
local ent = trace.Entity
if not self.point1 then
print("point1 set")
self.point1 = trace.Entity:WorldToLocal(trace.HitPos)
self.hitnormal = trace.HitNormal
else
print("point2 set")
self.point2 = trace.Entity:WorldToLocal(trace.HitPos)
hook.Add("PostDrawOpaqueRenderables", "DrawPlane", function()
--cam.Start3D()
render.SetColorMaterial()
DrawPlaneBetweenPoints(self.point1, self.point2, ent, self.hitnormal)
--cam.End3D()
end)
end
print("tool left click")
return true
end
function TOOL:RightClick( trace )
hook.Remove("PostDrawOpaqueRenderables", "DrawPlane")
self.point1 = nil
self.point2 = nil
self.hitnormal = nil
end
function TOOL.BuildCPanel( panel )
end
Рабочий код
if SERVER then return end
TOOL.Category = "Koshmarov"
TOOL.Name = "Plane Tool"
TOOL.Command = nil
TOOL.ConfigName = ""
language.Add("tool.planetool.name", "Инструмент разметки плоскости")
if SERVER then return end
local
function DrawPlaneBetweenPoints(point1, point2, point3, ent, hitnormal)
cam.Start3D2D(ent:LocalToWorld(point1), ent:LocalToWorldAngles(hitnormal), 1)
surface.SetDrawColor(245, 232, 51)
surface.DrawRect( 0, 0, (point2 - point1):Length(), (point3 - point2):Length() )
cam.End3D2D()
end
function TOOL:LeftClick( trace )
if not IsFirstTimePredicted() then return true end
if not IsValid(trace.Entity) then return end
local ent = trace.Entity
if not self.point1 then
print("point1 set")
self.point1 = trace.Entity:WorldToLocal(trace.HitPos)
self.hitnormalangle = trace.Entity:WorldToLocalAngles(trace.HitNormal:Angle())
self.hitnormalangle:RotateAroundAxis( self.hitnormalangle:Up(), 90 )
self.hitnormalangle:RotateAroundAxis( self.hitnormalangle:Forward(), 90 )
elseif not self.point2 then
print("point2 set")
self.point2 = trace.Entity:WorldToLocal(trace.HitPos)
else
self.point3 = trace.Entity:WorldToLocal(trace.HitPos)
end
print("tool left click")
hook.Add("PostDrawOpaqueRenderables", "DrawPlane", function()
--cam.Start3D()
if not IsValid(ent) then
return hook.Remove("PostDrawOpaqueRenderables", "DrawPlane")
end
render.SetColorMaterial()
DrawPlaneBetweenPoints( self.point1 or Vector(0,0,0),
self.point2 or Vector(0,0,0),
self.point3 or Vector(0,0,0), ent, self.hitnormalangle or Angle(0,0,0))
--cam.End3D()
end)
return true
end
function TOOL:RightClick( trace )
hook.Remove("PostDrawOpaqueRenderables", "DrawPlane")
self.point1 = nil
self.point2 = nil
self.hitnormalangle = nil
end
function TOOL.BuildCPanel( panel )
local Scratch = vgui.Create( "DNumberScratch", panel )
Scratch:SetPos( 50, 50 )
Scratch:SetValue( 5 )
Scratch:SetMin( -20 )
Scratch:SetMax( 20 )
Scratch:Dock(TOP)
end
function TOOL:Think()
end