예제 #1
0
        /// <summary>
        /// Resolves camera to the one contained in slot <see cref="Camera"/>.
        /// </summary>
        protected virtual CameraComponent ResolveCamera(RenderContext renderContext)
        {
            if (Camera == null && !cameraSlotResolutionFailed)
            {
                Logger.Warning($"{nameof(SceneCameraRenderer)} [{Id}] has no camera set. Make sure to set camera to the renderer via the Graphic Compositor Editor.");
            }

            cameraSlotResolutionFailed = Camera == null;
            if (cameraSlotResolutionFailed)
            {
                return(null);
            }

            var camera = Camera?.Camera;

            if (camera == null && !cameraResolutionFailed)
            {
                // no slot set, try to set one automatically
                SceneSystem        ss = renderContext.Services.GetService <SceneSystem>();
                GraphicsCompositor gc = ss?.GraphicsCompositor;
                if (gc != null)
                {
                    foreach (Entity e in ss.SceneInstance.RootScene.Entities)
                    {
                        CameraComponent cam = e.Get <CameraComponent>();
                        if (cam != null)
                        {
                            cam.Slot = gc.Cameras[0].ToSlotId();
                            camera   = cam;
                            break;
                        }
                    }
                }

                if (camera == null)
                {
                    Logger.Warning($"{nameof(SceneCameraRenderer)} [{Id}] has no camera assigned to its {nameof(CameraComponent.Slot)}[{Camera.Name}]. Make sure a camera is enabled and assigned to the corresponding {nameof(CameraComponent.Slot)}.");
                }
            }

            cameraResolutionFailed = camera == null;

            return(camera);
        }
예제 #2
0
        /// <summary>
        /// Resolves camera to the one contained in slot <see cref="Camera"/>.
        /// </summary>
        internal virtual CameraComponent ResolveCamera()
        {
            if (Camera == null && !cameraSlotResolutionFailed)
            {
                Logger.Warning($"{nameof(SceneCameraRenderer)} [{Id}] has no camera set. Make sure to set camera to the renderer via the Graphic Compositor Editor.");
            }

            cameraSlotResolutionFailed = Camera == null;
            if (cameraSlotResolutionFailed)
            {
                return(null);
            }

            var camera = Camera?.Camera;

            if (camera == null && !cameraResolutionFailed)
            {
                // no slot set, try to set one automatically
                SceneSystem        ss = ServiceRegistry.instance?.GetService <SceneSystem>();
                GraphicsCompositor gc = ss?.GraphicsCompositor;
                if (gc != null)
                {
                    var id = gc.Cameras[0].ToSlotId();
                    camera = SetFirstCamera(ref id, ss.SceneInstance.RootScene.Entities);
                }

                if (camera == null)
                {
                    Logger.Warning($"{nameof(SceneCameraRenderer)} [{Id}] has no camera assigned to its {nameof(CameraComponent.Slot)}[{Camera.Name}]. Make sure a camera is enabled and assigned to the corresponding {nameof(CameraComponent.Slot)}.");
                }
            }

            cameraResolutionFailed = camera == null;

            return(camera);
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SceneCameraSlotId"/> class.
 /// </summary>
 /// <param name="id">The identifier.</param>
 public SceneCameraSlotId(Guid id)
 {
     Id = id;
     AttachedCompositor = null;
 }