void DrawSpline(Spline3D spline, Viewport3D viewport) { var splineWorldMatrix = spline.GlobalTransform; var viewportToSceneFrame = viewport.CalcTransitionToSpaceOf(SceneView.Instance.Frame); for (var i = 0; i < spline.Nodes.Count - 1; i++) { var n1 = (SplinePoint3D)spline.Nodes[i]; var n2 = (SplinePoint3D)spline.Nodes[i + 1]; splineApproximation.Clear(); splineApproximation.Add(n1.Position); Approximate(n1.Position, n1.Position + n1.TangentA, n2.Position + n2.TangentB, n2.Position, 0.01f, 0, splineApproximation); splineApproximation.Add(n2.Position); var start = Vector2.Zero; for (var j = 0; j < splineApproximation.Count; j++) { var end = (Vector2)viewport.WorldToViewportPoint(splineApproximation[j] * spline.GlobalTransform) * viewportToSceneFrame; if (j > 0) { SplinePresenter.DrawColoredLine(start, end, Color4.White, Color4.Black); } start = end; } } }
bool HitTestControlPoint(Spline3D spline, Vector3 pointInSplineCoordinates) { var viewport = spline.Viewport; var viewportToScene = viewport.CalcTransitionToSpaceOf(SceneView.Instance.Scene); var screenPoint = (Vector2)viewport.WorldToViewportPoint(pointInSplineCoordinates * spline.GlobalTransform) * viewportToScene; return(SceneView.Instance.HitTestControlPoint(screenPoint)); }
static Plane CalcPlane(Spline3D spline, Vector3 point) { var m = spline.GlobalTransform; var normal = m.TransformNormal(new Vector3(0, 0, 1)).Normalized; var d = -Vector3.DotProduct(m.TransformVector(point), normal); return(new Plane(normal, d)); }
bool HitTestControlPoint(Spline3D spline, Vector3 pointInSplineCoordinates) { var viewport = spline.Viewport; var sv = SceneView.Instance; var viewportToScene = viewport.LocalToWorldTransform; var screenPoint = (Vector2)viewport.WorldToViewportPoint(pointInSplineCoordinates * spline.GlobalTransform) * viewportToScene; return(sv.HitTestControlPoint(screenPoint)); }
private Spline3D CalculateSpline3D(Func <double, double, double> fxy) { double dx = (XMax - XMin) / N, dy = (YMax - YMin) / N; double x, y, z; var spline3D = new Spline3D(); for (var ix = 0; ix <= N; ix++) { for (var iy = 0; iy <= N; iy++) { x = XMin + ix * dx; y = YMin + iy * dy; z = fxy(x, y); if (!double.IsNaN(z) && !double.IsInfinity(z)) { spline3D.addPoint(new Point3D(x, y, z)); } } } return(spline3D); }
private void AppendLine(Geometry geometry, Line line) { var spline = new Spline3D(line.points); var forward = (spline[1] - spline[0]).normalized; var left = Vector3.Cross(forward, Vector3.up); var point = spline.GetValue(0); geometry.vertices.Add(point + left * line.width / 2); geometry.vertices.Add(point - left * line.width / 2); geometry.normals.Add(Vector3.up); geometry.normals.Add(Vector3.up); geometry.uvs.Add(new Vector2(0, 0)); geometry.uvs.Add(new Vector2(1, 0)); geometry.colors.Add(line.color); geometry.colors.Add(line.color); var previousPoint = point; for (int i = 1; i < line.segments * spline.Length; i++) { var t = i / (float)line.segments; point = spline.GetValue(t); forward = (point - previousPoint).normalized; previousPoint = point; left = Vector3.Cross(forward, Vector3.up); var vertexCount = geometry.vertices.Count; geometry.vertices.Add(point + left * line.width / 2); geometry.vertices.Add(point - left * line.width / 2); geometry.normals.Add(Vector3.up); geometry.normals.Add(Vector3.up); geometry.uvs.Add(new Vector2(0, t)); geometry.uvs.Add(new Vector2(1, t)); geometry.colors.Add(line.color); geometry.colors.Add(line.color); geometry.triangles.Add(vertexCount + 0); geometry.triangles.Add(vertexCount + 1); geometry.triangles.Add(vertexCount - 2); geometry.triangles.Add(vertexCount + 1); geometry.triangles.Add(vertexCount - 1); geometry.triangles.Add(vertexCount - 2); } }