Is there a simple method to return a list of all Point3D present in a Viewport3D object in WPF? I need this collection in order to determine the XYZ bounds so that I can position the camera such that all Point3D are within the field of view.
If there is no simple method, which collections would I need to iterate over to ensure all Point3D are captured?
There is a very lengthy hierarchy we need to traverse to get to the data you want.
Viewport3D.Children
returns a Visual3DCollection
object which contains a set of Visual3D
Visual3D
has 3 child classes; we are interested in ModelVisual3D
ModelVisual3D.Children
returns another Visual3DCollection
; you can clearly see the recursive tree structure with Viewport3D
at the root
ModelVisual3D.Visual3DModel
returns a Model3D
object
Model3D
has 3 child classes; we are interested in GeometryModel3D
and Model3DGroup
Model3DGroup.Children
is another list of Model3D
; hence we have two layers of recursive containment
GeometryModel3D.Geometry
returns a Geometry3D
object
Curiously, Geometry3D
only has one child class MeshGeometry3D
MeshGeometry3D.Positions
finally gives a raw list of points
Note that these points are in the local bases of their parent Geometry3D
objects. In order to get the world coordinates, as you traverse the hierarchy you must accumulate a list of the transformations of any Model3D
objects you encounter, and use them to transform the output points.
Model3D.Transform
returns a Transform3D
object Transform3D
has 3 child classes - AffineTransform3D
, MatrixTransform3D
and Transform3DGroup
; however we won't need to deal with them separatelyTransform3D.Transform(Point3D)
is pretty self explanatory Transform3D
classes (except MatrixTransform3D
), so for each Point3D
you must traverse the list of transformations in reverse order and apply each transformation in successionThe above summarizes why almost no one uses WPF for 3D development... a discussion which should be reserved for linux.stackexchange.com .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.