Пример #1
0
        public static void WrapWith(IObject3D originalItem, IObject3D wrapper, InteractiveScene scene)
        {
            using (originalItem.RebuildLock())
            {
                originalItem.Parent.Children.Modify(list =>
                {
                    list.Remove(originalItem);

                    wrapper.Matrix = originalItem.Matrix;

                    originalItem.Matrix = Matrix4X4.Identity;
                    wrapper.Children.Add(originalItem);

                    list.Add(wrapper);
                });

                if (scene != null)
                {
                    var topParent = wrapper.Ancestors().LastOrDefault(i => i.Parent != null);
                    UiThread.RunOnIdle(() =>
                    {
                        scene.SelectedItem = topParent ?? wrapper;
                    });
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Got the top of this objects parent tree and get change the name of the object if
        /// required to make sure it is not the same as any other descendant
        /// </summary>
        /// <param name="root"></param>
        public static void MakeNameNonColliding(this IObject3D item)
        {
            var topParent = item.Ancestors().LastOrDefault();

            if (topParent != null)
            {
                var names = topParent.DescendantsAndSelf().Where((i) => i != item).Select((i2) => i2.Name).ToList();

                if (string.IsNullOrEmpty(item.Name))
                {
                    // Object3D authors should give their objects a simplified name, but if they fail to do so,
                    // fallback to a sane default before calling into GetNonCollidingName
                    item.Name = item.TypeName;
                }

                item.Name = agg_basics.GetNonCollidingName(item.Name, names);
            }
        }
        public void Dispose()
        {
            if (selectedItem == null)
            {
                return;
            }

            // if the item we had selected is still in the scene, re-select it
            if (scene.Children.Contains(selectedItem))
            {
                scene.SelectedItem = selectedItem;
                return;
            }

            // if the previously selected item is not in the scene
            if (!scene.Children.Contains(selectedItem))
            {
                // and we have only added one new item to the scene
                var newItems = scene.Children.Where(c => !childrenAtStart.Contains(c));
                // select it
                if (newItems.Count() == 1)
                {
                    scene.SelectedItem = newItems.First();
                    return;
                }
                else
                {
                    scene.SelectedItem = null;
                    return;
                }
            }

            // set the root item to the selection and then to the new item
            var rootItem = selectedItem.Ancestors().Where(i => scene.Children.Contains(i)).FirstOrDefault();

            if (rootItem != null)
            {
                scene.SelectedItem = rootItem;
                scene.SelectedItem = selectedItem;
            }
        }
Пример #4
0
 public static int Depth(this IObject3D item)
 {
     return(item.Ancestors().Count());
 }