コード例 #1
0
        private void ShowObjectInfo()
        {
            OverviewListBox.Items.Clear();

            if (_rootMesh == null)
            {
                TriangleIndicesTextBox.Text    = "";
                PositionsTextBox.Text          = "";
                NormalsTextBox.Text            = "";
                TextureCoordinatesTextBox.Text = "";
                XamlTextBox.Text = "";
            }
            else
            {
                StringBuilder sb;
                OverviewListBox.BeginInit();

                sb = new StringBuilder();
                for (int i = 0; i < _rootMesh.Positions.Count; i++)
                {
                    sb.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0,3}: {1:0.#}\r\n", i, _rootMesh.Positions[i]);
                }

                PositionsTextBox.Text = sb.ToString();


                sb = new StringBuilder();
                string oneTriangleInfo;
                int    j = 0;
                for (int i = 0; i < _rootMesh.TriangleIndices.Count; i += 3)
                {
                    try
                    {
                        oneTriangleInfo = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                        "{0,3} ({1,2}): {2} {3} {4} ({5:0.#}) ({6:0.#}) ({7:0.#})",
                                                        j, i,
                                                        _rootMesh.TriangleIndices[i], _rootMesh.TriangleIndices[i + 1], _rootMesh.TriangleIndices[i + 2],
                                                        _rootMesh.Positions[_rootMesh.TriangleIndices[i]], _rootMesh.Positions[_rootMesh.TriangleIndices[i + 1]], _rootMesh.Positions[_rootMesh.TriangleIndices[i + 2]]);
                    }
                    catch (Exception ex)
                    {
                        oneTriangleInfo = "Error: " + ex.Message;
                    }

                    OverviewListBox.Items.Add(oneTriangleInfo);

                    sb.AppendLine(oneTriangleInfo);

                    j++;
                }

                TriangleIndicesTextBox.Text = sb.ToString();


                if (_rootMesh.Normals != null && _rootMesh.Normals.Count > 0)
                {
                    sb = new StringBuilder();
                    for (int i = 0; i < _rootMesh.Normals.Count; i++)
                    {
                        sb.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0,3}: {1:0.###}\r\n", i, _rootMesh.Normals[i]);
                    }

                    NormalsTextBox.Text = sb.ToString();
                }
                else
                {
                    NormalsTextBox.Text = "No Normals defined";
                }


                if (_rootMesh.TextureCoordinates != null && _rootMesh.TextureCoordinates.Count > 0)
                {
                    sb = new StringBuilder();
                    for (int i = 0; i < _rootMesh.TextureCoordinates.Count; i++)
                    {
                        sb.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0,3}: {1:0.###}\r\n", i, _rootMesh.TextureCoordinates[i]);
                    }

                    TextureCoordinatesTextBox.Text = sb.ToString();
                }
                else
                {
                    TextureCoordinatesTextBox.Text = "No TextureCoordinates defined";
                }


                using (System.IO.StringWriter stringWriter = new System.IO.StringWriter())
                {
                    System.Xml.XmlWriterSettings settings;
                    settings        = new System.Xml.XmlWriterSettings();
                    settings.Indent = true;

                    using (System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create(stringWriter, settings))
                    {
                        System.Windows.Markup.XamlWriter.Save(_rootModel, xmlWriter);
                    }

                    XamlTextBox.Text = stringWriter.ToString();
                }

                OverviewListBox.EndInit();
            }
        }
コード例 #2
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;
        }