Update effector base and push apart effector
This commit is contained in:
@@ -21,16 +21,18 @@ namespace Misaki.ArtTool
|
||||
public float3 scale;
|
||||
public float uniformScale;
|
||||
|
||||
public override void Operate(int index, float4x4 nodeWorldMatrix, ReadOnlySpan<PointData> points, ref float4x4 pointWorldMatrix, ref bool isValid)
|
||||
public override void Operate(int index, float4x4 nodeWorldMatrix, Span<PointData> points)
|
||||
{
|
||||
if (!isEnablePosition && !isEnableRotation && !isEnableScale)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MatrixHelper.DecomposeMatrix(pointWorldMatrix, out var position, out var rotation, out var scale);
|
||||
var currentPoint = points[index];
|
||||
|
||||
var weight = CalculateFieldsWeight(pointWorldMatrix.c3.xyz);
|
||||
MatrixHelper.DecomposeMatrix(currentPoint.matrix, out var position, out var rotation, out var scale);
|
||||
|
||||
var weight = CalculateFieldsWeight(position);
|
||||
if (weight == 0)
|
||||
{
|
||||
return;
|
||||
@@ -48,7 +50,7 @@ namespace Misaki.ArtTool
|
||||
newPosition += math.mul(effectorMatrix, new float4(this.position, 0)).xyz;
|
||||
break;
|
||||
case TransformSpace.Object:
|
||||
newPosition += math.mul(pointWorldMatrix, new float4(this.position, 0)).xyz;
|
||||
newPosition += math.mul(currentPoint.matrix, new float4(this.position, 0)).xyz;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -70,7 +72,7 @@ namespace Misaki.ArtTool
|
||||
break;
|
||||
case TransformSpace.Object:
|
||||
newRotation = math.mul(rotation,
|
||||
quaternion.EulerXYZ(math.mul(pointWorldMatrix, new float4(math.radians(this.rotation), 0)).xyz));
|
||||
quaternion.EulerXYZ(math.mul(currentPoint.matrix, new float4(math.radians(this.rotation), 0)).xyz));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -92,7 +94,9 @@ namespace Misaki.ArtTool
|
||||
scale = math.lerp(scale, newScale, weight);
|
||||
}
|
||||
|
||||
pointWorldMatrix = float4x4.TRS(position, rotation, scale);
|
||||
currentPoint.matrix = float4x4.TRS(position, rotation, scale);
|
||||
|
||||
points[index] = currentPoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,14 @@ namespace Misaki.ArtTool
|
||||
{
|
||||
public float radius = 1.0f;
|
||||
public uint iteration = 10;
|
||||
public bool isHideMode = false;
|
||||
|
||||
// TODO: Average the push direction and distance of each point for more consistence result
|
||||
public override void Operate(int index, float4x4 nodeWorldMatrix, ReadOnlySpan<PointData> points, ref float4x4 pointWorldMatrix, ref bool isValid)
|
||||
public override void Operate(int index, float4x4 nodeWorldMatrix, Span<PointData> points)
|
||||
{
|
||||
var currentPoint = points[index];
|
||||
|
||||
var weight = CalculateFieldsWeight(pointWorldMatrix.c3.xyz);
|
||||
var weight = CalculateFieldsWeight(currentPoint.matrix.c3.xyz);
|
||||
if (weight == 0)
|
||||
{
|
||||
return;
|
||||
@@ -23,21 +24,26 @@ namespace Misaki.ArtTool
|
||||
{
|
||||
for (var p = 0; p < points.Length; p++)
|
||||
{
|
||||
var targetPoint = points[p];
|
||||
|
||||
if (ReferenceEquals(currentPoint, targetPoint))
|
||||
if (index == p)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var targetPoint = points[p];
|
||||
|
||||
var distance = math.distance(currentPoint.matrix.c3.xyz, targetPoint.matrix.c3.xyz);
|
||||
if (distance < radius)
|
||||
{
|
||||
var direction = math.normalizesafe(currentPoint.matrix.c3.xyz - targetPoint.matrix.c3.xyz);
|
||||
pointWorldMatrix.c3.xyz += distance * weight * direction;
|
||||
currentPoint.matrix.c3.xyz += (radius - distance) * weight * direction;
|
||||
|
||||
//Debug.Log($"Push at index {index} with distance {radius - distance} and direction {direction}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
points[index] = currentPoint;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,13 +26,15 @@ namespace Misaki.ArtTool
|
||||
public float3 scaleMinMax;
|
||||
public float uniformScaleMinMax;
|
||||
|
||||
public override void Operate(int index, float4x4 nodeWorldMatrix, ReadOnlySpan<PointData> points, ref float4x4 pointWorldMatrix, ref bool isValid)
|
||||
public override void Operate(int index, float4x4 nodeWorldMatrix, Span<PointData> points)
|
||||
{
|
||||
if (!isEnablePosition && !isEnableRotation && !isEnableScale)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var currentPoint = points[index];
|
||||
|
||||
Random random;
|
||||
if (synchronized)
|
||||
{
|
||||
@@ -50,9 +52,9 @@ namespace Misaki.ArtTool
|
||||
}
|
||||
}
|
||||
|
||||
MatrixHelper.DecomposeMatrix(pointWorldMatrix, out var position, out var rotation, out var scale);
|
||||
MatrixHelper.DecomposeMatrix(currentPoint.matrix, out var position, out var rotation, out var scale);
|
||||
|
||||
var weight = CalculateFieldsWeight(pointWorldMatrix.c3.xyz);
|
||||
var weight = CalculateFieldsWeight(position);
|
||||
if (weight == 0)
|
||||
{
|
||||
return;
|
||||
@@ -68,7 +70,7 @@ namespace Misaki.ArtTool
|
||||
newPosition = math.mul(effectorMatrix, new float4(newPosition, 0.0f)).xyz;
|
||||
break;
|
||||
case TransformSpace.Object:
|
||||
newPosition = math.mul(pointWorldMatrix, new float4(newPosition, 0.0f)).xyz;
|
||||
newPosition = math.mul(currentPoint.matrix, new float4(newPosition, 0.0f)).xyz;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -86,7 +88,7 @@ namespace Misaki.ArtTool
|
||||
angle = math.mul(effectorMatrix, new float4(angle, 0.0f)).xyz;
|
||||
break;
|
||||
case TransformSpace.Object:
|
||||
angle = math.mul(pointWorldMatrix, new float4(angle, 0.0f)).xyz;
|
||||
angle = math.mul(currentPoint.matrix, new float4(angle, 0.0f)).xyz;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -117,7 +119,9 @@ namespace Misaki.ArtTool
|
||||
scale = math.lerp(scale, scale + newScale, weight);
|
||||
}
|
||||
|
||||
pointWorldMatrix = float4x4.TRS(position, rotation, scale);
|
||||
currentPoint.matrix = float4x4.TRS(position, rotation, scale);
|
||||
|
||||
points[index] = currentPoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user