void RenderItem(Simple3DRenderer renderer, ResultItem item) { if (item.Object != null && item.Object.EnabledInHierarchy) { renderer.AddBounds(item.Object.SpaceBounds.CalculatedBoundingBox); //!!!! //!!!!radius if (item.Position.HasValue) { renderer.AddSphere(new Sphere(item.Position.Value, 0.05), 8); } //getting triangle to draw var triIdx = item.RayTestResult?.TriangleIndexProcessed ?? -1; //var tIdx = item.RayTestResult?.TriangleIndexSource ?? -1; if (triIdx >= 0) { if (item.RayTestResult?.Shape is Component_CollisionShape_Mesh csMesh) { var t = item.Object.Transform.Value.ToMatrix4(); var local = csMesh.TransformRelativeToParent.Value; if (!local.IsIdentity) { t *= local.ToMatrix4(); } if (csMesh.GetTriangleProcessedData(triIdx, true, out var triangle)) { var v1 = triangle.A; var v2 = triangle.B; var v3 = triangle.C; var thickness = Math.Max((v1 - v2).Length(), Math.Max((v2 - v3).Length(), (v3 - v1).Length())) * 0.02; renderer.AddLine(v1, v2, thickness); renderer.AddLine(v2, v3, thickness); renderer.AddLine(v3, v1, thickness); } } else if (item.RayTestResult?.Body is Component_SoftBody softBody) { var t = item.Object.Transform.Value.ToMatrix4(); if (softBody.GetTriangleSimulatedData(triIdx, true, out var triangle)) { var v1 = triangle.A; var v2 = triangle.B; var v3 = triangle.C; var thickness = Math.Max((v1 - v2).Length(), Math.Max((v2 - v3).Length(), (v3 - v1).Length())) * 0.02; renderer.AddLine(v1, v2, thickness); renderer.AddLine(v2, v3, thickness); renderer.AddLine(v3, v1, thickness); } } } } }
//!!!!по сути времнно пока нет корректной толщины public static void AddLineSegmented(Simple3DRenderer renderer, Vector3 start, Vector3 end, int steps = -1) { //draw line segments so that there is no problem with the thickness of the lines var ray = new Ray(start, end - start); int steps2 = steps; if (steps2 < 0) { steps2 = (int)MathEx.Lerp(2, 10, MathEx.Saturate(Math.Pow(ray.Direction.Length() / 100, 1.3))); } for (int n = 0; n < steps2; n++) { var p0 = ray.GetPointOnRay((double)n / steps2); var p1 = ray.GetPointOnRay((double)(n + 1) / steps2); renderer.AddLine(p0, p1); } }
public static void AddBoundsSegmented(Simple3DRenderer renderer, Bounds bounds, int steps = -1) { ref Vector3 bmin = ref bounds.Minimum;