WPF 3D - Positioning Visual3D Elements in a 3D Scene Using Nested Model3DGroup Transforms?

I have a 3D scene where my 3D models are loaded into code located behind the XAML files.

Each model consists of a tree of nested Model3DGroups, each of which has various transformations applied to it to position and orient the next subcomponent of the model in the tree. This model is then used as the contents of ModelVisual3D so that it can be displayed on the screen.

I want to bind the child ModelVisual3D to the parent ModelVisual3D. This child ModelVisual3D must use all of the nested transformations of the parent ModelVisual3D.Content in order to properly position and navigate in virtual space. For example, the first ModelVisual3D is a robotic arm that has various movable joints, and I want to attach a tool to the end of this shoulder - another ModelVisual3D. How can I access this compound transformation from the parent property of the ModelVisual3Ds content to allow the next ModelVisual3D to be correctly positioned relative to its parent?

+6
wpf 3d
source share
1 answer

As you have undoubtedly noticed when you group Model3Ds into Model3DGroup, the Transform properties of the children are combined with the properties of the parent.

It looks like you are asking how to calculate the network transform to a specific Model3D in the Model3D tree, which is what you call your β€œmodel”. To do this, you need to know (or be able to scan and detect) the path from the Model3DGroup root model to Model3D for which you want to find the transformation.

Once you have this path, all that is required is a union of the Transform properties at each level. To do this, simply create a Transform3DGroup and add individual transformations to it.

For example, if your robot has Model3D components called UpperArm, LowerArm, and Hand, and you would like to know the position and angle of the arm that you could do:

var combined = new Transform3DGroup(); combined.Children.Add(UpperArm.Transform); combined.Children.Add(LowerArm.Transform); combined.Children.Add(Hand.Transform); 

Now you can find the location (0,0,0) on the arm as follows:

  combined.Transform(new Point3D(0,0,0)); 

Similarly, you can find other points and use them to place another ModelVisual3D.

+2
source share

All Articles