@@ -177,7 +177,24 @@ public static void Render3DLineNoPrep(this WorldView world,
177177 }
178178 }
179179
180- // render the line mesh directly
180+ // When the D3D scene pipeline is active, create a fresh mesh with baked
181+ // world-space vertices and route it through the same pipeline as other
182+ // control geometry (opaque or overlay depending on current depth test state).
183+ if ( GL . Instance is INativeSceneRenderer nativeSceneRenderer
184+ && nativeSceneRenderer . IsSceneRenderingActive )
185+ {
186+ var lineMesh = CreateTransformedLineMesh ( lineTransform ) ;
187+
188+ if ( startArrow || endArrow )
189+ {
190+ AppendArrowHeads ( lineMesh , start , end , startScale , normal , arrowWidth , arrowLength , startArrow , endArrow ) ;
191+ }
192+
193+ RenderHelper . Render ( lineMesh , color , Matrix4X4 . Identity , RenderTypes . Shaded , forceCullBackFaces : false ) ;
194+ return ;
195+ }
196+
197+ // GL compat fallback: render the line mesh directly
181198 GL . Color4 ( color . Red0To255 , color . Green0To255 , color . Blue0To255 , color . Alpha0To255 ) ;
182199 GL . Enable ( EnableCap . Blend ) ;
183200
@@ -214,6 +231,78 @@ public static void Render3DLineNoPrep(this WorldView world,
214231 }
215232 }
216233
234+ /// <summary>
235+ /// Creates a fresh mesh from scaledLineMesh with vertices pre-transformed by lineTransform.
236+ /// Each line needs its own mesh because scaledLineMesh is shared and modified per-call.
237+ /// </summary>
238+ private static Mesh CreateTransformedLineMesh ( Matrix4X4 lineTransform )
239+ {
240+ var mesh = new Mesh ( ) ;
241+ for ( int i = 0 ; i < scaledLineMesh . Vertices . Count ; i ++ )
242+ {
243+ var pos = Vector3Ex . Transform ( new Vector3 ( scaledLineMesh . Vertices [ i ] ) , lineTransform ) ;
244+ mesh . Vertices . Add ( new Vector3Float ( pos ) ) ;
245+ }
246+
247+ for ( int faceIndex = 0 ; faceIndex < scaledLineMesh . Faces . Count ; faceIndex ++ )
248+ {
249+ mesh . Faces . Add ( scaledLineMesh . Faces [ faceIndex ] ) ;
250+ }
251+
252+ mesh . CalculateNormals ( ) ;
253+ return mesh ;
254+ }
255+
256+ /// <summary>
257+ /// Appends arrow head cone geometry to an existing mesh.
258+ /// </summary>
259+ private static void AppendArrowHeads ( Mesh mesh , Vector3 start , Vector3 end , double startScale , Vector3 normal , double arrowWidth , double arrowLength , bool startArrow , bool endArrow )
260+ {
261+ if ( startArrow )
262+ {
263+ AppendCone ( mesh , start , startScale , - normal , arrowWidth , arrowLength ) ;
264+ }
265+
266+ if ( endArrow )
267+ {
268+ AppendCone ( mesh , end , startScale , normal , arrowWidth , arrowLength ) ;
269+ }
270+ }
271+
272+ private static void AppendCone ( Mesh mesh , Vector3 basePos , double scale , Vector3 normal , double arrowWidth , double arrowLength )
273+ {
274+ var sides = 12 ;
275+ var perpendicular = normal . GetPerpendicular ( ) . GetNormal ( ) ;
276+ var rotation = Matrix4X4 . CreateRotation ( normal , MathHelper . Tau / sides ) ;
277+ var offset = perpendicular * arrowWidth * scale ;
278+ var tipPos = basePos + ( normal * arrowLength * scale ) ;
279+
280+ int baseVertexIndex = mesh . Vertices . Count ;
281+ // Add tip vertex
282+ mesh . Vertices . Add ( new Vector3Float ( tipPos ) ) ;
283+ // Add base center vertex
284+ mesh . Vertices . Add ( new Vector3Float ( basePos ) ) ;
285+
286+ // Add ring vertices
287+ for ( int side = 0 ; side <= sides ; side ++ )
288+ {
289+ mesh . Vertices . Add ( new Vector3Float ( basePos + offset ) ) ;
290+ offset = offset . Transform ( rotation ) ;
291+ }
292+
293+ int tipIndex = baseVertexIndex ;
294+ int baseCenterIndex = baseVertexIndex + 1 ;
295+ int ringStart = baseVertexIndex + 2 ;
296+
297+ for ( int side = 0 ; side < sides ; side ++ )
298+ {
299+ // Side triangle (tip to ring edge)
300+ mesh . Faces . Add ( ringStart + side , tipIndex , ringStart + side + 1 , mesh . Vertices ) ;
301+ // Base triangle (center to ring edge)
302+ mesh . Faces . Add ( baseCenterIndex , ringStart + side , ringStart + side + 1 , mesh . Vertices ) ;
303+ }
304+ }
305+
217306 private static void RenderHead ( Vector3 basePos , double startScale , Vector3 normal , double arrowWidth , double arrowLength , bool invert )
218307 {
219308 if ( invert )
0 commit comments