Switch points generation from managed thread to unmanaged thread; Change Spline to NativeSpline; Add converter for DistributionMode and update cloner editor ui; Add MeshData type for object distribution calculation; Add ObjectDistributionSetting and ObjectDistributionCalculation(Vertex and Edge Mode);

This commit is contained in:
Misaki
2024-09-17 18:27:35 +09:00
parent 1c39403cbf
commit 0ae44d6139
23 changed files with 559 additions and 148 deletions

View File

@@ -1,6 +1,5 @@
using System;
using Unity.Mathematics;
using UnityEngine;
namespace Misaki.ArtTool
{
@@ -10,7 +9,6 @@ namespace Misaki.ArtTool
public int3 count;
public float3 spacing;
public GridShape shape;
[Range(0.0f, 1.0f)]
public float fill;
public readonly int DistributionCount => count.x * count.y * count.z;

View File

@@ -1,13 +1,14 @@
using System;
using UnityEngine;
namespace Misaki.ArtTool
{
[Serializable]
public struct ObjectDistributionSetting
{
public MeshFilter meshFilter;
public MeshData meshData;
public ObjectDistributionMode mode;
public int count;
public uint seed;
public bool alignNormal;
}
}
}

View File

@@ -8,7 +8,7 @@ namespace Misaki.ArtTool
[Serializable]
public struct SplineDistributionSetting
{
public SplineContainer spline;
public NativeSpline nativeSpline;
public int indexOffset;
@@ -26,14 +26,9 @@ namespace Misaki.ArtTool
{
get
{
if (spline == null)
{
return 0;
}
if (isSpacingMode)
{
return Mathf.FloorToInt(spline.CalculateLength() / spacing) + 1;
return Mathf.FloorToInt(splineLength / spacing) + 1;
}
else
{

View File

@@ -0,0 +1,76 @@
using System;
using Unity.Collections;
using Unity.Mathematics;
using UnityEngine;
namespace Misaki.ArtTool
{
public struct MeshData : IDisposable
{
public Bounds bounds;
public NativeArray<int> triangles;
public NativeArray<float4> tangents;
public NativeArray<float3> vertices;
public NativeList<int2> edges;
public int vertexCount;
public float4x4 worldMatrix;
public MeshData(MeshFilter meshFilter, Allocator allocator)
{
var mesh = meshFilter.sharedMesh;
bounds = mesh.bounds;
triangles = new(mesh.triangles.Length, allocator);
for (var i = 0; i < triangles.Length; i++)
{
triangles[i] = mesh.triangles[i];
}
tangents = new(mesh.tangents.Length, allocator);
for (var i = 0; i < tangents.Length; i++)
{
tangents[i] = mesh.tangents[i];
}
vertices = new(mesh.vertices.Length, allocator);
for (var i = 0; i < vertices.Length; i++)
{
vertices[i] = mesh.vertices[i];
}
vertexCount = mesh.vertexCount;
edges = new((int)(vertexCount * 1.5f), allocator);
for (var i = 0; i < triangles.Length; i += 3)
{
AddEdge(edges, triangles[i], triangles[i + 1]);
AddEdge(edges, triangles[i + 1], triangles[i + 2]);
AddEdge(edges, triangles[i + 2], triangles[i]);
}
worldMatrix = meshFilter.transform.localToWorldMatrix;
static void AddEdge(NativeList<int2> edges, int a, int b)
{
if (a < b)
{
edges.Add(new int2(a, b));
}
else
{
edges.Add(new int2(b, a));
}
}
}
public void Dispose()
{
triangles.Dispose();
tangents.Dispose();
vertices.Dispose();
edges.Dispose();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 211ceb887d371d946b4b6617e565d329