private void CreateRandomScene() { SceneObjectsContainer.Children.Clear(); for (int i = 0; i < 10; i++) { var boxModel = new Ab3d.UIElements.BoxUIElement3D() { CenterPosition = new Point3D(_rnd.NextDouble() * 400 - 200, _rnd.NextDouble() * 40 - 20, _rnd.NextDouble() * 400 - 200), Size = new Size3D(50, 20, 50), Material = _normalMaterial }; SceneObjectsContainer.Children.Add(boxModel); // Use EventManager from Ab3d.PowerToys to add support for click event on the box model var visualEventSource3D = new Ab3d.Utilities.VisualEventSource3D(boxModel); visualEventSource3D.MouseClick += delegate(object sender, MouseButton3DEventArgs e) { var selectedBoxModel = e.HitObject as Ab3d.UIElements.BoxUIElement3D; SelectObject(selectedBoxModel); }; _eventManager.RegisterEventSource3D(visualEventSource3D); // Automatically select first box if (_selectedBoxModel == null) { boxModel.Refresh(); // Force creating the model SelectObject(boxModel); } } }
private void CreateRandomScene() { SceneObjectsContainer.Children.Clear(); for (int i = 0; i < 10; i++) { // Create simple box that user will be able to rotate // In order to support rotation, we need to create the box at (0,0,0) // and then after performing rotation, translate the object to its final location. // If we would create the object at its final rotation (basically applying translation before rotation), // then the box would not be rotated around its center but around the coordinate axes center. var boxModel = new Ab3d.UIElements.BoxUIElement3D() { CenterPosition = new Point3D(0, 0, 0), Size = new Size3D(50, 20, 50), Material = _normalMaterial }; // Create a StandardTransform3D // StandardTransform3D is a class that generates a MatrixTransform3D based on the translate, rotate and scale transform. // Note that because it is not possible to derive from WPF's Transform3D, the StandardTransform3D is a standalone class // that provides its own MatrixTransform3D object that can be assigned to the 3D model. // Its static SetStandardTransform3D and GetStandardTransform3D use a custom StandardTransform3DProperty // to "attach" the StandardTransform3D object to Model3D or Visual3D. But this does not automatically set the // object's transformation. var standardTransform3D = new StandardTransform3D() { TranslateX = _rnd.NextDouble() * 400 - 200, TranslateY = _rnd.NextDouble() * 40 - 20, TranslateZ = _rnd.NextDouble() * 400 - 200, }; // SetStandardTransform3D method will set the StandardTransform3DProperty to the standardTransform3D // The updateTransform3D argument will also set the boxModel.Transform to standardTransform3D.Transform StandardTransform3D.SetStandardTransform3D(boxModel, standardTransform3D, updateTransform3D: true); SceneObjectsContainer.Children.Add(boxModel); // Use EventManager from Ab3d.PowerToys to add support for click event on the box model var visualEventSource3D = new Ab3d.Utilities.VisualEventSource3D(boxModel); visualEventSource3D.MouseClick += delegate(object sender, MouseButton3DEventArgs e) { var selectedBoxModel = e.HitObject as Ab3d.UIElements.BoxUIElement3D; SelectObject(selectedBoxModel); }; _eventManager.RegisterEventSource3D(visualEventSource3D); // Automatically select first box if (_selectedBoxModel == null) { boxModel.Refresh(); // Force creating the model SelectObject(boxModel); } } }
private void CreateRandomScene() { SceneObjectsContainer.Children.Clear(); for (int i = 0; i < 10; i++) { // Create simple box that user will be able to rotate // In order to support rotation, we need to create the box at (0,0,0) // and then after performing rotation, translate the object to its final location. // If we would create the object at its final rotation (basically applying translation before rotation), // then the box would not be rotated around its center but around the coordinate axes center. var boxModel = new Ab3d.UIElements.BoxUIElement3D() { CenterPosition = new Point3D(0, 0, 0), Size = new Size3D(50, 20, 50), Material = _normalMaterial }; // Create Transform3DGroup that will hold the var transform3DGroup = new Transform3DGroup(); transform3DGroup.Children.Add(new TranslateTransform3D(_rnd.NextDouble() * 400 - 200, _rnd.NextDouble() * 40 - 20, _rnd.NextDouble() * 400 - 200)); boxModel.Transform = transform3DGroup; SceneObjectsContainer.Children.Add(boxModel); // Use EventManager from Ab3d.PowerToys to add support for click event on the box model var visualEventSource3D = new Ab3d.Utilities.VisualEventSource3D(boxModel); visualEventSource3D.MouseClick += delegate(object sender, MouseButton3DEventArgs e) { var selectedBoxModel = e.HitObject as Ab3d.UIElements.BoxUIElement3D; SelectObject(selectedBoxModel); }; _eventManager.RegisterEventSource3D(visualEventSource3D); // Automatically select first box if (_selectedBoxModel == null) { boxModel.Refresh(); // Force creating the model SelectObject(boxModel); } } }