public GetHermiteAtTime ( float t ) : Vector3 | ||
t | float | |
Résultat | Vector3 |
void OnDrawGizmos() { if (BiomeGenerator != null) { foreach (var s in BiomeGenerator.settlements) { foreach (var road in s.Roads) { var nodes = road.Points.Select((x, i) => new SplineInterpolator.SplineNode(new Vector3(x.x, 0, x.y), (float)i / road.Points.Count, new Vector2(0, 1))).ToList(); SplineInterpolator interp = new SplineInterpolator(nodes); Vector3 prevPos = interp.GetHermiteAtTime(0); for (int c = 1; c <= 100; c++) { float currTime = c * 1f / 100; Vector3 currPos = interp.GetHermiteAtTime(currTime); var height = GetTerrainHeight(new Vector2(currPos.x, currPos.z)); currPos.y = height + 1; float mag = (currPos - prevPos).magnitude * 2; var cross = Vector3.Cross(currPos - prevPos, Vector3.up).normalized * 10; Gizmos.DrawLine(prevPos - cross, currPos - cross); Gizmos.DrawLine(prevPos + cross, currPos + cross); prevPos = currPos; } } } } }
private void OnDrawGizmos() { if (Path.Length < 2) { return; } if (Array.Exists(Path, go => go == null)) { return; } SplineInterpolator spline = SetupSpline(Path); Gizmos.color = Color.red; Gizmos.DrawRay(spline.GetHermiteAtTime(Testing), Vector3.up); Gizmos.color = Color.white; Vector3 lastPosition = spline.GetHermiteAtTime(0); int nodeCount = spline.GetNodeCount(); if (nodeCount % 2 != 0) { nodeCount--; } //test if the node count is even, if odd subtract one for (float t = _period; t <= nodeCount; t += _period) { Vector3 curretPosition = spline.GetHermiteAtTime(t); Gizmos.DrawLine(lastPosition, curretPosition); lastPosition = curretPosition; } }
// Update is called once per frame public override void ConveyanceUpdate(Guest guest) { if (Path.Length < 2) { return; } //add guest to dictionary if (!_guests.ContainsKey(guest)) { _guests.Add(guest, 0); guest.transform.position = Path[0].transform.position; return; } //move guest along _guests[guest] += Time.deltaTime * Speed; Vector3 position = _mSplineInterp.GetHermiteAtTime(_guests[guest]); //+++ guest.transform.forward = position - guest.transform.position; //make sure guest is facing movement direction guest.transform.position = position; //once we reach end, remove the guest int nodeCount = _mSplineInterp.GetNodeCount(); //+++ if (nodeCount % 2 != 0) { nodeCount--; } //+++ if (_guests[guest] >= nodeCount) { _guests.Remove(guest); guest.NextDestination(); } }
void OnDrawGizmos() { if (ShowHelperSpline) { Transform[] trans = GetTransforms(); if (trans.Length < 2) { return; } SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator; SetupSplineInterpolator(interp, trans); interp.StartInterpolation(null, false, eWrapMode.ONCE); Vector3 prevPos = trans[0].position; for (int c = 0; c <= LineSoftnessFactor; c++) { float currTime = c * Duration / LineSoftnessFactor; Vector3 currPos = interp.GetHermiteAtTime(currTime); if (c == 0) { currPos = trans[0].position; } Gizmos.color = HelperSplineColor;//new Color(mag, 0, 0, 1); Gizmos.DrawLine(prevPos, currPos); prevPos = currPos; } } }
void OnDrawGizmos() { if (mSplineDrawer != null) { Transform[] trans = GetTransforms(); if (trans.Length < 2) { return; } SetupSplineInterpolator(mSplineDrawer, trans); mSplineDrawer.StartInterpolation(null, false, WrapMode, true); Vector3 prevPos = trans [0].position; for (int c = 1; c <= 100; c++) { float currTime = c * Duration / 100; Vector3 currPos = mSplineDrawer.GetHermiteAtTime(currTime); float mag = (currPos - prevPos).magnitude * 2; Gizmos.color = new Color(mag, 0, 0, 1); Gizmos.DrawLine(prevPos, currPos); prevPos = currPos; } } }
// -------------------------------------------------------------------------------------------- // UNITY CALLBACKS // -------------------------------------------------------------------------------------------- void OnDrawGizmos() { //Debug.Log("drawing gizmos SplineController"); SplineNode[] info = GetSplineNodes(); if (info.Length < 2) { return; } SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator; SetupSplineInterpolator(interp, info); interp.StartInterpolation(null, null, null, /* callbacks */ false /* no rotations */, WrapMode); Vector3 prevPos = info[0].Point; float endTime = GetDuration(info); Gizmos.color = Color.red; for (int c = 0; c <= 100; c++) { Vector3 currPos = interp.GetHermiteAtTime((float)c * endTime / 100.0f); /* USEFUL SANITY CHECK TO DO IN THE DEBUGGER*/ if (float.IsNaN(currPos.x)) { Debug.Log("NaN while drawing gizmos!!!!"); // should never arrive here! } //float mag = (currPos-prevPos).magnitude * 2; //Gizmos.color = new Color(mag, 0, 0, 1); Gizmos.DrawLine(prevPos, currPos); prevPos = currPos; } }
void OnDrawGizmos() { Transform[] trans = GetTransforms(); if (trans.Length < 2) { return; } SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator; SetupSplineInterpolator(interp, trans); interp.StartInterpolation(null, false, WrapMode); Vector3 prevPos = trans[0].position; for (int c = 1; c <= 100; c++) { float currTime = c * Duration / 100; Vector3 currPos = interp.GetHermiteAtTime(currTime); float mag = (currPos - prevPos).magnitude * 2; Gizmos.color = new Color(mag, 0, 0, 1); Gizmos.DrawLine(prevPos, currPos); prevPos = currPos; } }
private float SplineLength(SplineInterpolator spline, float period) { float length = 0; Vector3 lastPosition = spline.GetHermiteAtTime(0); int nodeCount = spline.GetNodeCount(); if (nodeCount % 2 != 0) { nodeCount--; } //test if the node count is even, if odd subtract one for (float t = _period; t <= nodeCount; t += _period) { Vector3 curretPosition = spline.GetHermiteAtTime(t); float distance = Vector3.Distance(lastPosition, curretPosition); length += distance; lastPosition = curretPosition; } return(length); }
void SavePathwaPos() { for (int c = 1; c <= 50; c++) { posData data = new posData(); float currTime = c * Duration / smooth; Vector3 currPos = mSplineInterp.GetHermiteAtTime(currTime); data.pos = currPos; data.Time = currTime; posList.Add(data); } }
void OnDrawGizmos() { Transform[] trans = GetTransforms(); if (trans.Length < 2) { return; } SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator; SetupSplineInterpolator(interp, trans); interp.StartInterpolation(null, eRotationMode.PATH_ANGLE, WrapMode); Vector3 prevPos = trans[0].position; //Quaternion prevRot = trans [0].rotation; int numberOfLines = 500; for (int c = 1; c <= numberOfLines; c++) { float currTime = c * Duration / numberOfLines; Vector3 currPos = interp.GetHermiteAtTime(currTime); Quaternion currRot = interp.GetRotationAtTime(currTime); //float mag = (currPos-prevPos).magnitude * 2; Gizmos.color = new Color(0, 0, 1, 1); Gizmos.DrawLine(prevPos, currPos); Vector3 dP = currPos - prevPos; Transform _transform = new GameObject().transform; _transform.rotation = currRot; Quaternion armDir = Quaternion.LookRotation(dP, _transform.up); Vector3 rightArm = armDir * Vector3.right; Vector3 leftArm = armDir * Vector3.left; Gizmos.color = new Color(0, 1, 0, 1); Gizmos.DrawRay(currPos, rightArm); Gizmos.DrawRay(currPos, leftArm); prevPos = currPos; //prevRot = currRot; DestroyImmediate(_transform.gameObject); } }
void OnDrawGizmos() { Transform[] trans = GetTransforms(); if (trans == null) { return; } if (trans.Length < 2) { return; } // This was semi-incorrectly changed in porting this to Unity's C#: // SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator; // that's not entirely correct; we need a *new* SplineInterpolator to draw the gizmos with. // The one that we have as a Component is the one used in game itself. // trying to use the same one for both means that the object just twitches in place, // since it then gets reset continuously by the gizmo drawing. // we might need to make SplineInterpolator into something other than a Monobehaviour -- // or create an empty gameobject to AddComponent() it to (only in Editor) --Matt M. GameObject GizmoSplineInterpolator = new GameObject(); SplineInterpolator interp = (SplineInterpolator)GizmoSplineInterpolator.AddComponent(typeof(SplineInterpolator)); SetupSplineInterpolator(interp, trans); interp.StartInterpolation(null, false, WrapMode); Vector3 prevPos = trans[0].position; for (int c = 1; c <= 100; c++) { float currTime = c * Duration / 100; Vector3 currPos = interp.GetHermiteAtTime(currTime); //Debug.Log("currPos = " + currPos + " at " + currTime); float mag = (currPos - prevPos).magnitude * 2; Gizmos.color = new Color(mag, 0, 0, 1); Gizmos.DrawLine(prevPos, currPos); prevPos = currPos; } DestroyImmediate(GizmoSplineInterpolator); }
public void CreateRacingLine() { CheckIfMeshAlreadyCreated(); Transform[] trans = GetTransforms(); if (trans.Length < 2) { return; } if (MeshResolution < 16) { MeshResolution = 16; LineSoftnessFactor = MeshResolution - 2; return; } LineSoftnessFactor = MeshResolution - 2; SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator; SetupSplineInterpolator(interp, trans); interp.StartInterpolation(null, false, eWrapMode.ONCE); Vector3 prevPos = trans[0].position; for (int c = 0; c <= LineSoftnessFactor; c++) { float currTime = c * Duration / LineSoftnessFactor; Vector3 currPos = interp.GetHermiteAtTime(currTime); SurfaceProperties oSurf = CastToCollider(GroundOffset, currPos, new Vector3(0f, -1f, 0f), 0, 1); lastindex = AddLineNode(oSurf.Position, oSurf.Normal, 1f, lastindex); prevPos = currPos; } UpdateMeshFilter(); lastindex = -1; numMarks = 0; }
void OnDrawGizmos() { Transform[] trans = GetTransforms(); if (trans.Length < 2) { return; } SplineInterpolator interp = new SplineInterpolator(getNodes(trans)); Vector3 prevPos = trans[0].position; for (int c = 1; c <= 100; c++) { float currTime = c * Duration / 100; Vector3 currPos = interp.GetHermiteAtTime(currTime); float mag = (currPos - prevPos).magnitude * 2; Gizmos.color = new Color(mag, 0, 0, 1); Gizmos.DrawLine(prevPos, currPos); prevPos = currPos; } }
void Start() { mSplineInterp = GetComponent <SplineInterpolator>(); mTransforms = GetTransforms(); var line = GetComponent <LineRenderer>(); if (line != null && line.enabled) { if (mTransforms.Length > 2) { line.SetVertexCount(100); SplineInterpolator interp = GetComponent <SplineInterpolator>(); SetupSplineInterpolator(interp, mTransforms); interp.StartInterpolation(null, false, WrapMode); for (int c = 0; c <= 100; c++) { float currTime = c * Duration / 100; Vector3 currPos = interp.GetHermiteAtTime(currTime); line.SetPosition(c, currPos); } } } if (HideOnExecute) { DisableTransforms(); } if (AutoStart) { FollowSpline(); } }
void Start() { RootTransform = GetTransforms(); if (CellAmount > 0) { StartCoroutine(InstantiateCells()); } Transform[] trans = GetTransforms(); if (trans.Length < 2) { return; } SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator; SetupSplineInterpolator(interp, trans); interp.StartInterpolation(null, false, WrapMode); Vector3 prevPos = trans[0].position; lineRenderer = GetComponent <LineRenderer>(); lineRenderer.positionCount = 100; for (int c = 1; c <= 100; c++) { float currTime = c * DURATION / 100; Vector3 currPos = interp.GetHermiteAtTime(currTime); float mag = (currPos - prevPos).magnitude * 2; prevPos = currPos; PositionsList[c - 1] = currPos; } lineRenderer.SetPositions(PositionsList); lineRenderer.SetWidth(2.5f, 2.5f); lineRenderer.sortingOrder = 6000; lineRenderer.materials[0].color = VesselColor; }
void OnDrawGizmos() { if (m_CameraPathRootObject != null) { List <Transform> childrenTransforms = new List <Transform>(m_CameraPathRootObject.GetComponentsInChildren <Transform>()); childrenTransforms.Remove(m_CameraPathRootObject.transform); childrenTransforms.Sort(delegate(Transform t1, Transform t2) { return(t1.name.CompareTo(t2.name)); }); m_PathTransforms = childrenTransforms.ToArray(); if (m_SplineInterpolator == null) { m_SplineInterpolator = this.gameObject.GetComponent <SplineInterpolator>(); if (m_SplineInterpolator == null) { m_SplineInterpolator = this.gameObject.AddComponent <SplineInterpolator>(); } } m_SplineInterpolator.SetupSplineInterpolator(m_PathTransforms); Vector3 prevPos = m_PathTransforms[0].position; for (int c = 1; c <= 100; c++) { float currTime = c * 1.0f / 100; Vector3 currPos = m_SplineInterpolator.GetHermiteAtTime(currTime); float mag = (currPos - prevPos).magnitude * 2; Gizmos.color = new Color(mag, 0, 0, 1); Gizmos.DrawLine(prevPos, currPos); prevPos = currPos; } } }
public void BuildTrack() { // Delete all of the children of the track holding game object List <Component> childComponents = new List <Component>(GetComponentsInChildren(typeof(Transform))); List <Transform> childTransforms = childComponents.ConvertAll(c => (Transform)c); childTransforms.Remove(transform); foreach (Transform childTransform in childTransforms) { if (childTransform.gameObject.name == "left rail" || childTransform.gameObject.name == "right rail") { DestroyImmediate(childTransform.gameObject.GetComponent <MeshFilter>().sharedMesh); } DestroyImmediate(childTransform.gameObject); } // Get all of the spline node information from the splineRoot Transform[] splineNodeTransforms = GetTransforms(); if (splineNodeTransforms.Length < 2) { return; } // Build the spline interpolator object SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator; SetupSplineInterpolator(interp, splineNodeTransforms); interp.StartInterpolation(null, eRotationMode.PATH_ANGLE, eWrapMode.ONCE); // Build a list of affine transformation matricies that represent the track sections List <Matrix4x4> leftTrackPolyline = new List <Matrix4x4>(); List <Matrix4x4> rightTrackPolyline = new List <Matrix4x4>(); float tMax = AutoClose ? splineNodeTransforms.Length : splineNodeTransforms.Length - 1; tMax += 2 * resolution; for (float t = 0; t < tMax; t += resolution) { Transform trans = new GameObject().transform; trans.position = interp.GetHermiteAtTime(t); trans.rotation = interp.GetPathAngleAtTime(t); leftTrackPolyline.Add(trans.localToWorldMatrix * LeftRailPrefab.transform.localToWorldMatrix); rightTrackPolyline.Add(trans.localToWorldMatrix * RightRailPrefab.transform.localToWorldMatrix); //Debug.Log(trans.localToWorldMatrix); DestroyImmediate(trans.gameObject); } // Generate the rails GameObject leftRail = new GameObject(); Mesh leftMesh = new Mesh(); leftRail.name = "left rail"; leftRail.transform.parent = transform; leftRail.AddComponent <MeshFilter>(); leftRail.GetComponent <MeshFilter>().sharedMesh = leftMesh; leftRail.AddComponent <MeshRenderer>(); leftRail.GetComponent <MeshRenderer> ().sharedMaterial = LeftRailPrefab.GetComponent <MeshRenderer>().sharedMaterial; MeshExtrusion.ExtrudeMesh(LeftRailPrefab.GetComponent <MeshFilter>().sharedMesh, leftRail.GetComponent <MeshFilter>().sharedMesh, leftTrackPolyline.ToArray(), false); GameObject rightRail = new GameObject(); Mesh rightMesh = new Mesh(); rightRail.name = "right rail"; rightRail.transform.parent = transform; rightRail.AddComponent <MeshFilter>(); rightRail.GetComponent <MeshFilter>().sharedMesh = rightMesh; rightRail.AddComponent <MeshRenderer>(); rightRail.GetComponent <MeshRenderer> ().sharedMaterial = RightRailPrefab.GetComponent <MeshRenderer>().sharedMaterial; MeshExtrusion.ExtrudeMesh(RightRailPrefab.GetComponent <MeshFilter>().sharedMesh, rightRail.GetComponent <MeshFilter>().sharedMesh, rightTrackPolyline.ToArray(), false); // Generate the cross bars float distSinceLastCrossbar = 0; float cbRes = resolution / 5.0f; for (float t = cbRes; t < tMax; t += cbRes) { Vector3 dP = interp.GetHermiteAtTime(t) - interp.GetHermiteAtTime(t - cbRes); distSinceLastCrossbar += dP.magnitude; if (distSinceLastCrossbar >= beamDistance) { GameObject crossbar = Instantiate(crossBeamPrefab); crossbar.transform.parent = transform; crossbar.transform.position = interp.GetHermiteAtTime(t); crossbar.transform.rotation = interp.GetPathAngleAtTime(t); crossbar.transform.position += crossbar.transform.right * crossBeamPrefab.transform.position.x; crossbar.transform.position += crossbar.transform.up * crossBeamPrefab.transform.position.y; crossbar.transform.position += crossbar.transform.forward * crossBeamPrefab.transform.position.z; crossbar.transform.rotation *= crossBeamPrefab.transform.rotation; distSinceLastCrossbar -= beamDistance; } } }
private void CreateDistanceMeasurementTransforms() { if (Waypoints == null) { return; } DistanceTransformContainer = new GameObject(); DistanceTransformContainer.name = "_DistanceContainer"; Transform[] trans = GetChildTransforms(Waypoints.transform); if (trans.Length < 2) { return; } if (DistancePointDensity < trans.Length) { DistancePointDensity = trans.Length; } SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator; SetupSplineInterpolator(interp, trans); interp.StartInterpolation(null, false, eWrapMode.ONCE); for (int c = 0; c <= DistancePointDensity - 1; c++) { float currTime = c * 5 / DistancePointDensity; Vector3 currPos = interp.GetHermiteAtTime(currTime); // float mag = (currPos - prevPos).magnitude * 2; GameObject _tempTrans = new GameObject(); if (c < 10) { _tempTrans.name = "0" + c.ToString(); } else { _tempTrans.name = c.ToString(); } _tempTrans.transform.parent = DistanceTransformContainer.transform; _tempTrans.transform.localPosition = currPos; } if (FinishPoint != null) { GameObject _finalPoint = new GameObject(); _finalPoint.name = DistancePointDensity.ToString(); _finalPoint.transform.parent = DistanceTransformContainer.transform; _finalPoint.transform.localPosition = FinishPoint.transform.position; _finalPoint.transform.localRotation = FinishPoint.transform.rotation; } else { Debug.LogWarning(RGKMessages.FinishPointMissing); return; } //Calculate total race distance between using this created transforms. DistanceMeasurementObjects = GetChildTransforms(DistanceTransformContainer.transform); for (int i = 0; i < DistanceMeasurementObjects.GetUpperBound(0); i++) { if (i < DistanceMeasurementObjects.GetUpperBound(0)) { if (i != DistanceMeasurementObjects.GetUpperBound(0)) { RaceLength += Vector3.Distance(DistanceMeasurementObjects[i].transform.position, DistanceMeasurementObjects[i + 1].transform.position); } //Debug.Log(i.ToString() + "=" + Vector3.Distance(wayPoints[i].transform.position, wayPoints[i + 1].transform.position)); } } FixDistancePointRotations(DistanceTransformContainer); }