Exemple #1
0
        public bool IntersectsMesh(TransformMatrix thisTransform, Octave3DMesh otherMesh, TransformMatrix otherTransform)
        {
            OrientedBox thisOOBB = new OrientedBox(ModelAABB);

            thisOOBB.Transform(thisTransform);
            OrientedBox otherOOBB = new OrientedBox(otherMesh.ModelAABB);

            otherOOBB.Transform(otherTransform);

            if (!thisOOBB.Intersects(otherOOBB))
            {
                return(false);
            }

            List <Triangle3D> thisTriangles = GetOverlappedTriangles(otherOOBB, thisTransform);

            for (int thisTriIndex = 0; thisTriIndex < thisTriangles.Count; ++thisTriIndex)
            {
                Triangle3D        thisTri        = thisTriangles[thisTriIndex];
                OrientedBox       thisTriOOBB    = new OrientedBox(thisTri.GetEncapsulatingBox());
                List <Triangle3D> otherTriangles = otherMesh.GetOverlappedTriangles(thisTriOOBB, otherTransform);
                for (int otherTriIndex = 0; otherTriIndex < otherTriangles.Count; ++otherTriIndex)
                {
                    Triangle3D otherTri = otherTriangles[otherTriIndex];
                    if (thisTri.IntersectsTriangle(otherTri))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public bool BoxIntersectsAnyObjectBoxes(OrientedBox box, HashSet <GameObject> ignoreObjects, bool allowFaceTouch)
        {
            if (ignoreObjects == null)
            {
                ignoreObjects = new HashSet <GameObject>();
            }
            List <SphereTreeNode <GameObject> > allOverlappedNodes = _sphereTree.OverlapBox(box);

            if (allOverlappedNodes.Count == 0)
            {
                return(false);
            }

            var overlappedObjects = new List <GameObject>();

            foreach (SphereTreeNode <GameObject> node in allOverlappedNodes)
            {
                GameObject gameObject = node.Data;
                if (gameObject == null)
                {
                    continue;
                }
                if (!gameObject.activeSelf)
                {
                    continue;
                }
                if (ignoreObjects.Contains(gameObject))
                {
                    continue;
                }

                OrientedBox objectWorldOrientedBox = gameObject.GetWorldOrientedBox();
                if (box.Intersects(objectWorldOrientedBox))
                {
                    if (!allowFaceTouch)
                    {
                        return(true);
                    }
                    else
                    {
                        if (!box.AreAllBoxPointsOnOrInFrontOfAnyFacePlane(objectWorldOrientedBox))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// Returns a list of all objects which are overlapped by the specified box.
        /// </summary>
        /// <param name="box">
        /// The box involved in the overlap query.
        /// </param>
        public List <GameObject> OverlapBox(Box box)
        {
            // Retrieve all the sphere tree nodes which are overlapped by the box. If no nodes are overlapped,
            // we can return an empty list because it means that no objects could possibly be overlapped either.
            List <SphereTreeNode <GameObject> > allOverlappedNodes = _sphereTree.OverlapBox(box);

            if (allOverlappedNodes.Count == 0)
            {
                return(new List <GameObject>());
            }

            // Loop through all overlapped nodes
            OrientedBox orientedBox       = box.ToOrientedBox();
            var         overlappedObjects = new List <GameObject>();

            foreach (SphereTreeNode <GameObject> node in allOverlappedNodes)
            {
                // Store the node's object for easy access
                GameObject gameObject = node.Data;
                if (gameObject == null)
                {
                    continue;
                }
                if (!gameObject.activeSelf)
                {
                    continue;
                }

                // We need to perform an additional check. Even though the box overlaps the object's node (which is
                // a sphere), we must also check if the box overlaps the object's world oriented box. This allows
                // for better precision.
                OrientedBox objectWorldOrientedBox = gameObject.GetWorldOrientedBox();
                if (orientedBox.Intersects(objectWorldOrientedBox))
                {
                    overlappedObjects.Add(gameObject);
                }
            }

            return(overlappedObjects);
        }
Exemple #4
0
        public List <Triangle3DIntersectInfo> GetIntersectingTriangles(TransformMatrix thisTransform, Octave3DMesh otherMesh, TransformMatrix otherTransform)
        {
            OrientedBox thisOOBB = new OrientedBox(ModelAABB);

            thisOOBB.Transform(thisTransform);
            OrientedBox otherOOBB = new OrientedBox(otherMesh.ModelAABB);

            otherOOBB.Transform(otherTransform);

            if (thisOOBB.Intersects(otherOOBB))
            {
                List <Triangle3D> thisTriangles = GetOverlappedTriangles(otherOOBB, thisTransform);

                var output = new List <Triangle3DIntersectInfo>(50);
                Triangle3DIntersectInfo intersectInfo;
                for (int thisTriIndex = 0; thisTriIndex < thisTriangles.Count; ++thisTriIndex)
                {
                    Triangle3D thisTri = thisTriangles[thisTriIndex];

                    OrientedBox       thisTriOOBB    = new OrientedBox(thisTri.GetEncapsulatingBox());
                    List <Triangle3D> otherTriangles = otherMesh.GetOverlappedTriangles(thisTriOOBB, otherTransform);

                    for (int otherTriIndex = 0; otherTriIndex < otherTriangles.Count; ++otherTriIndex)
                    {
                        Triangle3D otherTri = otherTriangles[otherTriIndex];
                        if (thisTri.IntersectsTriangle(otherTri, out intersectInfo))
                        {
                            output.Add(intersectInfo);
                        }
                    }
                }

                return(output);
            }
            else
            {
                return(new List <Triangle3DIntersectInfo>());
            }
        }
Exemple #5
0
        private bool DoesGuideIntersectPreviuslyPlacedObjectHierarchy()
        {
            OrientedBox guideWorldOrientedBox = ObjectPlacementGuide.SceneObject.GetHierarchyWorldOrientedBox();

            return(guideWorldOrientedBox.Intersects(_orientedBoxOfLastPlacedHierarchy));
        }