Adding LineVisual3D messes up unrelated transformations
Hello everyone,

my goal is quite simple: for a given hierarchy, take selected objects and draw them as a wireframe with center visualized as a sphere or as lines. For the sphere it works correctly as one would expect. I add a SphereVisual3D into a hierarchy of ContentVisual3D objects with only leaves as geometry. I attached ab3d dump file - correct.txt.

However, when I try adding LineVisual3D, it messes everything up. How messed up the result is depends on order and if the lines attached are under single ModelVisual3D or each by itself. Each of these object are added as a children of the selected ContentVisual3D. One wrong hierarchy attached as well - wrong1.txt.

So the question is: Where is the catch? Why does it do this nonsense? It even messes up with a grid defined outside the model itself (it takes the major lines of the grid as shown on the second image) or with the wireframe geometry, but not its solid part...

Thanks for reply and future insights

Attached Files
.txt   correct.txt (Size: 6.09 KB / Downloads: 2)
.txt   wrong1.txt (Size: 7.03 KB / Downloads: 1)
Hm, this really looks very strange.

Based on your hierarchy dumps I have tried to reproduce the problem but did not succeed. I used the following code to create the 3D scene:

           var wireGridVisual3D = new WireGridVisual3D()
                   CenterPosition = new Point3D(0, 0, 0),
                   Size = new Size(300, 300),
                   WidthDirection = new Vector3D(1, 0, 0),
                   HeightDirection = new Vector3D(0, 0, -1),
                   LineColor = Colors.Gray,
                   LineThickness = 1,
                   WidthCellsCount = 20,
                   HeightCellsCount =20,
                   MajorLineColor = Colors.Silver,
                   MajorLineThickness = 2,
                   MajorLinesFrequency = 5,
                   IsClosed = true

           var rootModelVisual3D = new ModelVisual3D();


           Camera1.Refresh(); // Recreate camera light after clearing

           var cv1 = new ContentVisual3D();

           var cv2 = new ContentVisual3D();
           cv2.Transform = new MatrixTransform3D(new Matrix3D(0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1));

           var cv3 = new ContentVisual3D();

           var b1 = new BoxVisual3D()
               CenterPosition = new Point3D(50, -5, 0),
               Size           = new Size3D(50, 1, 10),
               Material       = new DiffuseMaterial(Brushes.Orange)


           var cv4 = new ContentVisual3D();
           cv4.Transform = new MatrixTransform3D(new Matrix3D(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1));
           var cv5 = new ContentVisual3D();

           var sphereVisual3D = new SphereVisual3D()
               CenterPosition = new Point3D(50, 0, 0),
               Radius         = 5,
               Material       = new DiffuseMaterial(Brushes.Red)


           var geometryModel3D = Ab3d.Models.Model3DFactory.CreateBox(new Point3D(50, 0, 0), new Size3D(50, 5, 10), new DiffuseMaterial(Brushes.Green));

           var wireframeVisual3D = new WireframeVisual3D();
           wireframeVisual3D.OriginalModel = geometryModel3D;
           wireframeVisual3D.WireframeType = WireframeVisual3D.WireframeTypes.Wireframe;


           var modelVisual3D = new ModelVisual3D();

           var l1 = new LineVisual3D()
               StartPosition = new Point3D(50, 0, 0),
               EndPosition = new Point3D(0, 0, 0),
               LineColor = Colors.Red,
               LineThickness = 3

           var l2 = new LineVisual3D()
               StartPosition = new Point3D(50, 0, 0),
               EndPosition = new Point3D(50, 50, 0),
               LineColor = Colors.Green,
               LineThickness = 3

           var l3 = new LineVisual3D()
               StartPosition = new Point3D(50, 0, 0),
               EndPosition = new Point3D(50, 0, 50),
               LineColor = Colors.Blue,
               LineThickness = 3



           var cv6 = new ContentVisual3D();
           cv6.Transform = new MatrixTransform3D(new Matrix3D(1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1));

           var cv7 = new ContentVisual3D();

           var b2 = new BoxVisual3D()
               CenterPosition = new Point3D(50, -5, 0),
               Size           = new Size3D(50, 2, 5),
               Material       = new DiffuseMaterial(Brushes.Yellow)


This creates the following hierarchy:
Viewport3D ("MainViewport")  
       Model3DGroup   Children count: 3
           GeometryModel3D   Material: Group: [ [Diffuse: #FF000000] [Emissive: #FF808080] ] |  Geometry: null
           GeometryModel3D   Material: Group: [ [Diffuse: #FF000000] [Emissive: #FFC0C0C0] ] |  Geometry: null
           GeometryModel3D   Material: Group: [ [Diffuse: #FF000000] [Emissive: #FFC0C0C0] ] |  Geometry: null
           ContentVisual3D   Transform: 0,1,0,0,-1,0,0,0,0,0,1,0,0,0,0,1
                       GeometryModel3D   Material: Diffuse: #FFFFA500 |  Geometry: Positions: 24; TriangleIndices: 36 (12 triangles); Normals: 24; TextureCoordinates: 24  |  Center: 50 -5 0  |  Size: 50 x 1 x 10 |  Transform: 50,0,0,0,0,1,0,0,0,0,10,0,50,-5,0,1
               ContentVisual3D   Transform: -1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,1
                           GeometryModel3D   Material: Diffuse: #FFFF0000 |  Geometry: Positions: 961; TriangleIndices: 5220 (1740 triangles); Normals: 961; TextureCoordinates: 961  |  Center: 50 0 0  |  Size: 9.9 x 10 x 10 |  Transform: 5,0,0,0,0,5,0,0,0,0,5,0,50,0,0,1
                               GeometryModel3D   Material: Group: [ [Diffuse: #FF000000] [Emissive: #FFFF0000] ] |  Geometry: null
                               GeometryModel3D   Material: Group: [ [Diffuse: #FF000000] [Emissive: #FF008000] ] |  Geometry: null
                               GeometryModel3D   Material: Group: [ [Diffuse: #FF000000] [Emissive: #FF0000FF] ] |  Geometry: null
                           GeometryModel3D   Material: Group: [ [Diffuse: #FF000000] [Emissive: #FF008000] ] |  Geometry: Positions: 0; TriangleIndices: 0 (0 triangles); Normals: 0; TextureCoordinates: 0
               ContentVisual3D   Transform: 1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1
                           GeometryModel3D   Material: Diffuse: #FFFFFF00 |  Geometry: Positions: 24; TriangleIndices: 36 (12 triangles); Normals: 24; TextureCoordinates: 24  |  Center: 50 -5 0  |  Size: 50 x 2 x 5 |  Transform: 50,0,0,0,0,2,0,0,0,0,5,0,50,-5,0,1
       DirectionalLight   Direction: 0.5,-0.3,-0.8;  Color: #FFFFFFFF

I tried to change the order of objects and some other things but still the results were correct. I also tied adding and removing 3D lines.

Are you using Ab3d.DXEngine (DirectX 11 rendering engine) to render the scene (though I have also tried there and it looks correct)?

Do you have a Transformation set on the GeometryModel3D that is assigned to WireframeVisual3D's OriginalModel? (in your dump texts I do not see that object as child of WireframeVisual3D so you are probably adding that later).

Did you maybe get any additional clue on what could be the problem?

Btw: I do not like that you are using ContentVisual3D for grouping. You should use ModelVisual3D for that. The purpose of ContentVisual3D is to be able to use IsVisible property to quickly show or hide the Model3D that is assigned to its Content property (this is especially useful in Abd3.DXEngine). So you should only use Content property and not also Children. But because of a way how WPF 3D defined the object model (the only 3D object that can be derived from is ModelVisual3D) there is no easy way to prevent setting Children collection. Anyway, this is only a side note and should not have any effect on the problem that you are having.
Andrej Benedik
Are you using Ab3d.DXEngine? Yes, I am using DXEngine. 
Do you have a Transformation set? Yes, I do. I double checked. I think the missing transformations in the dump should correspond to matrix identities (at least in my case).

Did I find something? I tried to compare our initialization of the WireframeVisual3D. I had set UseModelColor = true. With this anytime I switched between wireframe and material highlight it would take other objects with it. When UseModelColor is set to false, this does not happen (still don't know why). When I replaced LineVisual3D with BoxVisual3D this did not happen as well.

ContentVisual3D I am using the content visual hierarchy on purpose. It allows me to hide each part of the object (basically each part of the geometry is an object by itself). When I tried creating Model3DGroup hierarchy and for each group create a ContentVisual, the hiding didn't work.
Setting UseModelColor to true was a good clue. With that set, I can reproduce the problems.

I will try to prepare a fix tomorrow and will then send you a pre-release fixed version of the Ab3d.DXEngine library.
Andrej Benedik
This issue was caused by a problem in Ab3d.DXEngine library.

The problem has been fixed. The fix will be released with the next version of the library (v3.3).

If you are also experiencing the same issue and would like to get the fixed version before the next release, then contact me by PM or by email.
Andrej Benedik

Forum Jump:

Users browsing this thread:
1 Guest(s)