Exemplo n.º 1
0
        /// <summary>
        /// Sets the scene specific properties of a source. Unspecified properties will remain unchanged. Coordinates are relative to the item's parent (the scene or group it belongs to).
        /// </summary>
        /// <param name="props">Object containing changes</param>
        /// <param name="sceneName">Option scene name</param>
        public void SetSceneItemProperties(SceneItemProperties props, string sceneName = null)
        {
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.NullValueHandling = NullValueHandling.Ignore;
            var requestFields = JObject.Parse(JsonConvert.SerializeObject(props, settings));

            if (sceneName != null)
            {
                requestFields.Add("scene-name", sceneName);
            }

            _webSocket.SendRequest("SetSceneItemProperties", requestFields);
        }
Exemplo n.º 2
0
        void StartLiveFeedAnimation(string itemName, string sceneName, double playerX, double videoAnchorHorizontal, double videoAnchorVertical, double videoWidth, double videoHeight, double targetScale, double timeMs)
        {
            SceneItem sceneItem = ObsManager.GetSceneItem(sceneName, itemName);

            SceneItemProperties sceneItemProperties = ObsManager.GetSceneItemProperties(itemName, sceneName);
            double startScale = sceneItemProperties.Bounds.Height / videoHeight;

            VideoFeed[]    videoFeeds        = GetVideoFeeds(sceneName, itemName, videoAnchorHorizontal, videoAnchorVertical, videoWidth, videoHeight);
            LiveFeedScaler liveFeedAnimation = new LiveFeedScaler(videoFeeds, playerX, startScale, targetScale, timeMs);

            if (!sceneItem.Render)
            {
                ObsManager.SizeAndPositionItem(liveFeedAnimation, (float)liveFeedAnimation.TargetScale);
            }
            else
            {
                liveFeedAnimation.Render += LiveFeedAnimation_Render;
            }
        }
Exemplo n.º 3
0
        public static void SizeAndPositionItem(BaseLiveFeedAnimator e, double scale, double opacity = 1, double rotation = 0, bool flipped = false)
        {
            if (e.HasLastCamera())
            {
                SetSourceVisibility(e.LastSceneName, e.LastItemName, false);
                e.ClearLastCamera();
            }

            double screenAnchorLeft = e.ScreenAnchorLeft;
            double screenAnchorTop  = e.ScreenAnchorTop;

            double newLeft = screenAnchorLeft - e.VideoAnchorHorizontal * Math.Abs(e.VideoWidth) * scale;
            double newTop  = screenAnchorTop - e.VideoAnchorVertical * e.VideoHeight * scale;

            try
            {
                SceneItemProperties sceneItemProperties = obsWebsocket.GetSceneItemProperties(e.ItemName, e.SceneName);
                sceneItemProperties.Visible = opacity > 0;

                if (sceneItemProperties.Visible)
                {
                    // TODO: Consider optimizing this to only change when the new value is different from the last one set. Confidence should be high (e.g., time between sets should be short, and everything else should match).
                    const string   ImageMaskFilter  = "Image Mask/Blend";
                    FilterSettings sourceFilterInfo = obsWebsocket.GetSourceFilterInfo(e.ItemName, ImageMaskFilter);
                    JObject        settings         = sourceFilterInfo.Settings;
                    int            newOpacity       = (int)(opacity * 100);
                    ImageMask      imageMask        = settings.ToObject <ImageMask>();
                    if (imageMask.opacity != newOpacity)
                    {
                        imageMask.opacity = newOpacity;
                        obsWebsocket.SetSourceFilterSettings(e.ItemName, ImageMaskFilter, JObject.FromObject(imageMask));
                    }
                }
                //if (rotation != sceneItemProperties.Rotation)
                //{
                sceneItemProperties.Rotation = rotation;

                // This will rotate around the top left.
                // ![](342CE4E3D8508B3F1D4B944701C25E97.png)

                // But we also need to rotate the upper left anchor by that amount..
                // ![](50D76BD4D4A4D1EF91B34011CF9EA1D7.png)

                // screenAnchorLeft and screenAnchorTop are the red point.
                // newLeft and newTop are the original yellow anchor point in the upper left.

                Point2d upperLeft   = new Point2d(newLeft, newTop);
                Point2d centerPoint = new Point2d(screenAnchorLeft, screenAnchorTop);

                Point2d newUpperLeft = Math2D.RotatePoint(upperLeft, centerPoint, rotation);
                newLeft = newUpperLeft.X;
                newTop  = newUpperLeft.Y;

                sceneItemProperties.Bounds = new SceneItemBoundsInfo()
                {
                    Height     = e.VideoHeight * scale,
                    Width      = Math.Abs(e.VideoWidth) * scale,
                    Alignnment = sceneItemProperties.Bounds.Alignnment,
                    Type       = sceneItemProperties.Bounds.Type
                };

                sceneItemProperties.Position = new SceneItemPositionInfo()
                {
                    X         = newLeft,
                    Y         = newTop,
                    Alignment = sceneItemProperties.Position.Alignment
                };

                obsWebsocket.SetSceneItemProperties(sceneItemProperties, e.SceneName);

                float flipMultiplier = 1;
                if (e.VideoWidth < 0)
                {
                    flipMultiplier = -1;
                }

                if (flipped)
                {
                    flipMultiplier *= -1;
                }

                // TODO: Verify that flipping the video still works!!!

                // Old
                //obsWebsocket.SetSceneItemTransform(e.ItemName, (float)rotation, flipMultiplier * (float)scale, (float)scale, e.SceneName);
            }
            catch             //(Exception ex)
            {
            }
        }