How to Write Text in a WPF Viewport3d That Always Reads Front

asked 2022-05-23T14:40:37.283+00:00
Marino Liranzo 21 Reputation points

Hello, I am using a following method to write text in a wpf viewport3d from Mr. Rod Stephens-CsharpHelper.com.

textLong = TextCreator.CreateTextLabelModel3D(.ToString(), colorTexto,
                        true, .20, new Point3D(new Point3D(x, y, z)),
            new Vector3D(1, 0, 0), new Vector3D(0, 0, 1));
                        modelg.Children.Add(textLong);

The problem is that the orientation and direction of the text depends on the vectors in the method and in this case the texts will always be seen in the position indicated by the vectors, I would like that when the camera rotates the text reads the same, that is, that the vectors change to adapt to the new position of the camera.

Greeting Marino Liranzo

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,171 questions
{count} votes

2 answers

Sort by: Most helpful
  1. answered 2022-05-24T17:12:08.907+00:00
    Marino Liranzo 21 Reputation points

    Hello Huiliu-MSFT, Thank you for your interest.
    In this case, in the "Vector3D(1, 0, 0)" method, it indicates that the text will be displayed in the X direction, the vector Vector3D(0, 0, 1) indicates that the text will have its elevation in Z, that is, will be displayed in the xz plane, when I rotate the model the text will rotate as well as the plane it lies on. I want the text to always be displayed as if the model had not rotated, I think that the components of the vectors should be modified in which they are automatically modified with the rotation of the model. My viewport is a Helix Viewport3D and the rotations are done through the mouse.


  2. answered 2022-05-25T15:53:40.687+00:00
    Marino Liranzo 21 Reputation points

    Hi,

    Attached code snippet.

    private void MostrarRepresentacionNudos(Model3DGroup modelg, Vector3D _v1, Vector3D _v2)
            {
                modelg.Children.Remove(textcreate);
                Brush colorTexto = colortextosProp;
    
                if (nudoList != null) 
                {
                    for (int i = 0; i < nudoList.Count; i++)
                    {
                        clodo = new clNodos();
                        clodo.pt = nudoList[i];
                        clodo.name = "N" + i;
                        cnodo.Add(clodo);
                    }
                    for (int i = 0; i < cnodo.Count; i++)
                    {
                        clNodos cln = new clNodos();
                        double x = cnodo[i].pt.X;
                        double y = cnodo[i].pt.Y;
                        double z = cnodo[i].pt.Z;
                        textLong = TextCreator.CreateTextLabelModel3D(cnodo[i].name, colorTexto,
                            true, .20, new Point3D(x, y + 0.20, z), _v1, _v2);
                        modelg.Children.Add(textLong);
                    }
                }
                if (nList != null)
                {
                    for (int i = 0; i < nList.Count; i++)
                    {
                        wlodo = new Node();
                        wlodo.Location = nList[i].Location;
                        wlodo.Label = "N" + (nudoList.Count + i);
                        Wnodo.Add(wlodo);
                    }
                    for (int i = 0; i < Wnodo.Count; i++)
                    {
                        Node cln = new Node();
                        double x = Wnodo[i].Location.X;
                        double y = Wnodo[i].Location.Y;
                        double z = Wnodo[i].Location.Z;
    
                        Draw3DNudos(MainModel3Dgroup, new Point3D(x, y, z), 0.025, colorMuros);
    
                        textLong = TextCreator.CreateTextLabelModel3D(Wnodo[i].Label, colorTexto,
                            true, .20, new Point3D(x, y +.15, z), _v1, _v2);
                        modelg.Children.Add(textLong);
                    }
                }
            }