Beispiel #1
1
        public Model3DGroup Create(Color modelColor,string pictureName, Point3D startPos, double maxHigh)
        {
            try
            {
                Uri inpuri = new Uri(@pictureName, UriKind.Relative);
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = inpuri;
                bi.EndInit();
                ImageBrush imagebrush = new ImageBrush(bi);
                imagebrush.Opacity = 100;
                imagebrush.Freeze();

                Point[] ptexture0 = { new Point(0, 0), new Point(0, 1), new Point(1, 0) };
                Point[] ptexture1 = { new Point(1, 0), new Point(0, 1), new Point(1, 1) };

                SolidColorBrush modelbrush = new SolidColorBrush(modelColor);
                Model3DGroup cube = new Model3DGroup();
                Point3D uppercircle = startPos;
                modelbrush.Freeze();
                uppercircle.Y = startPos.Y + maxHigh;
                cube.Children.Add(CreateEllipse2D(modelbrush, uppercircle, _EllipseHigh, new Vector3D(0, 1, 0)));
                cube.Children.Add(CreateEllipse2D(modelbrush, startPos, _EllipseHigh, new Vector3D(0, -1, 0)));
                cube.Children.Add(CreateEllipse3D(imagebrush, startPos, _EllipseHigh, maxHigh, ptexture0));
                return cube;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
 static Airplane()
 {
     try
     {
         Assembly assembly = Assembly.GetExecutingAssembly();
         string[] names = assembly.GetManifestResourceNames();
         string name = names.FirstOrDefault(x => x.Contains("WFTools3D.jpg"));
         if (name != null)
         {
             Stream stream = assembly.GetManifestResourceStream(name);
             if (stream != null)
             {
                 BitmapImage bitmap = new BitmapImage();
                 bitmap.BeginInit();
                 bitmap.StreamSource = stream;
                 bitmap.EndInit();
                 ImageBrush imbrush = new ImageBrush(bitmap);
                 imbrush.TileMode = TileMode.Tile;
                 imbrush.Viewport = new Rect(0, 0, 0.5, 1);
                 imbrush.Freeze();
                 brush = imbrush;
             }
         }
     }
     catch
     {
         brush = Brushes.Silver;
     }
 }
		private static void RegisterBrush(LibraryDevice libraryDevice)
		{
			var imageSource = GetImageSource(libraryDevice == null ? Guid.Empty : libraryDevice.DriverId);
			var brush = new ImageBrush(imageSource);
			brush.Freeze();
			_brushes.Add(libraryDevice == null ? Guid.Empty : libraryDevice.DriverId, brush);
		}
 /// <summary>
 /// Erzeugt einen gerenderten Brush aus einem Visual
 /// </summary>
 /// <param name="visual"></param>
 /// <returns></returns>
 public static Brush CreateBrushFromVisual(Visual visual, int width, int height)
 {
     if (visual == null)
         throw new ArgumentNullException("visual");
     RenderTargetBitmap target = new RenderTargetBitmap(Math.Max(width, 1), Math.Max(height, 1), 96, 96, PixelFormats.Pbgra32);
     target.Render(visual);
     ImageBrush brush = new ImageBrush(target);
     brush.Freeze();
     return brush;
 }
        private static void SetEnvironmentImageBrush(ResourceDictionary resources, BitmapSource bitmapImage, bool tileImage)
        {
            TileMode tileMode;
            ImageBrush imageBrush = new ImageBrush(bitmapImage);
            ImageBrush imageBrush1 = imageBrush;

            tileMode = tileImage ? TileMode.Tile : TileMode.None;

            imageBrush.TileMode = tileMode;
            imageBrush.Viewport = new Rect(0, 0, bitmapImage.Width, bitmapImage.Height);
            imageBrush.ViewboxUnits = BrushMappingMode.Absolute;
            if(imageBrush.CanFreeze)
                imageBrush.Freeze();

            //todo: Create a persistentance mechanism
            //SaveDefaultEnvironmentBrush(resources);

            resources[VsBrushes.EnvironmentBackgroundTextureKey] = imageBrush;
        }
Beispiel #6
0
        private void AddNewShapeLight(PatternMaker f)
        {
            DrawingBrush db = new DrawingBrush();

            var dv = new DrawingVisual();
            var dc = dv.RenderOpen();	// DrawingContextの取得
            Random rd = new Random();
            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    byte alpha = (byte)Math.Floor(f(x, y, w, h, ref rd) * 255);
                    dc.DrawRectangle(new SolidColorBrush(Color.FromArgb(alpha, 0, 0, 0)), null, new Rect(new Point(x, y), new Point(x + 1, y + 1)));
                }
            }
            dc.Close();
            var bitmap = new RenderTargetBitmap(w, h, 96, 96, PixelFormats.Pbgra32);
            bitmap.Render(dv);	// 描画結果を書き込む
            var brush = new ImageBrush(bitmap);	// ブラシの作成
            brush.ViewportUnits = BrushMappingMode.RelativeToBoundingBox;
            brush.Freeze();

            Border b = new Border();
            b.Background = brush;
            b.Width = w;
            b.Height = h;
            b.BorderBrush = Brushes.DarkGray;
            b.BorderThickness = new Thickness(0);
            b.Tag = new double[] { 0.0, 1.0 };
            b.RenderTransformOrigin = new Point(0.5, 0.5);

            RenderOptions.SetBitmapScalingMode(b, BitmapScalingMode.NearestNeighbor);//これを消すと描画モードが変わります。

            Random r = new Random();

            Canvas.SetLeft(b, r.Next(Math.Max((int)PictureCanvas.ActualWidth - w,0)));
            Canvas.SetTop(b, r.Next(Math.Max((int)PictureCanvas.ActualHeight - h,0)));

            b.MouseDown += new MouseButtonEventHandler(b_MouseDown);

            PictureCanvas.Children.Add(b);
        }
Beispiel #7
0
        protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
        {
            if (drawingContext == null)
            {
                throw new ArgumentNullException("drawingContext");
            }
            if (null == drawingAttributes)
            {
                throw new ArgumentNullException("drawingAttributes");
            }

            DrawingAttributes originalDa = drawingAttributes.Clone();
            originalDa.Width = this.size;
            originalDa.Height = this.size;
            //ImageBrush brush = new ImageBrush(new BitmapImage(new Uri(@"test3.png", UriKind.Relative)));

            string path = "pack://application:,,,/Resources/ColorBrush/BColor_" + color + ".png";
            ImageBrush brush = new ImageBrush(new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute)));
            brush.Freeze();
            drawingContext.DrawGeometry(brush, null, this.GetGeometry(originalDa));
        }
Beispiel #8
0
        /// <summary>
        /// Creates the brush from visual.
        /// </summary>
        /// <param name="v">The visual object.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <returns>The image brush created from the visual</returns>
        public static ImageBrush CreateBrushFromVisual(Visual v, double width, double height)
        {
            try
            {
                ImageBrush brush = null;

                if (height > 0 && width > 0)
                {
                    var target = new RenderTargetBitmap((int)width, (int)height, 96, 96, PixelFormats.Default);
                    target.Render(v);
                    brush = new ImageBrush(target);
                    brush.Stretch = Stretch.None;
                    brush.Freeze();
                }

                return brush;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }
 private static Brush CreateBrushFromVisual(Visual v, int width, int height)
 {
     if (v == null)
         throw new ArgumentNullException(nameof(v));
     var target = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
     target.Render(v);
     var brush = new ImageBrush(target);
     brush.Freeze();
     return brush;
 }
 /// <summary>
 /// Creates a brush based on the current appearnace of a visual element. The brush is an ImageBrush and once created, won't update its look
 /// </summary>
 /// <param name="v">The visual element to take a snapshot of</param>
 private Brush CreateBrushFromVisual(Visual v)
 {
     if (v == null)
         throw new ArgumentNullException("v");
     var target = new RenderTargetBitmap((int)this.ActualWidth, (int)this.ActualHeight, 96, 96, PixelFormats.Pbgra32);
     target.Render(v);
     var brush = new ImageBrush(target);
     brush.Freeze();
     return brush;
 }
Beispiel #11
0
        public void Load()
        {
            try
            {
                Uri uri = new Uri(ThumnailUrl, UriKind.RelativeOrAbsolute);
                WebClient web = new WebClient();
                Stream imgData = web.OpenRead(uri);
                MemoryStream memory = new MemoryStream();

                int data = imgData.ReadByte();
                while (data != -1)
                {
                    memory.WriteByte((byte)data);
                    data = imgData.ReadByte();
                }
                memory.Seek(0, SeekOrigin.Begin);

                BitmapImage bi = new BitmapImage();
                //bi.DecodePixelWidth = AppConfig.ThumbSize;
                bi.BeginInit();
                bi.StreamSource = memory;
                bi.EndInit();
                bi.Freeze();

                brush = new ImageBrush(bi);
                brush.Stretch = Stretch.UniformToFill;

                brush.Freeze();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("cannot load image! " + e);
            }
        }
Beispiel #12
0
        public Balloon()
        {
            InitializeComponent();

            this.frameRateList = new List<double>();
            this.messageCollection = new Collection<Message>();
            this.messageBuffer = new StringBuilder();
            this.inlineList = new System.Collections.ArrayList();
            this.embedColorStepDictionary = new Dictionary<int, double>();
            this.embedScrollStepDictionary = new Dictionary<int, double>();
            this.embedIsScrollableHashSet = new HashSet<int>();
            this.tagScrollStepDictionary = new Dictionary<int, double>();
            this.tagIsScrollableHashSet = new HashSet<int>();
            this.attachmentFadeStepDictionary = new Dictionary<int, double>();
            this.attachmentImageLoadingStepDictionary = new Dictionary<int, double>();
            this.attachmentImageSlideStepDictionary = new Dictionary<int, double>();
            this.attachmentImagePopupStepDictionary = new Dictionary<int, double>();
            this.attachmentHighlightStepDictionary = new Dictionary<int, double>();
            this.attachmentEnableStepDictionary = new Dictionary<int, double>();
            this.attachmentFilterStepDictionary = new Dictionary<int, double>();
            this.attachmentScrollStepDictionary = new Dictionary<int, double>();
            this.attachmentIsScrollableHashSet = new HashSet<int>();
            this.attachmentImageDictionary = new Dictionary<int, BitmapImage>();
            this.cachedInlineImageDictionary = new Dictionary<int, Image>();
            this.cachedAttachmentThumbnailImageDictionary = new Dictionary<int, Image>();
            this.cachedAttachmentTextImageDictionary = new Dictionary<int, Image>();
            this.cachedTitleImageDictionary = new Dictionary<int, Image>();
            this.cachedSubtitleImageDictionary = new Dictionary<int, Image>();
            this.cachedAuthorImageDictionary = new Dictionary<int, Image>();
            this.cachedTagImageDictionary = new Dictionary<int, Image>();
            this.thresholdQueue = new Queue<double>();
            this.scrollQueue = new Queue<double>();
            this.selectedPositionQueue = new Queue<double>();
            this.circulationQueue = new Queue<int>();
            this.imageUriQueue = new Queue<Uri>();
            this.imageDictionary = new Dictionary<Uri, BitmapImage>();
            this.imageUriHashSet = new HashSet<Uri>();
            this.messageTypeTimer = new DispatcherTimer(DispatcherPriority.Normal);
            this.messageTypeTimer.Tick += new EventHandler(this.OnTick);
            this.waitTimer = new DispatcherTimer(DispatcherPriority.Normal);
            this.waitTimer.Tick += new EventHandler(this.OnTick);
            this.switchTimer = new DispatcherTimer(DispatcherPriority.Normal);
            this.switchTimer.Tick += new EventHandler(this.OnTick);
            this.switchTimer.Interval = TimeSpan.FromSeconds(3);

            System.Configuration.Configuration config = null;
            string directory = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);

            if (Directory.Exists(directory))
            {
                string fileName = System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                foreach (string s in from s in Directory.EnumerateFiles(directory, "*.config") where fileName.Equals(System.IO.Path.GetFileNameWithoutExtension(s)) select s)
                {
                    System.Configuration.ExeConfigurationFileMap exeConfigurationFileMap = new System.Configuration.ExeConfigurationFileMap();

                    exeConfigurationFileMap.ExeConfigFilename = s;
                    config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(exeConfigurationFileMap, System.Configuration.ConfigurationUserLevel.None);
                }
            }

            if (config == null)
            {
                config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);
                directory = null;
            }

            if (config.AppSettings.Settings["FrameRate"] != null)
            {
                if (config.AppSettings.Settings["FrameRate"].Value.Length > 0)
                {
                    this.frameRate = Double.Parse(config.AppSettings.Settings["FrameRate"].Value, System.Globalization.CultureInfo.InvariantCulture);
                }
            }

            if (config.AppSettings.Settings["FontFamily"] != null)
            {
                if (config.AppSettings.Settings["FontFamily"].Value.Length > 0)
                {
                    this.FontFamily = new FontFamily(config.AppSettings.Settings["FontFamily"].Value);
                }
            }

            if (config.AppSettings.Settings["FontSize"] != null)
            {
                if (config.AppSettings.Settings["FontSize"].Value.Length > 0)
                {
                    this.FontSize = (double)new FontSizeConverter().ConvertFromString(config.AppSettings.Settings["FontSize"].Value);
                }
            }

            if (config.AppSettings.Settings["FontStretch"] != null)
            {
                if (config.AppSettings.Settings["FontStretch"].Value.Length > 0)
                {
                    this.FontStretch = (FontStretch)new FontStretchConverter().ConvertFromString(config.AppSettings.Settings["FontStretch"].Value);
                }
            }

            if (config.AppSettings.Settings["FontStyle"] != null)
            {
                if (config.AppSettings.Settings["FontStyle"].Value.Length > 0)
                {
                    this.FontStyle = (FontStyle)new FontStyleConverter().ConvertFromString(config.AppSettings.Settings["FontStyle"].Value);
                }
            }

            if (config.AppSettings.Settings["FontWeight"] != null)
            {
                if (config.AppSettings.Settings["FontWeight"].Value.Length > 0)
                {
                    this.FontWeight = (FontWeight)new FontWeightConverter().ConvertFromString(config.AppSettings.Settings["FontWeight"].Value);
                }
            }

            if (config.AppSettings.Settings["LineLength"] != null)
            {
                if (config.AppSettings.Settings["LineLength"].Value.Length > 0)
                {
                    this.baseWidth = Double.Parse(config.AppSettings.Settings["LineLength"].Value, System.Globalization.CultureInfo.InvariantCulture) + 30;
                }
            }

            if (config.AppSettings.Settings["LineHeight"] != null)
            {
                if (config.AppSettings.Settings["LineHeight"].Value.Length > 0)
                {
                    this.lineHeight = Double.Parse(config.AppSettings.Settings["LineHeight"].Value, System.Globalization.CultureInfo.InvariantCulture);
                }
            }

            if (config.AppSettings.Settings["BackgroundColor"] != null)
            {
                if (config.AppSettings.Settings["BackgroundColor"].Value.Length > 0)
                {
                    this.backgroundColor = (Color)ColorConverter.ConvertFromString(config.AppSettings.Settings["BackgroundColor"].Value);
                }
            }

            SolidColorBrush brush1 = new SolidColorBrush(Color.FromArgb((byte)(this.backgroundColor.A * 75 / 100), this.backgroundColor.R, this.backgroundColor.G, this.backgroundColor.B));

            if (brush1.CanFreeze)
            {
                brush1.Freeze();
            }

            this.OuterPath.Fill = brush1;

            if (config.AppSettings.Settings["BackgroundImage"] == null)
            {
                SolidColorBrush brush2 = new SolidColorBrush(this.backgroundColor);

                if (brush2.CanFreeze)
                {
                    brush2.Freeze();
                }

                this.InnerPath.Fill = brush2;
            }
            else
            {
                BitmapImage bi = new BitmapImage();

                using (FileStream fs = new FileStream(directory == null ? config.AppSettings.Settings["BackgroundImage"].Value : System.IO.Path.Combine(directory, config.AppSettings.Settings["BackgroundImage"].Value), FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    bi.BeginInit();
                    bi.StreamSource = fs;
                    bi.CacheOption = BitmapCacheOption.OnLoad;
                    bi.CreateOptions = BitmapCreateOptions.None;
                    bi.EndInit();
                }

                ImageBrush imageBrush = new ImageBrush(bi);

                imageBrush.TileMode = TileMode.Tile;
                imageBrush.ViewportUnits = BrushMappingMode.Absolute;
                imageBrush.Viewport = new Rect(0, 0, bi.Width, bi.Height);
                imageBrush.Stretch = Stretch.None;

                if (imageBrush.CanFreeze)
                {
                    imageBrush.Freeze();
                }

                this.InnerPath.Fill = imageBrush;
            }

            if (config.AppSettings.Settings["TextColor"] != null)
            {
                if (config.AppSettings.Settings["TextColor"].Value.Length > 0)
                {
                    this.textColor = (Color)ColorConverter.ConvertFromString(config.AppSettings.Settings["TextColor"].Value);
                    this.textBrush = new SolidColorBrush(this.textColor);
                }
            }

            if (this.textBrush == null)
            {
                this.textBrush = new SolidColorBrush(this.textColor);
            }

            if (this.textBrush.CanFreeze)
            {
                this.textBrush.Freeze();
            }

            if (config.AppSettings.Settings["LinkColor"] != null)
            {
                if (config.AppSettings.Settings["LinkColor"].Value.Length > 0)
                {
                    this.linkColor = (Color)ColorConverter.ConvertFromString(config.AppSettings.Settings["LinkColor"].Value);
                    this.linkBrush = new SolidColorBrush(this.linkColor);
                }
            }

            if (this.linkBrush == null)
            {
                this.linkBrush = new SolidColorBrush(this.linkColor);
            }

            if (this.linkBrush.CanFreeze)
            {
                this.linkBrush.Freeze();
            }

            this.maxMessageSize = new Size(this.baseWidth - 30, this.lineHeight * this.numberOfLines);

            Canvas.SetTop(this.FilterImage, this.baseHeaderHeight + 2);
            Canvas.SetLeft(this.ScrollCanvas, 10);
            Canvas.SetTop(this.ScrollCanvas, this.baseHeaderHeight);
            Canvas.SetTop(this.CloseImage, 8);
            Canvas.SetTop(this.BackImage, 7);

            CompositionTarget.Rendering += new EventHandler(this.OnRendering);
        }
Beispiel #13
0
        private void OnBackgroundDoWork(object sender, DoWorkEventArgs e)
        {
            PointCloudTileSource tileSource = e.Argument as PointCloudTileSource;
            Jacere.Core.Geometry.Extent3D extent = tileSource.Extent;

            m_overviewTextureBrush = new ImageBrush(tileSource.Preview.Image);
            m_overviewTextureBrush.ViewportUnits = BrushMappingMode.Absolute;
            m_overviewTextureBrush.Freeze();

            m_overviewMaterial = new DiffuseMaterial(m_overviewTextureBrush);
            m_overviewMaterial.Freeze();

            if (tileSource != null)
            {
                previewImageGrid.MouseMove -= OnViewportGridMouseMove;

                Action<string> logAction = value => Context.WriteLine(value);
                m_progressManager = new BackgroundWorkerProgressManager(m_backgroundWorker, e, logAction, null);

                m_gridDimensionLowRes = (ushort)Math.Sqrt(VERTEX_COUNT_FAST / tileSource.TileSet.ValidTileCount);
                //m_gridDimensionHighRes = (ushort)Math.Sqrt(VERTEX_COUNT_LARGE / tileSource.TileSet.ValidTileCount);

                m_gridDimensionHighRes = (ushort)(Math.Sqrt(tileSource.TileSet.Density.MedianTileCount) / 3);

                //m_gridDimensionLowRes = (ushort)20;
                //m_gridDimensionHighRes = (ushort)40;

                Jacere.Core.Geometry.Point3D centerOfMass = tileSource.CenterOfMass;
                m_overallCenteredExtent = new Rect3D(extent.MinX - extent.MidpointX, extent.MinY - extent.MidpointY, extent.MinZ - centerOfMass.Z, extent.RangeX, extent.RangeY, extent.RangeZ);

                // load tiles
                KeyValuePair<Grid<int>, Grid<float>> gridsLowRes = tileSource.GenerateGrid(m_gridDimensionLowRes);
                m_gridLowRes = gridsLowRes.Value;
                m_quantizedGridLowRes = gridsLowRes.Key;

                KeyValuePair<Grid<int>, Grid<float>> gridsHighRes = tileSource.GenerateGrid(m_gridDimensionHighRes);
                m_gridHighRes = gridsHighRes.Value;
                m_quantizedGridHighRes = gridsHighRes.Key;

                foreach (PointCloudTile tile in tileSource.TileSet)
                {
                    tileSource.LoadTileGrid(tile, m_buffer, m_gridLowRes, m_quantizedGridLowRes);
                    if (ENABLE_HEIGHT_EXAGGERATION)
                        m_gridLowRes.Multiply(m_heightExaggerationFactor, (float)centerOfMass.Z);

                    Jacere.Core.Geometry.Extent3D tileExtent = tile.Extent;
                    MeshGeometry3D mesh = tileSource.GenerateMesh(m_gridLowRes, tileExtent);

                    DiffuseMaterial material = new DiffuseMaterial();
                    if (USE_LOW_RES_TEXTURE)
                    {
                        material.Brush = m_overviewTextureBrush;
                        mesh.TextureCoordinates = MeshUtils.GeneratePlanarTextureCoordinates(mesh, m_overallCenteredExtent, MathUtils.ZAxis);
                    }
                    else
                    {
                        material.Brush = m_solidBrush;
                    }

                    material.Freeze();
                    GeometryModel3D geometryModel = new GeometryModel3D(mesh, material);
                    geometryModel.Freeze();

                    TileInfo3D tileInfo = new TileInfo3D(tile, geometryModel, m_gridLowRes);
                    m_tileInfo.Add(tile, tileInfo);

                    // add mappings
                    m_meshTileMap.Add(geometryModel, tile);
                    //m_lowResMap.Add(tile, geometryModel);

                    if (!m_progressManager.Update(tile, geometryModel))
                        break;
                }

                //// test
                //foreach (double level in new double[] { centerOfMass.Z })
                //{
                //    Grid<float> grid0 = new Grid<float>(20, 20, extent, false);
                //    grid0.FillVal = (float)level;
                //    grid0.Reset();
                //    grid0.FillVal = float.MinValue;
                //    MeshGeometry3D mesh0 = tileSource.GenerateMesh(grid0, extent);
                //    DiffuseMaterial material0 = new DiffuseMaterial(m_solidBrush);
                //    material0.Freeze();
                //    GeometryModel3D geometryModel0 = new GeometryModel3D(mesh0, material0);
                //    geometryModel0.Freeze();
                //    m_progressManager.Update(1.0f, geometryModel0);
                //}

                if (ENABLE_STITCHING)
                {
                    int validStitchingIndex = 0;
                    foreach (PointCloudTile tile in tileSource.TileSet)
                    {
                        TileInfo3D tileInfo = m_tileInfo[tile];
                        Model3DGroup stitchingGroup = GenerateTileStitching(tileSource, tileInfo);

                        if (stitchingGroup != null)
                            ++validStitchingIndex;

                        if (!m_progressManager.Update(1.0f, stitchingGroup))
                            break;
                    }
                }
            }
        }
Beispiel #14
0
        private void BuildTextures(OptFile opt)
        {
            this.nullTexture = null;
            this.textures = null;

            if (opt == null)
            {
                return;
            }

            this.nullTexture = new DiffuseMaterial(Brushes.White);

            this.textures = new Dictionary<string, Material>();

            foreach (var texture in opt.Textures.Values)
            {
                var image = CreateTexture(opt, texture.Name);
                image.Freeze();

                var brush = new ImageBrush(image)
                {
                    ViewportUnits = BrushMappingMode.Absolute,
                    Stretch = Stretch.Fill,
                    TileMode = TileMode.Tile,
                    Opacity = texture.HasAlpha ? 0.999 : 1.0
                };

                brush.Freeze();

                var material = new DiffuseMaterial(brush);
                material.Freeze();

                this.textures.Add(texture.Name, material);
            }
        }
Beispiel #15
0
		private Brush MakeBrushFromVisual(Visual visual, Rect bounds)
		{
			Viewport3D viewport = visual as Viewport3D;
			if (viewport == null)
			{
				Drawing drawing = VisualTreeHelper.GetDrawing(visual);
				if (this.drawOutlines)
				{
					bounds.Inflate(VisualTree3DView.OutlinePen.Thickness / 2, VisualTree3DView.OutlinePen.Thickness / 2);
				}

				Matrix offsetMatrix = new Matrix(1, 0, 0, 1, -bounds.Left, -bounds.Top);
				MatrixTransform offsetMatrixTransform = new MatrixTransform(offsetMatrix);
				offsetMatrixTransform.Freeze();

				DrawingVisual drawingVisual = new DrawingVisual();
				DrawingContext drawingContext = drawingVisual.RenderOpen();
				drawingContext.PushTransform(offsetMatrixTransform);
				if (this.drawOutlines)
				{
					drawingContext.DrawRectangle(null, VisualTree3DView.OutlinePen, bounds);
				}
				drawingContext.DrawDrawing(drawing);
				drawingContext.Pop();
				drawingContext.Close();

				visual = drawingVisual;
			}

			RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap((int)Math.Ceiling(bounds.Width), (int)Math.Ceiling(bounds.Height), 96, 96, PixelFormats.Default);
			if (viewport != null)
			{
				typeof(RenderTargetBitmap).GetMethod("RenderForBitmapEffect", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(renderTargetBitmap,
					new object[] { visual, Matrix.Identity, Rect.Empty });
			}
			else
			{
				renderTargetBitmap.Render(visual);
			}
			renderTargetBitmap.Freeze();
			ImageBrush imageBrush = new ImageBrush(renderTargetBitmap);
			imageBrush.Freeze();

			return imageBrush;
		}
 public override RBrush GetTextureBrush(RImage image, RRect dstRect, RPoint translateTransformLocation)
 {
     var brush = new ImageBrush(((ImageAdapter)image).Image);
     brush.Stretch = Stretch.None;
     brush.TileMode = TileMode.Tile;
     brush.Viewport = Utils.Convert(dstRect);
     brush.ViewportUnits = BrushMappingMode.Absolute;
     brush.Transform = new TranslateTransform(translateTransformLocation.X, translateTransformLocation.Y);
     brush.Freeze();
     return new BrushAdapter(brush);
 }
Beispiel #17
0
 /// <summary>
 /// Create image brush for picture image.
 /// </summary>
 /// <param name="pictureName"></param>
 /// <param name="isFreeze"></param>
 /// <returns></returns>
 private ImageBrush CreateImageBrush(string pictureName, bool isFreeze)
 {
     try
     {
         ImageBrush imagebrush = null;
         if (pictureName != string.Empty)
         {
             Uri inpuri = new Uri(@pictureName, UriKind.Relative);
             BitmapImage bi = new BitmapImage();
             bi.BeginInit();
             bi.UriSource = inpuri;
             bi.EndInit();
             imagebrush = new ImageBrush(bi);
             imagebrush.Opacity = 1;
             //imagebrush.Stretch = Stretch.UniformToFill;
             imagebrush.ViewportUnits = BrushMappingMode.Absolute;
             imagebrush.TileMode = TileMode.Tile;
             if (isFreeze)
             {
                 imagebrush.Freeze();
             }
         }
         return imagebrush;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #18
0
        /// <summary>
        /// create square 2D
        /// </summary>
        /// <param name="pictureName"></param>
        /// <param name="points"></param>
        /// <returns></returns>
        public Model3DGroup CreateSquare2D(string pictureName, Point3D[] points)
        {
            try
            {
                Uri inpuri = new Uri(@pictureName, UriKind.Relative);
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.UriSource = inpuri;
                bi.EndInit();
                ImageBrush imagebrush = new ImageBrush(bi);
                imagebrush.Opacity = 100;
                imagebrush.Freeze();

                Point[] ptexture0 = { new Point(0, 0), new Point(0, 1), new Point(1, 0) };
                Point[] ptexture1 = { new Point(1, 0), new Point(0, 1), new Point(1, 1) };

                Model3DGroup square = new Model3DGroup();
                square.Children.Add(CreateGeoModel2D(points[0], points[3], points[1], ptexture0, imagebrush));
                square.Children.Add(CreateGeoModel2D(points[1], points[3], points[2], ptexture1, imagebrush));
                square.Freeze();
                return square;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }