.NET - 如何确定单击了哪个Model3DGroup?

时间:2010-09-22 01:09:09

标签: c# .net visual-studio xaml

我有一堆Model3DGroups,想要确定哪一个被点击过。

以下是它们的样子示例:

<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>

1 个答案:

答案 0 :(得分:1)

您可以使用VisualTreeHelper.HitTest

有关详细说明,请参阅Hit Testing in a 3D Viewport