-
-
Save TigerHix/eaf8e05e5e1b687b8265420b9943903d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using Warudo.Core; | |
using Warudo.Core.Attributes; | |
using Warudo.Core.Data; | |
using Warudo.Core.Data.Models; | |
using Warudo.Core.Graphs; | |
using Warudo.Core.Utils; | |
namespace Warudo.Plugins.Core.Nodes { | |
[NodeType(Id = "852b69df-b2af-4577-9b37-e4c2dfef28ce", Title = "SMOOTH_TRANSFORM", Category = "CATEGORY_ARITHMETIC")] | |
public class SmoothTransformNode : Node { | |
[DataInput] | |
[Label("TRANSFORM")] | |
public TransformData InputTransform; | |
[DataInput] | |
[Label("SMOOTH_TIME")] | |
[FloatSlider(0f, 2f, 0.01f)] | |
public float SmoothTime = 0.4f; | |
[DataOutput] | |
[Label("OUTPUT_TRANSFORM")] | |
public TransformData SmoothedTransform() { | |
var currentVelocity = positionVelocity; | |
var smoothedPosition = Vector3.SmoothDamp( | |
lastPosition, | |
InputTransform.Position, | |
ref currentVelocity, | |
SmoothTime / 10f); | |
positionVelocity = currentVelocity; | |
lastPosition = smoothedPosition; | |
var smoothedRotation = UnityExtensions.SmoothDamp( | |
lastRotation, | |
InputTransform.RotationQuaternion, | |
ref rotationVelocity, | |
SmoothTime / 10f); | |
lastRotation = smoothedRotation; | |
var currentScaleVelocity = scaleVelocity; | |
var smoothedScale = Vector3.SmoothDamp( | |
lastScale, | |
InputTransform.Scale, | |
ref currentScaleVelocity, | |
SmoothTime / 10f); | |
scaleVelocity = currentScaleVelocity; | |
lastScale = smoothedScale; | |
smoothedTransform.Position = smoothedPosition; | |
smoothedTransform.RotationQuaternion = smoothedRotation; | |
smoothedTransform.Scale = smoothedScale; | |
return smoothedTransform; | |
} | |
private Vector3 positionVelocity; | |
private Vector3 lastPosition; | |
private Quaternion rotationVelocity; | |
private Quaternion lastRotation; | |
private Vector3 scaleVelocity; | |
private Vector3 lastScale; | |
private readonly TransformData smoothedTransform = StructuredData.Create<TransformData>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment