Added object distributuon calculationg
This commit is contained in:
@@ -52,5 +52,19 @@ namespace Misaki.ArtTool
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float ApplyRemapping(float weight, ref RemappingSetting remappingSetting)
|
||||
{
|
||||
if (!remappingSetting.enable)
|
||||
{
|
||||
return weight;
|
||||
}
|
||||
|
||||
weight = math.saturate(weight / (1.0f - remappingSetting.innerOffset));
|
||||
weight = math.lerp(remappingSetting.min, remappingSetting.max, weight);
|
||||
weight = remappingSetting.invert ? 1.0f - weight : weight;
|
||||
weight *= remappingSetting.strength;
|
||||
return weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Misaki.ArtTool
|
||||
{
|
||||
internal static partial class ShapeHelper
|
||||
{
|
||||
internal static float3 GetCubePosition(int index, int3 size)
|
||||
internal static float3 GetCubePosition(int index, float3 size)
|
||||
{
|
||||
float3 localPosition;
|
||||
var yIndex = index / (size.x * size.z);
|
||||
@@ -13,38 +13,96 @@ namespace Misaki.ArtTool
|
||||
var xIndex = remain % size.x;
|
||||
|
||||
localPosition = new float3(xIndex, yIndex, zIndex);
|
||||
localPosition -= (float3)(size - 1) * 0.5f;
|
||||
localPosition -= (size - 1) * 0.5f;
|
||||
return localPosition;
|
||||
}
|
||||
|
||||
internal static bool GetMeshVertexPosition(int index, MeshData meshData, out float3 position)
|
||||
internal static bool GetMeshVertexPosition(int index, ref MeshData meshData, out float3 position)
|
||||
{
|
||||
position = float3.zero;
|
||||
|
||||
if (!meshData.vertices.IsCreated || meshData.vertices.Length <= index)
|
||||
{
|
||||
position = float3.zero;
|
||||
return false;
|
||||
}
|
||||
|
||||
position = meshData.vertices[index];
|
||||
var meshScale = meshData.worldMatrix.GetScale();
|
||||
var meshPosition = meshData.worldMatrix.c3.xyz;
|
||||
|
||||
if (index >= meshData.vertices.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
position = meshData.vertices[index] * meshScale + meshPosition;
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static bool GetMeshEdgePosition(int index, MeshData meshData, out float3 position)
|
||||
internal static bool GetMeshEdgePosition(int index, ref MeshData meshData, out float3 position, out float3 forwardDirection, out float3 upDirection)
|
||||
{
|
||||
if (!meshData.edges.IsCreated || meshData.edges.Length <= index)
|
||||
position = float3.zero;
|
||||
forwardDirection = new float3(0.0f, 0.0f, 1.0f);
|
||||
upDirection = new float3(0.0f, 1.0f, 0.0f);
|
||||
|
||||
if (!meshData.edges.IsCreated || index >= meshData.edges.Length)
|
||||
{
|
||||
position = float3.zero;
|
||||
return false;
|
||||
}
|
||||
|
||||
var edge = meshData.edges[index];
|
||||
if (meshData.vertices.Length <= edge.x || meshData.vertices.Length <= edge.y)
|
||||
if (edge.x >= meshData.vertices.Length || edge.y >= meshData.vertices.Length)
|
||||
{
|
||||
position = float3.zero;
|
||||
return false;
|
||||
}
|
||||
|
||||
position = (meshData.vertices[edge.x] + meshData.vertices[edge.y]) / 2.0f;
|
||||
var meshScale = meshData.worldMatrix.GetScale();
|
||||
var meshPosition = meshData.worldMatrix.c3.xyz;
|
||||
|
||||
var a = meshData.vertices[edge.x] * meshScale + meshPosition;
|
||||
var b = meshData.vertices[edge.y] * meshScale + meshPosition;
|
||||
|
||||
position = (a + b) / 2.0f;
|
||||
forwardDirection = a - b;
|
||||
|
||||
var interpNormal = math.normalize(meshData.normals[edge.x] + meshData.normals[edge.y]);
|
||||
upDirection = math.normalize(math.cross(interpNormal, new float3(1.0f, 0.0f, 0.0f)));
|
||||
|
||||
if (math.all(upDirection <= float3.zero))
|
||||
{
|
||||
upDirection = math.normalize(math.cross(interpNormal, new float3(0.0f, 0.0f, 1.0f)));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static bool GetMeshPolygonPosition(int index, ref MeshData meshData, out float3 position)
|
||||
{
|
||||
position = float3.zero;
|
||||
|
||||
if (!meshData.edges.IsCreated || meshData.edges.Length <= index)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var meshScale = meshData.worldMatrix.GetScale();
|
||||
var meshPosition = meshData.worldMatrix.c3.xyz;
|
||||
|
||||
var triangleIndex = index * 3;
|
||||
|
||||
if (triangleIndex >= meshData.triangles.Length - 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var pointIndexA = meshData.triangles[triangleIndex];
|
||||
var pointIndexB = meshData.triangles[triangleIndex + 1];
|
||||
var pointIndexC = meshData.triangles[triangleIndex + 2];
|
||||
|
||||
var a = meshData.vertices[pointIndexA] * meshScale + meshPosition;
|
||||
var b = meshData.vertices[pointIndexB] * meshScale + meshPosition;
|
||||
var c = meshData.vertices[pointIndexC] * meshScale + meshPosition;
|
||||
|
||||
position = (a + b + c) / 3.0f;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,15 +41,17 @@ namespace Misaki.ArtTool
|
||||
return withinRadius && withinHeight;
|
||||
}
|
||||
|
||||
internal static bool IsPointInsideMesh(float3 pointPosition, float3 meshPosition, MeshData meshData)
|
||||
internal static bool IsPointInsideMesh(float3 pointPosition, ref MeshData meshData)
|
||||
{
|
||||
var windingNumber = 0;
|
||||
var meshScale = meshData.worldMatrix.GetScale();
|
||||
var meshPosition = meshData.worldMatrix.c3.xyz;
|
||||
|
||||
for (var i = 0; i < meshData.triangles.Length; i += 3)
|
||||
{
|
||||
var v1 = meshData.vertices[meshData.triangles[i]];
|
||||
var v2 = meshData.vertices[meshData.triangles[i + 1]];
|
||||
var v3 = meshData.vertices[meshData.triangles[i + 2]];
|
||||
var v1 = meshData.vertices[meshData.triangles[i]] * meshScale + meshPosition;
|
||||
var v2 = meshData.vertices[meshData.triangles[i + 1]] * meshScale + meshPosition;
|
||||
var v3 = meshData.vertices[meshData.triangles[i + 2]] * meshScale + meshPosition;
|
||||
|
||||
if (IsPointInsideTriangle(pointPosition, v1, v2, v3))
|
||||
{
|
||||
@@ -57,9 +59,10 @@ namespace Misaki.ArtTool
|
||||
}
|
||||
}
|
||||
|
||||
return windingNumber % 2 != 0;
|
||||
return windingNumber % 2 == 0;
|
||||
}
|
||||
|
||||
//TODO: Fix it
|
||||
private static bool IsPointInsideTriangle(float3 point, float3 a, float3 b, float3 c)
|
||||
{
|
||||
var v0 = c - a;
|
||||
@@ -76,7 +79,7 @@ namespace Misaki.ArtTool
|
||||
var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
|
||||
var v = (dot00 * dot12 - dot01 * dot02) * invDenom;
|
||||
|
||||
return (u >= 0) && (v >= 0) && (u + v < 1.0f);
|
||||
return (u >= 0) && (v >= 0) && (u + v < 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user