Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions VisualPinball.Engine/VPT/Surface/SurfaceMeshGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ private Mesh GenerateTopMesh(Table.Table table) {
var dx = pv1.X - pv2.X;
var dy = pv1.Y - pv2.Y;

var invLen = 1.0f / MathF.Sqrt(dx * dx + dy * dy);

rgNormal[i] = new Vertex2D {X = dy * invLen, Y = dx * invLen};
if (dx != 0.0f || dy != 0.0f) {
var invLen = 1.0f / MathF.Sqrt(dx * dx + dy * dy);
rgNormal[i] = new Vertex2D { X = dy * invLen, Y = dx * invLen };
} else {
rgNormal[i] = new Vertex2D { X = 0.0f, Y = 0.0f };
}
}

// draw top
Expand Down Expand Up @@ -180,9 +183,12 @@ private Mesh GenerateSideMesh(Table.Table table) {
var dx = pv1.X - pv2.X;
var dy = pv1.Y - pv2.Y;

var invLen = 1.0f / MathF.Sqrt(dx * dx + dy * dy);

rgNormal[i] = new Vertex2D {X = dy * invLen, Y = dx * invLen};
if (dx != 0.0f || dy != 0.0f) {
var invLen = 1.0f / MathF.Sqrt(dx * dx + dy * dy);
rgNormal[i] = new Vertex2D { X = dy * invLen, Y = dx * invLen };
} else {
rgNormal[i] = new Vertex2D { X = 0.0f, Y = 0.0f };
}
}

var bottom = _data.HeightBottom * table.GetScaleZ() + table.TableHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ protected virtual void OnSceneGUI()
} else if (DragPointsHandler.CurveTravellerVisible && HandleUtility.nearestControl == DragPointsHandler.CurveTravellerControlId) {
var command = new MenuCommand(this, 0);
EditorUtility.DisplayPopupMenu(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0, 0), DragPointMenuItems.CurveTravellerMenuPath, command);
Event.current.Use();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,16 @@ private void DisplayCurve()

// Render Curve with correct color regarding drag point properties & find curve section where the curve traveller is
_handler.CurveTravellerControlPointIdx = -1;
var minDist = float.MaxValue;
foreach (var controlPoint in _handler.ControlPoints) {
var segments = controlPointsSegments[controlPoint.Index].ToArray();
if (segments.Length > 1) {
Handles.color = _handler.DragPointEditable.GetDragPointExposition().Contains(DragPointExposure.SlingShot) && controlPoint.DragPoint.IsSlingshot ? CurveSlingShotColor : CurveColor;
Handles.DrawAAPolyLine(CurveWidth, segments);
var closestToPath = HandleUtility.ClosestPointToPolyLine(segments);
if (_handler.CurveTravellerControlPointIdx == -1 && closestToPath == _handler.CurveTravellerPosition) {
var dist = (closestToPath - _handler.CurveTravellerPosition).magnitude;
if (dist < minDist) {
minDist = dist;
_handler.CurveTravellerControlPointIdx = controlPoint.Index;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ private void UpdateMesh()

if (mf != null) {
var unityMesh = mf.sharedMesh;
ro.Mesh.ApplyToUnityMesh(unityMesh);
if (ro.Mesh != null) {
ro.Mesh.ApplyToUnityMesh(unityMesh);
}
}

if (mr != null) {
Expand Down