Build a tree with branches in threejs with Dotnet

I am trying to build tree that you look like picture below with threejs and dotnet which has one main branch, can many branches attached to it the children branches can have many children or branches added to it, the branches are placed left or right. My code is working fine until I start adding more branches to the children. Any assistance shifting the X position properly after a new item is added to any children.
My code is as follow.

if (networkObjects != null)
{
                var parentObjects = networkObjects.Where(a => a.Children.Count > 0).ToList();
                var networkSources = networkObjects.Where(a => a.ItemType == NetworkItemType.Source || a.ItemType == NetworkItemType.Distribution && a.Children.Count > 0);
                var xJump = 260;

                var sameChildX = new List<SceneObject>();
    var id = new List<(string,int)>();
                foreach (var parentObject in parentObjects)
                {
                    var parentSceneObject = NetworkSceneObjects.FirstOrDefault(a => a.id == parentObject?.SceneObjectId);
                    var yParent = parentSceneObject.location.Y + parentSceneObject.snappoints.Min(a => a.Y);
                    var test = networkObjects.Where(a => parentObject.Children.Contains(a.Uid)).Select(b => b.SceneObjectId).ToList();
                    var children = NetworkSceneObjects.Where(a => test.Contains(a.id))/*.OrderBy(a => a.Column)*/.ToList();
                    var childrenObject = networkObjects.Where(a => test.Contains(a.SceneObjectId))/*.OrderBy(a => a.Column)*/.ToList();
                    var isFirstparent = NetworkSceneObjects.FirstOrDefault();
        var Tier = children.FirstOrDefault().Tier;
                    if (parentObject == null) continue;
        
                    var parentindex = parentObjects.FindIndex(a => a.SceneObjectId == parentObject.SceneObjectId);
        if (parentindex > 0)
        {
            yParent += parentSceneObject.snappoints.Min(a => a.Y);
        }
                    var lastChild = children.LastOrDefault();
        var counter = 0;
        var Column = 0;                       
                    
                    var leftChildren = children.Where((a, i) => i % 2 == 0).ToList();
        var rightChildren = children.Where((a, i) => i % 2 == 1).ToList();                      

                    foreach (var oa in children)
        {
            Column = oa.Column;
            
            var childindex = children.FindIndex(a => a.id == oa.id);
                        
                        var isLastChild = oa.id.Equals(lastChild.id);
            var isFirst = isFirstparent.id == parentSceneObject.id;
            var childrens = /*new List<string>();*/networkObjects.FirstOrDefault(a => a.SceneObjectId == oa.id).Children;
           
                        switch (parentObject.Children.Count % 2)
                        {
                            case 0: //even
                                if (!childrenObject.Any(a => a.Children.Count > 0))
                                {
                                    if (childindex % 2 == 0) //even
                                    {
                                        oa.location = new System.Numerics.Vector3(parentSceneObject.location.X + xJump * oa.Column, yParent, oa.location.Z);
                                    }
                                    else //odd
                                    {
                                        if (parentindex > 0)
                                        {
                                            oa.location = new System.Numerics.Vector3(parentSceneObject.location.X + xJump * oa.Column, yParent, oa.location.Z);
                                        }
                                        else
                                            oa.location = new System.Numerics.Vector3(xJump * oa.Column, yParent, oa.location.Z);
                                    }
                                }
                                else
                                {
                                    if (childindex % 2 == 0) //even
                                    {
                            sameChildX = leftChildren.Where(a => a.location.X == oa.location.X && a.id != oa.id && a.Column < Column).ToList();
                                        if (id.Any(a => a.Item1 == oa.id))
                                        {
                                            var leftSceneObject = NetworkSceneObjects.Where((a, i) => i % 2 == 0).LastOrDefault();
                                            var diff = leftSceneObject.location.X - oa.location.X + oa.location.X;
                                            if (diff == leftSceneObject.location.X)
                                                Column = oa.Column = (int)(diff / 260);
                                        }
                                        if (childrens.Count > 0)
                                if (oa.Column > 0)
                                                Column = oa.Column + (int)Math.Floor((double)childrens.Count / 2);
                                else
                                                Column = oa.Column - (int)Math.Floor((double)childrens.Count / 2);
                                        for (int j = childindex; j < sameChildX.Count; j++)
                            {
                                if (!id.Any(a => a.Item1 == oa.id))
                                {
                                                id.Add((sameChildX[j].id, childrens.Count));
                                                id.Add((oa.id, childrens.Count));
                                            }                                                                                               
                                        }
                            
                                        oa.location = new System.Numerics.Vector3(parentSceneObject.location.X + (xJump * Column), yParent, oa.location.Z);
                                    }
                                    else //odd
                                    {
                            sameChildX = rightChildren.Where(a => a.location.X == oa.location.X && a.id != oa.id && a.Column > Column).ToList();
                                        if (id.Any(a => a.Item1 == oa.id))
                                        {
                                            var rightSceneObject = NetworkSceneObjects.Where((a, i) => i % 2 == 1).LastOrDefault();
                                            var diff = rightSceneObject.location.X + oa.location.X;
                                            if (diff > rightSceneObject.location.X)
                                                Column = oa.Column = (int)(diff / 260) + 1;
                                        }
                                        if (childrens.Count > 0)
                                            if (oa.Column > 0)
                                                Column = oa.Column + (int)Math.Floor((double)childrens.Count / 2);
                                else
                                                Column = oa.Column - (int)Math.Floor((double)childrens.Count / 2);
                                        for (int j = childindex; j <= sameChildX.Count; j++)
                                        {
                                            if (!id.Any(a => a.Item1 == oa.id))
                                            {
                                                id.Add((sameChildX[j - 1].id, childrens.Count));
                                                id.Add((oa.id, childrens.Count));
                                            }
                                        }
                                        oa.location = new System.Numerics.Vector3(parentSceneObject.location.X + (xJump * Column) , yParent, oa.location.Z);
                                    }
                                }
                                break;
                            case 1: //odd
                                if (childrenObject.Any(a => a.Children.Count > 0))
                                {
                                    if (childindex % 2 == 0) //even
                                    {
                                        if (childrens.Count > 0 && !isFirst)
                                            Column = oa.Column - (int)Math.Floor((double)childrens.Count / 2) ;
                                    }
                                    else //odd
                                    {
                                        if (childrens.Count > 0)
                                            Column = oa.Column + (int)Math.Floor((double)childrens.Count / 2);
                                    }
                                    oa.location = new System.Numerics.Vector3(parentSceneObject.location.X + (xJump * Column), yParent, oa.location.Z);
                                }
                                else
                                {
                                    if (childindex % 2 == 0) //even
                                    {                                           
                                            oa.location = new System.Numerics.Vector3(parentSceneObject.location.X + (xJump * Column), yParent, oa.location.Z);
                            var leftItems = NetworkSceneObjects.Where((a, i) => i % 2 == 0).ToList();
                            sameChildX = leftItems.Where(a => a.location.X == oa.location.X).ToList();
                            foreach (var item in leftItems)
                            {

                            }
                                    }
                                    else //odd
                                    {
                            if (oa.Tier == -2)
                                            oa.location = new System.Numerics.Vector3(xJump * (Column - 1), yParent, oa.location.Z);
                            else
                                            oa.location = new System.Numerics.Vector3(parentSceneObject.location.X + (xJump * Column), yParent, oa.location.Z);
                                        var rightItems = NetworkSceneObjects.Where((a, i) => i % 2 == 0).ToList();
                                        var sameChildXIDs = rightItems.Where(a => a.location.X == oa.location.X).Select( b => b.ParentID).ToList();
                            var parentIDs = new List<SceneObject>();                                            
                                    }

                                }
                            break;
                        }           
                        counter++;
        }

    }

                    
}

Your assistance is highly appreciated.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật