Finished the code for radial distribution
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Misaki.ArtTool
|
||||
public ObjectDistributionMode mode;
|
||||
public uint count;
|
||||
public uint seed;
|
||||
public bool alignNormal;
|
||||
public bool isAlignNormal;
|
||||
|
||||
public int DistributionCount
|
||||
{
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace Misaki.ArtTool
|
||||
{
|
||||
[Serializable]
|
||||
public struct RadialDistributionSetting
|
||||
{
|
||||
public uint count;
|
||||
public float radius;
|
||||
public PlaneDirection plane;
|
||||
public float2 angleMinMax;
|
||||
public bool align;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 577cc0a461b273d42be5e22ecc600d8a
|
||||
@@ -17,6 +17,10 @@ namespace Misaki.ArtTool
|
||||
public NativeArray<float3> vertices;
|
||||
[ReadOnly]
|
||||
public NativeList<int2> edges;
|
||||
[ReadOnly]
|
||||
public NativeArray<float> areas;
|
||||
|
||||
public float totalArea;
|
||||
|
||||
public int vertexCount;
|
||||
|
||||
@@ -31,6 +35,9 @@ namespace Misaki.ArtTool
|
||||
vertices = new(0, allocator);
|
||||
edges = new(0, allocator);
|
||||
|
||||
areas = new(0, allocator);
|
||||
totalArea = 0.0f;
|
||||
|
||||
vertexCount = 0;
|
||||
worldMatrix = float4x4.identity;
|
||||
}
|
||||
@@ -69,17 +76,37 @@ namespace Misaki.ArtTool
|
||||
AddEdge(edges, triangles[i + 2], triangles[i]);
|
||||
}
|
||||
|
||||
areas = new(mesh.triangles.Length / 3, allocator);
|
||||
totalArea = 0.0f;
|
||||
for (var i = 0; i < triangles.Length; i += 3)
|
||||
{
|
||||
Vector3 v0 = vertices[triangles[i]];
|
||||
Vector3 v1 = vertices[triangles[i + 1]];
|
||||
Vector3 v2 = vertices[triangles[i + 2]];
|
||||
var area = Vector3.Cross(v1 - v0, v2 - v0).magnitude * 0.5f;
|
||||
areas[i / 3] = area;
|
||||
totalArea += area;
|
||||
}
|
||||
|
||||
worldMatrix = meshFilter.transform.localToWorldMatrix;
|
||||
|
||||
static void AddEdge(NativeList<int2> edges, int a, int b)
|
||||
{
|
||||
if (a < b)
|
||||
{
|
||||
edges.Add(new int2(a, b));
|
||||
var edge = new int2(a, b);
|
||||
if (!edges.Contains(edge))
|
||||
{
|
||||
edges.Add(edge);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
edges.Add(new int2(b, a));
|
||||
var edge = new int2(b, a);
|
||||
if (!edges.Contains(edge))
|
||||
{
|
||||
edges.Add(edge);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,6 +117,7 @@ namespace Misaki.ArtTool
|
||||
normals.Dispose();
|
||||
vertices.Dispose();
|
||||
edges.Dispose();
|
||||
areas.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,38 +4,9 @@ using Unity.Mathematics;
|
||||
namespace Misaki.ArtTool
|
||||
{
|
||||
[Serializable]
|
||||
public struct PointData : IEquatable<PointData>
|
||||
public struct PointData
|
||||
{
|
||||
public bool isValid;
|
||||
public float4x4 matrix;
|
||||
|
||||
public bool Equals(PointData other)
|
||||
{
|
||||
return isValid == other.isValid && Equals(matrix, other.matrix);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is PointData other)
|
||||
{
|
||||
return Equals(other);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(isValid, matrix);
|
||||
}
|
||||
|
||||
public static bool operator ==(PointData left, PointData right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(PointData left, PointData right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user