Your comments
Thanks for the info. As an exercise, I attempted to write the subclass you suggested, but got stuck on setting the default property for the axis label. A snippet showing the problem is included below:
public static readonly DependencyProperty XAxisLabelProperty = DependencyProperty.Register( "XAxisLabel", typeof(BillboardTextItem), typeof(LabeledCoordSysVis3D), new UIPropertyMetadata("X"));
The above code compiles fine, but the line
<local:LabeledCoordSysVis3D />
shows the error "Default value type does not match tpe of property 'XAxisLabel' :-(
I confess that I really don't know what I'm doing in this DependencyPropery declaration, but I tried to copy from the CoordinateSystemVisual3D declaration as much as possible. What I'm trying to do here is set the default property of the X axis label to "X" - what's the proper way to do this?
Full code for the 'LabeledCoordSysVis3D' class is provided below:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using HelixToolkit.Wpf; using System.Windows; using System.Windows.Media; using System.Windows.Media.Media3D; namespace MyWPFMagViewer2 { class LabeledCoordSysVis3D:CoordinateSystemVisual3D { #region Constants and Fields /// <summary> /// The arrow lengths property. /// </summary> public static readonly DependencyProperty AxisLabelSizeProperty = DependencyProperty.Register( "AxisLabelSize", typeof(double), typeof(LabeledCoordSysVis3D), new UIPropertyMetadata(1.0, GeometryChanged)); /// <summary> /// The x axis color property. /// </summary> public static readonly DependencyProperty XAxisLabelProperty = DependencyProperty.Register( "XAxisLabel", typeof(BillboardTextItem), typeof(LabeledCoordSysVis3D), new UIPropertyMetadata("X")); /// <summary> /// The y axis color property. /// </summary> public static readonly DependencyProperty YAxisLabelProperty = DependencyProperty.Register( "YAxisLabel", typeof(BillboardTextItem), typeof(LabeledCoordSysVis3D), new UIPropertyMetadata("Y")); /// <summary> /// The z axis color property. /// </summary> public static readonly DependencyProperty ZAxisLabelProperty = DependencyProperty.Register( "ZAxisLabel", typeof(BillboardTextItem), typeof(LabeledCoordSysVis3D), new UIPropertyMetadata("Z")); #endregion #region Constructors and Destructors /// <summary> /// Initializes a new instance of the <see cref = "LabeledCoordSysVis3D" /> class. /// </summary> public LabeledCoordSysVis3D() { this.OnGeometryChanged(); } #endregion #region Public Properties /// <summary> /// Gets or sets the label size. /// </summary> /// <value>The label size.</value> public double AxisLabelSize { get { return (double)this.GetValue(AxisLabelSizeProperty); } set { this.SetValue(AxisLabelSizeProperty, value); } } /// <summary> /// Gets or sets the label of the X axis. /// </summary> /// <value>The label of the X axis.</value> public Color XAxisLabel { get { return (Color)this.GetValue(XAxisLabelProperty); } set { this.SetValue(XAxisLabelProperty, value); } } /// <summary> /// Gets or sets the label of the Y axis. /// </summary> /// <value>The label of the Y axis.</value> public Color YAxisLabel { get { return (Color)this.GetValue(YAxisLabelProperty); } set { this.SetValue(YAxisLabelProperty, value); } } /// <summary> /// Gets or sets the label of the Z axis. /// </summary> /// <value>The label of the Z axis.</value> public Color ZAxisLabel { get { return (Color)this.GetValue(ZAxisLabelProperty); } set { this.SetValue(ZAxisLabelProperty, value); } } #endregion #region Methods /// <summary> /// The geometry changed. /// </summary> /// <param name="obj"> /// The obj. /// </param> /// <param name="args"> /// The args. /// </param> protected new static void GeometryChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { ((LabeledCoordSysVis3D)obj).OnGeometryChanged(); } /// <summary> /// Called when the geometry has changed. /// </summary> protected override void OnGeometryChanged() { this.Children.Clear(); double h = this.AxisLabelSize; var xlabel = new BillboardTextVisual3D(); xlabel.Text = XAxisLabel.ToString(); xlabel.Foreground = new SolidColorBrush(this.XAxisColor); xlabel.HeightFactor = AxisLabelSize; xlabel.Position = new Point3D(ArrowLengths * 1.1, 0, 0); this.Children.Add(xlabel); var ylabel = new BillboardTextVisual3D(); ylabel.Text = XAxisLabel.ToString(); ylabel.Foreground = new SolidColorBrush(this.XAxisColor); ylabel.HeightFactor = AxisLabelSize; ylabel.Position = new Point3D(ArrowLengths * 1.1, 0, 0); this.Children.Add(ylabel); var zlabel = new BillboardTextVisual3D(); zlabel.Text = XAxisLabel.ToString(); zlabel.Foreground = new SolidColorBrush(this.XAxisColor); zlabel.HeightFactor = AxisLabelSize; zlabel.Position = new Point3D(ArrowLengths * 1.1, 0, 0); this.Children.Add(zlabel); } #endregion } }
Got it - Thanks! Is there any way at present to add labels to the 'geometry-centered' coordinate system? I saw there was an issue (Issue #18) about this, with the notation that labels were added, but I don't see that anywhere in the available properties for CoordinateSystemVisual3D, nor did I see anything in the class code source. Am I missing something?
Frank
Ergon,
You were correct - it was the lack of a lighting source. I didn't realize the problem, as the PointVisual3D collection renders fine without any lighting! Once I figured that out, and added a light to the scene, at least that part works well now ;-).
Frank
Ergon,
Tried the new class - no change in behavior. Here's the relevant code:
//try adding an ellipse to view //EllipsoidVisual3D ell1 = new EllipsoidVisual3D(); MyEllpsoidVisual ell1 = new MyEllpsoidVisual(); SolidColorBrush perimeterbrush = new SolidColorBrush(Colors.Red); System.Windows.Media.Media3D.Material mat = MaterialHelper.CreateMaterial(new SolidColorBrush(Colors.Red)); ell1.Material = mat; ell1.BackMaterial = mat; ell1.Fill = perimeterbrush; ell1.Center = new Point3D(0, 0, 0); ell1.RadiusX = 1; ell1.RadiusZ = 1; ell1.RadiusY = 1; ell1.Model.BackMaterial = mat; ell1.Model.Material = mat; ell1.Fill = new SolidColorBrush(Colors.White); vp_cal.Children.Add(ell1);
And here's a screenshot of the result. As you can see, I still get a completely black sphere.
Note: In the above code snippet, you'll see that I tried setting every visual property I could think of, including 'Material', 'BackMaterial', 'Fill', 'Model.Material', etc. None of these property changes had any effect on the displayed object color.
Any other thoughts?
Frank
Thanks Egon - I'll give that a try and report back. Does that class have to be in any particular namespace? IOW, can I place this class in it's own file as part of my current WPF project, or does it need to reside somewhere in the Helix Toolkit source tree?
TIA,
Frank
Hmm, I'll look into TubeVisual3D. Regarding the light - The rest of the objects in the view have color (red dots, yellow dots). Only the Ellipsoid object shows in black. Do I need to define the light separately for each item in the model?
TIA,
Frank
Suran,
Not sure if this helps exactly, but I recently did this with a WPF project consisting of a window, a grid, and a HelixViewport3D object. Here's the XAML and the MouseDown event code
<code>
private void vp_raw_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
</code>
And the XAML
<code>
<Window
</code>
Sorry, no preview feature, so cant tell how this is going to look :-(
Frank
Customer support service by UserEcho
Egon,
Thanks! With the clues you provided, I have been able to get the subclass working properly. Here's a screenshot of my magnetometer calibration tool, with the left-hand 'raw' viewport coordinate axis symbol created using '<local:LabeledCoordSysVis3D />', and the right-hand 'calibrated' viewport symbol created using
The only visible difference between the two is that the 'X', 'Y', & 'Z' labels on the left are colored the same as the axis arrows, while the ones on the right are all black text.
The next screenshot shows the XAML for both windows and the exposed properties for both the LabeledCoordSysVis3D and CoordinateSystemVisual3D classes
And here is the complete - now working thanks to Egon! - subclass code:
I'm sure others can do a better job than this, but I learned a LOT getting this far, and I really appreciate the help from Egon and others - THANKS!!
Frank