static Cube() { var b1 = new MeshBuilder(); b1.AddBox(new Vector3(0, 0, 0), 1, 1, 1); geometry = b1.ToMeshGeometry3D(); }
public Cube() { var b1 = new HelixToolkit.Wpf.SharpDX.MeshBuilder(); b1.AddBox(new Vector3(0, 0, 0), 1, 1, 1); Geometry = b1.ToMeshGeometry3D(); }
public Cube(double x, double y, double z) { var b1 = new HelixToolkit.Wpf.SharpDX.MeshBuilder(); b1.AddBox(new Vector3(0, 0, 0), x, y, z); Geometry = b1.ToMeshGeometry3D(); }
public MainViewModel() { Title = "ImageViewDemo"; SubTitle = "WPF & SharpDX"; this.OpenCommand = new RelayCommand((x) => OnOpenClick()); // camera setup this.defaultPerspectiveCamera = new PerspectiveCamera { Position = new Point3D(0, 0, 5), LookDirection = new Vector3D(0, 0, -5), UpDirection = new Vector3D(0, 1, 0), NearPlaneDistance = 0.5, FarPlaneDistance = 150 }; this.defaultOrthographicCamera = new OrthographicCamera { Position = new Point3D(0, 0, 5), LookDirection = new Vector3D(0, 0, -5), UpDirection = new Vector3D(0, 1, 0), NearPlaneDistance = 0, FarPlaneDistance = 100 }; this.Camera = defaultPerspectiveCamera; // setup lighting this.AmbientLightColor = new Color4(0f, 0f, 0f, 0f); this.DirectionalLightColor = Color.White; this.DirectionalLightDirection = new Vector3(-0, -0, -10); // floor plane grid this.Grid = LineBuilder.GenerateGrid(Vector3.UnitZ, -5, 5, -5, 5); this.GridColor = SharpDX.Color.Black; this.GridTransform = new Media3D.TranslateTransform3D(0, 0, 0); // plane var b2 = new MeshBuilder(); b2.AddBox(new Vector3(0, 0, 0), 10, 10, 0, BoxFaces.PositiveZ); this.Plane = b2.ToMeshGeometry3D(); this.PlaneMaterial = PhongMaterials.Blue; this.PlaneTransform = new Media3D.TranslateTransform3D(-0, -0, -0); //this.PlaneMaterial.ReflectiveColor = Color.Black; this.PlaneTransform = new Media3D.TranslateTransform3D(0, 0, 0); this.RenderTechnique = Techniques.RenderBlinn; }
public MainViewModel() { this.Title = "Environment Mapping Demo"; this.SubTitle = "HelixToolkitDX"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(10, 0, 0), LookDirection = new Vector3D(-10, 0, 0), UpDirection = new Vector3D(0, 1, 0) }; //this.Camera = new OrthographicCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) }; // lighting setup this.AmbientLightColor = new Color4(0.5f, 0.5f, 0.5f, 1.0f); this.DirectionalLightColor = Color.White; this.DirectionalLightDirection = new Vector3(-2, -1, 1); // scene model3d var b1 = new MeshBuilder(true); b1.AddSphere(new Vector3(0, 0, 0), 1.0, 64, 64); b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 3, BoxFaces.All); this.Model = b1.ToMeshGeometry3D(); this.ModelTransform = new Media3D.TranslateTransform3D(); this.ModelMaterial = PhongMaterials.Copper; RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); }
public void CreateBall() { var ballContainer = new HelixToolkit.Wpf.SharpDX.MeshBuilder(); ballContainer.AddSphere(BallCenter, 1.5); Geometry = ballContainer.ToMeshGeometry3D(); this.Material = PhongMaterials.White; }
/// <summary> /// Called when geometry has been changed. /// </summary> protected override void OnModelChanged() { var mb = new MeshBuilder(); var p0 = this.Offset;// new Vector3(0, 0, 0); var d = this.Direction; d.Normalize(); var p1 = p0 + (d * (float)this.Length); mb.AddArrow(p0, p1, this.Diameter, 2, 64); this.Geometry = mb.ToMeshGeometry3D(); }
public SingleCylinder(double radius) { Radius = radius; var b1 = new HelixToolkit.Wpf.SharpDX.MeshBuilder(); b1.AddCylinder(new Vector3(-1, 0, 0), new Vector3(1, 0, 0), radius, 32, true, true); b1.AddCylinder(new Vector3(-1.1f, 0, 0), new Vector3(1.1f, 0, 0), 0.05d, 32, true, true); Geometry = b1.ToMeshGeometry3D(); }
public MainViewModel() { // titles this.Title = "Simple Demo (Workitem 10043)"; this.SubTitle = "Please switch to Viewport 2 and then back to Viewport 1"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) }; if (this.RenderTechniquesManager != null) { // default render technique this.RenderTechnique = RenderTechniquesManager.RenderTechniques.Get(DefaultRenderTechniqueNames.Blinn); } // setup lighting this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); this.DirectionalLightColor = Color.White; this.DirectionalLightDirection = new Vector3(-2, -5, -2); // floor plane grid this.Grid = LineBuilder.GenerateGrid(); this.GridColor = SharpDX.Color.Black; this.GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5); b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All); var meshGeometry = b1.ToMeshGeometry3D(); meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4())); this.Model = meshGeometry; // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); this.Lines = e1.ToLineGeometry3D(); // model trafos this.Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0); this.Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0); this.Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0); // model materials this.RedMaterial = PhongMaterials.Red; this.GreenMaterial = PhongMaterials.Green; this.BlueMaterial = PhongMaterials.Blue; //var diffColor = this.RedMaterial.DiffuseColor; //diffColor.Alpha = 0.5f; //this.RedMaterial.DiffuseColor = diffColor; }
public void Setup() { closePoint = InitializePointWithId("closePoint"); farPoint = InitializePointWithId("farPoint", new Vector3(10000, 10000, 10000)); var builder = new MeshBuilder(); builder.AddBox(new Vector3(-10000, -10000, -5000), 5, 5, 5, BoxFaces.All); var boxGeom = builder.ToMeshGeometry3D(); cube = new MeshGeometryModel3D() { Geometry = boxGeom, Name = "cube" }; }
public MainViewModel() { RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); Title = "Shadow Map Demo"; SubTitle = "WPF & SharpDX"; // setup lighting this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); this.DirectionalLightColor = Color.White; this.DirectionalLightDirection = new Vector3(-0, -1, -1); this.LightDirectionTransform = CreateAnimatedTransform(-DirectionalLightDirection.ToVector3D(), new Vector3D(0, 1, -1), 24); this.ShadowMapResolution = new Vector2(2048, 2048); // camera setup this.Camera = new PerspectiveCamera { Position = (Point3D)(-DirectionalLightDirection.ToVector3D()), LookDirection = DirectionalLightDirection.ToVector3D(), UpDirection = new Vector3D(0, 1, 0) }; // floor plane grid //Grid = LineBuilder.GenerateGrid(); //GridColor = SharpDX.Color.Black; //GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5); b1.AddBox(new Vector3(0, 0, 0), 1, 0.25, 2, BoxFaces.All); Model = b1.ToMeshGeometry3D(); //Instances = new[] { Matrix.Translation(0, 0, -1.5f), Matrix.Translation(0, 0, 1.5f) }; var b2 = new MeshBuilder(); b2.AddBox(new Vector3(0, 0, 0), 10, 0, 10, BoxFaces.PositiveY); Plane = b2.ToMeshGeometry3D(); PlaneTransform = new Media3D.TranslateTransform3D(-0, -2, -0); GrayMaterial = PhongMaterials.LightGray; //GrayMaterial.TextureMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute)); // lines model3d Lines = LineBuilder.GenerateBoundingBox(Model); // model trafos Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0); Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0); Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0); // model materials RedMaterial = PhongMaterials.Glass; GreenMaterial = PhongMaterials.Green; BlueMaterial = PhongMaterials.Blue; }
public void LoadBalls() { try { string fileContent = File.ReadAllText("./data/balldata.txt"); string[] contentArray = fileContent.Split((string[])null, StringSplitOptions.RemoveEmptyEntries); MainViewModel.ProjData.BallCollection.Clear(); for (int i = 0; i < contentArray.Length; i += 5) { BallModel ball = new BallModel(); var ballContainer = new HelixToolkit.Wpf.SharpDX.MeshBuilder(); ball.BallCenter = new Vector3(Convert.ToSingle(contentArray[i]), Convert.ToSingle(contentArray[i + 1]), Convert.ToSingle(contentArray[i + 2])); ball.BallName = contentArray[i + 3]; ballContainer.AddSphere(ball.BallCenter, 1.5); ball.Geometry = ballContainer.ToMeshGeometry3D(); ball.Material = PhongMaterials.White; if (contentArray[i + 4].Equals("MovedMaxilla")) { ball.ModelType = ModelType.MovedMaxilla; } else if (contentArray[i + 4].Equals("MovedMandible")) { ball.ModelType = ModelType.MovedMandible; } foreach (BoneModel modeltem in MainViewModel.ProjData.BoneCollection) { if (modeltem.ModelType.Equals(ball.ModelType)) { ball.ModelType = modeltem.ModelType; System.Windows.Data.Binding binding = new System.Windows.Data.Binding("Transform"); binding.Source = modeltem; binding.Mode = BindingMode.OneWay; BindingOperations.SetBinding(ball, HelixToolkit.Wpf.SharpDX.Model3D.TransformProperty, binding); } } MainViewModel.ProjData.BallCollection.Add(ball); } } catch { System.Windows.MessageBox.Show("Load檔案失敗"); } }
public MainViewModel() { RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); this.Title = "Line Shading Demo (HelixToolkitDX)"; this.SubTitle = null; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(0, 5, 5), LookDirection = new Vector3D(-0, -5, -5), UpDirection = new Vector3D(0, 1, 0) }; // setup lighting this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); this.DirectionalLightColor = Color.White; this.DirectionalLightDirection = new Vector3(-2, -5, -2); // floor plane grid this.Grid = LineBuilder.GenerateGrid(); this.GridColor = SharpDX.Color.Black; this.GridTransform = new TranslateTransform3D(-5, -1, -5); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5); b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All); this.Model = b1.ToMeshGeometry3D(); // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); //e1.AddLine(new Vector3(-1, 0, 0), new Vector3(1, 0, 0)); this.Lines = e1.ToLineGeometry3D(); // lines params this.LineThickness = 2; this.LineSmoothness = 2.0; this.LinesEnabled = true; this.GridEnabled = true; // model trafos this.Model1Transform = new TranslateTransform3D(0, 0, 0); this.Model2Transform = new TranslateTransform3D(-2, 0, 0); this.Model3Transform = new TranslateTransform3D(+2, 0, 0); // model materials this.Material1 = PhongMaterials.PolishedGold; this.Material2 = PhongMaterials.Copper; this.Material3 = PhongMaterials.Glass; }
public Watch3DxControl() { InitializeComponent(); // DataContext = this; // titles view1.Title = "Watch3DxNode"; view1.SubTitle = "SharpDX"; // camera setup view1.Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0), FarPlaneDistance = 5000000 }; // default render technique view1.RenderTechniquesManager = new DefaultRenderTechniquesManager(); view1.RenderTechnique = view1.RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Phong]; view1.EffectsManager = new DefaultEffectsManager(view1.RenderTechniquesManager); // Setup lights var directionalLight3D = new DirectionalLight3D { Color = Color.White, Direction = new Vector3(-2, -5, -2) }; var ambientLight3D = new AmbientLight3D {Color = Color.White}; view1.Items.Add(ambientLight3D); view1.Items.Add(directionalLight3D); // Geometry var mb = new MeshBuilder(); mb.AddSphere(new Vector3(0, 0, 0), 0.5); mb.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All); var meshGeometry = mb.ToMeshGeometry3D(); var meshGeomModel = new MeshGeometryModel3D { Geometry = meshGeometry, Material = PhongMaterials.Red }; // Add the Model to the viewport view1.Items.Add(meshGeomModel); }
public void HighlightBounds(SharpDX.BoundingBox bounds) { var r3d = new Media3D.Rect3D(bounds.Minimum.ToPoint3D(), bounds.Size.ToSize3D()); var b = new Helix.MeshBuilder(); b.AddBoundingBox(r3d, 0.1); b.AddSphere(bounds.Center, 0.1); var geom = b.ToMeshGeometry3D(); box.Geometry = geom; if (!Viewport.Items.Contains(box)) { Viewport.Items.Add(box); } }
public MainViewModel() { RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); this.Title = "Manipulator Demo"; this.SubTitle = null; // camera setup this.Camera = new OrthographicCamera { Position = new Point3D(0, 0, 5), LookDirection = new Vector3D(0, 0, -5), UpDirection = new Vector3D(0, 1, 0) }; // setup lighting this.AmbientLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f); this.DirectionalLightColor = Color.White; this.DirectionalLightDirection = new Vector3(-2, -5, -2); // floor plane grid this.Grid = LineBuilder.GenerateGrid(); this.GridColor = SharpDX.Color.Black; this.GridTransform = new TranslateTransform3D(-5, -1, -5); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5); b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 1.5, BoxFaces.All); this.Model = b1.ToMeshGeometry3D(); // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 1.5); this.Lines = e1.ToLineGeometry3D(); // model trafos this.Model1Transform = CreateAnimatedTransform(new Vector3D(0, 0, 0), new Vector3D(1, 1, 1), 20); this.Model2Transform = new TranslateTransform3D(-3, 0, 0); this.Model3Transform = new TranslateTransform3D(+3, 0, 0); // model materials this.Material1 = PhongMaterials.Orange; this.Material2 = PhongMaterials.Orange; this.Material3 = PhongMaterials.Red; var dr = Color.DarkRed; Console.WriteLine(dr); }
static InteractionHandle3D() { var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0.0f, 0.0f, 0), 0.135); NodeGeometry = b1.ToMeshGeometry3D(); var b2 = new MeshBuilder(); b2.AddCylinder(new Vector3(0, 0, 0), new Vector3(1, 0, 0), 0.05, 32, true, true); EdgeHGeometry = b2.ToMeshGeometry3D(); var b3 = new MeshBuilder(); b3.AddCylinder(new Vector3(0, 0, 0), new Vector3(0, 1, 0), 0.05, 32, true, true); EdgeVGeometry = b3.ToMeshGeometry3D(); var b4 = new MeshBuilder(); b4.AddBox(new Vector3(0, 0, 0), 0.175, 0.175, 0.175); BoxGeometry = b4.ToMeshGeometry3D(); }
public MainViewModel() { Title = "Instancing Demo"; // camera setup Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) }; // setup lighting this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); this.DirectionalLightColor = (Color4)Color.White; this.DirectionalLightDirection = new Vector3(-2, -5, -2); // scene model3d var b1 = new MeshBuilder(); b1.AddBox(new Vector3(0, 0, 0), 0.8, 0.8, 0.5, BoxFaces.All); Model = b1.ToMeshGeometry3D(); var l1 = new LineBuilder(); l1.AddBox(new Vector3(0, 0, 0), 0.8, 0.8, 0.5); Lines = l1.ToLineGeometry3D(); int num = 10; var instances = new List<Matrix>(); for (int i = -num; i < num; i++) { for (int j = -num; j < num; j++) { instances.Add(Matrix.Translation(new Vector3(i / 1.0f, j / 1.0f, 0f))); } } ModelInstances = instances; SubTitle = "Number of Instances: " + instances.Count.ToString(); // model trafo ModelTransform = Media3D.Transform3D.Identity;// new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 0, 1), 45)); // model material ModelMaterial = PhongMaterials.Glass; RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); }
public MainViewModel() { RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); // titles this.Title = "Mouse Drag Demo"; this.SubTitle = "WPF & SharpDX"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(0, 0, 9), LookDirection = new Vector3D(-0, -0, -9), UpDirection = new Vector3D(0, 1, 0) }; // default render technique this.RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; // setup lighting this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); this.DirectionalLightColor = Color.White; this.DirectionalLightDirection = new Vector3(-2, -5, -2); // floor plane grid this.Grid = LineBuilder.GenerateGrid(Vector3.UnitZ, -5, 5); this.GridColor = SharpDX.Color.Black; this.GridTransform = new Media3D.TranslateTransform3D(-0, -0, -0); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.65); b1.AddBox(new Vector3(0, 0, 0), 1, 1, 1); var meshGeometry = b1.ToMeshGeometry3D(); meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4())); this.MeshGeometry = meshGeometry; this.Model1Instances = new List<Matrix>(); for (int i = 0; i < 5; i++) { this.Model1Instances.Add(Matrix.Translation(0, i, 0)); } // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); this.Lines = e1.ToLineGeometry3D(); // model trafos this.Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0.0); this.Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0); this.Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0); // model materials this.RedMaterial = PhongMaterials.Red; this.GreenMaterial = PhongMaterials.Green; this.BlueMaterial = PhongMaterials.Blue; // --- this.Shape3DCollection = new ObservableCollection<Shape3D> { new Shape3D() { Geometry = this.MeshGeometry, Material = this.BlueMaterial, Transform = this.Model3Transform, Instances = new List<Matrix>{Matrix.Identity}, DragZ = false, }, new Shape3D() { Geometry = this.MeshGeometry, Material = this.RedMaterial, Transform = this.Model1Transform, Instances = new List<Matrix>{Matrix.Identity}, DragZ = true, }, }; this.Element3DCollection = new ObservableCollection<Element3D>() { new DraggableGeometryModel3D() { Geometry = this.MeshGeometry, Material = this.BlueMaterial, Transform = this.Model3Transform, }, new DraggableGeometryModel3D() { Geometry = this.MeshGeometry, Material = this.RedMaterial, Transform = this.Model1Transform, }, }; this.AddCmd = new RelayCommand((o) => AddShape()); this.DelCmd = new RelayCommand((o) => DelShape()); }
public override void Calculate() { if (InputPorts[0].Data == null) return; // Use Tesselation Render Technique _control.view1.RenderTechniquesManager = new TessellationTechniquesManager(); _control.view1.RenderTechnique = _control.view1.RenderTechniquesManager.RenderTechniques[TessellationRenderTechniqueNames.PNTriangles]; _control.view1.EffectsManager = new TessellationEffectsManager(_control.view1.RenderTechniquesManager); // _control.view1.RenderTechniquesManager = new DefaultRenderTechniquesManager(); // _control.view1.RenderTechnique = _control.view1.RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; // _control.view1.EffectsManager = new DefaultEffectsManager(_control.view1.RenderTechniquesManager); _control.RemoveGeometryModels(); // Input is of Type GenericElement if (InputPorts[0].Data != null && InputPorts[0].Data.GetType() == typeof(List<DtObject>)) { var elements = InputPorts[0].Data as List<DtObject>; // Loop the items of each list foreach (var item in elements) { // Init the MeshBuilde var mb = new MeshBuilder(); var points = item.AttributeGroups["geometry"].GetProperty("threejspoints") as List<Point3D>; var indices = item.AttributeGroups["geometry"].GetProperty("geometryindices") as List<uint>; var color = item.AttributeGroups["geometry"].GetProperty("color") is System.Drawing.Color ? (System.Drawing.Color) item.AttributeGroups["geometry"].GetProperty("color") : new System.Drawing.Color(); var listIndices = indices.Select(value => (int) value).ToList(); for (var i = 0; i < indices.Count; i++) { switch (indices[i]) { case 0: mb.AddPolygon(new List<Vector3> { new Vector3((float)points[listIndices[i]].X, (float)points[listIndices[i]].Y, (float)points[listIndices[i]].Z), new Vector3((float)points[listIndices[i + 1]].X, (float)points[listIndices[i + 1]].Y, (float)points[listIndices[i + 1]].Z), new Vector3((float)points[listIndices[i + 2]].X, (float)points[listIndices[i + 2]].Y, (float)points[listIndices[i + 2]].Z) }); i = i + 3; break; case 1: mb.AddPolygon(new List<Vector3> { new Vector3((float)points[listIndices[i]].X, (float)points[listIndices[i]].Y, (float)points[listIndices[i]].Z), new Vector3((float)points[listIndices[i + 1]].X, (float)points[listIndices[i + 1]].Y, (float)points[listIndices[i + 1]].Z), new Vector3((float)points[listIndices[i + 2]].X, (float)points[listIndices[i + 2]].Y, (float)points[listIndices[i + 2]].Z), new Vector3((float)points[listIndices[i + 3]].X, (float)points[listIndices[i + 3]].Y, (float)points[listIndices[i + 3]].Z) }); i = i + 4; break; } } // for (var i = 0; i < indices.Count; i++) // { // switch (indices[i]) // { // case 0: // mb.AddTriangle( // new Vector3((float)points[(int)indices[i]].X, (float)points[(int)indices[i]].Y, (float)points[(int)indices[i]].Z), // new Vector3((float)points[(int)indices[i + 1]].X, (float)points[(int)indices[i + 1]].Y, (float)points[(int)indices[i + 1]].Z), // new Vector3((float)points[(int)indices[i + 2]].X, (float)points[(int)indices[i + 2]].Y, (float)points[(int)indices[i + 2]].Z)); // i = i + 3; // break; // case 1: // mb.AddQuad( // new Vector3((float)points[(int)indices[i]].X, (float)points[(int)indices[i]].Y, (float)points[(int)indices[i]].Z), // new Vector3((float)points[(int)indices[i + 1]].X, (float)points[(int)indices[i + 1]].Y, (float)points[(int)indices[i + 1]].Z), // new Vector3((float)points[(int)indices[i + 2]].X, (float)points[(int)indices[i + 2]].Y, (float)points[(int)indices[i + 2]].Z), // new Vector3((float)points[(int)indices[i + 3]].X, (float)points[(int)indices[i + 3]].Y, (float)points[(int)indices[i + 3]].Z)); // i = i + 4; // break; // } // } mb.ComputeNormalsAndTangents(MeshFaces.QuadPatches, true); var meshGeometry = mb.ToMeshGeometry3D(); var meshGeomModel = new MeshGeometryModel3D { Geometry = meshGeometry, Material = PhongMaterials.Red, // Material = new PhongMaterial // { // AmbientColor = new Color4 { Alpha = color.A, Red = color.R, Blue = color.B, Green = color.G }, // // DiffuseColor = new Color4 { Alpha = color.A, Red = color.R, Blue = color.B, Green = color.G }, // // SpecularColor = new Color4 { Alpha = color.A, Red = color.R, Blue = color.B, Green = color.G }, // // EmissiveColor = new Color4 { Alpha = color.A, Red = color.R, Blue = color.B, Green = color.G }, // // SpecularShininess = 89.6f, // }, Transform = new TranslateTransform3D() }; // Add the Model to the viewport base.VisualizeMesh(meshGeomModel); } } else { base.Calculate(); } }
/// <summary> /// Gets a unit sphere from the cache. /// </summary> /// <param name="subdivisions"> /// The number of subdivisions. /// </param> /// <returns> /// A unit sphere mesh. /// </returns> private static MeshGeometry3D GetUnitSphere(int subdivisions) { if (UnitSphereCache.ContainsKey(subdivisions)) { return UnitSphereCache[subdivisions]; } var mb = new MeshBuilder(false, false); mb.AddRegularIcosahedron(new Vector3(), 1, false); for (int i = 0; i < subdivisions; i++) { mb.SubdivideLinear(); } for (int i = 0; i < mb.positions.Count; i++) { var v = mb.positions[i]; v.Normalize(); mb.positions[i] = v; } var mesh = mb.ToMeshGeometry3D(); UnitSphereCache[subdivisions] = mesh; return mesh; }
/// <summary> /// Creates a MeshGeometry3D object from the loaded file. Polygons are triangulated using triangle fans. /// </summary> /// <returns> /// A MeshGeometry3D. /// </returns> public MeshGeometry3D CreateMeshGeometry3D(ModelInfo info = default(ModelInfo)) { var mb = new MeshBuilder(info.Normals, info.Tangents); foreach (var p in this.Vertices) { mb.Positions.Add(p); } foreach (var face in this.Faces) { mb.AddTriangleFan(face); } mb.ComputeNormalsAndTangents(info.Faces); return mb.ToMeshGeometry3D(); }
/// <summary> /// Called when geometry has been changed. /// </summary> protected override void OnModelChanged() { var mb = new MeshBuilder(); var p0 = this.Offset; //new Vector3(0, 0, 0); if (this.InnerDiameter >= this.OuterDiameter) this.OuterDiameter = this.InnerDiameter + 0.3; var d = this.Axis; d.Normalize(); var p1 = p0 - (d * (float)this.Length * 0.5f); var p2 = p0 + (d * (float)this.Length * 0.5f); mb.AddPipe(p1, p2, this.InnerDiameter, this.OuterDiameter, 64); this.Geometry = mb.ToMeshGeometry3D(); }
private void CreateFaceModels(IFCItem item, Vector3D center) { while (item != null) { if (item.ifcID != IntPtr.Zero && item.noVerticesForFaces != 0 && item.noPrimitivesForFaces != 0) { var positions = new List<Vector3>(); var normals = new List<Vector3>(); if (item.verticesForFaces != null) { for (int i = 0; i < item.noVerticesForFaces; i++) { var point = new Point3D(item.verticesForFaces[6 * i + 0] - center.X, item.verticesForFaces[6 * i + 1] - center.Y, item.verticesForFaces[6 * i + 2] - center.Z); var normal = new Vector3D(item.verticesForFaces[6 * i + 3], item.verticesForFaces[6 * i + 4], item.verticesForFaces[6 * i + 5]); positions.Add(new Vector3((float)point.X, (float)point.Y, (float)point.Z)); normals.Add(new Vector3((float)normal.X, (float)normal.Y, (float)normal.Z)); } Debug.Assert(item.verticesForFaces.Length == item.noVerticesForFaces * 6); } var indices = new Int32Collection(); if (item.indicesForFaces != null) { for (int i = 0; i < 3 * item.noPrimitivesForFaces; i++) { indices.Add(item.indicesForFaces[i]); } } List<Vector2> textureCoords = positions.Select(o => new Vector2(o.X, o.Y)).ToList(); var meshBuilder = new MeshBuilder(); meshBuilder.Append(positions, indices,normals,textureCoords); MeshGeometryModel3D mesh = new MeshGeometryModel3D() { Geometry = meshBuilder.ToMeshGeometry3D() }; item.Mesh3d = mesh; _meshToIfcItems[mesh] = item; #if DEBUG //OutputObj(item.ifcID.ToString(), mesh); #endif FillMeshByIfcColor(item); model.Add(mesh); } CreateFaceModels(item.child, center); item = item.next; } }
public MainViewModel() { // ---------------------------------------------- // titles this.Title = "Lighting Demo"; this.SubTitle = "WPF & SharpDX"; // ---------------------------------------------- // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(8, 9, 7), LookDirection = new Vector3D(-5, -12, -5), UpDirection = new Vector3D(0, 1, 0) }; // ---------------------------------------------- // setup scene this.AmbientLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f); this.RenderLight1 = true; this.RenderLight2 = true; this.RenderLight3 = true; this.RenderLight4 = true; this.Light1Color = (Color4)Color.White; this.Light2Color = (Color4)Color.Red; this.Light3Color = (Color4)Color.LightYellow; this.Light4Color = (Color4)Color.LightBlue; this.Light2Attenuation = new Vector3(1.0f, 0.5f, 0.10f); this.Light3Attenuation = new Vector3(1.0f, 0.1f, 0.05f); this.Light4Attenuation = new Vector3(1.0f, 0.2f, 0.0f); this.Light1Direction = new Vector3(0, -10, -10); this.Light1Transform = new TranslateTransform3D(-Light1Direction.ToVector3D()); this.Light1DirectionTransform = CreateAnimatedTransform2(-Light1Direction.ToVector3D(), new Vector3D(0, 1, -1), 24); this.Light2Transform = CreateAnimatedTransform1(new Vector3D(-4, 0, 0), new Vector3D(0, 0, 1), 3); this.Light3Transform = CreateAnimatedTransform1(new Vector3D(0, 0, 4), new Vector3D(0, 1, 0), 5); this.Light4Direction = new Vector3(0, -5, 0); this.Light4Transform = new TranslateTransform3D(-Light4Direction.ToVector3D()); this.Light4DirectionTransform = CreateAnimatedTransform2(-Light4Direction.ToVector3D(), new Vector3D(1, 0, 0), 12); // ---------------------------------------------- // light model3d var sphere = new MeshBuilder(); sphere.AddSphere(new Vector3(0, 0, 0), 0.2); Sphere = sphere.ToMeshGeometry3D(); this.LightModelMaterial = new PhongMaterial { AmbientColor = Color.Gray, DiffuseColor = Color.Gray, EmissiveColor = Color.Yellow, SpecularColor = Color.Black, }; // ---------------------------------------------- // scene model3d var b1 = new MeshBuilder(true, true, true); b1.AddSphere(new Vector3(0.25f, 0.25f, 0.25f), 0.75, 64, 64); b1.AddBox(-new Vector3(0.25f, 0.25f, 0.25f), 1, 1, 1, BoxFaces.All); b1.AddBox(-new Vector3(5.0f, 0.0f, 0.0f), 1, 1, 1, BoxFaces.All); b1.AddSphere(new Vector3(5f, 0f, 0f), 0.75, 64, 64); b1.AddCylinder(new Vector3(0f, -3f, -5f), new Vector3(0f, 3f, -5f), 1.2, 64); this.Model = b1.ToMeshGeometry3D(); this.ModelTransform = new Media3D.TranslateTransform3D(0, 0, 0); this.ModelMaterial = PhongMaterials.Chrome; //this.ModelMaterial.TextureMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute)); this.ModelMaterial.NormalMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute)); //odelMaterial.NormalMap = new BitmapImage(new System.Uri(@"TextureNoise1_dot3.jpg", System.UriKind.RelativeOrAbsolute)); // ---------------------------------------------- // floor model3d var b2 = new MeshBuilder(true, true, true); b2.AddBox(new Vector3(0.0f, -5.0f, 0.0f), 15, 0.1, 15, BoxFaces.All); b2.AddSphere(new Vector3(-5.0f, -5.0f, 5.0f), 4, 64, 64); b2.AddCone(new Vector3(6f, -9f, -6f), new Vector3(6f, -1f, -6f), 4f, true, 64); this.Floor = b2.ToMeshGeometry3D(); this.FloorTransform = new Media3D.TranslateTransform3D(0, 0, 0); this.FloorMaterial = new PhongMaterial { AmbientColor = Color.Gray, DiffuseColor = new Color4(0.75f, 0.75f, 0.75f, 1.0f), SpecularColor = Color.White, SpecularShininess = 100f, DiffuseMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute)), NormalMap = new BitmapImage(new System.Uri(@"TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute)), }; }
//用來輸入文字文件,然後輸出球的模型檔案 private void SaveBall() { string path = "D:\\Desktop\\新文字文件.txt"; try { string fileContent = File.ReadAllText(path); string[] contentArray = fileContent.Split((string[])null, StringSplitOptions.RemoveEmptyEntries); float[] pointInfo = Array.ConvertAll(contentArray, float.Parse); if (pointInfo.Length % 3 != 0) { throw new Exception(); } var ballContainer = new HelixToolkit.Wpf.SharpDX.MeshBuilder(); for (int i = 0; i < pointInfo.Length / 3; i++) { ballContainer.AddSphere(new Vector3(pointInfo[i * 3], pointInfo[i * 3 + 1], pointInfo[i * 3 + 2]), 1.5); } System.Windows.Media.Media3D.MeshGeometry3D ballMesh = new System.Windows.Media.Media3D.MeshGeometry3D { Positions = new Point3DCollection(), Normals = new Vector3DCollection(), TriangleIndices = new Int32Collection() }; HelixToolkit.Wpf.SharpDX.MeshGeometry3D geometry = ballContainer.ToMeshGeometry3D(); foreach (Vector3 position in geometry.Positions) { ballMesh.Positions.Add(new Point3D(position.X, position.Y, position.Z)); } foreach (Vector3 normal in geometry.Normals) { ballMesh.Normals.Add(new Vector3D(normal.X, normal.Y, normal.Z)); } foreach (int triangleindice in geometry.TriangleIndices) { ballMesh.TriangleIndices.Add(triangleindice); } System.Windows.Media.Media3D.GeometryModel3D ballModel = new System.Windows.Media.Media3D.GeometryModel3D { Geometry = ballMesh, }; Model3DGroup ballGroup = new Model3DGroup(); ballGroup.Children.Add(ballModel); StlExporter export1 = new StlExporter(); string name1 = "ball.stl"; using (var fileStream = File.Create("D:\\Desktop\\" + name1)) { export1.Export(ballGroup, fileStream); } } catch { System.Windows.MessageBox.Show("點的讀取錯誤"); } }
public void ComputeBoundsForSelectedNodeGeometry_OnePointOneCubeSelected_BoundingBoxIsCorrect() { var pointA = InitializePointWithId("A"); var builder = new MeshBuilder(); builder.AddBox(new Vector3(1000000, 1000000, 1000000), 5, 5, 5, BoxFaces.All); var boxGeom = builder.ToMeshGeometry3D(); var boxB = new MeshGeometryModel3D() { Geometry = boxGeom, Name = "B" }; var bounds = HelixWatch3DViewModel.ComputeBoundsForGeometry(new GeometryModel3D[] { pointA, boxB }); Assert.AreEqual(bounds.Minimum, pointA.Bounds().Minimum); Assert.AreEqual(bounds.Maximum, boxB.Bounds().Maximum); }
static Sphere() { var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5); geometry = b1.ToMeshGeometry3D(); }
public MainViewModel(Viewport3DX viewport, TreeView treeview) { // ---------------------------------------------- // titles this.Title = "Ifc Viewer"; this.SubTitle = "By LinJiarui"; // ---------------------------------------------- // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(8, 9, 7), LookDirection = new Vector3D(-5, -12, -5), UpDirection = new Vector3D(0, 0, 1) }; // ---------------------------------------------- // setup scene this.AmbientLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f); this.RenderLight1 = true; this.RenderLight2 = false; this.RenderLight3 = false; this.RenderLight4 = true; this.Light1Color = (Color4)Color.White; this.Light2Color = (Color4)Color.Red; this.Light3Color = (Color4)Color.LightYellow; this.Light4Color = (Color4)Color.LightBlue; this.Light2Attenuation = new Vector3(1.0f, 0.5f, 0.10f); this.Light3Attenuation = new Vector3(1.0f, 0.1f, 0.05f); this.Light4Attenuation = new Vector3(1.0f, 0.2f, 0.0f); this.Light1Direction = new Vector3(0, -10, -10); this.Light1Transform = new TranslateTransform3D(-Light1Direction.ToVector3D()); // this.Light1DirectionTransform = CreateAnimatedTransform2(-Light1Direction.ToVector3D(), new Vector3D(0, 1, -1), 24); // this.Light2Transform = CreateAnimatedTransform1(new Vector3D(-4, 0, 0), new Vector3D(0, 0, 1), 3); // this.Light3Transform = CreateAnimatedTransform1(new Vector3D(0, 0, 4), new Vector3D(0, 1, 0), 5); this.Light4Direction = new Vector3(0, -5, 0); this.Light4Transform = new TranslateTransform3D(-Light4Direction.ToVector3D()); // this.Light4DirectionTransform = CreateAnimatedTransform2(-Light4Direction.ToVector3D(), new Vector3D(1, 0, 0), 12); // ---------------------------------------------- // light model3d var sphere = new MeshBuilder(); sphere.AddSphere(new Vector3(0, 0, 0), 0.2); Sphere = sphere.ToMeshGeometry3D(); this.LightModelMaterial = new PhongMaterial { AmbientColor = Color.Gray, DiffuseColor = Color.Gray, EmissiveColor = Color.Yellow, SpecularColor = Color.Black, }; viewController = new ViewController(); Model = new Element3DCollection(); viewController.InitGraphics(viewport, Model, treeview); }
public override void Attach(IRenderHost host) { /// --- attach this.renderTechnique = Techniques.RenderCubeMap; base.Attach(host); /// --- get variables this.vertexLayout = EffectsManager.Instance.GetLayout(this.renderTechnique); this.effectTechnique = effect.GetTechniqueByName(this.renderTechnique.Name); this.effectTransforms = new EffectTransformVariables(this.effect); /// -- attach cube map if (this.Filename != null) { /// -- attach texture using (var texture = Texture2D.FromFile<Texture2D>(this.Device, this.Filename)) { this.texCubeMapView = new ShaderResourceView(this.Device, texture); } this.texCubeMap = effect.GetVariableByName("texCubeMap").AsShaderResource(); this.texCubeMap.SetResource(this.texCubeMapView); this.bHasCubeMap = effect.GetVariableByName("bHasCubeMap").AsScalar(); this.bHasCubeMap.Set(true); /// --- set up geometry var sphere = new MeshBuilder(false,true,false); sphere.AddSphere(new Vector3(0, 0, 0)); this.geometry = sphere.ToMeshGeometry3D(); /// --- set up vertex buffer this.vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer, CubeVertex.SizeInBytes, this.geometry.Positions.Select((x, ii) => new CubeVertex() { Position = new Vector4(x, 1f) }).ToArray()); /// --- set up index buffer this.indexBuffer = Device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), geometry.Indices.Array); /// --- set up rasterizer states var rasterStateDesc = new RasterizerStateDescription() { FillMode = FillMode.Solid, CullMode = CullMode.Back, IsMultisampleEnabled = true, IsAntialiasedLineEnabled = true, IsFrontCounterClockwise = false, }; this.rasterState = new RasterizerState(this.Device, rasterStateDesc); /// --- set up depth stencil state var depthStencilDesc = new DepthStencilStateDescription() { DepthComparison = Comparison.LessEqual, DepthWriteMask = global::SharpDX.Direct3D11.DepthWriteMask.All, IsDepthEnabled = true, }; this.depthStencilState = new DepthStencilState(this.Device, depthStencilDesc); } /// --- flush this.Device.ImmediateContext.Flush(); }
/// <summary> /// Cuts the mesh with the specified plane. (Modified from HelixToolkit.Wpf version) /// </summary> /// <param name="mesh"> /// The mesh. /// </param> /// <param name="plane"> /// The plane origin. /// </param> /// <param name="normal"> /// The plane normal. /// </param> /// <returns> /// The <see cref="MeshGeometry3D"/>. /// </returns> public static MeshGeometry3D CutMesh(this MeshGeometry3D mesh, Media3D.Point3D plane, Vector3 normal) { var hasTextureCoordinates = mesh.TextureCoordinates != null && mesh.TextureCoordinates.Count > 0; var hasNormals = mesh.Normals != null && mesh.Normals.Count > 0; var meshBuilder = new MeshBuilder(hasNormals, hasTextureCoordinates); var contourHelper = new HelixToolkit.Wpf.SharpDX.Helpers.ContourHelperDX(plane, normal, mesh); foreach (var position in mesh.Positions) { meshBuilder.Positions.Add(position); } if (hasTextureCoordinates) { foreach (var textureCoordinate in mesh.TextureCoordinates) { meshBuilder.TextureCoordinates.Add(textureCoordinate); } } if (hasNormals) { foreach (var n in mesh.Normals) { meshBuilder.Normals.Add(n); } } for (var i = 0; i < mesh.Indices.Count; i += 3) { var index0 = mesh.Indices[i]; var index1 = mesh.Indices[i + 1]; var index2 = mesh.Indices[i + 2]; Vector3[] positions; Vector3[] normals; Vector2[] textureCoordinates; int[] triangleIndices; contourHelper.ContourFacet(index0, index1, index2, out positions, out normals, out textureCoordinates, out triangleIndices); foreach (var p in positions) { meshBuilder.Positions.Add(p); } foreach (var tc in textureCoordinates) { meshBuilder.TextureCoordinates.Add(tc); } foreach (var n in normals) { meshBuilder.Normals.Add(n); } foreach (var ti in triangleIndices) { meshBuilder.TriangleIndices.Add(ti); } } return meshBuilder.ToMeshGeometry3D(); }
public Watch3DNodeDx(Core.VplControl hostCanvas) : base(hostCanvas) { // Add Control s _control = new Watch3DxControl(); AddControlToNode(_control); // Set Node resizable ... IsResizeable = true; // Add Control s _control = new Watch3DxControl(); /* * { * ViewPort3D = * { * * Background = new SolidColorBrush(Colors.White), * Camera = * new PerspectiveCamera * { * Position = new Point3D(0, 0, 0), * NearPlaneDistance = 0.1, * FarPlaneDistance = double.PositiveInfinity, * LookDirection = new Vector3D(-3, -3, -5), * UpDirection = new Vector3D(0, 1, 0) * }, * RenderTechnique = Techniques.RenderBlinn, * MaximumFieldOfView = 45, * MinimumFieldOfView = 20 * * } * }; */ // ViewPort3D = _control.ViewPort3D; var mb = new MeshBuilder(); for (var i = 0; i < 1000; i++) { mb.AddBox(new Vector3(i + 15, i + 15, i + 15), 100, 100, 100, BoxFaces.All); } // _control.meshModel.Material = PhongMaterials.Orange; // _control.meshModel.Geometry = mb.ToMeshGeometry3D(); //_control.meshModel.Visibility = Visibility.Visible; var model = new MeshGeometryModel3D(); model.Geometry = mb.ToMeshGeometry3D(); model.Material = PhongMaterials.Orange; // {Geometry = mb.ToMeshGeometry3D(), Material = PhongMaterials.Orange, Visibility = Visibility.Visible}; _control.ViewPort3D.Items.Add(model); _control.ViewPort3D.Items.Add(new AmbientLight3D { Color = Color4.White }); // control.ViewPort3D.Items.Add(new DirectionalLight3D() { Color = Color4.White , Direction = new Vector3(0,0,1)}); // _control.ViewPort3D.ShowTriangleCountInfo = true; // _control.ViewPort3D.ShowFieldOfView = true; AddControlToNode(_control); AddInputPortToNode("Elements", typeof(object)); }
public MainViewModel() { // titles Title = "Simple Demo"; SubTitle = "WPF & SharpDX"; // camera setup Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0), FarPlaneDistance = 5000000 }; // Create a custom render techniques manager that // only supports Phong and Blinn RenderTechniquesManager = new CustomRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques["RenderCustom"]; EffectsManager = new CustomEffectsManager(RenderTechniquesManager); // setup lighting AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); DirectionalLightColor = Color.White; DirectionalLightDirection = new Vector3(-2, -5, -2); // floor plane grid Grid = LineBuilder.GenerateGrid(); GridColor = Color.Black; GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5); b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All); var meshGeometry = b1.ToMeshGeometry3D(); meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4())); Model = meshGeometry; // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); Lines = e1.ToLineGeometry3D(); // model transform Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0); Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0); Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0); // model materials RedMaterial = PhongMaterials.Red; GreenMaterial = PhongMaterials.Green; BlueMaterial = PhongMaterials.Blue; Points = new PointGeometry3D(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); Text = new BillboardText3D(); for (int x = -5; x <= 5; x++) { for (int y = -5; y <= 5; y++) { ptIdx.Add(ptPos.Count); ptPos.Add(new Vector3(x, -1, y)); Text.TextInfo.Add(new TextInfo(string.Format("{0}:{1}", x, y), new Vector3(x, -1, y))); } } Points.Positions = ptPos; Points.Indices = ptIdx; }
public MainViewModel() { // titles Title = "Watch3DxNode"; // SubTitle = "SharpDX"; // camera setup Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0), FarPlaneDistance = 5000000 }; // default render technique RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); // Init RedMaterial = PhongMaterials.Red; // Choose the device -> BestAdapter is chosen here. // var text = EffectsManager.Device.DebugName; // setup lighting AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); DirectionalLightColor = Color.White; DirectionalLightDirection = new Vector3(-2, -5, -2); var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5);// floor plane grid // Grid = LineBuilder.GenerateGrid(); b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All);// GridColor = Color.Black; // GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5); var meshGeometry = b1.ToMeshGeometry3D();// meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4()));// scene model3d Model = meshGeometry; // var b1 = new MeshBuilder(); // // b1.AddSphere(new Vector3(0, 0, 0), 0.5); // // b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All); // // var meshGeometry = b1.ToMeshGeometry3D(); // meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4())); // Model = meshGeometry; // // lines model3d // var e1 = new LineBuilder(); // e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); // Lines = e1.ToLineGeometry3D(); // // // model trafos // Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0); // Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0); // Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0); // // // model materials // GreenMaterial = PhongMaterials.Green; // BlueMaterial = PhongMaterials.Blue; // // // var mat = new PhongMaterial(); // // mat.AmbientColor = new Color4(new Color3()); // // //var diffColor = this.RedMaterial.DiffuseColor; // //diffColor.Alpha = 0.5f; // //this.RedMaterial.DiffuseColor = diffColor; // // Points = new PointGeometry3D(); // var ptPos = new Vector3Collection(); // var ptIdx = new IntCollection(); // // for (int x = 0; x < 100; x++) // { // for (int y = 0; y < 100; y++) // { // for (int z = 0; z < 100; z++) // { // ptIdx.Add(ptPos.Count); // ptPos.Add(new Vector3(x, y, z)); // } // } // } // // Points.Positions = ptPos; // Points.Indices = ptIdx; // // Text = new BillboardText3D(); // // for (var i = 0; i < 50; i++) // { // for (var j = 0; j < 50; j++) // { // Text.TextInfo.Add(new TextInfo("Hello World", new Vector3(i,j,0))); // } // } }
/// <summary> /// Constructor of the MainViewModel /// </summary> public MainViewModel() { // titles this.Title = "Deferred Shading Demo"; this.SubTitle = "WPF & SharpDX"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(18, 64, 30), LookDirection = new Vector3D(-18, -64, -30), UpDirection = new Vector3D(0, 1, 0) }; // deferred render technique RenderTechniquesManager = new DeferredTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DeferredRenderTechniqueNames.Deferred]; EffectsManager = new DeferredEffectsManager(RenderTechniquesManager); SupportDeferredRender = true; //load model var reader = new ObjReader(); var objModel = reader.Read(@"./Media/bunny.obj"); this.Model = objModel[0].Geometry as MeshGeometry3D; var scale = 2.0; // model trafos var transf1 = new Transform3DGroup(); transf1.Children.Add(new ScaleTransform3D(scale, scale, scale)); transf1.Children.Add(new RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 1, 0), 40), 0.0, 0.0, 0.0)); transf1.Children.Add(new TranslateTransform3D(0, -2, 3)); this.Model1Transform = transf1; var transf2 = new Transform3DGroup(); transf2.Children.Add(new ScaleTransform3D(scale, scale, scale)); transf2.Children.Add(new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 1, 0), 66), 0.0, 0.0, 0.0)); transf2.Children.Add(new Media3D.TranslateTransform3D(-3.0, -2, -2.5)); this.Model2Transform = transf2; var transf3 = new Transform3DGroup(); transf3.Children.Add(new ScaleTransform3D(scale, scale, scale)); transf3.Children.Add(new TranslateTransform3D(+3.5, -2, -1.0)); this.Model3Transform = transf3; // floor plane var meshBuilder = new MeshBuilder(); meshBuilder.AddBox(new Vector3(0, 0, 0), 100, 0.0, 100, BoxFaces.PositiveY); this.Plane = meshBuilder.ToMeshGeometry3D(); this.PlaneTransform = new TranslateTransform3D(0, -1.05, 0); // model materials this.RedMaterial = PhongMaterials.Red; this.GreenMaterial = PhongMaterials.Green; this.BlueMaterial = PhongMaterials.Blue; this.PlaneMaterial = PhongMaterials.DefaultVRML; this.PlaneMaterial.DiffuseMap = new BitmapImage(new System.Uri(@"./Media/TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute)); this.PlaneMaterial.NormalMap = new BitmapImage(new System.Uri(@"./Media/TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute)); // setup lighting this.AmbientLightColor = new Color4(0.3f, 0.3f, 0.3f, 1.0f); this.DirectionalLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f); this.DirectionalLightDirection = new Vector3(-2, -5, -2); this.PointLightColor = (Color4)Color.White; this.PointLightAttenuation = new Vector3(0.0f, 0.0f, 0.18f); //1/0/0 ; 0.1, 0.2, 0.3 this.PointLightTransform1 = new TranslateTransform3D(new Vector3D(0, 1, 0)); this.PointLightTransform2 = new TranslateTransform3D(new Vector3D(6, 1, 3)); this.PointLightTransform3 = new TranslateTransform3D(new Vector3D(-3, 1, -6)); this.SpotLightColor = (Color4)Color.AntiqueWhite; this.SpotLightAttenuation = new Vector3(1.0f, 0.1f, 0.01f); // light collection this.PointLightCollection = new Element3DCollection(); this.PointLightCount = 7; this.PointLightSpread = 100; // spotlight collection this.SpotLightCollection = new Element3DCollection(); this.SpotLightCount = 7; this.SpotLightSpread = 100; }
private static MeshGeometry3D DrawTestMesh() { var b1 = new MeshBuilder(); for (var x = 0; x < 4; x++) { for (var y = 0; y < 4; y++) { for (var z = 0; z < 4; z++) { b1.AddBox(new Vector3(x, y, z), 0.5, 0.5, 0.5, BoxFaces.All); } } } var mesh = b1.ToMeshGeometry3D(); mesh.Colors = new Color4Collection(); foreach (var v in mesh.Positions) { mesh.Colors.Add(new Color4(1f,0f,0f,1f)); } return mesh; }
public MainViewModel() { // titles this.Title = "Simple Demo"; this.SubTitle = "WPF & SharpDX"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0), FarPlaneDistance = 5000000 }; // default render technique this.RenderTechnique = Techniques.RenderBlinn; // setup lighting this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f); this.DirectionalLightColor = Color.White; this.DirectionalLightDirection = new Vector3(-2, -5, -2); // floor plane grid this.Grid = LineBuilder.GenerateGrid(); this.GridColor = SharpDX.Color.Black; this.GridTransform = new Media3D.TranslateTransform3D(-5, -1, -5); // scene model3d var b1 = new MeshBuilder(); b1.AddSphere(new Vector3(0, 0, 0), 0.5); b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2, BoxFaces.All); var meshGeometry = b1.ToMeshGeometry3D(); meshGeometry.Colors = new Color4Collection(meshGeometry.TextureCoordinates.Select(x => x.ToColor4())); this.Model = meshGeometry; // lines model3d var e1 = new LineBuilder(); e1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 2); this.Lines = e1.ToLineGeometry3D(); // model trafos this.Model1Transform = new Media3D.TranslateTransform3D(0, 0, 0); this.Model2Transform = new Media3D.TranslateTransform3D(-2, 0, 0); this.Model3Transform = new Media3D.TranslateTransform3D(+2, 0, 0); // model materials this.RedMaterial = PhongMaterials.Red; this.GreenMaterial = PhongMaterials.Green; this.BlueMaterial = PhongMaterials.Blue; //var diffColor = this.RedMaterial.DiffuseColor; //diffColor.Alpha = 0.5f; //this.RedMaterial.DiffuseColor = diffColor; Points = new PointGeometry3D(); var ptPos = new Vector3Collection(); var ptIdx = new IntCollection(); for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { for (int z = 0; z < 10; z++) { ptIdx.Add(ptPos.Count); ptPos.Add(new Vector3(x, y, z)); } } } Points.Positions = ptPos; Points.Indices = ptIdx; Text = new BillboardText3D(); for (var i = 0; i < 50; i++) { for (var j = 0; j < 50; j++) { Text.TextInfo.Add(new TextInfo("Hello World", new Vector3(i,j,0))); } } }
public Watch3DNodeDx(Core.VplControl hostCanvas) : base(hostCanvas) { // Add Control s _control = new Watch3DxControl(); AddControlToNode(_control); // Set Node resizable ... IsResizeable = true; // Add Control s _control = new Watch3DxControl(); /* { ViewPort3D = { Background = new SolidColorBrush(Colors.White), Camera = new PerspectiveCamera { Position = new Point3D(0, 0, 0), NearPlaneDistance = 0.1, FarPlaneDistance = double.PositiveInfinity, LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) }, RenderTechnique = Techniques.RenderBlinn, MaximumFieldOfView = 45, MinimumFieldOfView = 20 } }; */ // ViewPort3D = _control.ViewPort3D; var mb = new MeshBuilder(); for (var i = 0; i < 1000; i++) { mb.AddBox(new Vector3(i + 15, i + 15, i + 15), 100, 100, 100, BoxFaces.All); } // _control.meshModel.Material = PhongMaterials.Orange; // _control.meshModel.Geometry = mb.ToMeshGeometry3D(); //_control.meshModel.Visibility = Visibility.Visible; var model = new MeshGeometryModel3D(); model.Geometry = mb.ToMeshGeometry3D(); model.Material = PhongMaterials.Orange; // {Geometry = mb.ToMeshGeometry3D(), Material = PhongMaterials.Orange, Visibility = Visibility.Visible}; _control.ViewPort3D.Items.Add(model); _control.ViewPort3D.Items.Add(new AmbientLight3D {Color = Color4.White}); // control.ViewPort3D.Items.Add(new DirectionalLight3D() { Color = Color4.White , Direction = new Vector3(0,0,1)}); // _control.ViewPort3D.ShowTriangleCountInfo = true; // _control.ViewPort3D.ShowFieldOfView = true; AddControlToNode(_control); AddInputPortToNode("Elements", typeof (object)); }
/// <summary> /// 連續點擊兩下產生出球 /// </summary> public void OnMouseDoubleClickHandler(object sender, System.Windows.Input.MouseButtonEventArgs e) { //如果當前可點擊的狀態為否則直接return if (!MainViewModel.ProjData.CanSelectPoints) { return; } Viewport3DX viewport = sender as Viewport3DX; if (viewport == null) { return; } var point = e.GetPosition(viewport); var hitTests = viewport.FindHits(point); //null或是點到的東西為少於零個 if (hitTests == null || hitTests.Count <= 0) { return; } foreach (var hit in hitTests) { //有可能點到對稱面,不是BoneModel的話換下一個模型 if (!(hit.ModelHit is BoneModel)) { continue; } BallModel ball = new BallModel { BallName = "Ball", }; //這邊很怪 拿不到該有的屬性資訊只有一些基底類別的資訊 BoneModel model = hit.ModelHit as BoneModel; foreach (BoneModel modeltem in MainViewModel.ProjData.BoneCollection) { //先找出當前點到的BoneModel是哪個,並將點擊的球的ModelType設定成跟該Model一樣 if (modeltem.Geometry.Positions.Count == model.Geometry.Positions.Count) { ball.ModelType = modeltem.ModelType; Binding binding = new Binding("Transform"); binding.Source = modeltem; binding.Mode = BindingMode.OneWay; BindingOperations.SetBinding(ball, HelixToolkit.Wpf.SharpDX.Model3D.TransformProperty, binding); } } var ballContainer = new HelixToolkit.Wpf.SharpDX.MeshBuilder(); ball.BallCenter = new Vector3(Convert.ToSingle(hit.PointHit.X), Convert.ToSingle(hit.PointHit.Y), Convert.ToSingle(hit.PointHit.Z)); ballContainer.AddSphere(ball.BallCenter, 1.5); ball.Geometry = ballContainer.ToMeshGeometry3D(); ball.Material = PhongMaterials.White; MainViewModel.ProjData.BallCollection.Add(ball); break; } }