/// <summary>
        /// This is the method that actually does the work.
        /// </summary>

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var pts          = new List <Rhino.Geometry.Point3d>();
            var obstructions = new List <Rhino.Geometry.Mesh>();
            var rays         = new List <Rhino.Geometry.Vector3d>();
            var hitCount     = new List <int>();

            if (!DA.GetDataList(0, pts))
            {
                return;
            }
            if (!DA.GetDataList(1, obstructions))
            {
                return;
            }
            if (!DA.GetDataList(2, rays))
            {
                return;
            }

            var scene = EmbreeTools.BuildScene(obstructions);

            if (rays.Count < 25) // Needs more benchmarking to pick right value
            {
                hitCount = EmbreeTools.OcclusionHits(scene, pts, rays, true);
            }
            else
            {
                hitCount = EmbreeTools.OcclusionHits4(scene, pts, rays, true);
            }

            DA.SetDataList(0, hitCount);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var pts          = new List <Rhino.Geometry.Point3d>();
            var obstructions = new List <Rhino.Geometry.Mesh>();
            var directions   = new List <Rhino.Geometry.Vector3d>();


            if (!DA.GetDataList(0, obstructions))
            {
                return;
            }
            if (!DA.GetDataList(1, pts))
            {
                return;
            }
            if (!DA.GetDataList(2, directions))
            {
                return;
            }

            var hitList = new List <bool>();

            var scene = EmbreeTools.BuildScene(obstructions);
            var intersectionPoints = EmbreeTools.Intersections(scene, pts, directions, ref hitList);

            DA.SetDataList(0, intersectionPoints);
            DA.SetDataList(1, hitList);
        }
Exemple #3
0
        public static bool TestIntersect(Mesh meshA, Mesh meshB, ref Point3d pt, bool fast = true)
        {
            bool meshInterects = false;

            bool bboxIntersection = TestBBIntersect(meshA, meshB);

            if (!bboxIntersection)
            {
                return(false); // if bounding boxes don't intersect then meshes don't interesect
            }
            Mesh largeMesh;
            Mesh smallMesh;

            if (meshA.Faces.Count > meshB.Faces.Count)
            {
                largeMesh = meshA;
                smallMesh = meshB;
            }
            else
            {
                largeMesh = meshB;
                smallMesh = meshA;
            }

            var scene = EmbreeTools.BuildScene(largeMesh);

            var meshVertices = smallMesh.Vertices.ToPoint3fArray();

            foreach (var face in smallMesh.Faces)
            {
                int numVertices = face.IsTriangle ? 3 : 4;
                for (int v = 0; v < numVertices; v++)
                {
                    var  ray    = RayFromVertices(meshVertices[face[v]], meshVertices[face[(v + 1) % numVertices]]);
                    var  packet = scene.Intersects(ray.Item1, 0, ray.Item2);
                    bool hit    = (packet.geomID != RTC.InvalidGeometryID);
                    if (hit)
                    {
                        meshInterects = true;
                        var intersect = packet.ToIntersection <Model>(scene);
                        var hitPos    = ray.Item1.PointAt(intersect.Distance);
                        pt = new Rhino.Geometry.Point3d(hitPos.X, hitPos.Y, hitPos.Z);
                        break;
                    }
                }
                if (meshInterects)
                {
                    break;
                }
            }

            return(meshInterects);
        }