views:

32

answers:

1

I've got a bunch of Model3DGroups and want to determine which one has been clicked on.

Here's an example of how they look like:

<Model3DGroup x:Name="Linie04OR23">
                        <!-- Linie04 (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[8]) -->
                        <Model3DGroup.Transform>
                            <Transform3DGroup>
                                <TranslateTransform3D OffsetX="14.0807" OffsetY="-76.5861" OffsetZ="-16.1045"/>
                                <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                                <RotateTransform3D>
                                    <RotateTransform3D.Rotation>
                                        <AxisAngleRotation3D Angle="0" Axis="0 1 0"/>
                                    </RotateTransform3D.Rotation>
                                </RotateTransform3D>
                                <TranslateTransform3D OffsetX="-336.736" OffsetY="76.5861" OffsetZ="48.5252"/>
                            </Transform3DGroup>
                        </Model3DGroup.Transform>
                        <GeometryModel3D x:Name="Linie04OR23GR24">
                            <GeometryModel3D.Material>
                                <MaterialGroup>
                                    <DiffuseMaterial>
                                        <DiffuseMaterial.Brush>
                                            <SolidColorBrush Color="#7A7A7A" Opacity="1.000000"/>
                                        </DiffuseMaterial.Brush>
                                    </DiffuseMaterial>
                                    <SpecularMaterial SpecularPower="37.5467">
                                        <SpecularMaterial.Brush>
                                            <SolidColorBrush Color="#ADADAD" Opacity="1.000000"/>
                                        </SpecularMaterial.Brush>
                                    </SpecularMaterial>
                                </MaterialGroup>
                            </GeometryModel3D.Material>
                            <GeometryModel3D.BackMaterial>
                                <MaterialGroup>
                                    <DiffuseMaterial>
                                        <DiffuseMaterial.Brush>
                                            <SolidColorBrush Color="#7A7A7A" Opacity="1.000000"/>
                                        </DiffuseMaterial.Brush>
                                    </DiffuseMaterial>
                                    <SpecularMaterial SpecularPower="37.5467">
                                        <SpecularMaterial.Brush>
                                            <SolidColorBrush Color="#ADADAD" Opacity="1.000000"/>
                                        </SpecularMaterial.Brush>
                                    </SpecularMaterial>
                                </MaterialGroup>
                            </GeometryModel3D.BackMaterial>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
    TriangleIndices="0,1,2 0,2,3 4,5,6 "
    Normals="0.546058,0,0.837747 0.546058,0,0.837747 0.546058,0,0.837747 0.546058,0,0.837747 0.840137,0,-0.542374 "
    Positions="35.6154,-5.9536e-014,268.126 42.4896,-5.85411e-014,263.645 42.4896,153.172 "
   />
                            </GeometryModel3D.Geometry>
                        </GeometryModel3D>
                    </Model3DGroup>
A: 

You can use VisualTreeHelper.HitTest for this.

For a detailed explanation, see Hit Testing in a 3D Viewport.

Reed Copsey
This method works but I don't know how to walk up the Visual Tree to find the Model3DGroup this visual3D is in.Can you explain that too?
Hedge