public static void test_AxisAlignedBox3() { Random r = new Random(31337); for (int iter = 0; iter < 10000; ++iter) { Vector3d[] pts = TestUtil.RandomPoints3(100, r, Vector3d.Zero, 100); for (int j = 0; j < pts.Length; j += 2) { AxisAlignedBox3d box1 = new AxisAlignedBox3d(pts[j], 10.0); AxisAlignedBox3d box2 = new AxisAlignedBox3d(pts[j + 1], 20); double dist_sqr = box1.DistanceSquared(ref box2); if (box1.Intersects(box2)) { Util.gDevAssert(dist_sqr == 0); } else { Util.gDevAssert(dist_sqr > 0); } dist_sqr -= MathUtil.ZeroTolerance; // numericals for (int k = 0; k < 8; ++k) { Vector3d p0 = box1.Corner(k); Util.gDevAssert(dist_sqr < p0.DistanceSquared(box2.Center)); for (int i = 0; i < 8; ++i) { Util.gDevAssert(dist_sqr <= p0.DistanceSquared(box2.Corner(i))); } } } } }
public static void CalculateUVs(this DMesh3 dMesh) { dMesh.EnableVertexUVs(Vector2f.Zero); OrthogonalPlaneFit3 orth = new OrthogonalPlaneFit3(dMesh.Vertices()); Frame3f frame = new Frame3f(orth.Origin, orth.Normal); AxisAlignedBox3d bounds = dMesh.CachedBounds; AxisAlignedBox2d boundsInFrame = new AxisAlignedBox2d(); for (int i = 0; i < 8; i++) { boundsInFrame.Contain(frame.ToPlaneUV((Vector3f)bounds.Corner(i), 3)); } Vector2f min = (Vector2f)boundsInFrame.Min; float width = (float)boundsInFrame.Width; float height = (float)boundsInFrame.Height; for (int i = 0; i < dMesh.VertexCount; i++) { Vector2f UV = frame.ToPlaneUV((Vector3f)dMesh.GetVertex(i), 3); UV.x = (UV.x - min.x) / width; UV.y = (UV.y - min.y) / height; dMesh.SetVertexUV(i, UV); } }