question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Hexlix WPF-v2.23] TranslateManipulator can not set position, and update wrong Transform in code behind

See original GitHub issue

I’m trying to use the C# code behind to create a TranslateManipulator with cutting plane and rectangleVisual3D. But I see that, I can not set position for TranslateManipulator if I use it together with translateManipulator.Bind(ModelVisual3D). TranslateManipulator seems it init then updates the wrong value.

case error 1: translateManipulator.Transform wrong update value (see cutting plane cut the box), translateManipulator not move

“aaaa”

case error 2: translateManipulator can not set and update position, it allway is (0,0,0)

https://user-images.githubusercontent.com/48544354/233834131-866ce676-fc08-4867-832c-7a06c4f00a29.mp4

Here is my code reproduction error ( see case error 1 and case error 2)

using HelixToolkit.Wpf;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Windows.Shapes;

namespace LearnHelixTookit.Wpf.Views
{
    /// <summary>
    /// Err update position TranslateManipulator position (see case 1 anfd case 2)
    /// </summary>
    public partial class FixManipulatorPosition : Window
    {
        Plane3D plane = new Plane3D(new Point3D(), new Vector3D(0, 0, 1));
        CuttingPlaneGroup cuttingGroup;
        RectangleVisual3D rectangle3D;
        TranslateManipulator translateManipulator;
        public FixManipulatorPosition()
        {
            InitializeComponent();
            translateManipulator = new TranslateManipulator()
            {
                Direction = new Vector3D(0, 0, 1),
                Length = 2,
                Color = Colors.Green,
                /*Position= new Point3D(0, 0, 2) not update */
            };
            translateManipulator.MouseMove += TranslateManipulator_MouseMove;
            rectangle3D = new RectangleVisual3D()
            {
                Width = 2,
                Length = 4,
                Normal = new Vector3D(0, 0, 1),
                Material = new DiffuseMaterial(Brushes.Red),
                Origin = new Point3D(0, 5, 1),
            };

            //Case err1 -  translateManipulator.Transform wrong update value (see cutting plane cut the box), translateManipulator not move
            translateManipulator.Bind(rectangle3D);
            translateManipulator.Position = new Point3D(0, 5, 2);

            ////Case err2 translateManipulator can not set and update position, it allway is (0,0,0)
            //translateManipulator.Position = new Point3D(0, 5, 2);
            //translateManipulator.Bind(rectangle3D);


            CubeVisual3D cube = new CubeVisual3D() { Center = new Point3D(0, 5, 1) };
            cuttingGroup = new CuttingPlaneGroup();
            cuttingGroup.CuttingPlanes = new List<Plane3D> { plane };

            cuttingGroup.Children.Add(cube);
            viewport.Children.Add(translateManipulator);
            viewport.Children.Add(rectangle3D);
            viewport.Children.Add(cuttingGroup);

            BillboardTextVisual3D billboard = new BillboardTextVisual3D() { Text = "C# behavior (see case err 1 and case err 2 in code behide )", Position = new Point3D(0, 5, 3) };
            viewport.Children.Add(billboard);
        }

        private void TranslateManipulator_MouseMove(object sender, MouseEventArgs e)
        {
            plane.Position = translateManipulator.Transform.Transform(rectangle3D.Origin);
            cuttingGroup.UpdateModel();
        }

        private void manipulator_MouseMove(object sender, MouseEventArgs e)
        {
            xamlCutting.UpdateModel();
        }
    }
}

<Window x:Class="LearnHelixTookit.Wpf.Views.FixManipulatorPosition"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:LearnHelixTookit.Wpf.Views"
           xmlns:ht="http://helix-toolkit.org/wpf"
        mc:Ignorable="d"
        Title="FixManipulator" Height="450" Width="800">
    <Grid>
        <ht:HelixViewport3D x:Name="viewport">
            <ht:SunLight></ht:SunLight>
            <ht:GridLinesVisual3D ></ht:GridLinesVisual3D>
            <ht:TranslateManipulator x:Name="manipulator" Color="Red" MouseMove="manipulator_MouseMove"
                                          Length="4" 
                                     Position="{Binding ElementName=pl, Path=Position}"
                                         Direction="0,0,1"
                                     ></ht:TranslateManipulator>
            <ht:RectangleVisual3D Width="2" Length="3" Origin="{Binding ElementName=manipulator, Path=Position}"></ht:RectangleVisual3D>
            <ht:CuttingPlaneGroup x:Name="xamlCutting">
                <ht:CuttingPlaneGroup.CuttingPlanes>
                    <ht:Plane3D x:Name="pl" Position="5,0,0" Normal="0,0,1"></ht:Plane3D>
                </ht:CuttingPlaneGroup.CuttingPlanes>
                <ht:CubeVisual3D x:Name="cube" Center="5,0,0"></ht:CubeVisual3D>
            </ht:CuttingPlaneGroup>

            <ht:BillboardTextVisual3D Text="xaml behavior"  Position="5,0,4"></ht:BillboardTextVisual3D>


        </ht:HelixViewport3D>
    </Grid>
</Window>

Issue Analytics

  • State:open
  • Created 5 months ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
holancecommented, May 6, 2023

Breaking change should be fine if it is necessary to fix bugs.

0reactions
MauNguyenVancommented, May 7, 2023

what are the purposes of BindableTranslateManipulator/BindableRotateManipulator vs TranslateManipulator/ RotateManipulator? I think they are the same functions. and should be reduce 2 of them in 1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does two Transform do not work with a Helix Toolkit ...
I have put together some code where I am manipulating two Helix Toolkit Torus objects by using WPF slider controls. This code is...
Read more >
Resolved - transform.position does not work
I've been trying to make my own save and load features for my game. I got everything working until the last few lines...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found