CreateIndices() public static method

Creates the triangle indices.
public static CreateIndices ( int n ) : System.Windows.Media.Int32Collection
n int /// The number of points. ///
return System.Windows.Media.Int32Collection
        /// <summary>
        /// Initializes a new instance of the <see cref="BillboardVisual3D" /> class.
        /// </summary>
        public BillboardVisual3D()
        {
            this.builder = new BillboardGeometryBuilder(this);
            this.Mesh    = new MeshGeometry3D
            {
                TriangleIndices    = BillboardGeometryBuilder.CreateIndices(1),
                TextureCoordinates =
                    new PointCollection
                {
                    new Point(0, 1),
                    new Point(1, 1),
                    new Point(1, 0),
                    new Point(0, 0)
                }
            };

            this.Model = new GeometryModel3D {
                Geometry = this.Mesh
            };
            this.Content = this.Model;
            this.OnMaterialChanged();
            this.OnGeometryChanged();
        }
Beispiel #2
0
        /// <summary>
        /// Updates the visual appearance (texture and geometry).
        /// </summary>
        private void VisualChanged()
        {
            this.meshes.Clear();
            this.pinMeshes.Clear();

            if (this.Items == null)
            {
                this.Content = null;
                return;
            }

            var pinMaterial = new DiffuseMaterial(this.PinBrush);

            var items = this.Items.Where(i => !string.IsNullOrEmpty(i.Text)).ToList();
            var group = new Model3DGroup();

            while (items.Count > 0)
            {
                Dictionary <string, FrameworkElement> elementMap;
                Dictionary <FrameworkElement, Rect>   elementPositions;
                var material = TextGroupVisual3D.CreateTextMaterial(
                    items, this.CreateElement, this.Background, out elementMap, out elementPositions);
                material.Freeze();

                var billboards         = new List <Billboard>();
                var addedChildren      = new List <BillboardTextItem>();
                var textureCoordinates = new PointCollection();
                foreach (var item in items)
                {
                    var element = elementMap[item.Text];
                    var r       = elementPositions[element];
                    if (r.Bottom > 1)
                    {
                        break;
                    }

                    billboards.Add(
                        new Billboard(
                            item.Position,
                            element.ActualWidth,
                            element.ActualHeight,
                            item.HorizontalAlignment,
                            item.VerticalAlignment,
                            item.DepthOffset,
                            item.WorldDepthOffset));
                    textureCoordinates.Add(new Point(r.Left, r.Bottom));
                    textureCoordinates.Add(new Point(r.Right, r.Bottom));
                    textureCoordinates.Add(new Point(r.Right, r.Top));
                    textureCoordinates.Add(new Point(r.Left, r.Top));

                    addedChildren.Add(item);
                }

                var triangleIndices = BillboardGeometryBuilder.CreateIndices(billboards.Count);
                triangleIndices.Freeze();

                var g = new MeshGeometry3D
                {
                    TriangleIndices    = triangleIndices,
                    TextureCoordinates = textureCoordinates,
                    Positions          = this.builder.GetPositions(billboards, this.Offset)
                };
                group.Children.Add(new GeometryModel3D(g, material));
                this.meshes.Add(g, billboards);

                if (this.Offset.Length > 0)
                {
                    var pinGeometry = new MeshGeometry3D
                    {
                        TriangleIndices = triangleIndices,
                        Positions       = this.builder.GetPinPositions(billboards, this.Offset, this.PinWidth)
                    };
                    group.Children.Add(new GeometryModel3D(pinGeometry, pinMaterial));
                    this.pinMeshes.Add(pinGeometry, billboards);
                }

                foreach (var c in addedChildren)
                {
                    items.Remove(c);
                }
            }

            this.Content = group;
        }
        /// <summary>
        /// Updates the text block when the visual appearance changed.
        /// </summary>
        private void VisualChanged()
        {
            this.meshes.Clear();

            if (this.Items == null)
            {
                this.Content = null;
                return;
            }

            var items = this.Items.Where(i => !string.IsNullOrEmpty(i.Text)).ToList();
            var group = new Model3DGroup();

            while (items.Count > 0)
            {
                Dictionary <string, FrameworkElement> elementMap;
                Dictionary <FrameworkElement, Rect>   elementPositions;
                /// DELETED BY SJT FOR .NET 3.5
                //var material = TextGroupVisual3D.CreateTextMaterial(items, this.CreateElement, this.Background, out elementMap, out elementPositions);
                //material.Freeze();

                var billboards         = new List <Billboard>();
                var addedChildren      = new List <BillboardTextItem>();
                var textureCoordinates = new PointCollection();
                /// DELETED BY SJT FOR .NET 3.5
                //foreach (var item in items)
                //{
                //    var element = elementMap[item.Text];
                //    var r = elementPositions[element];
                //    if (r.Bottom > 1)
                //    {
                //        break;
                //    }

                //    billboards.Add(
                //        new Billboard(
                //            item.Position,
                //            element.ActualWidth,
                //            element.ActualHeight,
                //            item.HorizontalAlignment,
                //            item.VerticalAlignment,
                //            item.DepthOffset));
                //    textureCoordinates.Add(new Point(r.Left, r.Bottom));
                //    textureCoordinates.Add(new Point(r.Right, r.Bottom));
                //    textureCoordinates.Add(new Point(r.Right, r.Top));
                //    textureCoordinates.Add(new Point(r.Left, r.Top));

                //    addedChildren.Add(item);
                //}

                var g = new MeshGeometry3D
                {
                    TriangleIndices    = BillboardGeometryBuilder.CreateIndices(billboards.Count),
                    TextureCoordinates = textureCoordinates,
                    Positions          = this.builder.GetPositions(billboards)
                };
                /// DELETED BY SJT FOR .NET 3.5
                //group.Children.Add(new GeometryModel3D(g, material));
                this.meshes.Add(g, billboards);
                foreach (var c in addedChildren)
                {
                    items.Remove(c);
                }
            }

            this.Content = group;
        }