public static List <GameObject> GetVisibleObjects(this Camera camera, CameraViewVolume viewVolume)
        {
            // Retrieve the objects which are overlapped by the camera volume's OBB
            List <GameObject> overlappedObjects = RTScene.Get.OverlapBox(viewVolume.WorldOBB);

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

            // Loop through each overlapped object
            var boundsQConfig = new ObjectBounds.QueryConfig();

            boundsQConfig.ObjectTypes  = GameObjectTypeHelper.AllCombined;
            boundsQConfig.NoVolumeSize = Vector3Ex.FromValue(1e-5f);

            var visibleObjects = new List <GameObject>(overlappedObjects.Count);

            foreach (var gameObject in overlappedObjects)
            {
                // Retrieve the object's world AABB
                AABB worldAABB = ObjectBounds.CalcWorldAABB(gameObject, boundsQConfig);

                // If the AABB is valid and if the camera's view volume intersects the AABB,
                // it means we are dealing with a visible object so we store it inside the
                // output list.
                if (worldAABB.IsValid && viewVolume.CheckAABB(worldAABB))
                {
                    visibleObjects.Add(gameObject);
                }
            }

            return(visibleObjects);
        }
        /// <summary>
        /// Checks if the handle is visible on the screen (i.e. it is visible to the
        /// specified camera.
        /// </summary>
        /// <param name="camera">The camera which is involved in the visibility test.</param>
        /// <param name="frustumWorldPlanes">The camera frustum world planes.</param>
        /// <returns>
        /// True if at least one shape (either 2D or 3D) that belongs to the handle is
        /// visible and false otehrwise. Note: When the gizmo position lies behind the
        /// camera near plane, all 2D shapes are considered NOT visible.
        /// </returns>
        public bool IsVisibleToCamera(Camera camera, Plane[] frustumWorldPlanes)
        {
            bool found2DVisible = false;
            bool found3DVisible = false;

            if (Num2DShapes != 0)
            {
                if (camera.IsPointInFrontNearPlane(Gizmo.Transform.Position3D))
                {
                    foreach (var shape in _2DShapes)
                    {
                        Rect enclosingRect = shape.Shape.GetEncapsulatingRect();
                        if (camera.pixelRect.Overlaps(enclosingRect, true))
                        {
                            found2DVisible = true;
                            break;
                        }
                    }
                }
            }

            if (found2DVisible)
            {
                return(true);
            }

            if (Num3DShapes != 0)
            {
                foreach (var shape in _3DShapes)
                {
                    AABB aabb = shape.Shape.GetAABB();
                    if (CameraViewVolume.CheckAABB(camera, aabb, frustumWorldPlanes))
                    {
                        found3DVisible = true;
                        break;
                    }
                }
            }

            return(found3DVisible);
        }
Beispiel #3
0
        public void Render_SystemCall()
        {
            _pipelineStage = GizmosEnginePipelineStage.Render;
            Camera renderCamera = Camera.current;

            if (!IsSceneGizmoCamera(renderCamera) && !IsRenderCamera(renderCamera))
            {
                _pipelineStage = GizmosEnginePipelineStage.PostRender;
                return;
            }

            if (Settings.EnableGizmoSorting)
            {
                Vector3 camPos       = RenderStageCamera.transform.position;
                var     sortedGizmos = new List <Gizmo>(_gizmos);
                sortedGizmos.Sort(delegate(Gizmo g0, Gizmo g1)
                {
                    float d0 = (g0.Transform.Position3D - camPos).sqrMagnitude;
                    float d1 = (g1.Transform.Position3D - camPos).sqrMagnitude;

                    return(d1.CompareTo(d0));
                });

                var worldFrustumPlanes = CameraViewVolume.GetCameraWorldPlanes(renderCamera);
                foreach (var gizmo in sortedGizmos)
                {
                    gizmo.Render_SystemCall(renderCamera, worldFrustumPlanes);
                }
            }
            else
            {
                var worldFrustumPlanes = CameraViewVolume.GetCameraWorldPlanes(renderCamera);
                foreach (var gizmo in _gizmos)
                {
                    gizmo.Render_SystemCall(renderCamera, worldFrustumPlanes);
                }
            }

            _pipelineStage = GizmosEnginePipelineStage.PostRender;
        }