3D Motion Setup Script

ansonmccosh wrote on 3/17/2025, 6:30 PM

i'm a but curious but is there a script that involves creating a 3D scene instantly rather than having to set all the different tracks and parent to 3d. Basically just as a way to create 3d motion scenes faster. so im guessing it would go something like this. Create parent track > all tracks under this track becomes compositing Child > enable 3d Source Alpha for all compositing child..

Would be appreciated if someone could help me with this

Comments

jetdv wrote on 3/18/2025, 7:36 AM

That can be done but you'd need to define exactly what tracks need to be added.

ansonmccosh wrote on 3/18/2025, 12:57 PM

That can be done but you'd need to define exactly what tracks need to be added.

Thanks i will look this up

andy-0 wrote on 3/27/2025, 3:09 PM

hi @ansonmccosh I managed to make a simple version by following some jetdv videos and also using a script that does something "similar" created by zzzzzz9125 I'm not sure if it will work very well for your purpose but here is my contribution to this thread. Also a question @jetdv and @zzzzzz9125 do you approve of this script? is it well done or is there something to improve?

using System;
using ScriptPortal.Vegas;

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Project project = vegas.Project;
        
        // Cria e adiciona a faixa "3D Parent" sem definir o Composite Mode imediatamente
        VideoTrack parentTrack = new VideoTrack(project, project.Tracks.Count, null);
        project.Tracks.Add(parentTrack);
        parentTrack.Name = "3D Parent";
        parentTrack.CompositeNestingLevel = 0;
        
        // Cria e adiciona a faixa "Front Plane" como filha da "3D Parent"
        VideoTrack frontTrack = new VideoTrack(project, project.Tracks.Count, null);
        project.Tracks.Add(frontTrack);
        frontTrack.Name = "Front Plane";
        frontTrack.SetCompositeMode(CompositeMode.SrcAlpha3D, false);
        frontTrack.CompositeNestingLevel = parentTrack.CompositeNestingLevel + 1;
        
        // Cria e adiciona a faixa "Back Plane" como filha da "3D Parent"
        VideoTrack backTrack = new VideoTrack(project, project.Tracks.Count, null);
        project.Tracks.Add(backTrack);
        backTrack.Name = "Back Plane";
        backTrack.SetCompositeMode(CompositeMode.SrcAlpha3D, false);
        backTrack.CompositeNestingLevel = parentTrack.CompositeNestingLevel + 1;
        
        // Por último, aplica o Composite Mode na faixa "3D Parent"
        parentTrack.SetCompositeMode(CompositeMode.SrcAlpha3D, false);
        // Se a track for reconhecida como pai na composição, define também o Parent Composite Mode
        if (parentTrack.IsCompositingParent)
        {
            parentTrack.SetParentCompositeMode(CompositeMode.SrcAlpha3D, false);
        }
    }
}

 

ansonmccosh wrote on 3/27/2025, 9:35 PM

hi @ansonmccosh I managed to make a simple version by following some jetdv videos and also using a script that does something "similar" created by zzzzzz9125 I'm not sure if it will work very well for your purpose but here is my contribution to this thread. Also a question @jetdv and @zzzzzz9125 do you approve of this script? is it well done or is there something to improve?

using System;
using ScriptPortal.Vegas;

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Project project = vegas.Project;
        
        // Cria e adiciona a faixa "3D Parent" sem definir o Composite Mode imediatamente
        VideoTrack parentTrack = new VideoTrack(project, project.Tracks.Count, null);
        project.Tracks.Add(parentTrack);
        parentTrack.Name = "3D Parent";
        parentTrack.CompositeNestingLevel = 0;
        
        // Cria e adiciona a faixa "Front Plane" como filha da "3D Parent"
        VideoTrack frontTrack = new VideoTrack(project, project.Tracks.Count, null);
        project.Tracks.Add(frontTrack);
        frontTrack.Name = "Front Plane";
        frontTrack.SetCompositeMode(CompositeMode.SrcAlpha3D, false);
        frontTrack.CompositeNestingLevel = parentTrack.CompositeNestingLevel + 1;
        
        // Cria e adiciona a faixa "Back Plane" como filha da "3D Parent"
        VideoTrack backTrack = new VideoTrack(project, project.Tracks.Count, null);
        project.Tracks.Add(backTrack);
        backTrack.Name = "Back Plane";
        backTrack.SetCompositeMode(CompositeMode.SrcAlpha3D, false);
        backTrack.CompositeNestingLevel = parentTrack.CompositeNestingLevel + 1;
        
        // Por último, aplica o Composite Mode na faixa "3D Parent"
        parentTrack.SetCompositeMode(CompositeMode.SrcAlpha3D, false);
        // Se a track for reconhecida como pai na composição, define também o Parent Composite Mode
        if (parentTrack.IsCompositingParent)
        {
            parentTrack.SetParentCompositeMode(CompositeMode.SrcAlpha3D, false);
        }
    }
}

 

i appreciate this..This is actually very good and it will help. i was actually looking at trying to implement @zzzzzz9125  the depth value and z value and testing if it will work. so far i get errors but i feel like i'm learning more as i go

ansonmccosh wrote on 3/27/2025, 10:06 PM

meant to say "Rate and offset"

zzzzzz9125 wrote on 3/28/2025, 8:36 AM

i appreciate this..This is actually very good and it will help. i was actually looking at trying to implement @zzzzzz9125  the depth value and z value and testing if it will work. so far i get errors but i feel like i'm learning more as i go

@ansonmccosh Something like this? I made a few changes to the original one. It now works for all selected tracks.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;

using ScriptPortal.Vegas;  // "ScriptPortal.Vegas" for Magix Vegas Pro 14 or above, "Sony.Vegas" for Sony Vegas Pro 13 or below

namespace Test_Script
{
    public class Test_Class
    {
        public Vegas myVegas;
        public const double RATE3DDEFAULT = 10, OFFSET3DDEFAULT = 0;
        
        public void Main(Vegas vegas)
        {
            myVegas = vegas;
            myVegas.ResumePlaybackOnScriptExit = true;
            Project project = myVegas.Project;

            List<VideoTrack> tracks = GetSelectedTracks<VideoTrack>(project);
            if (tracks.Count == 0)
            {
                return;
            }

            double rate3D = RATE3DDEFAULT, offset3D = OFFSET3DDEFAULT;
            DialogResult result = PopUpWindow(out rate3D, out offset3D);
            if (result != DialogResult.OK)
            {
                return;
            }

            int index = 0, parentCompositeLevel = tracks[0].CompositeNestingLevel;
            for (int i = 0; i < tracks.Count; i++)
            {
                SetTrackMotion3D(project, tracks[i], i, parentCompositeLevel, rate3D, offset3D);
            }
            foreach (VideoTrack track in tracks)
            {
                if (track.IsCompositingParent)
                {
                    track.SetParentCompositeMode(CompositeMode.SrcAlpha3D, false);
                }
            }
        }

        static DialogResult PopUpWindow(out double rate, out double offset)
        {
            rate = RATE3DDEFAULT;
            offset  = OFFSET3DDEFAULT;
            Form form = new Form();
            form.SuspendLayout();
            form.ShowInTaskbar = false;
            form.AutoSize = true;
            form.BackColor = Color.FromArgb(45,45,45);
            form.ForeColor = Color.FromArgb(200,200,200);
            if (System.Diagnostics.FileVersionInfo.GetVersionInfo(Application.ExecutablePath).FileMajorPart < 15)
            {
                form.BackColor = Color.FromArgb(153,153,153);
                form.ForeColor = Color.FromArgb(0,0,0);
            }
            form.Font = new Font("Arial", 9);
            form.Text = "Layer 3D";
            form.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.AutoSizeMode = AutoSizeMode.GrowAndShrink;

            Panel p = new Panel();
            p.AutoSize = true;
            p.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            form.Controls.Add(p);

            TableLayoutPanel l = new TableLayoutPanel();
            l.AutoSize = true;
            l.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            l.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
            l.ColumnCount = 2;
            l.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 70));
            l.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 70));
            p.Controls.Add(l);

            Label label = new Label();
            label.Margin = new Padding(6, 10, 6, 6);
            label.Text = "Rate";
            label.AutoSize = true;
            l.Controls.Add(label);

            TextBox rateBox = new TextBox();
            rateBox.AutoSize = true;
            rateBox.Margin = new Padding(6, 6, 6, 6);
            rateBox.Text = rate.ToString();
            l.Controls.Add(rateBox);

            label = new Label();
            label.Margin = new Padding(6, 10, 6, 6);
            label.Text = "Offset";
            label.AutoSize = true;
            l.Controls.Add(label);

            TextBox offsetBox = new TextBox();
            offsetBox.AutoSize = true;
            offsetBox.Margin = new Padding(6, 6, 6, 6);
            offsetBox.Text = offset.ToString();
            l.Controls.Add(offsetBox);

            FlowLayoutPanel panel = new FlowLayoutPanel();
            panel.FlowDirection = FlowDirection.RightToLeft;
            panel.AutoSize = true;
            panel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            panel.Anchor = AnchorStyles.None;
            l.Controls.Add(panel);
            l.SetColumnSpan(panel, 3);
            panel.Font = new Font("Arial", 8);

            Button ok = new Button();
            ok.Text = "OK";
            ok.DialogResult = DialogResult.OK;
            panel.Controls.Add(ok);
            form.AcceptButton = ok;

            form.ResumeLayout();

            DialogResult result = form.ShowDialog();
            double.TryParse(rateBox.Text, out rate);
            double.TryParse(offsetBox.Text, out offset);
            return result;
        }

        public static List<T> GetSelectedTracks<T>(Project project) where T : Track
        {
            List<T> l = new List<T>();
            foreach (Track myTrack in project.Tracks)
            {
                if (myTrack.Selected)
                {
                    if ((typeof(T) == typeof(VideoTrack) && !myTrack.IsVideo()) || (typeof(T) == typeof(AudioTrack) && !myTrack.IsAudio()))
                    {
                        continue;
                    }
                    l.Add((T)myTrack);
                }
            }
            return l;
        }

        public static void SetTrackMotion3D(Project project, VideoTrack track, int i, int parentCompositeLevel, double rate = 0, double offset = 0)
        {
            if (i != 0 && track.CompositeNestingLevel == parentCompositeLevel)
            {
                track.CompositeNestingLevel += 1;
            }

            track.SetCompositeMode(CompositeMode.SrcAlpha3D, false);

            double unit = project.Video.Height / 20, m = Math.Pow(2.71828, (i * rate - offset) / 100) - 1;

            foreach (TrackMotionKeyframe kf in track.TrackMotion.MotionKeyframes)
            {
                kf.Width = project.Video.Width * (1 + m) * kf.Depth / unit;
                kf.Height = project.Video.Height * (1 + m) * kf.Depth / unit;
                kf.PositionZ = unit * m * 193 / 9;
            }
        }
    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Test_Class test = new Test_Script.Test_Class();
        test.Main(vegas);
    }
}

 

Last changed by zzzzzz9125 on 3/28/2025, 8:40 AM, changed a total of 1 times.

Using VEGAS Pro 22 build 248 & VEGAS Pro 21 build 208.

Information about my PC:
Brand Name: HP VICTUS Laptop
System: Windows 11.0 (64-bit) 10.00.22631
CPU: 12th Gen Intel(R) Core(TM) i7-12700H
GPU: NVIDIA GeForce RTX 3050 Laptop GPU
GPU Driver: NVIDIA Studio Driver 560.70

ansonmccosh wrote on 3/29/2025, 1:11 AM

i appreciate this..This is actually very good and it will help. i was actually looking at trying to implement @zzzzzz9125  the depth value and z value and testing if it will work. so far i get errors but i feel like i'm learning more as i go

@ansonmccosh Something like this? I made a few changes to the original one. It now works for all selected tracks.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;

using ScriptPortal.Vegas;  // "ScriptPortal.Vegas" for Magix Vegas Pro 14 or above, "Sony.Vegas" for Sony Vegas Pro 13 or below

namespace Test_Script
{
    public class Test_Class
    {
        public Vegas myVegas;
        public const double RATE3DDEFAULT = 10, OFFSET3DDEFAULT = 0;
        
        public void Main(Vegas vegas)
        {
            myVegas = vegas;
            myVegas.ResumePlaybackOnScriptExit = true;
            Project project = myVegas.Project;

            List<VideoTrack> tracks = GetSelectedTracks<VideoTrack>(project);
            if (tracks.Count == 0)
            {
                return;
            }

            double rate3D = RATE3DDEFAULT, offset3D = OFFSET3DDEFAULT;
            DialogResult result = PopUpWindow(out rate3D, out offset3D);
            if (result != DialogResult.OK)
            {
                return;
            }

            int index = 0, parentCompositeLevel = tracks[0].CompositeNestingLevel;
            for (int i = 0; i < tracks.Count; i++)
            {
                SetTrackMotion3D(project, tracks[i], i, parentCompositeLevel, rate3D, offset3D);
            }
            foreach (VideoTrack track in tracks)
            {
                if (track.IsCompositingParent)
                {
                    track.SetParentCompositeMode(CompositeMode.SrcAlpha3D, false);
                }
            }
        }

        static DialogResult PopUpWindow(out double rate, out double offset)
        {
            rate = RATE3DDEFAULT;
            offset  = OFFSET3DDEFAULT;
            Form form = new Form();
            form.SuspendLayout();
            form.ShowInTaskbar = false;
            form.AutoSize = true;
            form.BackColor = Color.FromArgb(45,45,45);
            form.ForeColor = Color.FromArgb(200,200,200);
            if (System.Diagnostics.FileVersionInfo.GetVersionInfo(Application.ExecutablePath).FileMajorPart < 15)
            {
                form.BackColor = Color.FromArgb(153,153,153);
                form.ForeColor = Color.FromArgb(0,0,0);
            }
            form.Font = new Font("Arial", 9);
            form.Text = "Layer 3D";
            form.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.AutoSizeMode = AutoSizeMode.GrowAndShrink;

            Panel p = new Panel();
            p.AutoSize = true;
            p.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            form.Controls.Add(p);

            TableLayoutPanel l = new TableLayoutPanel();
            l.AutoSize = true;
            l.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            l.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
            l.ColumnCount = 2;
            l.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 70));
            l.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 70));
            p.Controls.Add(l);

            Label label = new Label();
            label.Margin = new Padding(6, 10, 6, 6);
            label.Text = "Rate";
            label.AutoSize = true;
            l.Controls.Add(label);

            TextBox rateBox = new TextBox();
            rateBox.AutoSize = true;
            rateBox.Margin = new Padding(6, 6, 6, 6);
            rateBox.Text = rate.ToString();
            l.Controls.Add(rateBox);

            label = new Label();
            label.Margin = new Padding(6, 10, 6, 6);
            label.Text = "Offset";
            label.AutoSize = true;
            l.Controls.Add(label);

            TextBox offsetBox = new TextBox();
            offsetBox.AutoSize = true;
            offsetBox.Margin = new Padding(6, 6, 6, 6);
            offsetBox.Text = offset.ToString();
            l.Controls.Add(offsetBox);

            FlowLayoutPanel panel = new FlowLayoutPanel();
            panel.FlowDirection = FlowDirection.RightToLeft;
            panel.AutoSize = true;
            panel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            panel.Anchor = AnchorStyles.None;
            l.Controls.Add(panel);
            l.SetColumnSpan(panel, 3);
            panel.Font = new Font("Arial", 8);

            Button ok = new Button();
            ok.Text = "OK";
            ok.DialogResult = DialogResult.OK;
            panel.Controls.Add(ok);
            form.AcceptButton = ok;

            form.ResumeLayout();

            DialogResult result = form.ShowDialog();
            double.TryParse(rateBox.Text, out rate);
            double.TryParse(offsetBox.Text, out offset);
            return result;
        }

        public static List<T> GetSelectedTracks<T>(Project project) where T : Track
        {
            List<T> l = new List<T>();
            foreach (Track myTrack in project.Tracks)
            {
                if (myTrack.Selected)
                {
                    if ((typeof(T) == typeof(VideoTrack) && !myTrack.IsVideo()) || (typeof(T) == typeof(AudioTrack) && !myTrack.IsAudio()))
                    {
                        continue;
                    }
                    l.Add((T)myTrack);
                }
            }
            return l;
        }

        public static void SetTrackMotion3D(Project project, VideoTrack track, int i, int parentCompositeLevel, double rate = 0, double offset = 0)
        {
            if (i != 0 && track.CompositeNestingLevel == parentCompositeLevel)
            {
                track.CompositeNestingLevel += 1;
            }

            track.SetCompositeMode(CompositeMode.SrcAlpha3D, false);

            double unit = project.Video.Height / 20, m = Math.Pow(2.71828, (i * rate - offset) / 100) - 1;

            foreach (TrackMotionKeyframe kf in track.TrackMotion.MotionKeyframes)
            {
                kf.Width = project.Video.Width * (1 + m) * kf.Depth / unit;
                kf.Height = project.Video.Height * (1 + m) * kf.Depth / unit;
                kf.PositionZ = unit * m * 193 / 9;
            }
        }
    }
}

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Test_Class test = new Test_Script.Test_Class();
        test.Main(vegas);
    }
}

 

with the help of @andy-0 and @jetdv i was able to get exactly what i needed..thanks again for the much needed help!