Example #1
0
        private MeshUtils.Edge[] FindPrincipalEdges(Collide.Shape shape, float principalEdgeExtension)
        {
            if (shape != null && shape.GetUtils() != null)
            {
                return(shape.GetUtils().GetPrincipalEdgesWorld(principalEdgeExtension));
            }

            Mesh mesh = shape is Collide.Mesh ?
                        (shape as Collide.Mesh).SourceObjects.FirstOrDefault() :
                        Target.GetComponent <MeshFilter>() != null?
                        Target.GetComponent <MeshFilter>().sharedMesh:
                        null;

            Vector3 halfExtents = 0.5f * Vector3.one;

            if (mesh != null)
            {
                halfExtents = mesh.bounds.extents;
            }

            MeshUtils.Edge[] edges = ShapeUtils.ExtendAndTransformEdgesToWorld(Target.transform,
                                                                               new MeshUtils.Edge[]
            {
                new MeshUtils.Edge(BoxShapeUtils.GetLocalFace(halfExtents, ShapeUtils.Direction.Negative_X),
                                   BoxShapeUtils.GetLocalFace(halfExtents, ShapeUtils.Direction.Positive_X),
                                   ShapeUtils.GetLocalFaceDirection(ShapeUtils.Direction.Positive_Y),
                                   MeshUtils.Edge.EdgeType.Principal),
                new MeshUtils.Edge(BoxShapeUtils.GetLocalFace(halfExtents, ShapeUtils.Direction.Negative_Y),
                                   BoxShapeUtils.GetLocalFace(halfExtents, ShapeUtils.Direction.Positive_Y),
                                   ShapeUtils.GetLocalFaceDirection(ShapeUtils.Direction.Positive_Z),
                                   MeshUtils.Edge.EdgeType.Principal),
                new MeshUtils.Edge(BoxShapeUtils.GetLocalFace(halfExtents, ShapeUtils.Direction.Negative_Z),
                                   BoxShapeUtils.GetLocalFace(halfExtents, ShapeUtils.Direction.Positive_Z),
                                   ShapeUtils.GetLocalFaceDirection(ShapeUtils.Direction.Positive_X),
                                   MeshUtils.Edge.EdgeType.Principal)
            },
                                                                               principalEdgeExtension);

            return(edges);
        }