Fix error amd Update features.
Changed Span<PointData> to ReadOnlySpan<PointData> on method Operate in EffectorBase.cs Changed the return type of method Operate in EffectorBase.cs from void to PointDate Added FieldHelper and BlendField function to make the blending work.
This commit is contained in:
@@ -137,7 +137,7 @@ namespace Misaki.ArtTool
|
||||
|
||||
if (inputMeshFilter == null)
|
||||
{
|
||||
throw new NullReferenceException();
|
||||
throw new NullReferenceException("You need to set the target mesh filter before using the object distribution mode");
|
||||
}
|
||||
|
||||
objectDistributionSetting.meshData = new(inputMeshFilter, Allocator.TempJob);
|
||||
@@ -147,7 +147,7 @@ namespace Misaki.ArtTool
|
||||
|
||||
if (inputSplineContainer == null)
|
||||
{
|
||||
throw new NullReferenceException();
|
||||
throw new NullReferenceException("You need to set the target spline container before using the spline distribution mode");
|
||||
}
|
||||
|
||||
splineDistributionSetting.splineWorldMatrix = inputSplineContainer.transform.localToWorldMatrix;
|
||||
@@ -268,7 +268,7 @@ namespace Misaki.ArtTool
|
||||
continue;
|
||||
}
|
||||
|
||||
effectors[e].effector.Operate(i, worldMatrix, _points);
|
||||
_points[i] = effectors[e].effector.Operate(i, worldMatrix, _points);
|
||||
}
|
||||
|
||||
if (math.all(_points[i].matrix.GetScale() == float3.zero))
|
||||
|
||||
@@ -56,10 +56,7 @@ namespace Misaki.ArtTool
|
||||
effectorMatrix = transform.localToWorldMatrix;
|
||||
}
|
||||
|
||||
public virtual void Operate(int index, float4x4 nodeWorldMatrix, Span<PointData> points)
|
||||
{
|
||||
|
||||
}
|
||||
public abstract PointData Operate(int index, float4x4 nodeWorldMatrix, ReadOnlySpan<PointData> points);
|
||||
|
||||
protected float CalculateFieldsWeight(float3 worldPosition)
|
||||
{
|
||||
@@ -73,7 +70,8 @@ namespace Misaki.ArtTool
|
||||
continue;
|
||||
}
|
||||
|
||||
weight = math.lerp(weight, fieldData.field.Operate(worldPosition), fieldData.opacity);
|
||||
//weight = math.lerp(weight, fieldData.field.Operate(worldPosition), fieldData.opacity);
|
||||
weight = FieldHelper.BlendField(weight, fieldData.field.Operate(worldPosition), fieldData.opacity, fieldData.blending);
|
||||
}
|
||||
|
||||
weight *= strength;
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Misaki.ArtTool
|
||||
{
|
||||
public class IterateEffectorBase : EffectorBase
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5144695703dc3434c93bc038017a3ac3
|
||||
@@ -21,21 +21,21 @@ namespace Misaki.ArtTool
|
||||
public float3 scale;
|
||||
public float uniformScale;
|
||||
|
||||
public override void Operate(int index, float4x4 nodeWorldMatrix, Span<PointData> points)
|
||||
public override PointData Operate(int index, float4x4 nodeWorldMatrix, ReadOnlySpan<PointData> points)
|
||||
{
|
||||
var currentPoint = points[index];
|
||||
if (!isEnablePosition && !isEnableRotation && !isEnableScale)
|
||||
{
|
||||
return;
|
||||
return currentPoint;
|
||||
}
|
||||
|
||||
var currentPoint = points[index];
|
||||
|
||||
MatrixHelper.DecomposeMatrix(currentPoint.matrix, out var position, out var rotation, out var scale);
|
||||
|
||||
var weight = CalculateFieldsWeight(position);
|
||||
if (weight == 0)
|
||||
{
|
||||
return;
|
||||
return currentPoint;
|
||||
}
|
||||
|
||||
if (isEnablePosition)
|
||||
@@ -96,7 +96,7 @@ namespace Misaki.ArtTool
|
||||
|
||||
currentPoint.matrix = float4x4.TRS(position, rotation, scale);
|
||||
|
||||
points[index] = currentPoint;
|
||||
return currentPoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,39 +10,37 @@ namespace Misaki.ArtTool
|
||||
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, Span<PointData> points)
|
||||
public override PointData Operate(int index, float4x4 nodeWorldMatrix, ReadOnlySpan<PointData> points)
|
||||
{
|
||||
var currentPoint = points[index];
|
||||
|
||||
var weight = CalculateFieldsWeight(currentPoint.matrix.c3.xyz);
|
||||
if (weight == 0)
|
||||
if (weight > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < iteration; i++)
|
||||
{
|
||||
for (var p = 0; p < points.Length; p++)
|
||||
for (var i = 0; i < iteration; i++)
|
||||
{
|
||||
if (index == p)
|
||||
for (var p = 0; p < points.Length; p++)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (index == p)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var targetPoint = points[p];
|
||||
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);
|
||||
currentPoint.matrix.c3.xyz += (radius - distance) * weight * direction;
|
||||
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);
|
||||
currentPoint.matrix.c3.xyz += (radius - distance) * weight * direction;
|
||||
|
||||
//Debug.Log($"Push at index {index} with distance {radius - distance} and direction {direction}");
|
||||
//Debug.Log($"Push at index {index} with distance {radius - distance} and direction {direction}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
points[index] = currentPoint;
|
||||
return currentPoint;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,15 +26,15 @@ namespace Misaki.ArtTool
|
||||
public float3 scaleMinMax;
|
||||
public float uniformScaleMinMax;
|
||||
|
||||
public override void Operate(int index, float4x4 nodeWorldMatrix, Span<PointData> points)
|
||||
public override PointData Operate(int index, float4x4 nodeWorldMatrix, ReadOnlySpan<PointData> points)
|
||||
{
|
||||
var currentPoint = points[index];
|
||||
|
||||
if (!isEnablePosition && !isEnableRotation && !isEnableScale)
|
||||
{
|
||||
return;
|
||||
return currentPoint;
|
||||
}
|
||||
|
||||
var currentPoint = points[index];
|
||||
|
||||
Random random;
|
||||
if (synchronized)
|
||||
{
|
||||
@@ -57,7 +57,7 @@ namespace Misaki.ArtTool
|
||||
var weight = CalculateFieldsWeight(position);
|
||||
if (weight == 0)
|
||||
{
|
||||
return;
|
||||
return currentPoint;
|
||||
}
|
||||
|
||||
if (isEnablePosition)
|
||||
@@ -121,7 +121,7 @@ namespace Misaki.ArtTool
|
||||
|
||||
currentPoint.matrix = float4x4.TRS(position, rotation, scale);
|
||||
|
||||
points[index] = currentPoint;
|
||||
return currentPoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
56
Runtime/Cloner/Helper/FieldHelper.cs
Normal file
56
Runtime/Cloner/Helper/FieldHelper.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace Misaki.ArtTool
|
||||
{
|
||||
internal class FieldHelper
|
||||
{
|
||||
public static float BlendField(float a, float b, float t, BlendingMode blendingMode)
|
||||
{
|
||||
var result = 0.0f;
|
||||
switch (blendingMode)
|
||||
{
|
||||
case BlendingMode.Normal:
|
||||
result = math.lerp(a, b, t);
|
||||
break;
|
||||
|
||||
case BlendingMode.Min:
|
||||
result = math.lerp(a, math.min(a, b), t);
|
||||
break;
|
||||
|
||||
case BlendingMode.Subtract:
|
||||
result = math.lerp(a, a - b, t);
|
||||
break;
|
||||
|
||||
case BlendingMode.Multiply:
|
||||
result = math.lerp(a, a * b, t);
|
||||
break;
|
||||
|
||||
case BlendingMode.Overlay:
|
||||
var o1 = 1.0f - 2.0f * (1.0f - a) * (1.0f - b);
|
||||
var o2 = 2.0f * a * b;
|
||||
var zeroOrOne = math.step(a, 0.5f);
|
||||
result = o2 * zeroOrOne + (1.0f - zeroOrOne) * o1;
|
||||
result = math.lerp(a, result, t);
|
||||
break;
|
||||
|
||||
case BlendingMode.Max:
|
||||
result = math.lerp(a, math.max(a, b), t);
|
||||
break;
|
||||
|
||||
case BlendingMode.Add:
|
||||
result = math.lerp(a, a + b, t);
|
||||
break;
|
||||
|
||||
case BlendingMode.Screen:
|
||||
result = 1.0f - (1.0f - b) * (1.0f - a);
|
||||
result = math.lerp(a, result, t);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/Cloner/Helper/FieldHelper.cs.meta
Normal file
2
Runtime/Cloner/Helper/FieldHelper.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b595dad6b33daab4cb33b42c0a7ee43c
|
||||
Reference in New Issue
Block a user