Upload project files
This commit is contained in:
55
Runtime/Cloner/Distribution/GridDistribution.cs
Normal file
55
Runtime/Cloner/Distribution/GridDistribution.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace Misaki.ArtTool
|
||||
{
|
||||
public static partial class Distribution
|
||||
{
|
||||
public static void GridDistribution(int index, GridDistributionSetting setting, out float4x4 localMatrix, out bool isValid)
|
||||
{
|
||||
var random = Random.CreateFromIndex((uint)index);
|
||||
|
||||
var localPosition = GetCubePosition(index, setting.count) * setting.spacing;
|
||||
|
||||
switch (setting.shape)
|
||||
{
|
||||
case GridShape.Cube:
|
||||
isValid = true;
|
||||
break;
|
||||
|
||||
case GridShape.Sphere:
|
||||
var isInsideSphere = ShapeHelper.IsInsideSphere(localPosition, 0.0f, setting.count * setting.spacing);
|
||||
|
||||
isValid = isInsideSphere;
|
||||
break;
|
||||
|
||||
case GridShape.Cylinder:
|
||||
var isInsideCylinder = ShapeHelper.IsInsideCylinder(localPosition, 0.0f, setting.count * setting.spacing);
|
||||
isValid = isInsideCylinder;
|
||||
break;
|
||||
default:
|
||||
isValid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (random.NextFloat() > setting.fill && isValid == true)
|
||||
{
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
localMatrix = float4x4.TRS(localPosition, quaternion.identity, new float3(1.0f));
|
||||
}
|
||||
|
||||
private static float3 GetCubePosition(int index, int3 size)
|
||||
{
|
||||
float3 localPosition;
|
||||
var yIndex = index / (size.x * size.z);
|
||||
var remain = index % (size.x * size.z);
|
||||
var zIndex = remain / size.x;
|
||||
var xIndex = remain % size.x;
|
||||
|
||||
localPosition = new float3(xIndex, yIndex, zIndex);
|
||||
localPosition -= (float3)(size - 1) * 0.5f;
|
||||
return localPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/Cloner/Distribution/GridDistribution.cs.meta
Normal file
2
Runtime/Cloner/Distribution/GridDistribution.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 776811becd42a27408b353bb0cc8e54e
|
||||
21
Runtime/Cloner/Distribution/LinearDistribution.cs
Normal file
21
Runtime/Cloner/Distribution/LinearDistribution.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace Misaki.ArtTool
|
||||
{
|
||||
public static partial class Distribution
|
||||
{
|
||||
public static void LinearDistribution(int index, LinearDistributionSetting setting, out float4x4 localMatrix, out bool isValid)
|
||||
{
|
||||
var pointIndex = (uint)index + setting.indexOffset;
|
||||
var localPosition = pointIndex * setting.positionSpacing;
|
||||
var localEulerRotation = pointIndex * setting.rotationSpacing;
|
||||
var localScale = 1.0f - (pointIndex * (1.0f - setting.scaleSpacing));
|
||||
|
||||
localPosition = math.mul(float3x3.EulerXYZ(math.radians(setting.stepRotation * pointIndex)), localPosition);
|
||||
var localRotation = math.mul(quaternion.EulerXYZ(math.radians(localEulerRotation)), quaternion.EulerXYZ(math.radians(setting.stepRotation * pointIndex)));
|
||||
|
||||
localMatrix = float4x4.TRS(localPosition, localRotation, localScale);
|
||||
isValid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/Cloner/Distribution/LinearDistribution.cs.meta
Normal file
2
Runtime/Cloner/Distribution/LinearDistribution.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6bf561350efd524a9a65100521eb388
|
||||
47
Runtime/Cloner/Distribution/SplineDistribution.cs
Normal file
47
Runtime/Cloner/Distribution/SplineDistribution.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine.Splines;
|
||||
|
||||
namespace Misaki.ArtTool
|
||||
{
|
||||
public static partial class Distribution
|
||||
{
|
||||
public static void SplineDistribution(int index, int pointSize, float splineLength, float4x4 splineWorldMatrix, SplineDistributionSetting setting, out float4x4 localMatrix, out bool isValid)
|
||||
{
|
||||
var pointIndex = index + setting.indexOffset;
|
||||
|
||||
|
||||
if (pointIndex > pointSize)
|
||||
{
|
||||
localMatrix = float4x4.zero;
|
||||
isValid = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var spline = setting.spline;
|
||||
float t;
|
||||
|
||||
if (setting.isSpacingMode)
|
||||
{
|
||||
t = (pointIndex * setting.spacing) / splineLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
t = pointIndex / (float)(pointSize - 1);
|
||||
}
|
||||
|
||||
if (SplineUtility.Evaluate(spline.Spline, t, out var position, out var normal, out var upVector))
|
||||
{
|
||||
var localRotation = quaternion.LookRotationSafe(normal, upVector);
|
||||
|
||||
localMatrix = math.mul(splineWorldMatrix, float4x4.TRS(position, localRotation, new float3(1.0f)));
|
||||
isValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
localMatrix = float4x4.zero;
|
||||
isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/Cloner/Distribution/SplineDistribution.cs.meta
Normal file
2
Runtime/Cloner/Distribution/SplineDistribution.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 843f013f896d37543a4d48166e71b6b6
|
||||
Reference in New Issue
Block a user