public override void OnInspectorGUI() { component = target as SplineComponent; int newtool = GUILayout.Toolbar(tool, new string[] { "Edit", "Junction", "Spline" }); if (tool != newtool) { tool = newtool; if (tool >= 2) { activeSpline = -1; selectedIndex = -1; } SceneView.RepaintAll(); } EditorGUILayout.Space(); switch (tool) { case 0: DrawEditInspector(); break; case 1: DrawJunctionInspector(); break; case 2: DrawSplineInspector(); break; } }
//No constructor because it's a MonoBehaviour and it gets angry if I try to make one public void Extrude(Mesh m, SplineComponent splineComponent, int stepCount) //Should add 'leniency' later... could it be done with scale? { tempTubeVertices = new List <Vector3>(); spline = splineComponent; extrudeShape = m; for (int i = 0; i < extrudeShape.vertexCount; i++) //converting Array to List, otherwise tempTubeVertices would be empty { tempTubeVertices.Add(extrudeShape.vertices[i]); } divisions = (float)stepCount; CreateTubeMesh(); MeshCollider tubeCollider; if (this.gameObject.GetComponent <MeshCollider>() == null) { tubeCollider = this.gameObject.AddComponent <MeshCollider>(); } else { tubeCollider = this.gameObject.GetComponent <MeshCollider>(); } tubeCollider.sharedMesh = tubeMesh; }
protected void Start() { if (spline == null) { spline = GetComponent <SplineComponent> (); } if (spline == null) { Debug.LogError ("'spline' in 'SplineDrawer' is null!"); } m_LineMeshGenerator = GetComponent <LineMeshGenerator> (); m_MeshFilter = GetComponent <MeshFilter> (); }
void CenterAroundOrigin(SplineComponent spline, List <Vector3> points) { var center = Vector3.zero; for (int i = 0; i < points.Count; i++) { center += points[i]; } center /= points.Count; for (int i = 0; i < points.Count; i++) { points[i] -= center; } }
private void DrawSpline(DrawMode mode, SplineComponent s) { int length = (int)(s.TotalLength() / SegmentLength); bool selected = (mode & DrawMode.Selected) != 0; if ((mode & DrawMode.Line) != 0) { for (int i = 0; i <= length - 1; i++) { bool isEven = i % 2 == 0; var startPoint = (Vector3)s.Point((float)i / length); var endPoint = (Vector3)s.Point((float)(i + 1) / length); var color = (selected ? (isEven ? Color.red : Color.green) : Color.white); if ((mode & DrawMode.Darker) != 0) { color *= 0.75f; } Gizmos.color = color; Gizmos.DrawLine(startPoint + OffsetZ, endPoint + OffsetZ); } } if ((mode & DrawMode.Arrow) != 0) { Gizmos.color = selected ? Color.cyan : Color.white; var center = s.Point(0.5f); var forward = s.Tangent(0.5f); Mesh coneMesh = null; if (transform.parent.GetComponent <RoadSetup>() != null) { coneMesh = transform.parent.GetComponent <RoadSetup>().ConeMesh; } if (transform.parent.GetComponent <RoadPiece>() != null) { coneMesh = transform.parent.GetComponent <RoadPiece>().ConeMesh; } if (coneMesh != null) { Gizmos.DrawMesh(coneMesh, center, Quaternion.LookRotation(forward), new Vector3(1f, 1f, 2f)); } } }
static void DrawGizmo(SplineComponent spline, int stepCount) { if (spline.points.Count > 0) { var P = 0f; var start = spline.GetNonUniformPoint(0); var step = 1f / stepCount; do { P += step; var here = spline.GetNonUniformPoint(P); Gizmos.DrawLine(start, here); start = here; } while (P + step <= 1); } }
static void DrawPointProperties(SplineComponent spline) { Vector3 tangent = spline.GetTangent(spline.CurrentPointT); // Vector3 up = spline.GetUp(spline.CurrentPointT); Vector3 normal = spline.GetNormal(spline.CurrentPointT, Vector3.up); Vector3 p = spline.GetPoint(spline.CurrentPointT); Gizmos.color = Color.blue; Gizmos.DrawRay(p, tangent.normalized); Gizmos.color = Color.green; // Gizmos.DrawRay(p, up.normalized); Gizmos.DrawRay(p, normal.normalized); Gizmos.color = Color.red; Gizmos.DrawRay(p, Vector3.Cross(normal, tangent)); Gizmos.color = Color.black; Gizmos.DrawSphere(p, 0.05f); }
public Vector3 GetPoint(float t) { int num = linearPoints.Length - ((!spline.closed) ? 3 : 0); int num2 = Mathf.Min(Mathf.FloorToInt(t * (float)num), num - 1); int num3 = linearPoints.Length; if (num2 < 0) { num2 += num3; } float u = t * (float)num - (float)num2; Vector3 a = linearPoints[num2 % num3]; Vector3 b = linearPoints[(num2 + 1) % num3]; Vector3 c = linearPoints[(num2 + 2) % num3]; Vector3 d = linearPoints[(num2 + 3) % num3]; return(SplineComponent.Interpolate(a, b, c, d, u)); }
public Vector3 GetPoint(float t) { var sections = linearPoints.Length - (spline.closed ? 0 : 3); var i = Mathf.Min(Mathf.FloorToInt(t * (float)sections), sections - 1); var count = linearPoints.Length; if (i < 0) { i += count; } var u = t * (float)sections - (float)i; var a = linearPoints[(i + 0) % count]; var b = linearPoints[(i + 1) % count]; var c = linearPoints[(i + 2) % count]; var d = linearPoints[(i + 3) % count]; return(SplineComponent.Interpolate(a, b, c, d, u)); }
public Vector3 GetPoint(float t) //takes a float & converts it into an int, why not just take an int? { int sections = linearPoints.Length - 3; //should never be closed, if I f****d up, swap 3 with 0 int i = Mathf.Min(Mathf.FloorToInt(t * (float)sections), sections - 1); int count = linearPoints.Length; if (i < 0) { i += count; } float u = t * sections - i; //Interpolation Position (?) Vector3 a = linearPoints[(i + 0) % count]; //Control Point (?) Vector3 b = linearPoints[(i + 1) % count]; //Control Point (?) Vector3 c = linearPoints[(i + 2) % count]; //Start Point (?) Vector3 d = linearPoints[(i + 3) % count]; //End Point (?) return(SplineComponent.Interpolate(a, b, c, d, u)); }
// Draw splines and handles private void OnSceneGUI() { component = target as SplineComponent; componentTransform = component.transform; componentRotation = Tools.pivotRotation == PivotRotation.Local ? componentTransform.rotation : Quaternion.identity; DrawBeziers(); if (Tools.pivotRotation != currentPivotRotation) { currentPivotRotation = Tools.pivotRotation; handleRotation = Quaternion.identity; if (activeSpline >= 0 && selectedIndex >= 0) { pointRotation = component.GetRotation(activeSpline, selectedIndex); } } }
internal static unsafe void Invoke(IntPtr obj, SplineComponent InSplineComponent, float StartWidth, float EndWidth, float StartSideFalloff, float EndSideFalloff, float StartRoll, float EndRoll, int NumSubdivisions, bool bRaiseHeights, bool bLowerHeights, LandscapeLayerInfoObject PaintLayer) { long *p = stackalloc long[] { 0L, 0L, 0L, 0L, 0L, 0L, 0L }; byte *b = (byte *)p; *((IntPtr *)(b + 0)) = InSplineComponent; *((float *)(b + 8)) = StartWidth; *((float *)(b + 12)) = EndWidth; *((float *)(b + 16)) = StartSideFalloff; *((float *)(b + 20)) = EndSideFalloff; *((float *)(b + 24)) = StartRoll; *((float *)(b + 28)) = EndRoll; *((int *)(b + 32)) = NumSubdivisions; *((bool *)(b + 36)) = bRaiseHeights; *((bool *)(b + 37)) = bLowerHeights; *((IntPtr *)(b + 40)) = PaintLayer; Main.GetProcessEvent(obj, EditorApplySpline_ptr, new IntPtr(p));; } }
public static void DrawSpline(SplineComponent a_Spline, GizmoType a_Type) { Color l_GizmosColor = Gizmos.color; if (a_Spline.Spline.IsValid && a_Spline.Spline.Count >= 4) { // Start and end points Gizmos.color = SplineWindow.StartEndPointColor; Gizmos.DrawLine (a_Spline.Spline [0].transform.position, a_Spline.Spline [1].transform.position); Gizmos.DrawLine (a_Spline.Spline [a_Spline.Spline.Count - 2].transform.position, a_Spline.Spline [a_Spline.Spline.Count - 1].transform.position); // Spline curve Gizmos.color = SplineWindow.DefaultColor; float l_TDelta = (a_Spline.Spline.LastControlPoint.T - a_Spline.Spline.FirstControlPoint.T) / SplineWindow.CurveSegmentCount; SplineEnumerator <SplineControlPointComponent> l_Enumerator = new SplineEnumerator <SplineControlPointComponent> (a_Spline.Spline); l_Enumerator.MoveToStart (); Vector3 l_PositionA; Vector3 l_PositionB = l_Enumerator.CurrentPosition; while (!l_Enumerator.IsAtEnd ()) { l_Enumerator.MoveForward (l_TDelta); l_PositionA = l_PositionB; l_PositionB = l_Enumerator.CurrentPosition; Gizmos.DrawLine (l_PositionA, l_PositionB); } // Curve spheres if (SplineWindow.CurveSphereCount > 1) { Gizmos.color = SplineWindow.CurveSphereColor; l_TDelta = (a_Spline.Spline.LastControlPoint.T - a_Spline.Spline.FirstControlPoint.T) / (SplineWindow.CurveSphereCount - 1); l_Enumerator.MoveToStart (); Gizmos.DrawSphere (l_Enumerator.CurrentPosition, SplineWindow.SphereRadius); while (!l_Enumerator.IsAtEnd ()) { l_Enumerator.MoveForward (l_TDelta); Gizmos.DrawSphere (l_Enumerator.CurrentPosition, SplineWindow.SphereRadius); } } } Gizmos.color = l_GizmosColor; }
static void DrawGizmo(SplineComponent spline, int stepCount) { Gizmos.color = Color.white; if (spline.points.Count > 0) { float p = 0f; Vector3 start = spline.GetNonUniformPoint(0); float step = 1f / stepCount; do { p += step; Vector3 here = spline.GetNonUniformPoint(p); Gizmos.DrawLine(start, here); start = here; } while(p + step <= 1); foreach (Vector3 item in spline.points) { Gizmos.DrawSphere(item, .25f); } } }
public void CreateNode(SplineComponent splineComponent) { GameObject controlPoint = new GameObject("ControlPoint"); // Add the splineComponent component controlPoint.AddComponent <ControlPointComponent>(); SplineCurve splineCurve = splineComponent.GetSplineObject(); Vector3 targetPosition = Vector3.one; Vector3[] controlPoints = splineCurve.controlPoints; int cpLength = controlPoints.Length; int controlPointsPerSegment = splineComponent.GetControlPointsPerSegment(); if (cpLength >= controlPointsPerSegment) { // extrapolate the position from the last two points targetPosition = controlPoints[cpLength - 1] + (controlPoints[cpLength - 1] - controlPoints[cpLength - controlPointsPerSegment]); } controlPoint.transform.position = targetPosition; controlPoint.transform.parent = splineComponent.transform; }
public override void OnInspectorGUI() { EditorGUILayout.HelpBox("Hold Shift and click to append and insert curve points. Backspace to delete points.", MessageType.Info); spline = target as SplineComponent; base.OnInspectorGUI(); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); var closed = GUILayout.Toggle(spline.closed, "Closed", "button"); if (spline.closed != closed) { spline.closed = closed; spline.ResetIndex(); } if (GUILayout.Button("Flatten Y Axis")) { Undo.RecordObject(target, "Flatten Y Axis"); TODO : Flatten(spline.points); spline.ResetIndex(); } if (GUILayout.Button("Center around Origin")) { Undo.RecordObject(target, "Center around Origin"); TODO : CenterAroundOrigin(spline.points); spline.ResetIndex(); } GUILayout.EndHorizontal(); spline.CurrentPointT = EditorGUILayout.Slider(spline.CurrentPointT, 0.0f, 1.0f); spline.CurrentPointT = Mathf.Clamp01(spline.CurrentPointT); GUILayout.EndVertical(); }
public void OnDrawGizmosSelected() { Transform t = transform.parent; if (t == null) { return; } SplineComponent splineComponent = t.gameObject.GetComponent <SplineComponent>(); if (splineComponent == null) { return; } splineComponent.OnDrawGizmosSelected(); Gizmos.color = splineComponent.controlPointColorSelected; Gizmos.DrawSphere(transform.position, splineComponent.sphereRadius * 1.2f); if (!position.Equals(oldPos)) { oldPos = position; splineComponent.UpdateSpline(); } }
protected static void FindSpline() { SplineComponent l_Spline = null; Transform l_Transform = Selection.activeTransform; if (l_Transform != null) { l_Spline = l_Transform.GetComponent <SplineComponent> (); if (l_Spline == null) { while (l_Spline == null) { if (l_Transform.parent == null) { break; } l_Transform = l_Transform.parent; l_Spline = l_Transform.GetComponent <SplineComponent> (); } } } s_Spline = l_Spline; }
static void DrawGizmosHiRes(SplineComponent spline, GizmoType gizmoType) { Gizmos.color = Color.white; DrawGizmo(spline, 1024); }
///<summary> ///Deform landscape using a given spline ///@ ///</summary> ///<remarks> ///param StartWidth - Width of the spline at the start node, in Spline Component local space ///@param EndWidth - Width of the spline at the end node, in Spline Component local space ///@param StartSideFalloff - Width of the falloff at either side of the spline at the start node, in Spline Component local space ///@param EndSideFalloff - Width of the falloff at either side of the spline at the end node, in Spline Component local space ///@param StartRoll - Roll applied to the spline at the start node, in degrees. 0 is flat ///@param EndRoll - Roll applied to the spline at the end node, in degrees. 0 is flat ///@param NumSubdivisions - Number of triangles to place along the spline when applying it to the landscape. Higher numbers give better results, but setting it too high will be slow and may cause artifacts ///@param bRaiseHeights - Allow the landscape to be raised up to the level of the spline. If both bRaiseHeights and bLowerHeights are false, no height modification of the landscape will be performed ///@param bLowerHeights - Allow the landscape to be lowered down to the level of the spline. If both bRaiseHeights and bLowerHeights are false, no height modification of the landscape will be performed ///@param PaintLayer - LayerInfo to paint, or none to skip painting. The landscape must be configured with the same layer info in one of its layers or this will do nothing! ///</remarks> public void EditorApplySpline(SplineComponent InSplineComponent, float StartWidth, float EndWidth, float StartSideFalloff, float EndSideFalloff, float StartRoll, float EndRoll, int NumSubdivisions, bool bRaiseHeights, bool bLowerHeights, LandscapeLayerInfoObject PaintLayer) => LandscapeProxy_methods.EditorApplySpline_method.Invoke(ObjPointer, InSplineComponent, StartWidth, EndWidth, StartSideFalloff, EndSideFalloff, StartRoll, EndRoll, NumSubdivisions, bRaiseHeights, bLowerHeights, PaintLayer);
private List <Entity> GenerateSegmentEntities(Dictionary <RoadNode, Entity> roadNodes) { List <Entity> segments = new List <Entity>(); Dictionary <RoadSegment, Entity> roadSegmentsMap = new Dictionary <RoadSegment, Entity>(); foreach (var roadPiece in roadPieces) { foreach (var segment in roadPiece.RoadSegments) { var segmentEntity = dstManager.CreateEntity(typeof(SegmentConfigComponent), typeof(SplineComponent), typeof(SegmentComponent), typeof(SegmentTrafficTypeComponent)); var splineComponent = SplineComponent.CreateSpline(segment.StartNode.transform, segment.EndNode.transform, segment.CurveIn); var segmentComponent = dstManager.GetComponentData <SegmentConfigComponent>(segmentEntity); segmentComponent.StartNode = roadNodes[segment.StartNode]; segmentComponent.EndNode = roadNodes[segment.EndNode]; segmentComponent.Length = splineComponent.TotalLength(); var nodeBuffer = dstManager.GetBuffer <ConnectedSegmentBufferElement>(segmentComponent.StartNode); nodeBuffer.Add(new ConnectedSegmentBufferElement { segment = segmentEntity }); dstManager.SetComponentData(segmentEntity, segmentComponent); dstManager.SetComponentData(segmentEntity, splineComponent); dstManager.SetComponentData(segmentEntity, new SegmentComponent { AvailableLength = segmentComponent.Length }); segments.Add(segmentEntity); roadSegmentsMap.Add(segment, segmentEntity); } } foreach (var roadPiece in roadPieces) { //is intersection if (roadPiece.intersectionGroups.Length > 0) { var intersectionEntity = dstManager.CreateEntity(typeof(IntersectionComponent), typeof(IntersectionTimerComponent)); dstManager.AddBuffer <IntersectionSegmentsGroupBufferElement>(intersectionEntity); var intersectionSegmentBufferElements = dstManager.AddBuffer <IntersectionSegmentBufferElement>(intersectionEntity); var intersectionSegmentsGroupBufferElements = dstManager.GetBuffer <IntersectionSegmentsGroupBufferElement>(intersectionEntity); var counter = 0; for (int i = 0; i < roadPiece.intersectionGroups.Length; i++) { var group = roadPiece.intersectionGroups[i]; intersectionSegmentsGroupBufferElements.Add(new IntersectionSegmentsGroupBufferElement { StartIndex = counter, EndIndex = counter + group.Segments.Length - 1, Time = group.Time }); foreach (var roadSegment in group.Segments) { var segmentEntity = roadSegmentsMap[roadSegment]; intersectionSegmentBufferElements.Add(new IntersectionSegmentBufferElement { Segment = segmentEntity }); counter++; dstManager.SetComponentData(segmentEntity, new SegmentTrafficTypeComponent { TrafficType = ConnectionTrafficType.NoEntrance }); } } } } return(segments); }
public SplineIndex(SplineComponent spline) { this.spline = spline; ReIndex(); }
private void TestSpline() { cube = Actor.GetComponent <StaticMeshComponent>(); spline = Actor.GetComponent <SplineComponent>(); }
static void DrawGizmosLoRes(SplineComponent spline, GizmoType gizmoType) { Gizmos.color = Color.white; DrawGizmo(spline, 64); DrawPointProperties(spline); }
private void DrawConnection(DrawMode mode) { var s = SplineComponent.CreateSpline(StartNode.transform, EndNode.transform, CurveIn); DrawSpline(mode, s); }
static void DrawGizmosLoRes(SplineComponent spline, GizmoType gizmoType) { Gizmos.color = Color.gray; DrawGizmo(spline, 256); }
MenuFunction MakeFlattenDelegate(SplineComponent spline, string axisName, Vector3 projectionNormal) { return(() => { }); }