private Material GetTexture(string name) { var texture = Manager.Files.Where(x => x.Path.StartsWith(ModelFilePath.RemoveFirstSeparator()) && x.Path.EndsWith(name)); if (texture.Count() > 0) { return(MaterialHelper.CreateImageMaterial(Manager.GetFile(texture.First()).ToImage(), 1.0)); } return(HelixToolkit.Wpf.Materials.Gray); }
/// <summary> /// Initializes a new instance of the <see cref="_3DViewModel"/> class with textures for each mesh /// </summary> /// <param name="meshes">The meshes.</param> /// <param name="bitmaps">The bitmaps.</param> public _3DViewModel(List <Mesh> meshes, List <string> bitmaps) { List <Material> mats = new List <Material>(); //for each mesh, create an image material based on the matching bitmaps for (int i = 0; i < meshes.Count; i++) { mats.Add(MaterialHelper.CreateImageMaterial(bitmaps[i % bitmaps.Count], 1, UriKind.Absolute, false)); } //set up the model setupModel(meshes, mats, true); }
public Flag(string image) { Mesh = new MeshGeometry3D(); Material = MaterialHelper.CreateImageMaterial(image); Damping = 0.98; integrator = new VerletIntegrator() { Iterations = 4, Damping = this.Damping }; WindSpeed = 6; WindDirection = 180; PoleHeight = 12; Height = 3; Length = 4; Mass = 0.8; }
private void client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { if (e.Error != null) { SetDefaultClouds(); return; } var image = new BitmapImage(); image.BeginInit(); image.StreamSource = new MemoryStream(e.Result); image.EndInit(); Clouds = MaterialHelper.CreateImageMaterial(image, 0.5); }
private void CreateBilboard() { BitmapImage im = new BitmapImage(new System.Uri(@"C:\Users\Public\Pictures\Sample Pictures\Lighthouse.jpg")); var mat = MaterialHelper.CreateImageMaterial(im, 1); var bboard = new BillboardVisual3D(); bboard.Material = mat; var position = new System.Windows.Media.Media3D.Point3D(0, 0, 0); var width = 100; var height = 100; //set coordinates bboard.Position = position; bboard.Width = width; bboard.Height = height; //add the billboard viewPort.Children.Add(bboard); }
public Model3DGroup GetModel() { Model3DGroup model3DGroup = new Model3DGroup(); meshs.ForEach(x => { List <Point3D> list1 = new List <Point3D>(); List <Vector3D> list2 = new List <Vector3D>(); List <Point> list3 = new List <Point>(); for (int i = 0; i < x.vertices.Count; ++i) { list1.Add(x.vertices[i].position); list2.Add(x.normals[i]); list3.Add(x.vertices[i].uvcoord); } List <int> list4 = new List <int>(); x.faces.ForEach(y => { list4.Add(y[0]); list4.Add(y[1]); list4.Add(y[2]); }); MeshGeometry3D geometry = new MeshGeometry3D { Normals = new Vector3DCollection(list2), Positions = new Point3DCollection(list1), TextureCoordinates = new PointCollection(list3), TriangleIndices = new Int32Collection(list4) }; Material material = Materials.Gray; byte[] buffer = MainWindow.Buildings.ReadFile(x.texture[0].ToLower()); if (buffer.Length > 0) { material = MaterialHelper.CreateImageMaterial(ToImage(buffer), 1.0); } model3DGroup.Children.Add(new GeometryModel3D { Geometry = geometry, Material = material, BackMaterial = material }); }); return(model3DGroup); }
/// <summary> /// The load image. /// </summary> /// <param name="url"> /// The url. /// </param> /// <param name="setter"> /// The setter. /// </param> private void LoadImage(string url, Action <Material> setter) { var client = new WebClient(); client.DownloadDataCompleted += (sender, e) => { if (e.Error != null) { return; } var image = new BitmapImage(); image.BeginInit(); image.StreamSource = new MemoryStream(e.Result); image.EndInit(); setter(MaterialHelper.CreateImageMaterial(image, 0.5)); }; client.DownloadDataAsync(new Uri(url)); }
/// <summary> /// Initializes a new instance of the <see cref="MainWindow"/> class. /// </summary> public MainWindow() { this.InitializeComponent(); this.Clouds = MaterialHelper.CreateImageMaterial("pack://application:,,,/Examples/Earth/clouds.jpg", 0.5); // download the latest cloud image if (false) { // todo: the link does not work // LoadImage("http://xplanet.sourceforge.net/clouds/clouds_2048.jpg", m => Clouds = m); } // http://wiki.naturalfrequency.com/wiki/Solar_Position // http://www.geoastro.de/elevaz/basics/index.htm // http://stjarnhimlen.se/comp/ppcomp.html // http://www.daylightmap.com/about.php // http://www.sjsu.edu/faculty/watkins/elevsun.htm // http://www.physicalgeography.net/fundamentals/6h.html // http://www.die.net/earth/ // http://static.die.net/earth/mercator/1600.jpg var now = DateTime.UtcNow; var juneSolstice = new DateTime(now.Year, 6, 22); // todo: check calculation - this is probably not correct var declination = 23.45 * Math.Cos((now.DayOfYear - juneSolstice.DayOfYear) / 365.25 * 2 * Math.PI); var phi = -now.Hour / 24.0 * Math.PI * 2; var theta = declination / 180 * Math.PI; this.SunlightDirection = -new Vector3D(Math.Cos(phi) * Math.Cos(theta), Math.Sin(phi) * Math.Cos(theta), Math.Sin(theta)); this.view3.Camera.LookDirection = this.SunlightDirection; this.view3.Camera.Position = new Point3D() - this.view3.Camera.LookDirection; this.view3.Title = now.ToString("u"); this.view3.TextBrush = Brushes.White; this.DataContext = this; }
/// <summary> /// Initializes a new instance of the <see cref="MapTexture"/> class. /// </summary> /// <param name="source"> /// The source. /// </param> /// public MapTexture(System.Drawing.Bitmap image, double opacity) { this.Material = MaterialHelper.CreateImageMaterial(HelixToolkit.Wpf.cSurveySpecialized.Textures.cBitmapConverter.ToWpfBitmap(image), opacity); }
private void SetDefaultClouds() { Clouds = MaterialHelper.CreateImageMaterial("clouds.jpg", 0.5); }
public MainWindow() { this.InitializeComponent(); this.Clouds = MaterialHelper.CreateImageMaterial("pack://application:,,,/Examples/Earth/clouds.jpg", 0.5); this.DataContext = this; }
private Model3DGroup GetModel(GameObject newObject, String resourceName, String fileExt) { Transform3DGroup TransformGroup = new Transform3DGroup(); TranslateTransform3D TranslateTransform = new TranslateTransform3D(newObject.Position * ViewportScalingFactor); ModelVisual3D newModel = null; Model3DGroup newGroup = new Model3DGroup(); string assemblyLocation = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string resourceBase = "pack://*****:*****@"\GameAssets\" + resourceName); break; case "3ds": ModelImporter importer = new ModelImporter(); newGroup = importer.Load(assemblyLocation + @"\GameAssets\" + resourceName); foreach (var material in newObject.Model.Materials) { MaterialGroup materialGroup = new MaterialGroup(); Brush materialBrush = new SolidColorBrush(material.DiffuseColor); materialBrush.Opacity = material.Opacity; materialGroup.Children.Add(MaterialHelper.CreateMaterial(materialBrush, material.SpecularPower)); if (!String.IsNullOrWhiteSpace(material.TextureFile)) { if (File.Exists(assemblyLocation + @"\GameAssets\" + material.TextureFile)) { var texture = MaterialHelper.CreateImageMaterial(new BitmapImage(new Uri(assemblyLocation + @"\GameAssets\" + material.TextureFile, UriKind.Relative)), material.Opacity); materialGroup.Children.Add(texture); } } var specular = new SpecularMaterial(); specular.SpecularPower = material.SpecularPower; specular.Color = material.SpecularColor; var emissive = new EmissiveMaterial(); emissive.Color = material.EmissiveColor; materialGroup.Children.Add(specular); materialGroup.Children.Add(emissive); ((GeometryModel3D)newGroup.Children[material.MeshIndex]).Material = materialGroup; } break; } #if DEBUG if (resourceName.IndexOf("Rink") < 0) { HelixToolkit.Wpf.MeshBuilder meshBuilder = new MeshBuilder(); var boundingRect = newGroup.Bounds; meshBuilder.AddBoundingBox(boundingRect, 3); } #endif double CenterX = newGroup.Bounds.SizeX / 2; double CenterY = newGroup.Bounds.SizeY / 2; double CenterZ = newGroup.Bounds.SizeZ / 2; ScaleTransform3D ScaleTransform = new ScaleTransform3D(newObject.Scale.X, newObject.Scale.Y, newObject.Scale.Z, CenterX, CenterY, CenterZ); TransformGroup.Children.Add(TranslateTransform); TransformGroup.Children.Add(ScaleTransform); newGroup.Transform = TransformGroup; if (newObject.ApplyPhysics) { var rinkBounds = _gameObjects.Where(x => x.Key.Model.IsGameWorld).First().Value.Content.Bounds; TranslateTransform.OffsetZ -= (newGroup.Bounds.Z - rinkBounds.Z); } newObject.Bounds = newGroup.Bounds; return(newGroup); }
//private Material sand = MaterialHelper.CreateImageMaterial("sand.jpg", 1); public MainViewModel() { Model = m_modelGroup; topMaterial = MaterialHelper.CreateImageMaterial("maglev.png", 1); }
public MapTexture(BitmapImage image, double opacity) { this.Material = MaterialHelper.CreateImageMaterial(image, opacity); }
public MapTexture(string source) { Material = MaterialHelper.CreateImageMaterial(source, 1); }
public MapTexture(string source, double opacity) { this.Material = MaterialHelper.CreateImageMaterial(source, opacity); }
/// <summary> /// Gets the thumbnail image /// </summary> /// <param name="width">The width of the image that should be returned.</param> /// <returns> /// The image for the thumbnail /// </returns> protected override Bitmap GetThumbnailImage(uint width) { // Attempt to open the stream with a reader var pmx = PMXLoaderScript.Import(SelectedItemPath); MeshCreationInfo creation_info = CreateMeshCreationInfoSingle(pmx); var diffuseMat = MaterialHelper.CreateMaterial(Colors.Gray); var models = new Model3DGroup(); for (int i = 0, i_max = creation_info.value.Length; i < i_max; ++i) { int[] indices = creation_info.value[i].plane_indices.Select(x => (int)creation_info.reassign_dictionary[x]) .ToArray(); var mesh = new MeshGeometry3D { Positions = new Point3DCollection(pmx.vertex_list.vertex.Select(x => x.pos)), TextureCoordinates = new PointCollection(pmx.vertex_list.vertex.Select(x => new System.Windows.Point(x.uv.X, x.uv.Y))) }; indices.ToList() .ForEach(x => mesh.TriangleIndices.Add(x)); var textureIndex = pmx.material_list.material[creation_info.value[i].material_index].usually_texture_index; var texturePath = pmx.texture_list.texture_file.ElementAtOrDefault((int)textureIndex); var material = diffuseMat; if (!string.IsNullOrWhiteSpace(texturePath)) { texturePath = Path.Combine(Path.GetDirectoryName(SelectedItemPath), texturePath); //Log($"Texture found: {texturePath}"); if (!string.IsNullOrWhiteSpace(texturePath) && File.Exists(texturePath)) { // dds and tga if (new string[] { ".dds", ".tga" }.Any(x => x.Equals(Path.GetExtension(texturePath)))) { var bitmap = PFimToBitmap(texturePath); material = MaterialHelper.CreateImageMaterial(Bitmap2BitmapImage(bitmap), 1); } else { material = MaterialHelper.CreateImageMaterial(BitmapImageFromFile(texturePath), 1); } } } models.Children.Add(new GeometryModel3D(mesh, material)); } var sorting = new SortingVisual3D() { Content = models }; var view = new HelixViewport3D(); view.Children.Add(sorting); view.Camera.Position = new Point3D(0, 15, -30); view.Camera.LookDirection = new Vector3D(0, -5, 30); view.Background = System.Windows.Media.Brushes.Transparent; view.Children.Add(new SunLight() { Altitude = 260 }); view.Children.Add(new DefaultLights()); try { var bitmap = view.Viewport.RenderBitmap(width, width, new SolidColorBrush(Colors.Transparent)); view.Children.Clear(); view = null; sorting = null; models = null; GC.Collect(); return(BitmapFromSource(bitmap)); } catch (Exception exception) { view.Children.Clear(); view = null; sorting = null; models = null; GC.Collect(); LogError("An exception occurred Rendering bitmap.", exception); //MessageBox.Show(exception.Message); //MessageBox.Show(exception.StackTrace); return(null); } }