protected override ICADObject OnHover(Vector3 mouse, Camera camera, UnityEngine.Matrix4x4 tf, ref double dist) { var sk = source as SketchFeature; var points = sk.GetSketch().entityList.OfType <PointEntity>(); double min = -1.0; IEntity hover = null; var sktf = tf * sk.GetTransform(); foreach (var p in points) { var e = new RevolvedPointEntity(p, this); double d = e.Hover(mouse, camera, tf); if (d < 0) { continue; } if (d > Sketch.hoverRadius) { continue; } if (min >= 0.0 && d > min) { continue; } min = d; hover = e; } foreach (var p in sketch.entityList) { var e = new RevolvedEntity(p, this, 0); double d = e.Hover(mouse, camera, tf); if (d < 0) { continue; } if (d > Sketch.hoverRadius) { continue; } if (min >= 0.0 && d > min) { continue; } min = d; hover = e; } foreach (var p in sketch.entityList) { var e = new RevolvedEntity(p, this, 1); double d = e.Hover(mouse, camera, tf); if (d < 0) { continue; } if (d > Sketch.hoverRadius) { continue; } if (min >= 0.0 && d > min) { continue; } min = d; hover = e; } if (hover != null) { dist = min; } return(hover); }
protected override void OnUpdateDirty() { canvas.SetStyle("entities"); var sk = (source as SketchFeature).GetSketch(); bool axisDirectionFound = false; var ax = axis.GetDirectionInPlane(null).Eval(); var o = GetOrigin(null).Eval(); foreach (var e in sk.entityList) { if (e.type != IEntityType.Point) { continue; } var pos = e.PointExpInPlane(null).Eval(); var prj = ExpVector.ProjectPointToLine(pos, o, o + ax); if ((prj - pos).magnitude < 1e-6) { continue; } var ax1 = Vector3.Cross(sketch.plane.n, pos - prj); shouldInvertAxis = (Vector3.Dot(ax, ax1) > 0f); axisDirectionFound = true; break; } // probably, some curved enity, so try actual curve points if (!axisDirectionFound) { foreach (var e in sk.entityList) { if (e.type == IEntityType.Point) { continue; } foreach (var pos in e.SegmentsInPlane(null)) { var prj = ExpVector.ProjectPointToLine(pos, o, o + ax); if ((prj - pos).magnitude < 1e-6) { continue; } var ax1 = Vector3.Cross(sketch.plane.n, pos - prj); shouldInvertAxis = (Vector3.Dot(ax, ax1) > 0f); axisDirectionFound = true; break; } } } foreach (var e in sk.entityList.OfType <PointEntity>()) { var ext = new RevolvedPointEntity(e, this); canvas.DrawSegments(ext.segments); } foreach (var e in sk.entityList) { var ext = new RevolvedEntity(e, this, 0); canvas.DrawSegments(ext.segments); ext = new RevolvedEntity(e, this, 1); canvas.DrawSegments(ext.segments); } }