+1
Under review

HelixVisual3d not updating after created

Rodrigo Basniak 10 years ago updated by Kong Lee 3 years ago 212
Hi,

I'm need to show a circular torus on the viewport. The closest option I found was the HelixVisual3D, but it has open ends. So I tried to create my own class to draw this, with a HelixVisual3D and two thin cones to close the ends. I used the classes from the Building Demo as reference, so I came up with this:

public class TorusVisual3D : UIElement3D
{
    public static readonly DependencyProperty AngleProperty = DependencyPropertyEx.Register("Angle", 90, (s, e) => s.AppearanceChanged());
    public static readonly DependencyProperty RadiusProperty = DependencyPropertyEx.Register("Radius", 0.35, (s, e) => s.AppearanceChanged());
    public static readonly DependencyProperty DiameterProperty = DependencyPropertyEx.Register("Diameter", 0.1, (s, e) => s.AppearanceChanged());

    private GeometryModel3D torus = new GeometryModel3D();
    private GeometryModel3D cap1 = new GeometryModel3D();
    private GeometryModel3D cap2 = new GeometryModel3D();

    public TorusVisual3D()
    {
        AppearanceChanged();

        Model3DGroup model = new Model3DGroup();

        model.Children.Add(this.torus);
        model.Children.Add(this.cap1);
        model.Children.Add(this.cap2);

        this.Visual3DModel = model;
    }


    public double Angle
    {
        get
        {
            return (double)this.GetValue(AngleProperty);
        }
        set
       {
           this.SetValue(AngleProperty, value);
       }
    }

    public double Radius
    {
        get
        {
            return (double)this.GetValue(RadiusProperty);
        }
        set
        {
            this.SetValue(RadiusProperty, value);
        }
    }

    public double Diameter
    {
        get
        {
            return (double)this.GetValue(DiameterProperty);
        }
        set
        {
            this.SetValue(DiameterProperty, value);
        }
    }

    private void AppearanceChanged()
    {
        Material mat = MaterialHelper.CreateMaterial(Utils.GetRandomColor());

        HelixVisual3D h = new HelixVisual3D();
        h.Origin = new Point3D(0, 0, 0);
        h.Diameter = Diameter;
        h.Turns = Angle / 360.0;
        h.Radius = Radius;
        h.Length = 0;
        h.BackMaterial = mat;
        h.Material = mat;
        h.UpdateModel();
        this.torus = h.Model;

        MeshBuilder cap1Builder = new MeshBuilder(false, false);
        Point3D p1 = new Point3D(0, Radius, 0);
        cap1Builder.AddCone(p1, new Vector3D(0, 1, 0), h.Diameter / 2, h.Diameter / 2, 0.0001, true, true, 40);
        this.cap1.Material = MaterialHelper.CreateMaterial(Colors.Yellow);
        this.cap1.Geometry = cap1Builder.ToMesh();


        MeshBuilder cap2Builder = new MeshBuilder(false, false);
        Point3D p2 = new Point3D(-1, 0, 0);
        cap2Builder.AddCone(p2, new Vector3D(1, 0, 0), h.Diameter / 2, h.Diameter / 2, 0.0001, true, true, 40);
        this.cap2.Material = MaterialHelper.CreateMaterial(Colors.Red);
        this.cap2.Geometry = cap2Builder.ToMesh();
    }
}

To draw it I'm using the following code: 

    TorusVisual3D t = new TorusVisual3D();
    t.Angle = m_angle;
    t.Radius = m_radius1;
    t.Diameter = m_radius2 * 2.0;
    t.Transform = new TranslateTransform3D(0, 0, 0);
    ModelVisual3D model = new ModelVisual3D();
    model.Children.Add(t);
    var container = new ContainerUIElement3D();
    container.Children.Add(model);
    viewport.Children.Add(container);

The problem is that the Helix is drawn with the default values (Radius=0.35, Diameter=0.1 and Angle=90) and is never updated again. No matter what values I set on the Properties, it stays the same. The both cylinder are updated correctly, just the Helix isn't.

What am I'm doing wrong?

Thanks in advance,
Rodrigo

You seemed to have thought of everything in this topic! I will save your site and come back here real soon to read more informative post from you.

sa gaming

เล่นคาสิโนsa gamingเว็บไหนดี

เล่นคาสิโนสดsa gamingเว็บไหนดี

These are great wise words from the voice of experience and talented person like you! Thank your for sharing all of this and more motivating us.

pg slot

ทางเข้าเว็บสล็อตPG Slot

ทางเข้าเล่นเว็บสล็อตออนไลน์PG Slot

I will encourage my friends to follow your amazing website to read all your extremely useful and valuable blogs.

itp slot

ทางเข้าเว็บสล็อตITP Slot

ทางเข้าเว็บสล็อตITP Slotบนมือถือ

These are great wise words from the voice of experience and talented person like you! Thank your for sharing all of this and more motivating us.

Spade Gaming

ทางเข้าเว็บสล็อตSpade Gaming

ทางเข้าเว็บสล็อตSpade Gamingบนมือถือ

These are great wise words from the voice of experience and talented person like you! Thank your for sharing all of this and more motivating us.

gold diamond gaming

ทางเข้าเล่นคาสิโนgold diamond gaming

ทางเข้าเล่นgdg casino

You seemed to have thought of everything in this topic! I will save your site and come back here real soon to read more informative post from you.

Joker Gaming

ทางเข้าเว็บสล็อตJoker Gaming

ทางเข้าเว็บสล็อตJoker Gamingบนมือถือ

These are great wise words from the voice of experience and talented person like you! Thank your for sharing all of this and more motivating us.

sexy baccara

เล่นคาสิโนsexy baccaratเว็บไหนดี

เล่นคาสิโนsexy baccaratเว็บไหนดีpantip

You seemed to have thought of everything in this topic! I will save your site and come back here real soon to read more informative post from you.

Red Tiger

ทางเข้าเว็บสล็อตRed Tiger

ทางเข้าเว็บสล็อตRed Tigerบนมือถือ

These are great wise words from the voice of experience and talented person like you! Thank your for sharing all of this and more motivating us.

เล่นบอลตู้

สมัครเล่นบอลตู้

สมัครแทงบอลvirtual sports

I will encourage my friends to follow your amazing website to read all your extremely useful and valuable blogs.

Red Tiger

ทางเข้าเว็บสล็อตRed Tiger

ทางเข้าเว็บสล็อตRed Tigerบนมือถือ

These are great wise words from the voice of experience and talented person like you! Thank your for sharing all of this and more motivating us.

แทงบอลออนไลน์

เว็บพนันบอลไม่ผ่านเอเย่นต์

เดิมพันบอลเว็บตรง