0

Manipulators in code

Anonymous 10 years ago 0
This discussion was imported from CodePlex

ChrisKerridge wrote at 2012-04-30 10:52:

First off, great toolkit.

I want to be able to dynamically add objects to a 3D scene and be able to move them with manipulators using code similar to:

 

            var builder = new MeshBuilder(true, true);

            var position = new Point3D(0, 0, 0);

            builder.AddSphere(position, 1);


            var geom = new GeometryModel3D(builder.ToMesh(), Materials.Red);
            var visual = new ModelVisual3D();
            visual.Content = geom;

            var manipulator = new TranslateManipulator();
            manipulator.Bind(visual);
            manipulator.Position = position;
            manipulator.Direction = new Vector3D(0, 0, 1);
            manipulator.Offset = new Vector3D(0, 0, 1);
            manipulator.Color = Colors.Blue;

            
            vp.Children.Add(manipulator);
            vp.Children.Add(visual);
 

 

This gives me a sphere and an arrow pointing upwards (great), but dragging the arrow up and down has no affect on the sphere. How can I get the manipulator to affect the sphere?

Thanks a lot


objo wrote at 2012-05-02 21:36:

I found a bug in the code - the Manipulator.Bind method should not use CombinedManipulator.TargetTransformProperty, but its own. I will submit the fix soon. Thanks for providing the code that made it easy to find the error.

Also, move your code line

manipulator.Bind(visual);
below the manipulator.Position setter (this will actually modify the Transform and break the Transform binding).

Sorry there is no more documentation than the XML comments and the example on these features - it was experimental code that seemed to work well, so I just put it into the library...


christianw42 wrote at 2013-06-06 11:13:

Hello,

is there still anything broken in the toolkit? Here you can see my code, I can see the box and the manipulator, but when i click the manipulator, nothing happens.
var volumeBox = new BoxVisual3D();
volumeBox.Center = new Point3D(0, 0, 0);
volumeBox.Length = 0.3;
volumeBox.Width = 0.3;
volumeBox.Height = 0.3;
volumeBox.Material = MaterialHelper.CreateMaterial(Colors.SkyBlue, 0.3);

var manipulator = new TranslateManipulator();
manipulator.Color = Colors.Red;
manipulator.Length = 0.4;
manipulator.Diameter = 0.02;
manipulator.Position = new Point3D(0, 0, 0);
manipulator.Direction = new Vector3D(1, 0, 0);
manipulator.Bind(volumeBox);

this.VolumeBoxModel.Children.Add(volumeBox);
this.VolumeBoxModel.Children.Add(manipulator);
Thanks a lot

christianw42 wrote at 2013-06-06 11:30:

Ok, now it works. I think it's an initialize bug of UIElement3D.

Workaround: add the following two lines after the code above.
this.HelixViewport.Visibility = Visibility.Collapsed;
this.HelixViewport.Visibility = Visibility.Visible;
Thanks for a great framework!