private static void AssertExpectedPlane(BoundedPlane plane, Vector3 bounds, Matrix4x4 vertDataTransform, Matrix4x4 meshTransform) { float expectedArea = 4.0f * bounds.x * bounds.y; Vector3 expectedPlaneNormal = meshTransform.TransformDirection(vertDataTransform.TransformDirection(new Vector3(0, 0, 1))); Vector3 expectedPlaneCenter = meshTransform.TransformPoint(vertDataTransform.TransformPoint(Vector3.zero)); Assert.AreEqual(expectedArea, plane.Area, expectedArea * 0.01f); AssertAreEqual(expectedPlaneNormal, plane.Plane.normal, 0.01f, "Normal"); AssertAreEqual(expectedPlaneCenter, plane.Bounds.Center, bounds.Length() * 0.01f, "Center"); }
/// <summary> /// Helper function that creates a simple mesh for use in the PlaneFinding API. The mesh is built as tesselated /// quad spanning the x and y dimensions of the specified Bounds. Each vert in the mesh is randomly perturbed /// along the z axis with in the specified Bounds. This results in a somewhat more realistic noisy planar mesh /// that simulates the sort of data we might get from SR. /// </summary> /// public static PlaneFinding.MeshData CreateSimpleMesh(int dimension, Vector3 bounds, Matrix4x4 vertDataTransform, Matrix4x4 meshTransform) { System.Random r = new System.Random(); Vector3[] vertices = Enumerable.Range(0, dimension + 1) .SelectMany(x => Enumerable.Range(0, dimension + 1) .Select(y => new Vector3( bounds.x * (2.0f * (float)x / (float)(dimension) - 1.0f), bounds.y * (2.0f * (float)y / (float)(dimension) - 1.0f), bounds.z * (2.0f * (float)r.NextDouble() - 1.0f)) ) ) .Select(p => vertDataTransform.TransformPoint(p)) .ToArray(); Vector3[] normals = Enumerable.Repeat(new Vector3(0, 0, 1), (dimension + 1) * (dimension + 1)) .Select(n => vertDataTransform.TransformDirection(n)) .ToArray(); int[] indices = Enumerable.Range(0, dimension) .SelectMany(x => Enumerable.Range(0, dimension) .SelectMany(y => new int[] { ((dimension + 1) * (x + 0) + (y + 0)), ((dimension + 1) * (x + 1) + (y + 0)), ((dimension + 1) * (x + 0) + (y + 1)), ((dimension + 1) * (x + 0) + (y + 1)), ((dimension + 1) * (x + 1) + (y + 0)), ((dimension + 1) * (x + 1) + (y + 1)), }) ).ToArray(); PlaneFinding.MeshData mesh = new PlaneFinding.MeshData(); mesh.Transform = meshTransform; mesh.Verts = vertices; mesh.Normals = normals; mesh.Indices = indices; return mesh; }
public Vector3 TransformPoint(Vector3 point) { return(localToWorldMatrix.TransformPoint(point)); }