Finished the code for radial distribution
This commit is contained in:
@@ -17,14 +17,11 @@ namespace Misaki.ArtTool
|
||||
break;
|
||||
|
||||
case GridShape.Sphere:
|
||||
var isInsideSphere = ShapeHelper.IsPointInsideSphere(localPosition, 0.0f, setting.count * setting.spacing);
|
||||
|
||||
isValid = isInsideSphere;
|
||||
isValid = ShapeHelper.IsPointInsideSphere(localPosition, 0.0f, setting.count * setting.spacing);
|
||||
break;
|
||||
|
||||
case GridShape.Cylinder:
|
||||
var isInsideCylinder = ShapeHelper.IsPointInsideCylinder(localPosition, 0.0f, setting.count * setting.spacing);
|
||||
isValid = isInsideCylinder;
|
||||
isValid = ShapeHelper.IsPointInsideCylinder(localPosition, 0.0f, setting.count * setting.spacing);
|
||||
break;
|
||||
default:
|
||||
isValid = false;
|
||||
|
||||
@@ -1,80 +1,39 @@
|
||||
using Unity.Mathematics;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
|
||||
namespace Misaki.ArtTool
|
||||
{
|
||||
public static partial class Distribution
|
||||
{
|
||||
public static void ObjectDistribution(int index, ObjectDistributionSetting setting, out float4x4 localMatrix, out bool isValid)
|
||||
public static void ObjectDistribution(int index, ref ObjectDistributionSetting setting, out float4x4 localMatrix, out bool isValid)
|
||||
{
|
||||
var random = new Random();
|
||||
if (index > uint.MaxValue - setting.seed)
|
||||
{
|
||||
random = Random.CreateFromIndex(setting.seed - (uint)index);
|
||||
}
|
||||
else
|
||||
{
|
||||
random = Random.CreateFromIndex(setting.seed + (uint)index);
|
||||
}
|
||||
|
||||
var position = float3.zero;
|
||||
var forwardDirection = new float3(0.0f, 0.0f, 1.0f);
|
||||
var upDirection = new float3(0.0f, 1.0f, 0.0f);
|
||||
isValid = false;
|
||||
localMatrix = float4x4.identity;
|
||||
|
||||
switch (setting.mode)
|
||||
{
|
||||
case ObjectDistributionMode.Surface:
|
||||
isValid = ShapeHelper.TryGetMatrixOnMeshSurface(index, setting.seed, setting.isAlignNormal, ref setting.meshData, out localMatrix);
|
||||
break;
|
||||
|
||||
case ObjectDistributionMode.Volume:
|
||||
|
||||
var meshScale = setting.meshData.worldMatrix.GetScale();
|
||||
var meshPosition = setting.meshData.worldMatrix.c3.xyz;
|
||||
|
||||
position = random.NextFloat3(-setting.meshData.bounds.extents * meshScale + meshPosition, setting.meshData.bounds.extents * meshScale + meshPosition);
|
||||
|
||||
var isInsideMesh = ShapeHelper.IsPointInsideMesh(position, ref setting.meshData);
|
||||
while (!isInsideMesh)
|
||||
{
|
||||
position = random.NextFloat3(-setting.meshData.bounds.extents * meshScale + meshPosition, setting.meshData.bounds.extents * meshScale + meshPosition);
|
||||
isInsideMesh = ShapeHelper.IsPointInsideMesh(position, ref setting.meshData);
|
||||
}
|
||||
isValid = true;
|
||||
isValid = ShapeHelper.TryGetPositionInMeshVolume(index, setting.seed, ref setting.meshData, out localMatrix);
|
||||
break;
|
||||
|
||||
case ObjectDistributionMode.Vertex:
|
||||
if (ShapeHelper.GetMeshVertexPosition(index, ref setting.meshData, out var vertexPosition))
|
||||
{
|
||||
position = vertexPosition;
|
||||
isValid = true;
|
||||
}
|
||||
isValid = ShapeHelper.TryGetMeshVertexMatrix(index, setting.isAlignNormal, ref setting.meshData, out localMatrix);
|
||||
break;
|
||||
|
||||
case ObjectDistributionMode.Edge:
|
||||
if (ShapeHelper.GetMeshEdgePosition(index, ref setting.meshData, out var edgePosition, out var edgeForward, out var edgeUp))
|
||||
{
|
||||
position = edgePosition;
|
||||
forwardDirection = edgeForward;
|
||||
upDirection = edgeUp;
|
||||
isValid = true;
|
||||
}
|
||||
isValid = ShapeHelper.TryGetMeshEdgeMatrix(index, setting.isAlignNormal, ref setting.meshData, out localMatrix);
|
||||
break;
|
||||
|
||||
case ObjectDistributionMode.PolygonCenter:
|
||||
if (ShapeHelper.GetMeshPolygonPosition(index, ref setting.meshData, out var polygonPosition))
|
||||
{
|
||||
position = polygonPosition;
|
||||
isValid = true;
|
||||
}
|
||||
isValid = ShapeHelper.TryGetMeshPolygonMatrix(index, setting.isAlignNormal, ref setting.meshData, out localMatrix);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
var rotation = quaternion.LookRotationSafe(forwardDirection, upDirection);
|
||||
|
||||
localMatrix = float4x4.TRS(position, rotation, new float3(1.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Runtime/Cloner/Distribution/RadialDistribution.cs
Normal file
13
Runtime/Cloner/Distribution/RadialDistribution.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace Misaki.ArtTool
|
||||
{
|
||||
public static partial class Distribution
|
||||
{
|
||||
public static void RadialDistribution(int index, RadialDistributionSetting setting, out float4x4 localMatrix, out bool isValid)
|
||||
{
|
||||
localMatrix = ShapeHelper.GetRadialMatrix(index, setting);
|
||||
isValid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/Cloner/Distribution/RadialDistribution.cs.meta
Normal file
2
Runtime/Cloner/Distribution/RadialDistribution.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c448aeab246b714458fee8084dd0974c
|
||||
Reference in New Issue
Block a user