08-07-2019, 03:07 PM
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:
This creates the following hierarchy:
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.
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:
Code:
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();
MainViewport.Children.Clear();
MainViewport.Children.Add(wireGridVisual3D);
MainViewport.Children.Add(rootModelVisual3D);
Camera1.Refresh(); // Recreate camera light after clearing
var cv1 = new ContentVisual3D();
rootModelVisual3D.Children.Add(cv1);
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));
cv1.Children.Add(cv2);
var cv3 = new ContentVisual3D();
cv2.Children.Add(cv3);
var b1 = new BoxVisual3D()
{
CenterPosition = new Point3D(50, -5, 0),
Size = new Size3D(50, 1, 10),
Material = new DiffuseMaterial(Brushes.Orange)
};
cv3.Children.Add(b1);
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));
cv2.Children.Add(cv4);
var cv5 = new ContentVisual3D();
cv4.Children.Add(cv5);
var sphereVisual3D = new SphereVisual3D()
{
CenterPosition = new Point3D(50, 0, 0),
Radius = 5,
Material = new DiffuseMaterial(Brushes.Red)
};
cv5.Children.Add(sphereVisual3D);
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;
cv5.Children.Add(wireframeVisual3D);
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
};
modelVisual3D.Children.Add(l1);
modelVisual3D.Children.Add(l2);
modelVisual3D.Children.Add(l3);
cv5.Children.Add(modelVisual3D);
//cv5.Children.Add(l1);
//cv5.Children.Add(l2);
//cv5.Children.Add(l3);
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));
cv2.Children.Add(cv6);
var cv7 = new ContentVisual3D();
cv6.Children.Add(cv7);
var b2 = new BoxVisual3D()
{
CenterPosition = new Point3D(50, -5, 0),
Size = new Size3D(50, 2, 5),
Material = new DiffuseMaterial(Brushes.Yellow)
};
cv7.Children.Add(b2);This creates the following hierarchy:
Code:
Viewport3D ("MainViewport")
WireGridVisual3D
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
ModelVisual3D
ContentVisual3D
ContentVisual3D Transform: 0,1,0,0,-1,0,0,0,0,0,1,0,0,0,0,1
ContentVisual3D
BoxVisual3D
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
ContentVisual3D
SphereVisual3D
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
ModelVisual3D
LineVisual3D
GeometryModel3D Material: Group: [ [Diffuse: #FF000000] [Emissive: #FFFF0000] ] | Geometry: null
LineVisual3D
GeometryModel3D Material: Group: [ [Diffuse: #FF000000] [Emissive: #FF008000] ] | Geometry: null
LineVisual3D
GeometryModel3D Material: Group: [ [Diffuse: #FF000000] [Emissive: #FF0000FF] ] | Geometry: null
WireframeVisual3D
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
ContentVisual3D
BoxVisual3D
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
ModelVisual3D
DirectionalLight Direction: 0.5,-0.3,-0.8; Color: #FFFFFFFFI 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

