public AABB GetTargetObjectGroupWorldAABB()
        {
            if (_targetObjects == null)
            {
                return(AABB.GetInvalid());
            }

            var  boundsQConfig   = GetObjectBoundsQConfig();
            AABB targetGroupAABB = AABB.GetInvalid();

            foreach (var targetObject in _targetObjects)
            {
                AABB targetAABB = ObjectBounds.CalcWorldAABB(targetObject, boundsQConfig);
                if (targetGroupAABB.IsValid)
                {
                    targetGroupAABB.Encapsulate(targetAABB);
                }
                else
                {
                    targetGroupAABB = targetAABB;
                }
            }

            return(targetGroupAABB);
        }
Пример #2
0
        public static AABB CalcHierarchyModelAABB(GameObject root, QueryConfig queryConfig)
        {
            Matrix4x4 rootTransform = root.transform.localToWorldMatrix;
            AABB      finalAABB     = CalcModelAABB(root, queryConfig, root.GetGameObjectType());

            List <GameObject> allChildren = root.GetAllChildren();

            foreach (var child in allChildren)
            {
                AABB modelAABB = CalcModelAABB(child, queryConfig, child.GetGameObjectType());
                if (modelAABB.IsValid)
                {
                    // All children must have their AABBs calculated in the root local space, so we must
                    // first calculate a matrix that transforms the child object in the local space of the
                    // root. We will use this matrix to transform the child's AABB in root space.
                    Matrix4x4 rootRelativeTransform = child.transform.localToWorldMatrix.GetRelativeTransform(rootTransform);
                    modelAABB.Transform(rootRelativeTransform);

                    if (finalAABB.IsValid)
                    {
                        finalAABB.Encapsulate(modelAABB);
                    }
                    else
                    {
                        finalAABB = modelAABB;
                    }
                }
            }

            return(finalAABB);
        }
        /// <summary>
        /// Calculates and returns the AABB that encloses all the 3D shapes which belong to the handle.
        /// If the handle doesn't contain any 3D shapes or if none of them are marked as visible, an
        /// invalid AABB will be returned. The 'Is3DVisible' property is ignored.
        /// </summary>
        public AABB GetVisible3DShapesAABB()
        {
            AABB aabb = AABB.GetInvalid();

            if (Num3DShapes == 0)
            {
                return(aabb);
            }

            foreach (var shape in  _3DShapes)
            {
                if (!shape.IsVisible)
                {
                    continue;
                }

                AABB shapeAABB = shape.Shape.GetAABB();
                if (shapeAABB.IsValid)
                {
                    if (aabb.IsValid)
                    {
                        aabb.Encapsulate(shapeAABB);
                    }
                    else
                    {
                        aabb = shapeAABB;
                    }
                }
            }

            return(aabb);
        }
        public override AABB GetAABB()
        {
            AABB aabb = new AABB(GetBaseExtents());

            aabb.Encapsulate(Tip);

            return(aabb);
        }
        private void OnBorderPointsFoundDirty()
        {
            _borderPoints = PrimitiveFactory.Generate3DArcBorderPoints(_origin, _startPoint, _plane, _degreeAngleFromStart, _forceShortestArc, _numBorderPoints);
            _aabb         = new AABB(_borderPoints);
            _aabb.Encapsulate(_origin);

            _areBorderPointsDirty = false;
        }
Пример #6
0
        public void Encapsulate(OBB otherOBB)
        {
            var otherPts = BoxMath.CalcBoxCornerPoints(otherOBB.Center, otherOBB.Size, otherOBB.Rotation);

            Matrix4x4 transformMtx = Matrix4x4.TRS(Center, Rotation, Vector3.one);
            var       modelPts     = transformMtx.inverse.TransformPoints(otherPts);

            AABB modelAABB = new AABB(Vector3.zero, Size);

            modelAABB.Encapsulate(modelPts);

            Center = (Rotation * modelAABB.Center) + Center;
            Size   = modelAABB.Size;
        }
Пример #7
0
        public static AABB CalcObjectCollectionWorldAABB(IEnumerable <GameObject> gameObjectCollection, QueryConfig queryConfig)
        {
            AABB aabb = AABB.GetInvalid();

            foreach (var gameObject in gameObjectCollection)
            {
                AABB worldAABB = CalcWorldAABB(gameObject, queryConfig);
                if (worldAABB.IsValid)
                {
                    if (aabb.IsValid)
                    {
                        aabb.Encapsulate(worldAABB);
                    }
                    else
                    {
                        aabb = worldAABB;
                    }
                }
            }

            return(aabb);
        }
Пример #8
0
        public static AABB CalcHierarchyCollectionWorldAABB(IEnumerable <GameObject> roots, QueryConfig queryConfig)
        {
            AABB aabb = AABB.GetInvalid();

            foreach (var root in roots)
            {
                AABB hierarchyAABB = CalcHierarchyWorldAABB(root, queryConfig);
                if (hierarchyAABB.IsValid)
                {
                    if (aabb.IsValid)
                    {
                        aabb.Encapsulate(hierarchyAABB);
                    }
                    else
                    {
                        aabb = hierarchyAABB;
                    }
                }
            }

            return(aabb);
        }
Пример #9
0
        public AABB CalculateBounds()
        {
            var activeScene = SceneManager.GetActiveScene();
            var roots       = new List <GameObject>(Mathf.Max(10, activeScene.rootCount));

            SceneManager.GetActiveScene().GetRootGameObjects(roots);

            var boundsQConfig = new ObjectBounds.QueryConfig();

            boundsQConfig.NoVolumeSize = Vector3.zero;
            boundsQConfig.ObjectTypes  = GameObjectType.Mesh | GameObjectType.Sprite;

            AABB sceneAABB = new AABB();

            foreach (var root in roots)
            {
                var allChildrenAndSelf = root.GetAllChildrenAndSelf();
                foreach (var sceneObject in allChildrenAndSelf)
                {
                    AABB aabb = ObjectBounds.CalcWorldAABB(sceneObject, boundsQConfig);
                    if (aabb.IsValid)
                    {
                        if (sceneAABB.IsValid)
                        {
                            sceneAABB.Encapsulate(aabb);
                        }
                        else
                        {
                            sceneAABB = aabb;
                        }
                    }
                }
            }

            return(sceneAABB);
        }
Пример #10
0
        public AABB GetVisible3DHandlesAABB()
        {
            AABB aabb       = AABB.GetInvalid();
            int  numHandles = _handles.Count;

            for (int handleIndex = 0; handleIndex < numHandles; ++handleIndex)
            {
                var  handle     = _handles[handleIndex];
                AABB handleAABB = handle.GetVisible3DShapesAABB();
                if (handleAABB.IsValid)
                {
                    if (aabb.IsValid)
                    {
                        aabb.Encapsulate(handleAABB);
                    }
                    else
                    {
                        aabb = handleAABB;
                    }
                }
            }

            return(aabb);
        }