public static void CreateFill(float[] points, int numPoints, Vector3 offset, ref GPStroke subMesh) { Vector3[] p3D = new Vector3[numPoints]; for (int i = 0; i < numPoints; i++) { p3D[i].x = points[i * 5 + 0]; p3D[i].y = points[i * 5 + 1]; p3D[i].z = points[i * 5 + 2]; } Vector3 x = Vector3.right; Vector3 y = Vector3.up; Vector3 z = Vector3.forward; Matrix4x4 mat = Matrix4x4.identity; if (numPoints >= 3) { Vector3 p0 = p3D[0]; Vector3 p1 = p3D[numPoints / 3]; Vector3 p2 = p3D[2 * numPoints / 3]; x = (p1 - p0).normalized; y = (p2 - p1).normalized; if (x != y) { z = Vector3.Cross(x, y).normalized; x = Vector3.Cross(y, z).normalized; Vector4 pos = new Vector4(p0.x, p0.y, p0.z, 1); mat = new Matrix4x4(x, y, z, pos); } } Matrix4x4 invMat = mat.inverse; Vector3[] p3D2 = new Vector3[numPoints]; for (int i = 0; i < numPoints; i++) { p3D2[i] = invMat.MultiplyPoint(p3D[i]); } Vector2[] p = new Vector2[numPoints]; for (int i = 0; i < numPoints; i++) { p[i].x = p3D2[i].x; p[i].y = p3D2[i].y; } Triangulator.Triangulator.Triangulate(p, Triangulator.WindingOrder.CounterClockwise, out Vector2[] outputVertices, out int[] indices); Vector3[] positions = new Vector3[outputVertices.Length]; for (int i = 0; i < outputVertices.Length; i++) { positions[i] = mat.MultiplyPoint(new Vector3(outputVertices[i].x, outputVertices[i].y)) + offset; } subMesh.vertices = positions; subMesh.triangles = indices; }
public static void CreateStroke(float[] points, int numPoints, int lineWidth, Vector3 offset, ref GPStroke subMesh) { FreeDraw freeDraw = new FreeDraw(); for (int i = 0; i < numPoints; i++) { Vector3 position = new Vector3(points[i * 5 + 0] + offset.x, points[i * 5 + 1] + offset.y, points[i * 5 + 2] + offset.z); float ratio = lineWidth * 0.0006f * points[i * 5 + 3]; // pressure freeDraw.AddRawControlPoint(position, ratio); } subMesh.vertices = freeDraw.vertices; subMesh.triangles = freeDraw.triangles; }