Upload project files
This commit is contained in:
98
Runtime/Cloner/Effector/PlainEffector.cs
Normal file
98
Runtime/Cloner/Effector/PlainEffector.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Misaki.ArtTool
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
public class PlainEffector : EffectorBase
|
||||
{
|
||||
public TransformSpace transformSpace;
|
||||
|
||||
public bool isEnablePosition;
|
||||
public float3 position;
|
||||
|
||||
public bool isEnableRotation;
|
||||
public float3 rotation;
|
||||
|
||||
public bool isEnableScale;
|
||||
public bool isAbsoluteScale;
|
||||
public bool isUniformScale;
|
||||
public float3 scale;
|
||||
public float uniformScale;
|
||||
|
||||
public override void Operate(int index, float4x4 nodeWorldMatrix, ReadOnlySpan<PointData> points, ref float4x4 pointWorldMatrix, ref bool isValid)
|
||||
{
|
||||
if (!isEnablePosition && !isEnableRotation && !isEnableScale)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MatrixHelper.DecomposeMatrix(pointWorldMatrix, out var position, out var rotation, out var scale);
|
||||
|
||||
var weight = CalculateFieldsWeight(pointWorldMatrix.c3.xyz);
|
||||
if (weight == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnablePosition)
|
||||
{
|
||||
var newPosition = position;
|
||||
switch (transformSpace)
|
||||
{
|
||||
case TransformSpace.Node:
|
||||
newPosition += this.position;
|
||||
break;
|
||||
case TransformSpace.Effector:
|
||||
newPosition += math.mul(effectorMatrix, new float4(this.position, 0)).xyz;
|
||||
break;
|
||||
case TransformSpace.Object:
|
||||
newPosition += math.mul(pointWorldMatrix, new float4(this.position, 0)).xyz;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
position = math.lerp(position, newPosition, weight);
|
||||
}
|
||||
|
||||
if (isEnableRotation)
|
||||
{
|
||||
var newRotation = rotation;
|
||||
switch (transformSpace)
|
||||
{
|
||||
case TransformSpace.Node:
|
||||
newRotation = math.mul(rotation, quaternion.EulerXYZ(math.radians(this.rotation)));
|
||||
break;
|
||||
case TransformSpace.Effector:
|
||||
newRotation = math.mul(rotation,
|
||||
quaternion.EulerXYZ(math.mul(effectorMatrix, new float4(math.radians(this.rotation), 0)).xyz));
|
||||
break;
|
||||
case TransformSpace.Object:
|
||||
newRotation = math.mul(rotation,
|
||||
quaternion.EulerXYZ(math.mul(pointWorldMatrix, new float4(math.radians(this.rotation), 0)).xyz));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
rotation = Quaternion.Lerp(rotation, newRotation, weight);
|
||||
}
|
||||
|
||||
if (isEnableScale)
|
||||
{
|
||||
var newScale = scale;
|
||||
if (isUniformScale)
|
||||
{
|
||||
newScale = isAbsoluteScale ? uniformScale : scale - uniformScale;
|
||||
}
|
||||
else
|
||||
{
|
||||
newScale = isAbsoluteScale ? this.scale : scale - this.scale;
|
||||
}
|
||||
scale = math.lerp(scale, newScale, weight);
|
||||
}
|
||||
|
||||
pointWorldMatrix = float4x4.TRS(position, rotation, scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/Cloner/Effector/PlainEffector.cs.meta
Normal file
2
Runtime/Cloner/Effector/PlainEffector.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6601a6a85943a3444a503fdeb1cba30e
|
||||
43
Runtime/Cloner/Effector/PushApartEffector.cs
Normal file
43
Runtime/Cloner/Effector/PushApartEffector.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace Misaki.ArtTool
|
||||
{
|
||||
public class PushApartEffector : EffectorBase
|
||||
{
|
||||
public float radius = 1.0f;
|
||||
public uint iteration = 10;
|
||||
|
||||
// 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)
|
||||
{
|
||||
var currentPoint = points[index];
|
||||
|
||||
var weight = CalculateFieldsWeight(pointWorldMatrix.c3.xyz);
|
||||
if (weight == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < iteration; i++)
|
||||
{
|
||||
for (var p = 0; p < points.Length; p++)
|
||||
{
|
||||
var targetPoint = points[p];
|
||||
|
||||
if (ReferenceEquals(currentPoint, targetPoint))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/Cloner/Effector/PushApartEffector.cs.meta
Normal file
2
Runtime/Cloner/Effector/PushApartEffector.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c74fdb9922181d940a34522dd3878624
|
||||
123
Runtime/Cloner/Effector/RandomEffector.cs
Normal file
123
Runtime/Cloner/Effector/RandomEffector.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
|
||||
namespace Misaki.ArtTool
|
||||
{
|
||||
public class RandomEffector : EffectorBase
|
||||
{
|
||||
public float2 minMax = new(-1.0f, 1.0f);
|
||||
|
||||
public bool synchronized;
|
||||
public uint seed = 123456;
|
||||
|
||||
public TransformSpace transformSpace;
|
||||
|
||||
public bool isEnablePosition;
|
||||
public float3 positionMinMax;
|
||||
|
||||
public bool isEnableRotation;
|
||||
public float3 rotationMinMax;
|
||||
|
||||
public bool isEnableScale;
|
||||
public bool isAbsoluteScale;
|
||||
public bool isUniformScale;
|
||||
public float3 scaleMinMax;
|
||||
public float uniformScaleMinMax;
|
||||
|
||||
public override void Operate(int index, float4x4 nodeWorldMatrix, ReadOnlySpan<PointData> points, ref float4x4 pointWorldMatrix, ref bool isValid)
|
||||
{
|
||||
if (!isEnablePosition && !isEnableRotation && !isEnableScale)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Random random;
|
||||
if (synchronized)
|
||||
{
|
||||
random = Random.CreateFromIndex(seed);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (index > uint.MaxValue - seed)
|
||||
{
|
||||
random = Random.CreateFromIndex(seed - (uint)index);
|
||||
}
|
||||
else
|
||||
{
|
||||
random = Random.CreateFromIndex(seed + (uint)index);
|
||||
}
|
||||
}
|
||||
|
||||
MatrixHelper.DecomposeMatrix(pointWorldMatrix, out var position, out var rotation, out var scale);
|
||||
|
||||
var weight = CalculateFieldsWeight(pointWorldMatrix.c3.xyz);
|
||||
if (weight == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnablePosition)
|
||||
{
|
||||
var newPosition = random.NextFloat3(positionMinMax * minMax.x, positionMinMax * minMax.y);
|
||||
|
||||
switch (transformSpace)
|
||||
{
|
||||
case TransformSpace.Effector:
|
||||
newPosition = math.mul(effectorMatrix, new float4(newPosition, 0.0f)).xyz;
|
||||
break;
|
||||
case TransformSpace.Object:
|
||||
newPosition = math.mul(pointWorldMatrix, new float4(newPosition, 0.0f)).xyz;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
position = math.lerp(position, position + newPosition, weight);
|
||||
}
|
||||
|
||||
if (isEnableRotation)
|
||||
{
|
||||
var angle = random.NextFloat3(rotationMinMax * minMax.x, rotationMinMax * minMax.y);
|
||||
|
||||
switch (transformSpace)
|
||||
{
|
||||
case TransformSpace.Effector:
|
||||
angle = math.mul(effectorMatrix, new float4(angle, 0.0f)).xyz;
|
||||
break;
|
||||
case TransformSpace.Object:
|
||||
angle = math.mul(pointWorldMatrix, new float4(angle, 0.0f)).xyz;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
var newRotation = quaternion.Euler(math.radians(angle));
|
||||
rotation = Quaternion.Lerp(rotation, math.mul(rotation, newRotation), weight);
|
||||
}
|
||||
|
||||
if (isEnableScale)
|
||||
{
|
||||
float3 newScale;
|
||||
if (isUniformScale)
|
||||
{
|
||||
var minScale = isAbsoluteScale ? uniformScaleMinMax : 1.0f + (uniformScaleMinMax - 1.0f) * minMax.x;
|
||||
var maxScale = isAbsoluteScale ? 0.0f : 1.0f + (uniformScaleMinMax - 1.0f) * minMax.y;
|
||||
|
||||
newScale = random.NextFloat(minScale, maxScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
var minScale = isAbsoluteScale ? scaleMinMax : 1.0f + ((scaleMinMax - 1.0f) * minMax.x);
|
||||
var maxScale = isAbsoluteScale ? 0.0f : 1.0f + ((scaleMinMax - 1.0f) * minMax.y);
|
||||
|
||||
newScale = random.NextFloat3(minScale, maxScale);
|
||||
}
|
||||
|
||||
scale = math.lerp(scale, scale + newScale, weight);
|
||||
}
|
||||
|
||||
pointWorldMatrix = float4x4.TRS(position, rotation, scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/Cloner/Effector/RandomEffector.cs.meta
Normal file
2
Runtime/Cloner/Effector/RandomEffector.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd224efbdb8a5bb41bdc7a5db7a08533
|
||||
Reference in New Issue
Block a user