Class ToolRenderContext
Namespace: ValveResourceFormat.Renderer.Editor.ToolRender
Assembly: Renderer.dll
Draws the shapes of the editor the way Hammer's tool render context does: a stack of render modes that say whether shapes are lines or faces, opaque or blended, hidden by the scene or over it, a stack of transforms, and a draw color and line width that the shapes take as they are drawn. What is drawn goes into a ToolGeometry.
public sealed class ToolRenderContextInheritance
object ← ToolRenderContext
Constructors
ToolRenderContext(ToolGeometry)
Initializes a context drawing into some geometry, in the default mode and without a transform.
public ToolRenderContext(ToolGeometry output)Parameters
output ToolGeometry
Where the shapes go.
Properties
Camera
Gets or sets the camera the shapes that face the camera are turned towards.
public Camera? Camera { get; set; }Property Value
ComputeFaceNormals
Gets or sets whether triangles get the normal of their face, which the shaded modes light them by.
public bool ComputeFaceNormals { get; set; }Property Value
bool
DrawColor
Gets or sets the color shapes take when they are not given one.
public Color32 DrawColor { get; set; }Property Value
LayerOverride
Gets or sets the layer shapes are drawn in whatever their mode, or null for the one of their mode.
public ToolRenderLayer? LayerOverride { get; set; }Property Value
LineWidth
Gets or sets the width lines are drawn with, in pixels. At zero they are the thinnest the GPU draws.
public float LineWidth { get; set; }Property Value
float
Output
Gets what is drawn.
public ToolGeometry Output { get; }Property Value
RenderMode
Gets the current render mode.
public ToolRenderMode RenderMode { get; }Property Value
Transform
Gets the transform shapes are drawn with.
public Matrix4x4 Transform { get; }Property Value
Methods
BeginPickObject(ToolPickTargets, int)
Makes the faces and handles drawn until ToolRenderContext.EndPickObject() pickable as one object, as well as drawn unless the mode is ToolRenderMode.PickProxy.
public void BeginPickObject(ToolPickTargets targets, int id)Parameters
targets ToolPickTargets
Where what can be picked goes.
id int
What the object is picked as.
DrawAngleArc(Vector3, Vector3, Vector3, int, Color32, ToolFaceSides)
Draws a filled slice of a circle around a center, from the direction of one point to the direction of another, as far out as the first point.
public void DrawAngleArc(Vector3 center, Vector3 start, Vector3 end, int segments, Color32 color, ToolFaceSides sides)Parameters
center Vector3
The center.
start Vector3
The point the slice starts towards.
end Vector3
The point the slice ends towards.
segments int
How many faces the slice is drawn with.
color Color32
The color.
sides ToolFaceSides
Which sides of the faces are drawn.
DrawArcEx(Vector3, Vector3, Vector3, float, int, float, float, Color32, bool, ToolFaceSides)
Draws an arc from one angle to another around a center, as lines with both ends joined to the center, or as the faces of the slice it bounds.
public void DrawArcEx(Vector3 center, Vector3 axisX, Vector3 axisY, float radius, int segments, float startDegrees, float endDegrees, Color32 color, bool wireframe, ToolFaceSides sides)Parameters
center Vector3
The center.
axisX Vector3
The axis at zero degrees.
axisY Vector3
The axis at ninety degrees.
radius float
The radius, the axes being scaled by it.
segments int
How many lines or faces the arc is drawn with.
startDegrees float
The angle the arc starts at.
endDegrees float
The angle the arc ends at.
color Color32
The color.
wireframe bool
Whether the arc is drawn as lines rather than faces.
sides ToolFaceSides
Which sides of the faces are drawn.
DrawBoxFaceOutlines(Vector3, Vector3)
Draws the outline of each face of a box in the draw color, so every edge is drawn twice.
public void DrawBoxFaceOutlines(Vector3 mins, Vector3 maxs)Parameters
mins Vector3
maxs Vector3
DrawBoxFaces(Vector3, Vector3, Color32)
Draws the six faces of a box in one color, each face lit by the CPU in the flat modes. Leaves the draw color as the last face was drawn in.
public void DrawBoxFaces(Vector3 mins, Vector3 maxs, Color32 color)Parameters
mins Vector3
maxs Vector3
color Color32
DrawCircle(Vector3, Vector3, Vector3, float, int)
Draws a circle in the draw color, through the tip of axisA reversed and on around towards axisB.
public void DrawCircle(Vector3 center, Vector3 axisA, Vector3 axisB, float radius, int segments)Parameters
center Vector3
The center.
axisA Vector3
One axis of the plane of the circle.
axisB Vector3
The other axis of the plane.
radius float
The radius, the axes being scaled by it.
segments int
How many lines the circle is drawn with.
DrawHandle(float, ToolHandleType, Color32, Vector3, bool, bool, bool)
Draws a handle, a marker that keeps its size on the screen, at a point.
public void DrawHandle(float size, ToolHandleType type, Color32 color, Vector3 position, bool noZ, bool border, bool translucent)Parameters
size float
Half its width, in pixels.
type ToolHandleType
Its shape.
color Color32
Its color.
position Vector3
The point.
noZ bool
Whether it is drawn over the scene.
border bool
Whether it is edged in black.
translucent bool
Whether it is drawn after the opaque shapes and keeps the faint parts of its shape.
DrawLine(Vector3, Vector3)
Draws a line in the draw color.
public void DrawLine(Vector3 start, Vector3 end)Parameters
start Vector3
end Vector3
DrawLine(Vector3, Vector3, Color32)
Draws a line in one color.
public void DrawLine(Vector3 start, Vector3 end, Color32 color)Parameters
start Vector3
end Vector3
color Color32
DrawLine(Vector3, Vector3, Color32, Color32)
Draws a line fading from one color to another.
public void DrawLine(Vector3 start, Vector3 end, Color32 startColor, Color32 endColor)Parameters
start Vector3
end Vector3
startColor Color32
endColor Color32
DrawOrientedRect(Vector3, Vector3, Vector3, float, float, float, float, Color32, bool)
Draws a rectangle in the plane of two axes, spanning from one distance to another along each, filled from both sides or as its outline.
public void DrawOrientedRect(Vector3 origin, Vector3 axisA, Vector3 axisB, float minA, float maxA, float minB, float maxB, Color32 color, bool outline)Parameters
origin Vector3
Where the distances are measured from.
axisA Vector3
The first axis.
axisB Vector3
The second axis.
minA float
Where the rectangle starts along the first axis.
maxA float
Where the rectangle ends along the first axis.
minB float
Where the rectangle starts along the second axis.
maxB float
Where the rectangle ends along the second axis.
color Color32
The color.
outline bool
Whether only the edges are drawn.
DrawPolyLine(ReadOnlySpan<Vector3>, bool, Vector3?)
Draws lines through points in the draw color, from the last back to the first when closed.
public void DrawPolyLine(ReadOnlySpan<Vector3> points, bool closed, Vector3? normal = null)Parameters
points ReadOnlySpan<Vector3>
The points.
closed bool
Whether the last point joins the first.
normal Vector3?
The normal the lines carry.
DrawQuad(Vector3, Vector3, Vector3, Vector3, Color32, bool)
Draws a quad as two triangles in one color, from both sides when double sided.
public void DrawQuad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Color32 color, bool doubleSided = false)Parameters
a Vector3
b Vector3
c Vector3
d Vector3
color Color32
doubleSided bool
DrawQuadOutline(Vector3, Vector3, Vector3, Vector3, Color32)
Draws the four edges of a quad in one color.
public void DrawQuadOutline(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Color32 color)Parameters
a Vector3
b Vector3
c Vector3
d Vector3
color Color32
DrawScreenAlignedLine(Vector3, Vector3, float, Color32, bool)
Draws a line as a quad of some width in one color, turned around the line to face the ToolRenderContext.Camera.
public void DrawScreenAlignedLine(Vector3 start, Vector3 end, float width, Color32 color, bool doubleSided = false)Parameters
start Vector3
Where the line starts.
end Vector3
Where the line ends.
width float
The width of the quad.
color Color32
The color.
doubleSided bool
Whether the quad is drawn from both sides.
DrawScreenAlignedRect(Vector3, float, float, Color32)
Draws a square of some size in one color around a point, in the plane of the screen of the ToolRenderContext.Camera.
public void DrawScreenAlignedRect(Vector3 center, float width, float height, Color32 color)Parameters
center Vector3
The center of the square.
width float
How wide the square is.
height float
How high the square is.
color Color32
The color.
DrawSolidBox(Vector3, Vector3, bool)
Draws a box as solid faces in the draw color, each with its own normal, seen from inside too when double sided.
public void DrawSolidBox(Vector3 mins, Vector3 maxs, bool doubleSided = false)Parameters
mins Vector3
maxs Vector3
doubleSided bool
DrawSolidCapsule(Vector3, Vector3, float, int, Color32)
Draws a capsule as faces in one color: a half sphere around each end, the start one first, and a band joining their rims. Every vertex has its normal on the sphere it lies on, which the shaded modes light it by.
public void DrawSolidCapsule(Vector3 start, Vector3 end, float radius, int segments, Color32 color)Parameters
start Vector3
The center of the sphere at one end.
end Vector3
The center of the sphere at the other end.
radius float
The radius.
segments int
How many sides the capsule has around, from 4 to 256. Each half sphere has a quarter as many rings.
color Color32
The color.
DrawSolidCone(Vector3, Vector3, float, int, Color32, Color32, bool, ToolFaceSides)
Draws a cone as faces from a disc around its base to its tip, the base in one color and the tip in another, with the disc itself lit by the CPU when it is capped.
public void DrawSolidCone(Vector3 baseCenter, Vector3 tip, float radius, int segments, Color32 baseColor, Color32 tipColor, bool capped = true, ToolFaceSides sides = ToolFaceSides.Front)Parameters
baseCenter Vector3
The center of the base.
tip Vector3
The tip.
radius float
The radius of the base.
segments int
How many sides the cone has.
baseColor Color32
The color at the base, and of the cap.
tipColor Color32
The color at the tip.
capped bool
Whether the base is closed.
sides ToolFaceSides
Which sides of the faces are drawn.
DrawSolidCylinderPart(Vector3, Vector3, float, int, bool, Color32, bool, ToolFaceSides)
Draws the side of a cylinder as faces, and the end caps when capped. When shaded, each face is lit by the CPU and blends into the next, and each cap is lit as one face; otherwise everything is in the color.
public void DrawSolidCylinderPart(Vector3 start, Vector3 end, float radius, int segments, bool capped, Color32 color, bool shaded, ToolFaceSides sides)Parameters
start Vector3
The center of one end.
end Vector3
The center of the other end.
radius float
The radius.
segments int
How many sides the cylinder has.
capped bool
Whether the ends are closed.
color Color32
The color.
shaded bool
Whether the faces are lit by the CPU.
sides ToolFaceSides
Which sides of the faces are drawn.
DrawSolidRing(Vector3, Vector3, float, float, int, Color32)
Draws a whole ring around a normal, as ToolRenderContext.DrawSolidRingArc(Vector3, Vector3, Vector3, float, float, int, float, float, Color32) does.
public void DrawSolidRing(Vector3 center, Vector3 normal, float radius, float width, int segments, Color32 color)Parameters
center Vector3
The center of the circle.
normal Vector3
The normal of the plane of the circle.
radius float
The radius of the circle.
width float
The width of the band.
segments int
How many quads the band is drawn with, at least three.
color Color32
The color.
DrawSolidRingArc(Vector3, Vector3, Vector3, float, float, int, float, float, Color32)
Draws a ring as a band of some width in one color, between two angles of a circle in the plane of two axes. The band is turned around the circle to face the ToolRenderContext.Camera, so it keeps its width on the screen.
public void DrawSolidRingArc(Vector3 center, Vector3 axisX, Vector3 axisY, float radius, float width, int segments, float startDegrees, float endDegrees, Color32 color)Parameters
center Vector3
The center of the circle.
axisX Vector3
The axis at zero degrees.
axisY Vector3
The axis at ninety degrees.
radius float
The radius of the circle.
width float
The width of the band.
segments int
How many quads the band is drawn with, at least three.
startDegrees float
The angle the band starts at.
endDegrees float
The angle the band ends at, the whole circle when a turn or more from the start.
color Color32
The color.
DrawSolidSphere(Vector3, float, int, int, Color32)
Draws a sphere as faces in one color, as a grid of rows from its +Z pole to its -Z pole.
public void DrawSolidSphere(Vector3 center, float radius, int slices, int stacks, Color32 color)Parameters
center Vector3
The center.
radius float
The radius.
slices int
How many points each row has around, the last one closing it.
stacks int
How many rows there are, the first and last at the poles.
color Color32
The color.
DrawSphereCircles(Vector3, float, int, Color32?)
Draws three circles around a center, in the XY, XZ and YZ planes in that order, in the draw color.
public void DrawSphereCircles(Vector3 center, float radius, int segments, Color32? color = null)Parameters
center Vector3
radius float
segments int
color Color32?
DrawText(string, Vector3, Color32)
Writes text at a point, facing the screen and over everything else.
public void DrawText(string text, Vector3 position, Color32 color)Parameters
text string
position Vector3
color Color32
DrawTriangle(Vector3, Vector3, Vector3, Color32)
Draws a triangle in one color.
public void DrawTriangle(Vector3 a, Vector3 b, Vector3 c, Color32 color)Parameters
a Vector3
b Vector3
c Vector3
color Color32
DrawTriangle(Vector3, Vector3, Vector3, Color32, Color32, Color32)
Draws a triangle with a color at each corner.
public void DrawTriangle(Vector3 a, Vector3 b, Vector3 c, Color32 colorA, Color32 colorB, Color32 colorC)Parameters
a Vector3
b Vector3
c Vector3
colorA Color32
colorB Color32
colorC Color32
DrawWireBox(Vector3, Vector3)
Draws the twelve edges of a box in the draw color: the bottom, the top, then the sides.
public void DrawWireBox(Vector3 mins, Vector3 maxs)Parameters
mins Vector3
maxs Vector3
DrawWireSphere(Vector3, float, int, int, float, float, Color32?)
Draws the part of a sphere around Z between two angles from its +Z pole as a grid of lines: along the meridians between rows, and along each row but the last.
public void DrawWireSphere(Vector3 center, float radius, int slices, int stacks, float thetaStart, float thetaEnd, Color32? color = null)Parameters
center Vector3
The center.
radius float
The radius.
slices int
How many meridians.
stacks int
How many rows, the first at thetaStart and the last at thetaEnd.
thetaStart float
Angle of the first row from +Z, in radians.
thetaEnd float
Angle of the last row from +Z, in radians.
color Color32?
The color, or the draw color.
DrawWireSphere(Vector3, float, int, int, Color32?)
Draws a whole sphere as a grid of lines.
public void DrawWireSphere(Vector3 center, float radius, int slices, int stacks, Color32? color = null)Parameters
center Vector3
radius float
slices int
stacks int
color Color32?
EndPickObject()
Stops making what is drawn pickable.
public void EndPickObject()PopRenderMode()
Goes back to the mode before the last ToolRenderContext.PushRenderMode(ToolRenderMode).
public void PopRenderMode()PopTransform()
Goes back to the transform before the last push.
public void PopTransform()PushAbsoluteTransform(in Matrix4x4)
Draws in a space placed in the world, whatever the current one, until ToolRenderContext.PopTransform().
public void PushAbsoluteTransform(in Matrix4x4 transform)Parameters
transform Matrix4x4
Where the space is.
PushRenderMode(ToolRenderMode)
Draws in another mode until ToolRenderContext.PopRenderMode().
public void PushRenderMode(ToolRenderMode mode)Parameters
mode ToolRenderMode
The mode, or ToolRenderMode.Current to repeat the current one.
PushTransform(in Matrix4x4)
Draws in a space placed in the current one until ToolRenderContext.PopTransform().
public void PushTransform(in Matrix4x4 transform)Parameters
transform Matrix4x4
Where the space is, in the current one.

