0

Get position of selected model?

B 8 years ago updated by Basil Paudel 8 years ago 1

Hi, Using the example RectSelection I have a 3d viewport in which I can select my objects, which are BoxVisual3D.

What I need to do, is return the 3d position of the selected object. I have:

  foreach (var model in models)
            {
                var geometryModel = model as GeometryModel3D;
                if (geometryModel != null)
                {
                    geometryModel.Material = geometryModel.BackMaterial = material;

                    
                    //do stuff 
                    UserControl1.Point1Position = model.Transform; 
                    
                    UserControl1.returnPoint.X = model.Transform.Value.M14;
                    UserControl1.returnPoint.Y = geometryModel.Transform.Value.M24;
                    UserControl1.returnPoint.Z = geometryModel.Transform.Value.M34;
                }
            }

But the values always return as 0. (I spawn the box myself, so i know they are not 0.
When I step through, there is a selected object, but the transform reads as all zeros. How can i get the positin of a BoxVisual3D?

Thanks.

-1

You probably need to use the Position property to get the Position data back instead of Transform Property, unless you used both Positions property and transformed it later, then you need to use combined data. When you transform a visual or model3d, its actual position property is not changed. That data is retained by Transform property and used for displaying that object