コード例 #1
0
        private void SelectTriangle(int triangleIndex)
        {
            if (_selectedTriangleIndex == triangleIndex)
            {
                return;
            }

            _isSelectionChangedInternally = true;

            OverlayCanvas.Children.Clear();

            if (triangleIndex >= 0)
            {
                OverviewListBox.SelectedIndex = triangleIndex;
                OverviewListBox.ScrollIntoView(OverviewListBox.Items[triangleIndex]);

                OverviewListBox.Focus(); // Without calling focus the blue selection is not visible

                int     i = triangleIndex * 3;
                Point3D p1, p2, p3;

                int index1 = _rootMesh.TriangleIndices[i];
                int index2 = _rootMesh.TriangleIndices[i + 1];
                int index3 = _rootMesh.TriangleIndices[i + 2];

                p1 = _rootMesh.Positions[index1];
                p2 = _rootMesh.Positions[index2];
                p3 = _rootMesh.Positions[index3];

                if (_rootMesh.Normals != null && _rootMesh.Normals.Count == _rootMesh.Positions.Count)
                {
                    // we can offset the Polyline so it will not be fighting for Z-depth with the object
                    // This way the selection lines will be drawn on top of the selected object
                    Vector3D n1 = _rootMesh.Normals[index1];
                    n1.Normalize();

                    Vector3D n2 = _rootMesh.Normals[index2];
                    n2.Normalize();

                    Vector3D n3 = _rootMesh.Normals[index2];
                    n3.Normalize();

                    p1 += n1 * _selectedTriangleOffset;
                    p2 += n2 * _selectedTriangleOffset;
                    p3 += n3 * _selectedTriangleOffset;
                }

                SelectedTrianglePolyline.Positions = new Point3DCollection(new Point3D[] { p1, p2, p3 });
                SelectedTrianglePolyline.IsVisible = true;


                if (ShowSelectedIndexesCheckBox.IsChecked ?? false)
                {
                    AddPositionIndexTextBlocks(i);
                }
            }
            else
            {
                OverviewListBox.SelectedIndex      = -1;
                SelectedTrianglePolyline.IsVisible = false;
            }

            _isSelectionChangedInternally = false;

            _selectedTriangleIndex = triangleIndex;
        }