private void NodeGroup_OnAddChildNode(object sender, OnChildNodeChangedArgs e) { OctreeManager?.AddPendingItem(e); }
protected void ItemsModel3D_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Reset: OctreeManager?.Clear(); OctreeManager?.RequestRebuild(); break; } switch (e.Action) { case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Remove: if (e.OldItems != null) { foreach (var item in e.OldItems) { if (mDictionary.ContainsKey(item)) { var model = mDictionary[item]; if (model is GeometryModel3D) { OctreeManager?.RemoveItem(model as GeometryModel3D); } model.DataContext = null; this.Children.Remove(model); mDictionary.Remove(item); } } InvalidateRender(); } break; case NotifyCollectionChangedAction.Reset: var array = this.Children.ToArray(); foreach (var item in array) { item.DataContext = null; this.Children.Remove(item); } mDictionary.Clear(); break; } switch (e.Action) { case NotifyCollectionChangedAction.Reset: if (this.ItemsSource != null) { if (this.ItemTemplate == null) { foreach (var item in this.ItemsSource) { var model = item as Model3D; if (model != null) { this.Children.Add(model); mDictionary.Add(item, model); } else { throw new InvalidOperationException("Cannot create a Model3D from ItemTemplate."); } } } else { foreach (var item in this.ItemsSource) { var model = this.ItemTemplate.LoadContent() as Model3D; if (model != null) { model.DataContext = item; this.Children.Add(model); mDictionary.Add(item, model); } else { throw new InvalidOperationException("Cannot create a Model3D from ItemTemplate."); } } } } InvalidateRender(); break; case NotifyCollectionChangedAction.Add: case NotifyCollectionChangedAction.Replace: if (e.NewItems != null) { if (this.ItemTemplate != null) { foreach (var item in e.NewItems) { if (mDictionary.ContainsKey(item)) { continue; } var model = this.ItemTemplate.LoadContent() as Model3D; if (model != null) { OctreeManager?.AddPendingItem(model); model.DataContext = item; this.Children.Add(model); mDictionary.Add(item, model); } else { throw new InvalidOperationException("Cannot create a Model3D from ItemTemplate."); } } } else { foreach (var item in e.NewItems) { if (mDictionary.ContainsKey(item)) { continue; } var model = item as Model3D; if (model != null) { OctreeManager?.AddPendingItem(model); this.Children.Add(model); mDictionary.Add(item, model); } else { throw new InvalidOperationException("Cannot create a Model3D from ItemTemplate."); } } } } break; } }