MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / OnDraw

Method OnDraw

Source/Editor/ViewportDebugDrawData.cs:107–164  ·  view source on GitHub ↗

Called when task calls event. The rendering context.

(ref RenderContext renderContext)

Source from the content-addressed store, hash-verified

105 /// </summary>
106 /// <param name="renderContext">The rendering context.</param>
107 public virtual void OnDraw(ref RenderContext renderContext)
108 {
109 if (_highlightMaterial == null
110 || (_highlights.Count == 0 && _highlightTriangles.Count == 0)
111 || renderContext.View.Pass == DrawPass.Depth
112 )
113 return;
114 Profiler.BeginEvent("ViewportDebugDrawData.OnDraw");
115
116 Matrix world;
117 for (var i = 0; i < _highlights.Count; i++)
118 {
119 HighlightData highlight = _highlights[i];
120 if (highlight.Target is StaticModel staticModel)
121 {
122 var model = staticModel.Model;
123 if (model == null)
124 continue;
125 staticModel.Transform.GetWorld(out world);
126 var bounds = BoundingSphere.FromBox(staticModel.Box);
127
128 // Pick a proper LOD
129 Float3 center = bounds.Center - renderContext.View.Origin;
130 int lodIndex = RenderTools.ComputeModelLOD(model, ref center, (float)bounds.Radius, ref renderContext);
131 var lods = model.LODs;
132 if (lods == null || lods.Length < lodIndex || lodIndex < 0)
133 continue;
134 var lod = lods[lodIndex];
135
136 // Draw meshes
137 for (int meshIndex = 0; meshIndex < lod.Meshes.Length; meshIndex++)
138 {
139 if (lod.Meshes[meshIndex].MaterialSlotIndex == highlight.EntryIndex)
140 {
141 lod.Meshes[meshIndex].Draw(ref renderContext, _highlightMaterial, ref world);
142 }
143 }
144 }
145 }
146
147 if (_highlightTriangles.Count > 0)
148 {
149 var mesh = _highlightTrianglesModel.LODs[0].Meshes[0];
150 if (!Utils.ArraysEqual(_highlightTrianglesSet, _highlightTriangles))
151 {
152 _highlightIndicesSet = new int[_highlightTriangles.Count];
153 for (int i = 0; i < _highlightIndicesSet.Length; i++)
154 _highlightIndicesSet[i] = i;
155 _highlightTrianglesSet = _highlightTriangles.ToArray();
156 mesh.UpdateMesh(_highlightTrianglesSet, _highlightIndicesSet);
157 }
158
159 world = Matrix.Identity;
160 mesh.Draw(ref renderContext, _highlightMaterial, ref world);
161 }
162
163 Profiler.EndEvent();
164 }

Callers

nothing calls this directly

Calls 9

ComputeModelLODMethod · 0.80
ArraysEqualMethod · 0.80
BeginEventMethod · 0.45
GetWorldMethod · 0.45
FromBoxMethod · 0.45
DrawMethod · 0.45
ToArrayMethod · 0.45
UpdateMeshMethod · 0.45
EndEventMethod · 0.45

Tested by

no test coverage detected